• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "usb_device_lite_cdcacm_test.h"
10 
11 #define HDF_LOG_TAG usb_device_sdk_test
12 
ReadComplete(uint8_t pipe,struct UsbFnRequest * req)13 static void ReadComplete(uint8_t pipe, struct UsbFnRequest *req)
14 {
15     struct AcmDevice *acmDevice = UsbGetAcmDevice();
16     if ((req == NULL) || (acmDevice == NULL)) {
17         return;
18     }
19     if (req->actual) {
20         uint8_t *data = (uint8_t *)req->buf;
21         data[req->actual] = '\0';
22         dprintf("receive [%d] bytes data: %s\n", req->actual, data);
23         if (strcmp((const char *)data, "q") == 0 || strcmp((const char *)data, "q\n") == 0) {
24             acmDevice->submitExit = 1;
25         }
26     }
27     acmDevice->submit = 1;
28 }
29 
UsbFnDviceTestRequestAsync(void)30 int32_t UsbFnDviceTestRequestAsync(void)
31 {
32     struct UsbFnRequest *req = NULL;
33     int32_t ret;
34 
35     ret = UsbFnSubmitRequestAsync(req);
36     if (HDF_SUCCESS == ret) {
37         HDF_LOGE("%s: async Request success!!", __func__);
38         return HDF_FAILURE;
39     }
40     return HDF_SUCCESS;
41 }
42 
UsbFnDviceTestRequestAsync002(void)43 int32_t UsbFnDviceTestRequestAsync002(void)
44 {
45     struct UsbFnRequest *req = NULL;
46     int32_t ret = HDF_SUCCESS;
47     int32_t ret1;
48     struct AcmDevice *acmDevice = UsbGetAcmDevice();
49     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
50         HDF_LOGE("%s: dataIface.fn is invail", __func__);
51         return HDF_FAILURE;
52     }
53     dprintf("wait receiving data form host, please connect\n");
54     req =
55         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
56     if (req == NULL) {
57         HDF_LOGE("%s: alloc req fail", __func__);
58         return HDF_FAILURE;
59     }
60     req->complete = ReadComplete;
61     req->context = acmDevice;
62     while (acmDevice->connect == false) {
63         OsalMSleep(WAIT_100MS);
64     }
65     while (1) {
66         acmDevice->submit = 0;
67         ret = UsbFnSubmitRequestAsync(req);
68         if (HDF_SUCCESS != ret) {
69             HDF_LOGE("%s: async Request error", __func__);
70             ret = HDF_FAILURE;
71             break;
72         }
73         while (acmDevice->submit == 0) {
74             OsalMSleep(WAIT_100MS);
75         }
76         if (req->actual > 0) {
77             break;
78         }
79     }
80     ret1 = UsbFnFreeRequest(req);
81     if (HDF_SUCCESS != ret1) {
82         HDF_LOGE("%s: free Request error", __func__);
83         return HDF_FAILURE;
84     }
85     return ret;
86 }
87 
UsbFnDviceTestRequestAsync003(void)88 int32_t UsbFnDviceTestRequestAsync003(void)
89 {
90     struct UsbFnRequest *req = NULL;
91     int32_t ret = HDF_SUCCESS;
92     int32_t ret1;
93     struct AcmDevice *acmDevice = UsbGetAcmDevice();
94     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
95         HDF_LOGE("%s: dataIface.fn is invail", __func__);
96         return HDF_FAILURE;
97     }
98     dprintf("wait receiving data form host, please connect\n");
99     req =
100         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
101     if (req == NULL) {
102         HDF_LOGE("%s: alloc req fail", __func__);
103         return HDF_FAILURE;
104     }
105     req->complete = ReadComplete;
106     req->context = acmDevice;
107     while (acmDevice->connect == false) {
108         OsalMSleep(WAIT_100MS);
109     }
110     acmDevice->submitExit = 0;
111     while (acmDevice->submitExit == 0) {
112         acmDevice->submit = 0;
113         ret = UsbFnSubmitRequestAsync(req);
114         if (HDF_SUCCESS != ret) {
115             HDF_LOGE("%s: async Request error", __func__);
116             ret = HDF_FAILURE;
117             break;
118         }
119         while (acmDevice->submit == 0) {
120             OsalMSleep(WAIT_100MS);
121         }
122     }
123     ret1 = UsbFnFreeRequest(req);
124     if (HDF_SUCCESS != ret1) {
125         HDF_LOGE("%s: free Request error", __func__);
126         return HDF_FAILURE;
127     }
128     return ret;
129 }
130 
WriteComplete(uint8_t pipe,struct UsbFnRequest * req)131 static void WriteComplete(uint8_t pipe, struct UsbFnRequest *req)
132 {
133     struct AcmDevice *acmDevice = UsbGetAcmDevice();
134     if (acmDevice == NULL) {
135         return;
136     }
137     dprintf("write data status = %d\n", req->status);
138     acmDevice->submit = 1;
139 }
140 
UsbFnDviceTestRequestAsync004(void)141 int32_t UsbFnDviceTestRequestAsync004(void)
142 {
143     struct UsbFnRequest *req = NULL;
144     int32_t ret;
145     struct AcmDevice *acmDevice = UsbGetAcmDevice();
146 
147     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
148         HDF_LOGE("%s: dataIface.fn is invail", __func__);
149         return HDF_FAILURE;
150     }
151     req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
152     if (req == NULL) {
153         HDF_LOGE("%s: alloc req fail", __func__);
154         return HDF_FAILURE;
155     }
156     req->complete = WriteComplete;
157     req->context = acmDevice;
158     acmDevice->submit = 0;
159     dprintf("------send \"abc\" to host------\n");
160     if (acmDevice->dataInPipe.maxPacketSize < strlen("abc")) {
161         ret = UsbFnFreeRequest(req);
162         if (HDF_SUCCESS != ret) {
163             HDF_LOGE("%s: free Request error", __func__);
164         }
165         return HDF_FAILURE;
166     }
167     if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")) != EOK) {
168         HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
169     }
170     req->length = strlen("abc");
171     ret = UsbFnSubmitRequestAsync(req);
172     if (HDF_SUCCESS != ret) {
173         HDF_LOGE("%s: async Request error", __func__);
174         return HDF_FAILURE;
175     }
176     while (acmDevice->submit == 0) {
177         OsalMSleep(1);
178     }
179     acmDevice->submit = 0;
180     ret = UsbFnFreeRequest(req);
181     if (HDF_SUCCESS != ret) {
182         HDF_LOGE("%s: free Request error", __func__);
183         return HDF_FAILURE;
184     }
185     return HDF_SUCCESS;
186 }
187 
UsbFnDviceTestRequestAsync005(void)188 int32_t UsbFnDviceTestRequestAsync005(void)
189 {
190     struct UsbFnRequest *req = NULL;
191     int32_t loopTime = TEST_TIMES;
192     struct AcmDevice *acmDevice = UsbGetAcmDevice();
193 
194     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
195         HDF_LOGE("%s: dataIface.fn is invail", __func__);
196         return HDF_FAILURE;
197     }
198     dprintf("------send \"xyz\" 10 times to host------\n");
199     while (loopTime--) {
200         req = UsbFnAllocRequest(
201             acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
202         if (req == NULL) {
203             HDF_LOGE("%s: alloc req fail", __func__);
204             return HDF_FAILURE;
205         }
206         req->complete = WriteComplete;
207         req->context = acmDevice;
208         acmDevice->submit = 0;
209         if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "xyz", strlen("xyz")) != EOK) {
210             HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
211         }
212         req->length = strlen("xyz");
213         int32_t ret = UsbFnSubmitRequestAsync(req);
214         if (ret != HDF_SUCCESS) {
215             HDF_LOGE("%s: async Request error", __func__);
216             return HDF_FAILURE;
217         }
218         while (acmDevice->submit == 0) {
219             OsalMSleep(1);
220         }
221         acmDevice->submit = 0;
222         ret = UsbFnFreeRequest(req);
223         if (ret != HDF_SUCCESS) {
224             HDF_LOGE("%s: free Request error", __func__);
225             return HDF_FAILURE;
226         }
227     }
228     return HDF_SUCCESS;
229 }
230 
UsbFnDviceTestRequestAsync006(void)231 int32_t UsbFnDviceTestRequestAsync006(void)
232 {
233     return HDF_SUCCESS;
234 }
235 
UsbFnDviceTestRequestSync(void)236 int32_t UsbFnDviceTestRequestSync(void)
237 {
238     struct UsbFnRequest *req = NULL;
239     int32_t ret;
240     ret = UsbFnSubmitRequestSync(req, 0);
241     if (HDF_SUCCESS == ret) {
242         HDF_LOGE("%s: sync Request success!!", __func__);
243         return HDF_FAILURE;
244     }
245     return HDF_SUCCESS;
246 }
247 
UsbFnDviceTestRequestSync002(void)248 int32_t UsbFnDviceTestRequestSync002(void)
249 {
250     struct UsbFnRequest *req = NULL;
251     int32_t ret;
252     uint8_t *data = NULL;
253     struct AcmDevice *acmDevice = UsbGetAcmDevice();
254     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
255         HDF_LOGE("%s: dataIface.fn is invail", __func__);
256         return HDF_FAILURE;
257     }
258     dprintf("wait receiving data form host\n");
259     req =
260         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
261     if (req == NULL) {
262         HDF_LOGE("%s: alloc req fail", __func__);
263         return HDF_FAILURE;
264     }
265     ret = UsbFnSubmitRequestSync(req, 0);
266     if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) {
267         HDF_LOGE("%s: Sync Request error", __func__);
268         return HDF_FAILURE;
269     }
270     data = (uint8_t *)req->buf;
271     data[req->actual] = '\0';
272     dprintf("receive data from host: %s\n", data);
273     ret = UsbFnFreeRequest(req);
274     if (HDF_SUCCESS != ret) {
275         HDF_LOGE("%s: free Request error", __func__);
276         return HDF_FAILURE;
277     }
278     return HDF_SUCCESS;
279 }
280 
UsbFnDviceTestRequestSync003(void)281 int32_t UsbFnDviceTestRequestSync003(void)
282 {
283     struct UsbFnRequest *req = NULL;
284     int32_t ret;
285     int32_t submitExit = 0;
286     uint8_t *data = NULL;
287     struct AcmDevice *acmDevice = UsbGetAcmDevice();
288     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
289         HDF_LOGE("%s: dataIface.fn is invail", __func__);
290         return HDF_FAILURE;
291     }
292     dprintf("receive data until 'q' exit\n");
293     req =
294         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
295     if (req == NULL) {
296         HDF_LOGE("%s: alloc req fail", __func__);
297         return HDF_FAILURE;
298     }
299     while (submitExit == 0) {
300         ret = UsbFnSubmitRequestSync(req, 0);
301         if (ret != 0 || req->actual <= 0 || req->status != USB_REQUEST_COMPLETED) {
302             HDF_LOGE("%s: Sync Request error", __func__);
303             break;
304         }
305         data = (uint8_t *)req->buf;
306         data[req->actual] = '\0';
307         if (strcmp((const char *)data, "q") == 0 || strcmp((const char *)data, "q\n") == 0) {
308             submitExit = 1;
309         }
310         dprintf("receive data from host: %s\n", data);
311     }
312     ret = UsbFnFreeRequest(req);
313     if (HDF_SUCCESS != ret) {
314         HDF_LOGE("%s: free Request error", __func__);
315         return HDF_FAILURE;
316     }
317     return HDF_SUCCESS;
318 }
319 
UsbFnDviceTestRequestSync004(void)320 int32_t UsbFnDviceTestRequestSync004(void)
321 {
322     struct UsbFnRequest *req = NULL;
323     int32_t ret;
324     struct AcmDevice *acmDevice = UsbGetAcmDevice();
325 
326     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
327         HDF_LOGE("%s: dataIface.fn is invail", __func__);
328         return HDF_FAILURE;
329     }
330     req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
331     if (req == NULL) {
332         HDF_LOGE("%s: alloc req fail", __func__);
333         return HDF_FAILURE;
334     }
335     dprintf("------send \"abc\" to host------\n");
336     if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")) != EOK) {
337         HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
338     }
339     req->length = strlen("abc");
340     ret = UsbFnSubmitRequestSync(req, 0);
341     if (HDF_SUCCESS != ret || (req->actual != strlen("abc")) || (req->status != USB_REQUEST_COMPLETED)) {
342         HDF_LOGE("%s: async Request error", __func__);
343         return HDF_FAILURE;
344     }
345     ret = UsbFnFreeRequest(req);
346     if (HDF_SUCCESS != ret) {
347         HDF_LOGE("%s: free Request error", __func__);
348         return HDF_FAILURE;
349     }
350     return HDF_SUCCESS;
351 }
352 
UsbFnDviceTestRequestSync005(void)353 int32_t UsbFnDviceTestRequestSync005(void)
354 {
355     struct UsbFnRequest *req = NULL;
356     int32_t loopTime = TEST_TIMES;
357     struct AcmDevice *acmDevice = UsbGetAcmDevice();
358 
359     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
360         HDF_LOGE("%s: dataIface.fn is invail", __func__);
361         return HDF_FAILURE;
362     }
363     dprintf("------send \"abcdefg\" 10 times to host------\n");
364     while (loopTime--) {
365         req = UsbFnAllocRequest(
366             acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
367         if (req == NULL) {
368             HDF_LOGE("%s: alloc req fail", __func__);
369             return HDF_FAILURE;
370         }
371         if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abcdefg", strlen("abcdefg")) != EOK) {
372             HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
373         }
374         req->length = strlen("abcdefg");
375         int32_t ret = UsbFnSubmitRequestSync(req, 0);
376         if (ret != HDF_SUCCESS || (req->actual != strlen("abcdefg")) || (req->status != USB_REQUEST_COMPLETED)) {
377             HDF_LOGE("%s: async Request error", __func__);
378             return HDF_FAILURE;
379         }
380         ret = UsbFnFreeRequest(req);
381         if (ret != HDF_SUCCESS) {
382             HDF_LOGE("%s: free Request error", __func__);
383             return HDF_FAILURE;
384         }
385     }
386     return HDF_SUCCESS;
387 }
388 
UsbFnDviceTestRequestSync006(void)389 int32_t UsbFnDviceTestRequestSync006(void)
390 {
391     struct UsbFnRequest *req = NULL;
392     int32_t ret;
393     struct AcmDevice *acmDevice = UsbGetAcmDevice();
394     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
395         HDF_LOGE("%s: dataIface.fn is invail", __func__);
396         return HDF_FAILURE;
397     }
398     dprintf("test sync timeout 5s:\n");
399     req =
400         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
401     if (req == NULL) {
402         HDF_LOGE("%s: alloc req fail", __func__);
403         return HDF_FAILURE;
404     }
405     ret = UsbFnSubmitRequestSync(req, SYNC_5000MS);
406     if (ret == 0) {
407         HDF_LOGE("%s: Sync Request success", __func__);
408         return HDF_FAILURE;
409     }
410     ret = UsbFnFreeRequest(req);
411     if (HDF_SUCCESS != ret) {
412         HDF_LOGE("%s: free Request error", __func__);
413         return HDF_FAILURE;
414     }
415     return HDF_SUCCESS;
416 }
417 
UsbFnDviceTestRequestSync007(void)418 int32_t UsbFnDviceTestRequestSync007(void)
419 {
420     struct UsbFnRequest *req = NULL;
421     int32_t ret;
422 
423     ret = UsbFnSubmitRequestSync(req, SYNC_5000MS);
424     if (ret == 0) {
425         HDF_LOGE("%s: Sync Request error", __func__);
426         return HDF_FAILURE;
427     }
428     return HDF_SUCCESS;
429 }
430 
TestCancelComplete(uint8_t pipe,struct UsbFnRequest * req)431 static void TestCancelComplete(uint8_t pipe, struct UsbFnRequest *req)
432 {
433     (void)req;
434     struct AcmDevice *acmDevice = UsbGetAcmDevice();
435     if (acmDevice == NULL) {
436         return;
437     }
438 
439     acmDevice->havedSubmit = true;
440 }
441 
UsbFnDviceTestCancelRequest(void)442 int32_t UsbFnDviceTestCancelRequest(void)
443 {
444     int32_t ret;
445     struct UsbFnRequest *notifyReq = NULL;
446     ret = UsbFnCancelRequest(notifyReq);
447     if (HDF_SUCCESS == ret) {
448         HDF_LOGE("%s: cancel request success!!", __func__);
449         return HDF_FAILURE;
450     }
451     return HDF_SUCCESS;
452 }
453 
UsbFnDviceTestCancelRequest002(void)454 int32_t UsbFnDviceTestCancelRequest002(void)
455 {
456     int32_t ret;
457     struct UsbFnRequest *req = NULL;
458     struct AcmDevice *acmDevice = UsbGetAcmDevice();
459 
460     if (acmDevice == NULL || acmDevice->ctrlIface.handle == NULL) {
461         HDF_LOGE("%s: CtrlIface.handle is invail", __func__);
462         return HDF_FAILURE;
463     }
464     req = UsbFnAllocCtrlRequest(acmDevice->ctrlIface.handle, sizeof(struct UsbCdcNotification));
465     if (req == NULL) {
466         HDF_LOGE("%s: alloc req fail", __func__);
467         return HDF_FAILURE;
468     }
469     ret = UsbFnCancelRequest(req);
470     if (HDF_SUCCESS == ret) {
471         HDF_LOGE("%s: cancel request success", __func__);
472         ret = UsbFnFreeRequest(req);
473         if (HDF_SUCCESS != ret) {
474             HDF_LOGE("%s: free Request error", __func__);
475             return HDF_FAILURE;
476         }
477         return HDF_FAILURE;
478     }
479     ret = UsbFnFreeRequest(req);
480     if (HDF_SUCCESS != ret) {
481         HDF_LOGE("%s: free Request error", __func__);
482         return HDF_FAILURE;
483     }
484     return HDF_SUCCESS;
485 }
486 
UsbFnDviceTestCancelRequest003(void)487 int32_t UsbFnDviceTestCancelRequest003(void)
488 {
489     int32_t ret;
490     struct UsbFnRequest *req = NULL;
491     struct AcmDevice *acmDevice = UsbGetAcmDevice();
492 
493     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
494         HDF_LOGE("%s: dataIface.handle is invail", __func__);
495         return HDF_FAILURE;
496     }
497     req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
498     if (req == NULL) {
499         HDF_LOGE("%s: alloc req fail", __func__);
500         return HDF_FAILURE;
501     }
502     ret = UsbFnCancelRequest(req);
503     if (HDF_SUCCESS == ret) {
504         dprintf("%s: cancel request success\n", __func__);
505         ret = UsbFnFreeRequest(req);
506         if (HDF_SUCCESS != ret) {
507             dprintf("%s: free Request error", __func__);
508             return HDF_FAILURE;
509         }
510         return HDF_FAILURE;
511     }
512     ret = UsbFnFreeRequest(req);
513     if (HDF_SUCCESS != ret) {
514         HDF_LOGE("%s: free Request error", __func__);
515         return HDF_FAILURE;
516     }
517     return HDF_SUCCESS;
518 }
519 
UsbFnDviceTestCancelRequest004(void)520 int32_t UsbFnDviceTestCancelRequest004(void)
521 {
522     int32_t ret;
523     struct UsbFnRequest *req = NULL;
524     struct AcmDevice *acmDevice = UsbGetAcmDevice();
525 
526     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
527         HDF_LOGE("%s: dataIface.handle is invail", __func__);
528         return HDF_FAILURE;
529     }
530     req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
531     if (req == NULL) {
532         HDF_LOGE("%s: alloc req fail", __func__);
533         return HDF_FAILURE;
534     }
535     ret = UsbFnCancelRequest(req);
536     if (HDF_SUCCESS == ret) {
537         dprintf("%s: cancel request success\n", __func__);
538         ret = UsbFnFreeRequest(req);
539         if (HDF_SUCCESS != ret) {
540             dprintf("%s: free Request error", __func__);
541             return HDF_FAILURE;
542         }
543         return HDF_FAILURE;
544     }
545     ret = UsbFnFreeRequest(req);
546     if (HDF_SUCCESS != ret) {
547         HDF_LOGE("%s: free Request error", __func__);
548         return HDF_FAILURE;
549     }
550     return HDF_SUCCESS;
551 }
552 
UsbFnDviceTestCancelRequest005(void)553 int32_t UsbFnDviceTestCancelRequest005(void)
554 {
555     int32_t ret;
556     struct UsbFnRequest *req = NULL;
557     struct AcmDevice *acmDevice = UsbGetAcmDevice();
558 
559     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
560         HDF_LOGE("%s: dataIface.handle is invail", __func__);
561         return HDF_FAILURE;
562     }
563     req = UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataInPipe.id, acmDevice->dataInPipe.maxPacketSize);
564     if (req == NULL) {
565         HDF_LOGE("%s: alloc req fail", __func__);
566         return HDF_FAILURE;
567     }
568     acmDevice->havedSubmit = false;
569     req->complete = TestCancelComplete;
570     req->context = acmDevice;
571     dprintf("------send \"abc\" to host------\n");
572     if (memcpy_s(req->buf, acmDevice->dataInPipe.maxPacketSize, "abc", strlen("abc")) != EOK) {
573         HDF_LOGE("%s:%d memcpy_s fail", __func__, __LINE__);
574     }
575     req->length = strlen("abc");
576     ret = UsbFnSubmitRequestAsync(req);
577     if (HDF_SUCCESS != ret) {
578         HDF_LOGE("%s: request async error", __func__);
579         return HDF_FAILURE;
580     }
581     while (acmDevice->havedSubmit == 0) {
582         OsalMSleep(1);
583     }
584     ret = UsbFnCancelRequest(req);
585     if (HDF_SUCCESS == ret) {
586         dprintf("%s: cancel request error", __func__);
587         return HDF_FAILURE;
588     }
589     acmDevice->havedSubmit = false;
590     ret = UsbFnFreeRequest(req);
591     if (HDF_SUCCESS != ret) {
592         HDF_LOGE("%s: free Request error", __func__);
593         return HDF_FAILURE;
594     }
595     return HDF_SUCCESS;
596 }
597 
TestCancelRequest(struct UsbFnRequest * req,struct UsbFnRequest * req2)598 int32_t TestCancelRequest(struct UsbFnRequest *req, struct UsbFnRequest *req2)
599 {
600     int32_t ret;
601     ret = UsbFnSubmitRequestAsync(req2);
602     if (HDF_SUCCESS != ret) {
603         HDF_LOGE("%s: request async error", __func__);
604         return HDF_FAILURE;
605     }
606     ret = UsbFnCancelRequest(req2);
607     if (HDF_SUCCESS != ret) {
608         dprintf("%s: cancel request error", __func__);
609         return HDF_FAILURE;
610     }
611     ret = UsbFnCancelRequest(req);
612     if (HDF_SUCCESS != ret) {
613         dprintf("%s: cancel request error", __func__);
614         return HDF_FAILURE;
615     }
616     ret = UsbFnFreeRequest(req);
617     if (HDF_SUCCESS != ret) {
618         dprintf("%s: free Request error", __func__);
619         return HDF_FAILURE;
620     }
621     ret = UsbFnFreeRequest(req2);
622     if (HDF_SUCCESS != ret) {
623         dprintf("%s: free Request error", __func__);
624         return HDF_FAILURE;
625     }
626     return HDF_SUCCESS;
627 }
628 
UsbFnDviceTestCancelRequest006(void)629 int32_t UsbFnDviceTestCancelRequest006(void)
630 {
631     int32_t ret;
632     struct UsbFnRequest *req = NULL;
633     struct UsbFnRequest *req2 = NULL;
634     struct AcmDevice *acmDevice = UsbGetAcmDevice();
635 
636     if (acmDevice == NULL || acmDevice->dataIface.handle == NULL) {
637         HDF_LOGE("%s: dataIface.handle is invail", __func__);
638         return HDF_FAILURE;
639     }
640     req =
641         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
642     if (req == NULL) {
643         HDF_LOGE("%s: alloc req fail", __func__);
644         return HDF_FAILURE;
645     }
646     acmDevice->havedSubmit = false;
647     req->complete = TestCancelComplete;
648     req->context = acmDevice;
649 
650     req2 =
651         UsbFnAllocRequest(acmDevice->dataIface.handle, acmDevice->dataOutPipe.id, acmDevice->dataOutPipe.maxPacketSize);
652     if (req2 == NULL) {
653         HDF_LOGE("%s: alloc req fail", __func__);
654         return HDF_FAILURE;
655     }
656     acmDevice->submit = false;
657     req2->complete = ReadComplete;
658     req2->context = acmDevice;
659     ret = UsbFnSubmitRequestAsync(req);
660     if (HDF_SUCCESS != ret) {
661         HDF_LOGE("%s: request async error", __func__);
662         return HDF_FAILURE;
663     }
664     return TestCancelRequest(req, req2);
665 }
666