1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdio>
17 #include <cstring>
18 #include <gtest/gtest.h>
19 #include <unistd.h>
20 extern "C" {
21 #include "hdf_base.h"
22 #include "hdf_log.h"
23 #include "hdf_usb_pnp_manage.h"
24 #include "osal_mem.h"
25 #include "osal_time.h"
26 #include "securec.h"
27 #include "usb_raw_sdk_if_test.h"
28 }
29
30 using namespace std;
31 using namespace testing::ext;
32
33 namespace {
34 class UsbRawSdkIfTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 };
39
40 #define USB_RAW_IO_SLEEP_MS_TIME 500
41 #define USB_IO_THREAD_STACK_SIZE 8192
42
43 static struct UsbSession *g_session = nullptr;
44 static struct AcmDevice *g_acm = nullptr;
45 static struct AcmDevice g_deviceService;
46 static UsbRawHandle *g_devHandle = nullptr;
47 static UsbRawDevice *g_dev = nullptr;
48 static int32_t g_activeConfig;
49 static bool g_stopIoThreadFlag = false;
50
UsbIoThread(void * data)51 static int32_t UsbIoThread(void *data)
52 {
53 int32_t ret;
54 struct AcmDevice *acm = (struct AcmDevice *)data;
55
56 for (;;) {
57 if (acm == nullptr) {
58 printf("%s:%d acm is nullptr\n", __func__, __LINE__);
59 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
60 continue;
61 }
62
63 if (acm->devHandle == nullptr) {
64 printf("%s:%d acm->devHandle is nullptr!\n", __func__, __LINE__);
65 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
66 continue;
67 }
68
69 ret = UsbRawHandleRequests(acm->devHandle);
70 if (ret < 0) {
71 printf("%s:%d UsbRawHandleRequests failed, ret = %d \n", __func__, __LINE__, ret);
72 if (ret == HDF_DEV_ERR_NO_DEVICE) {
73 printf("%s:%d, ret = %d\n", __func__, __LINE__, ret);
74 OsalMSleep(USB_RAW_IO_SLEEP_MS_TIME);
75 }
76 }
77
78 if (g_stopIoThreadFlag) {
79 printf("%s:%d\n", __func__, __LINE__);
80 g_stopIoThreadFlag = false;
81 break;
82 }
83 }
84
85 return HDF_SUCCESS;
86 }
87
UsbStartIo(struct AcmDevice * acm)88 static int32_t UsbStartIo(struct AcmDevice *acm)
89 {
90 struct OsalThreadParam threadCfg;
91 int32_t ret;
92
93 printf("%s start\n", __func__);
94
95 /* create Io thread */
96 (void)memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg));
97 threadCfg.name = (char *)("usb io thread");
98 threadCfg.priority = OSAL_THREAD_PRI_LOW;
99 threadCfg.stackSize = USB_IO_THREAD_STACK_SIZE;
100
101 ret = OsalThreadCreate(&acm->ioThread, (OsalThreadEntry)UsbIoThread, (void *)acm);
102 if (ret != HDF_SUCCESS) {
103 printf("%s:%d OsalThreadCreate failed, ret=%d \n", __func__, __LINE__, ret);
104 return ret;
105 }
106
107 ret = OsalThreadStart(&acm->ioThread, &threadCfg);
108 if (ret != HDF_SUCCESS) {
109 printf("%s:%d OsalThreadStart failed, ret=%d \n", __func__, __LINE__, ret);
110 return ret;
111 }
112
113 return HDF_SUCCESS;
114 }
115
UsbStopIo(struct AcmDevice * acm)116 static int32_t UsbStopIo(struct AcmDevice *acm)
117 {
118 int32_t ret;
119
120 HDF_LOGD("%{public}s:%{public}d", __func__, __LINE__);
121 if (!g_stopIoThreadFlag) {
122 HDF_LOGD("%{public}s:%{public}d", __func__, __LINE__);
123 g_stopIoThreadFlag = true;
124 }
125 ret = OsalThreadDestroy(&acm->ioThread);
126 if (ret != HDF_SUCCESS) {
127 HDF_LOGE("%{public}s:%{public}d OsalThreadDestroy failed, ret=%{public}d ", __func__, __LINE__, ret);
128 return ret;
129 }
130
131 return HDF_SUCCESS;
132 }
133
SetUpTestCase()134 void UsbRawSdkIfTest::SetUpTestCase()
135 {
136 g_acm = &g_deviceService;
137 UsbStartIo(g_acm);
138 }
139
TearDownTestCase()140 void UsbRawSdkIfTest::TearDownTestCase()
141 {
142 g_acm = &g_deviceService;
143 if (UsbStopIo(g_acm) != HDF_SUCCESS) {
144 HDF_LOGW("%s:%d UsbStopIo error!", __func__, __LINE__);
145 }
146 }
147
AcmWriteBulkCallback(const void * requestArg)148 static void AcmWriteBulkCallback(const void *requestArg)
149 {
150 struct UsbRawRequest *req = reinterpret_cast<struct UsbRawRequest *>(const_cast<void *>(requestArg));
151
152 printf("%s:%d entry!", __func__, __LINE__);
153 if (req == nullptr) {
154 printf("%s:%d req is nullptr!", __func__, __LINE__);
155 return;
156 }
157 struct AcmWb *wb = static_cast<struct AcmWb *>(req->userData);
158 if (wb == nullptr) {
159 printf("%s:%d userData(wb) is nullptr!", __func__, __LINE__);
160 return;
161 }
162
163 if (req->status != USB_REQUEST_COMPLETED) {
164 printf("%s: write req failed, status = %d", __func__, req->status);
165 }
166
167 wb->use = 0;
168 }
169
AcmReadBulkCallback(const void * requestArg)170 static void AcmReadBulkCallback(const void *requestArg)
171 {
172 struct UsbRawRequest *req = reinterpret_cast<struct UsbRawRequest *>(const_cast<void *>(requestArg));
173
174 printf("%s:%d entry!", __func__, __LINE__);
175 if (req == nullptr) {
176 printf("%s:%d req is nullptr!", __func__, __LINE__);
177 return;
178 }
179 struct AcmDevice *acm = static_cast<struct AcmDevice *>(req->userData);
180 if (acm == nullptr) {
181 printf("%s:%d userData(acm) is nullptr!", __func__, __LINE__);
182 return;
183 }
184 size_t size = req->actualLength;
185
186 switch (req->status) {
187 case USB_REQUEST_COMPLETED:
188 HDF_LOGD("Bulk status: %{public}d+size:%{public}zu\n", req->status, size);
189 if (size) {
190 uint8_t *data = req->buffer;
191 uint32_t count;
192
193 OsalMutexLock(&acm->readLock);
194 if (DataFifoIsFull(&acm->port->readFifo)) {
195 DataFifoSkip(&acm->port->readFifo, size);
196 }
197 count = DataFifoWrite(&acm->port->readFifo, data, size);
198 if (count != size) {
199 printf("%s: write %u less than expected %zu", __func__, count, size);
200 }
201 OsalMutexUnlock(&acm->readLock);
202 }
203 break;
204 case USB_REQUEST_CANCELLED:
205 printf("%s: the request is cancelled", __func__);
206 break;
207 default:
208 printf("%s: the request is failed", __func__);
209 break;
210 }
211 }
212
AcmProcessNotification(struct AcmDevice * acm,struct UsbCdcNotification * dr)213 static void AcmProcessNotification(struct AcmDevice *acm, struct UsbCdcNotification *dr)
214 {
215 (void)acm;
216 printf("%s:%d entry!", __func__, __LINE__);
217
218 switch (dr->bNotificationType) {
219 case USB_DDK_CDC_NOTIFY_NETWORK_CONNECTION:
220 printf("%s - network connection: %d\n", __func__, dr->wValue);
221 break;
222 case USB_DDK_CDC_NOTIFY_SERIAL_STATE:
223 printf("the serial State change\n");
224 break;
225 default:
226 printf("%s-%d received: index %d len %d\n", __func__, dr->bNotificationType, dr->wIndex, dr->wLength);
227 }
228 }
229
AcmNotifyReqCallback(const void * requestArg)230 static void AcmNotifyReqCallback(const void *requestArg)
231 {
232 struct UsbRawRequest *req = reinterpret_cast<struct UsbRawRequest *>(const_cast<void *>(requestArg));
233 if (req == nullptr) {
234 return;
235 }
236 struct AcmDevice *acm = static_cast<struct AcmDevice *>(req->userData);
237 struct UsbCdcNotification *dr = reinterpret_cast<struct UsbCdcNotification *>(req->buffer);
238 if (acm == nullptr || dr == nullptr) {
239 return;
240 }
241 unsigned int currentSize = req->actualLength;
242 unsigned int expectedSize, copySize, allocSize;
243 if (req->status != USB_REQUEST_COMPLETED) {
244 goto EXIT;
245 }
246 if (acm->nbIndex) {
247 dr = reinterpret_cast<struct UsbCdcNotification *>(acm->notificationBuffer);
248 }
249 expectedSize = sizeof(struct UsbCdcNotification) + LE16_TO_CPU(dr->wLength);
250 if (currentSize < expectedSize) {
251 if (acm->nbSize < expectedSize) {
252 if (acm->nbSize) {
253 OsalMemFree(acm->notificationBuffer);
254 acm->nbSize = 0;
255 }
256 allocSize = expectedSize;
257 acm->notificationBuffer = (uint8_t *)OsalMemCalloc(allocSize);
258 if (!acm->notificationBuffer) {
259 goto EXIT;
260 }
261 acm->nbSize = allocSize;
262 }
263 copySize = MIN(currentSize, expectedSize - acm->nbIndex);
264 if (memcpy_s(&acm->notificationBuffer[acm->nbIndex], acm->nbSize - acm->nbIndex, req->buffer, copySize) !=
265 EOK) {
266 printf("memcpy_s fail\n");
267 }
268 acm->nbIndex += copySize;
269 currentSize = acm->nbIndex;
270 }
271 if (currentSize >= expectedSize) {
272 AcmProcessNotification(acm, dr);
273 acm->nbIndex = 0;
274 }
275 if (UsbRawSubmitRequest(req) != HDF_SUCCESS) {
276 printf("%s - UsbRawSubmitRequest failed", __func__);
277 }
278 EXIT:
279 printf("%s:%d exit", __func__, __LINE__);
280 }
281
AcmWriteBufAlloc(struct AcmDevice * acm)282 static int32_t AcmWriteBufAlloc(struct AcmDevice *acm)
283 {
284 struct AcmWb *wb = &acm->wb[0];
285 int32_t i;
286
287 for (i = 0; i < ACM_NW; i++, wb++) {
288 wb->buf = (uint8_t *)OsalMemCalloc(acm->dataOutEp->maxPacketSize);
289 if (!wb->buf) {
290 while (i != 0) {
291 --i;
292 --wb;
293 OsalMemFree(wb->buf);
294 wb->buf = NULL;
295 }
296 return -HDF_ERR_MALLOC_FAIL;
297 }
298 }
299 return HDF_SUCCESS;
300 }
301
AcmCtrlReqCallback(const void * requestArg)302 static void AcmCtrlReqCallback(const void *requestArg)
303 {
304 (void)requestArg;
305 printf("%s:%d entry!", __func__, __LINE__);
306 }
307
UsbParseConfigDescriptor(struct AcmDevice * acm,struct UsbRawConfigDescriptor * config)308 static int32_t UsbParseConfigDescriptor(struct AcmDevice *acm, struct UsbRawConfigDescriptor *config)
309 {
310 const struct UsbRawInterface *interface = NULL;
311 uint8_t numInterfaces = config->configDescriptor.bNumInterfaces;
312 for (uint8_t i = 0; i < numInterfaces; i++) {
313 interface = config->interface[i];
314 uint8_t ifaceClass = interface->altsetting->interfaceDescriptor.bInterfaceClass;
315 uint8_t numEndpoints = interface->altsetting->interfaceDescriptor.bNumEndpoints;
316 if (UsbRawClaimInterface(acm->devHandle, i) != HDF_SUCCESS) {
317 printf("%s:%d claim interface %u failed\n", __func__, __LINE__, i);
318 continue;
319 }
320 switch (ifaceClass) {
321 case USB_DDK_CLASS_COMM:
322 acm->ctrlIface = i;
323 acm->notifyEp = (UsbEndpoint *)OsalMemAlloc(sizeof(struct UsbEndpoint));
324 if (acm->notifyEp == nullptr) {
325 printf("%s:%d allocate endpoint failed\n", __func__, __LINE__);
326 return HDF_ERR_MALLOC_FAIL;
327 }
328 /* get the first endpoint by default */
329 acm->notifyEp->addr = interface->altsetting->endPoint[0].endpointDescriptor.bEndpointAddress;
330 acm->notifyEp->interval = interface->altsetting->endPoint[0].endpointDescriptor.bInterval;
331 acm->notifyEp->maxPacketSize = interface->altsetting->endPoint[0].endpointDescriptor.wMaxPacketSize;
332 break;
333 case USB_DDK_CLASS_CDC_DATA:
334 acm->dataIface = i;
335 for (uint8_t j = 0; j < numEndpoints; j++) {
336 const struct UsbRawEndpointDescriptor *endPoint = &interface->altsetting->endPoint[j];
337
338 /* get bulk in endpoint */
339 if ((endPoint->endpointDescriptor.bEndpointAddress & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN) {
340 acm->dataInEp = (UsbEndpoint *)OsalMemAlloc(sizeof(struct UsbEndpoint));
341 if (acm->dataInEp == nullptr) {
342 printf("%s:%d allocate dataInEp failed\n", __func__, __LINE__);
343 break;
344 }
345 acm->dataInEp->addr = endPoint->endpointDescriptor.bEndpointAddress;
346 acm->dataInEp->interval = endPoint->endpointDescriptor.bInterval;
347 acm->dataInEp->maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize;
348 } else { /* get bulk out endpoint */
349 acm->dataOutEp = (UsbEndpoint *)OsalMemAlloc(sizeof(struct UsbEndpoint));
350 if (acm->dataOutEp == nullptr) {
351 printf("%s:%d allocate dataOutEp failed\n", __func__, __LINE__);
352 break;
353 }
354 acm->dataOutEp->addr = endPoint->endpointDescriptor.bEndpointAddress;
355 acm->dataOutEp->interval = endPoint->endpointDescriptor.bInterval;
356 acm->dataOutEp->maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize;
357 }
358 }
359 break;
360 default:
361 printf("%s:%d wrong descriptor type\n", __func__, __LINE__);
362 }
363 }
364
365 return HDF_SUCCESS;
366 }
367
368 /**
369 * @tc.number : CheckRawSdkIfInit001
370 * @tc.name :
371 * @tc.type : PERF
372 * @tc.level : Level 1
373 */
374 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfInit001, TestSize.Level1)
375 {
376 int32_t ret;
377
378 ret = UsbRawInit(&g_session);
379 EXPECT_EQ(HDF_SUCCESS, ret);
380 g_acm->session = g_session;
381 }
382
383 /**
384 * @tc.number : CheckRawSdkIfExit001
385 * @tc.name :
386 * @tc.type : PERF
387 * @tc.level : Level 1
388 */
389 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfExit001, TestSize.Level1)
390 {
391 int32_t ret;
392
393 ret = UsbRawExit(g_acm->session);
394 EXPECT_EQ(HDF_SUCCESS, ret);
395 }
396
397 /**
398 * @tc.number : CheckRawSdkIfInit002
399 * @tc.name :
400 * @tc.type : PERF
401 * @tc.level : Level 1
402 */
403 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfInit002, TestSize.Level1)
404 {
405 int32_t ret;
406
407 ret = UsbRawInit(NULL);
408 EXPECT_EQ(HDF_SUCCESS, ret);
409 g_acm->session = g_session;
410 }
411
412 /**
413 * @tc.number : CheckRawSdkIfExit002
414 * @tc.name :
415 * @tc.type : PERF
416 * @tc.level : Level 1
417 */
418 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfExit002, TestSize.Level1)
419 {
420 int32_t ret;
421
422 ret = UsbRawExit(NULL);
423 EXPECT_EQ(HDF_SUCCESS, ret);
424 }
425
426 /**
427 * @tc.number : CheckRawSdkIfInit003
428 * @tc.name :
429 * @tc.type : PERF
430 * @tc.level : Level 1
431 */
432 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfInit003, TestSize.Level1)
433 {
434 int32_t ret;
435 int32_t i;
436
437 for (i = 0; i < 100; i++) {
438 ret = UsbRawInit(&g_session);
439 EXPECT_EQ(HDF_SUCCESS, ret);
440 g_acm->session = g_session;
441 ret = UsbRawExit(g_acm->session);
442 EXPECT_EQ(HDF_SUCCESS, ret);
443 }
444 }
445
446 /**
447 * @tc.number : CheckRawSdkIfInit004
448 * @tc.name :
449 * @tc.type : PERF
450 * @tc.level : Level 1
451 */
452 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfInit004, TestSize.Level1)
453 {
454 int32_t ret;
455 int32_t i;
456
457 for (i = 0; i < 100; i++) {
458 ret = UsbRawInit(NULL);
459 EXPECT_EQ(HDF_SUCCESS, ret);
460 ret = UsbRawExit(NULL);
461 EXPECT_EQ(HDF_SUCCESS, ret);
462 }
463 }
464
465 /**
466 * @tc.number : CheckRawSdkIfInit005
467 * @tc.name :
468 * @tc.type : PERF
469 * @tc.level : Level 1
470 */
471 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfInit005, TestSize.Level1)
472 {
473 int32_t ret;
474
475 ret = UsbRawInit(&g_session);
476 EXPECT_EQ(HDF_SUCCESS, ret);
477 g_acm->session = g_session;
478 }
479
480 /**
481 * @tc.number : CheckRawSdkIfOpenDevice001
482 * @tc.name :
483 * @tc.type : PERF
484 * @tc.level : Level 1
485 */
486 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice001, TestSize.Level1)
487 {
488 g_acm->busNum = 1U;
489 g_acm->devAddr = 2U;
490
491 g_devHandle = UsbRawOpenDevice(NULL, g_acm->busNum, g_acm->devAddr);
492 EXPECT_EQ(nullptr, g_devHandle);
493 g_acm->devHandle = g_devHandle;
494 }
495
496 /**
497 * @tc.number : CheckRawSdkIfOpenDevice002
498 * @tc.name :
499 * @tc.type : PERF
500 * @tc.level : Level 1
501 */
502 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice002, TestSize.Level1)
503 {
504 g_acm->busNum = 1U;
505 g_acm->devAddr = 100U;
506
507 g_devHandle = UsbRawOpenDevice(g_acm->session, g_acm->busNum, g_acm->devAddr);
508 EXPECT_EQ(nullptr, g_devHandle);
509 g_acm->devHandle = g_devHandle;
510 }
511
512 /**
513 * @tc.number : CheckRawSdkIfOpenDevice003
514 * @tc.name :
515 * @tc.type : PERF
516 * @tc.level : Level 1
517 */
518 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice003, TestSize.Level1)
519 {
520 g_acm->busNum = 1U;
521 g_acm->devAddr = 255U;
522
523 g_devHandle = UsbRawOpenDevice(g_acm->session, g_acm->busNum, g_acm->devAddr);
524 EXPECT_EQ(nullptr, g_devHandle);
525 g_acm->devHandle = g_devHandle;
526 }
527
528 /**
529 * @tc.number : CheckRawSdkIfOpenDevice004
530 * @tc.name :
531 * @tc.type : PERF
532 * @tc.level : Level 1
533 */
534 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice004, TestSize.Level1)
535 {
536 g_acm->busNum = 100U;
537 g_acm->devAddr = 2U;
538
539 g_devHandle = UsbRawOpenDevice(g_acm->session, g_acm->busNum, g_acm->devAddr);
540 EXPECT_EQ(nullptr, g_devHandle);
541 g_acm->devHandle = g_devHandle;
542 }
543
544 /**
545 * @tc.number : CheckRawSdkIfOpenDevice005
546 * @tc.name :
547 * @tc.type : PERF
548 * @tc.level : Level 1
549 */
550 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice005, TestSize.Level1)
551 {
552 g_acm->busNum = 255U;
553 g_acm->devAddr = 2U;
554
555 g_devHandle = UsbRawOpenDevice(g_acm->session, g_acm->busNum, g_acm->devAddr);
556 EXPECT_EQ(nullptr, g_devHandle);
557 g_acm->devHandle = g_devHandle;
558 }
559
560 /**
561 * @tc.number : CheckRawSdkIfOpenDevice006
562 * @tc.name :
563 * @tc.type : PERF
564 * @tc.level : Level 1
565 */
566 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice006, TestSize.Level1)
567 {
568 g_acm->busNum = 1U;
569 g_acm->devAddr = 2U;
570
571 g_devHandle = UsbRawOpenDevice(g_acm->session, g_acm->busNum, g_acm->devAddr);
572 EXPECT_NE(nullptr, g_devHandle);
573 g_acm->devHandle = g_devHandle;
574 }
575
576 /**
577 * @tc.number : CheckRawSdkIfResetDevice001
578 * @tc.name :
579 * @tc.type : PERF
580 * @tc.level : Level 1
581 */
582 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfResetDevice001, TestSize.Level1)
583 {
584 int32_t ret;
585
586 ret = UsbRawResetDevice(NULL);
587 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
588 }
589
590 /**
591 * @tc.number : CheckRawSdkIfResetDevice002
592 * @tc.name :
593 * @tc.type : PERF
594 * @tc.level : Level 1
595 */
596 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfResetDevice002, TestSize.Level1)
597 {
598 int32_t ret;
599
600 ret = UsbRawResetDevice(g_acm->devHandle);
601 EXPECT_EQ(HDF_SUCCESS, ret);
602 }
603
604 /**
605 * @tc.number : CheckRawSdkIfCloseDevice001
606 * @tc.name :
607 * @tc.type : PERF
608 * @tc.level : Level 1
609 */
610 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfCloseDevice001, TestSize.Level1)
611 {
612 int32_t ret;
613
614 ret = UsbRawCloseDevice(NULL);
615 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
616 }
617
618 /**
619 * @tc.number : CheckRawSdkIfCloseDevice002
620 * @tc.name :
621 * @tc.type : PERF
622 * @tc.level : Level 1
623 */
624 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfCloseDevice002, TestSize.Level1)
625 {
626 int32_t ret;
627
628 ret = UsbRawCloseDevice(g_acm->devHandle);
629 EXPECT_EQ(HDF_SUCCESS, ret);
630 }
631
632 /**
633 * @tc.number : CheckRawSdkIfOpenDevice007
634 * @tc.name :
635 * @tc.type : PERF
636 * @tc.level : Level 1
637 */
638 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfOpenDevice007, TestSize.Level1)
639 {
640 g_acm->busNum = 1U;
641 g_acm->devAddr = 2U;
642
643 g_devHandle = UsbRawOpenDevice(g_session, g_acm->busNum, g_acm->devAddr);
644 EXPECT_NE(nullptr, g_devHandle);
645 g_acm->devHandle = g_devHandle;
646 }
647
648 /**
649 * @tc.number : CheckRawSdkIfGetConfiguration001
650 * @tc.name :
651 * @tc.type : PERF
652 * @tc.level : Level 1
653 */
654 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfiguration001, TestSize.Level1)
655 {
656 int32_t ret;
657
658 ret = UsbRawGetConfiguration(NULL, &g_activeConfig);
659 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
660 }
661
662 /**
663 * @tc.number : CheckRawSdkIfGetConfiguration002
664 * @tc.name :
665 * @tc.type : PERF
666 * @tc.level : Level 1
667 */
668 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfiguration002, TestSize.Level1)
669 {
670 int32_t ret;
671
672 ret = UsbRawGetConfiguration(g_acm->devHandle, NULL);
673 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
674 }
675
676 /**
677 * @tc.number : CheckRawSdkIfGetConfiguration003
678 * @tc.name :
679 * @tc.type : PERF
680 * @tc.level : Level 1
681 */
682 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfiguration003, TestSize.Level1)
683 {
684 int32_t ret;
685
686 ret = UsbRawGetConfiguration(NULL, NULL);
687 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
688 }
689
690 /**
691 * @tc.number : CheckRawSdkIfGetConfiguration004
692 * @tc.name :
693 * @tc.type : PERF
694 * @tc.level : Level 1
695 */
696 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfiguration004, TestSize.Level1)
697 {
698 int32_t ret;
699
700 ret = UsbRawGetConfiguration(g_acm->devHandle, &g_activeConfig);
701 printf("------activeConfig = [%d]------\n", g_activeConfig);
702 EXPECT_EQ(HDF_SUCCESS, ret);
703 }
704
705 /**
706 * @tc.number : CheckRawSdkIfGetDevice001
707 * @tc.name :
708 * @tc.type : PERF
709 * @tc.level : Level 1
710 */
711 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDevice001, TestSize.Level1)
712 {
713 g_dev = UsbRawGetDevice(NULL);
714 EXPECT_EQ(nullptr, g_dev);
715 }
716
717 /**
718 * @tc.number : CheckRawSdkIfGetDevice002
719 * @tc.name :
720 * @tc.type : PERF
721 * @tc.level : Level 1
722 */
723 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDevice002, TestSize.Level1)
724 {
725 g_dev = UsbRawGetDevice(g_acm->devHandle);
726 EXPECT_NE(nullptr, g_dev);
727 }
728
729 /**
730 * @tc.number : CheckRawSdkIfGetConfigDescriptor001
731 * @tc.name :
732 * @tc.type : PERF
733 * @tc.level : Level 1
734 */
735 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfigDescriptor001, TestSize.Level1)
736 {
737 int32_t ret;
738
739 ret = UsbRawGetConfigDescriptor(NULL, g_activeConfig, &g_acm->config);
740 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
741 }
742
743 /**
744 * @tc.number : CheckRawSdkIfGetConfigDescriptor002
745 * @tc.name :
746 * @tc.type : PERF
747 * @tc.level : Level 1
748 */
749 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfigDescriptor002, TestSize.Level1)
750 {
751 int32_t ret;
752
753 ret = UsbRawGetConfigDescriptor(g_dev, g_activeConfig, NULL);
754 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
755 UsbRawFreeConfigDescriptor(NULL);
756 }
757
758 /**
759 * @tc.number : CheckRawSdkIfGetConfigDescriptor003
760 * @tc.name :
761 * @tc.type : PERF
762 * @tc.level : Level 1
763 */
764 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfigDescriptor003, TestSize.Level1)
765 {
766 int32_t ret;
767
768 ret = UsbRawGetConfigDescriptor(NULL, g_activeConfig, NULL);
769 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
770 }
771
772 /**
773 * @tc.number : CheckRawSdkIfGetConfigDescriptor004
774 * @tc.name :
775 * @tc.type : PERF
776 * @tc.level : Level 1
777 */
778 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfigDescriptor004, TestSize.Level1)
779 {
780 int32_t ret;
781
782 printf("------activeConfig = [%d]------\n", g_activeConfig);
783 ret = UsbRawGetConfigDescriptor(g_dev, g_activeConfig, &g_acm->config);
784 EXPECT_EQ(HDF_SUCCESS, ret);
785 }
786
787 /**
788 * @tc.number : CheckRawSdkIfSetConfiguration001
789 * @tc.name :
790 * @tc.type : PERF
791 * @tc.level : Level 1
792 */
793 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration001, TestSize.Level1)
794 {
795 int32_t ret;
796 int32_t config = 0;
797
798 ret = UsbRawSetConfiguration(NULL, config);
799 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
800 }
801
802 /**
803 * @tc.number : CheckRawSdkIfSetConfiguration002
804 * @tc.name :
805 * @tc.type : PERF
806 * @tc.level : Level 1
807 */
808 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration002, TestSize.Level1)
809 {
810 int32_t ret;
811 int32_t config = 0;
812
813 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
814 EXPECT_EQ(HDF_SUCCESS, ret);
815 }
816
817 /**
818 * @tc.number : CheckRawSdkIfSetConfiguration003
819 * @tc.name :
820 * @tc.type : PERF
821 * @tc.level : Level 1
822 */
823 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration003, TestSize.Level1)
824 {
825 int32_t ret;
826 int32_t config = 1;
827
828 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
829 EXPECT_EQ(HDF_SUCCESS, ret);
830 }
831
832 /**
833 * @tc.number : CheckRawSdkIfSetConfiguration004
834 * @tc.name :
835 * @tc.type : PERF
836 * @tc.level : Level 1
837 */
838 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration004, TestSize.Level1)
839 {
840 int32_t ret;
841 int32_t config = 10;
842
843 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
844 EXPECT_EQ(HDF_FAILURE, ret);
845 }
846
847 /**
848 * @tc.number : CheckRawSdkIfSetConfiguration005
849 * @tc.name :
850 * @tc.type : PERF
851 * @tc.level : Level 1
852 */
853 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration005, TestSize.Level1)
854 {
855 int32_t ret;
856 int32_t config = 100;
857
858 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
859 EXPECT_EQ(HDF_FAILURE, ret);
860 }
861
862 /**
863 * @tc.number : CheckRawSdkIfSetConfiguration006
864 * @tc.name :
865 * @tc.type : PERF
866 * @tc.level : Level 1
867 */
868 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration006, TestSize.Level1)
869 {
870 int32_t ret;
871 int32_t config = 200;
872
873 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
874 EXPECT_EQ(HDF_FAILURE, ret);
875 }
876
877 /**
878 * @tc.number : CheckRawSdkIfSetConfiguration007
879 * @tc.name :
880 * @tc.type : PERF
881 * @tc.level : Level 1
882 */
883 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration007, TestSize.Level1)
884 {
885 int32_t ret;
886 int32_t config = 255;
887
888 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
889 EXPECT_EQ(HDF_FAILURE, ret);
890 }
891
892 /**
893 * @tc.number : CheckRawSdkIfSetConfiguration008
894 * @tc.name :
895 * @tc.type : PERF
896 * @tc.level : Level 1
897 */
898 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfSetConfiguration008, TestSize.Level1)
899 {
900 int32_t ret;
901 int32_t config = 1;
902
903 ret = UsbRawSetConfiguration(g_acm->devHandle, config);
904 EXPECT_EQ(HDF_SUCCESS, ret);
905 }
906
907 /**
908 * @tc.number : CheckRawSdkIfGetDeviceDescriptor001
909 * @tc.name :
910 * @tc.type : PERF
911 * @tc.level : Level 1
912 */
913 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDeviceDescriptor001, TestSize.Level1)
914 {
915 struct UsbDeviceDescriptor desc;
916 int32_t ret;
917
918 ret = UsbRawGetDeviceDescriptor(NULL, &desc);
919 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
920 }
921
922 /**
923 * @tc.number : CheckRawSdkIfGetDeviceDescriptor002
924 * @tc.name :
925 * @tc.type : PERF
926 * @tc.level : Level 1
927 */
928 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDeviceDescriptor002, TestSize.Level1)
929 {
930 int32_t ret;
931
932 ret = UsbRawGetDeviceDescriptor(g_dev, NULL);
933 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
934 }
935
936 /**
937 * @tc.number : CheckRawSdkIfGetDeviceDescriptor003
938 * @tc.name :
939 * @tc.type : PERF
940 * @tc.level : Level 1
941 */
942 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDeviceDescriptor003, TestSize.Level1)
943 {
944 int32_t ret;
945
946 ret = UsbRawGetDeviceDescriptor(NULL, NULL);
947 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
948 }
949
950 /**
951 * @tc.number : CheckRawSdkIfGetDeviceDescriptor004
952 * @tc.name :
953 * @tc.type : PERF
954 * @tc.level : Level 1
955 */
956 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDeviceDescriptor004, TestSize.Level1)
957 {
958 struct UsbDeviceDescriptor desc;
959 int32_t ret;
960
961 ret = UsbRawGetDeviceDescriptor(g_dev, &desc);
962 EXPECT_EQ(HDF_SUCCESS, ret);
963 }
964
965 /**
966 * @tc.number : CheckRawSdkIfGetConfigDescriptor005
967 * @tc.name :
968 * @tc.type : PERF
969 * @tc.level : Level 1
970 */
971 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetConfigDescriptor005, TestSize.Level1)
972 {
973 int32_t ret;
974
975 printf("------activeConfig = [%d]------\n", g_activeConfig);
976 ret = UsbRawGetConfigDescriptor(g_dev, g_activeConfig, &g_acm->config);
977 EXPECT_EQ(HDF_SUCCESS, ret);
978 }
979
980 /**
981 * @tc.number : CheckRawSdkIfGetDeviceDescriptor005
982 * @tc.name :
983 * @tc.type : PERF
984 * @tc.level : Level 1
985 */
986 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDeviceDescriptor005, TestSize.Level1)
987 {
988 struct UsbDeviceDescriptor desc;
989 int32_t ret;
990
991 ret = UsbRawGetDeviceDescriptor(g_dev, &desc);
992 EXPECT_EQ(HDF_SUCCESS, ret);
993 }
994
995 /**
996 * @tc.number : CheckRawSdkIfClaimInterface001
997 * @tc.name :
998 * @tc.type : PERFs
999 * @tc.level : Level 1
1000 */
1001 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfClaimInterface001, TestSize.Level1)
1002 {
1003 int32_t ret;
1004 int32_t interfaceNumber = 1;
1005
1006 ret = UsbRawClaimInterface(NULL, interfaceNumber);
1007 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1008 }
1009
1010 /**
1011 * @tc.number : CheckRawSdkIfClaimInterface002
1012 * @tc.name :
1013 * @tc.type : PERFs
1014 * @tc.level : Level 1
1015 */
1016 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfClaimInterface002, TestSize.Level1)
1017 {
1018 int32_t ret;
1019 int32_t interfaceNumber = 1;
1020
1021 ret = UsbRawClaimInterface(g_devHandle, interfaceNumber);
1022 EXPECT_EQ(HDF_SUCCESS, ret);
1023 }
1024
1025 /**
1026 * @tc.number : CheckRawSdkIfClaimInterface003
1027 * @tc.name :
1028 * @tc.type : PERFs
1029 * @tc.level : Level 1
1030 */
1031 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfClaimInterface003, TestSize.Level1)
1032 {
1033 int32_t ret;
1034 int32_t interfaceNumber = 0;
1035
1036 ret = UsbRawClaimInterface(g_devHandle, interfaceNumber);
1037 EXPECT_EQ(HDF_SUCCESS, ret);
1038 }
1039
1040 /**
1041 * @tc.number : CheckRawSdkIfClaimInterface004
1042 * @tc.name :
1043 * @tc.type : PERFs
1044 * @tc.level : Level 1
1045 */
1046 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfClaimInterface004, TestSize.Level1)
1047 {
1048 int32_t ret;
1049 int32_t interfaceNumber = 255;
1050
1051 ret = UsbRawClaimInterface(g_devHandle, interfaceNumber);
1052 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1053 }
1054
1055 /**
1056 * @tc.number : CheckRawSdkIfClaimInterface005
1057 * @tc.name :
1058 * @tc.type : PERFs
1059 * @tc.level : Level 1
1060 */
1061 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfClaimInterface005, TestSize.Level1)
1062 {
1063 int32_t ret;
1064
1065 ret = UsbParseConfigDescriptor(g_acm, g_acm->config);
1066 EXPECT_EQ(HDF_SUCCESS, ret);
1067 }
1068
1069 /**
1070 * @tc.number : CheckRawSdkIfReleaseInterface001
1071 * @tc.name :
1072 * @tc.type : PERFs
1073 * @tc.level : Level 1
1074 */
1075 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfReleaseInterface001, TestSize.Level1)
1076 {
1077 int32_t ret;
1078
1079 ret = UsbRawReleaseInterface(NULL, g_acm->ctrlIface);
1080 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1081 }
1082
1083 /**
1084 * @tc.number : CheckRawSdkIfReleaseInterface002
1085 * @tc.name :
1086 * @tc.type : PERFs
1087 * @tc.level : Level 1
1088 */
1089 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfReleaseInterface002, TestSize.Level1)
1090 {
1091 int32_t ret;
1092
1093 ret = UsbRawReleaseInterface(g_acm->devHandle, g_acm->ctrlIface);
1094 EXPECT_EQ(HDF_SUCCESS, ret);
1095 }
1096
1097 /**
1098 * @tc.number : CheckRawSdkIfReleaseInterface003
1099 * @tc.name :
1100 * @tc.type : PERFs
1101 * @tc.level : Level 1
1102 */
1103 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfReleaseInterface003, TestSize.Level1)
1104 {
1105 int32_t ret;
1106
1107 ret = UsbRawReleaseInterface(NULL, g_acm->dataIface);
1108 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1109 }
1110
1111 /**
1112 * @tc.number : CheckRawSdkIfReleaseInterface004
1113 * @tc.name :
1114 * @tc.type : PERFs
1115 * @tc.level : Level 1
1116 */
1117 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfReleaseInterface004, TestSize.Level1)
1118 {
1119 int32_t ret;
1120
1121 ret = UsbRawReleaseInterface(g_acm->devHandle, g_acm->dataIface);
1122 EXPECT_EQ(HDF_SUCCESS, ret);
1123 }
1124
1125 /**
1126 * @tc.number : CheckRawSdkIfClaimInterface006
1127 * @tc.name :
1128 * @tc.type : PERFs
1129 * @tc.level : Level 1
1130 */
1131 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfClaimInterface006, TestSize.Level1)
1132 {
1133 int32_t ret;
1134
1135 ret = UsbParseConfigDescriptor(g_acm, g_acm->config);
1136 EXPECT_EQ(HDF_SUCCESS, ret);
1137 UsbRawFreeConfigDescriptor(g_acm->config);
1138 g_acm->config = nullptr;
1139 }
1140
1141 /**
1142 * @tc.number : CheckRawSdkIfAllocRequest001
1143 * @tc.name :
1144 * @tc.type : PERFs
1145 * @tc.level : Level 1
1146 */
1147 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest001, TestSize.Level1)
1148 {
1149 int32_t i;
1150 int32_t ret;
1151
1152 ret = AcmWriteBufAlloc(g_acm);
1153 EXPECT_EQ(HDF_SUCCESS, ret);
1154
1155 for (i = 0; i < ACM_NW; i++) {
1156 g_acm->wb[i].request = UsbRawAllocRequest(NULL, 0, g_acm->dataOutEp->maxPacketSize);
1157 g_acm->wb[i].instance = g_acm;
1158 EXPECT_EQ(nullptr, g_acm->wb[i].request);
1159 }
1160 }
1161
1162 /**
1163 * @tc.number : CheckRawSdkIfAllocRequest002
1164 * @tc.name :
1165 * @tc.type : PERFs
1166 * @tc.level : Level 1
1167 */
1168 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest002, TestSize.Level1)
1169 {
1170 int32_t i;
1171 int32_t ret;
1172
1173 ret = AcmWriteBufAlloc(g_acm);
1174 EXPECT_EQ(HDF_SUCCESS, ret);
1175
1176 for (i = 0; i < ACM_NW; i++) {
1177 g_acm->wb[i].request = UsbRawAllocRequest(g_acm->devHandle, 0, g_acm->dataOutEp->maxPacketSize);
1178 g_acm->wb[i].instance = g_acm;
1179 ((struct UsbHostRequest *)(g_acm->wb[i].request))->devHandle = (struct UsbDeviceHandle *)g_acm->devHandle;
1180 EXPECT_NE(nullptr, g_acm->wb[i].request);
1181 }
1182 }
1183
1184 /**
1185 * @tc.number : CheckRawSdkIfAllocRequest003
1186 * @tc.name :
1187 * @tc.type : PERFs
1188 * @tc.level : Level 1
1189 */
1190 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest003, TestSize.Level1)
1191 {
1192 int32_t i;
1193
1194 for (i = 0; i < ACM_NR; i++) {
1195 g_acm->readReq[i] = UsbRawAllocRequest(NULL, 0, g_acm->dataInEp->maxPacketSize);
1196 EXPECT_EQ(nullptr, g_acm->readReq[i]);
1197 }
1198 }
1199
1200 /**
1201 * @tc.number : CheckRawSdkIfAllocRequest004
1202 * @tc.name :
1203 * @tc.type : PERFs
1204 * @tc.level : Level 1
1205 */
1206 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest004, TestSize.Level1)
1207 {
1208 int32_t i;
1209
1210 for (i = 0; i < ACM_NR; i++) {
1211 g_acm->readReq[i] = UsbRawAllocRequest(g_acm->devHandle, 0, g_acm->dataInEp->maxPacketSize);
1212 ((struct UsbHostRequest *)(g_acm->readReq[i]))->devHandle = (struct UsbDeviceHandle *)g_acm->devHandle;
1213 EXPECT_NE(nullptr, g_acm->readReq[i]);
1214 }
1215 }
1216
1217 /**
1218 * @tc.number : CheckRawSdkIfAllocRequest005
1219 * @tc.name :
1220 * @tc.type : PERFs
1221 * @tc.level : Level 1
1222 */
1223 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest005, TestSize.Level1)
1224 {
1225 g_acm->ctrlReq = UsbRawAllocRequest(NULL, 0, USB_CTRL_REQ_SIZE);
1226 EXPECT_EQ(nullptr, g_acm->ctrlReq);
1227 }
1228
1229 /**
1230 * @tc.number : CheckRawSdkIfAllocRequest006
1231 * @tc.name :
1232 * @tc.type : PERFs
1233 * @tc.level : Level 1
1234 */
1235 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest006, TestSize.Level1)
1236 {
1237 g_acm->ctrlReq = UsbRawAllocRequest(g_acm->devHandle, 0, USB_CTRL_REQ_SIZE);
1238 struct UsbHostRequest *tmp = reinterpret_cast<struct UsbHostRequest *>(g_acm->ctrlReq);
1239 tmp->devHandle = reinterpret_cast<struct UsbDeviceHandle *>(g_acm->devHandle);
1240 EXPECT_NE(nullptr, g_acm->ctrlReq);
1241 }
1242
1243 /**
1244 * @tc.number : CheckRawSdkIfAllocRequest007
1245 * @tc.name :
1246 * @tc.type : PERFs
1247 * @tc.level : Level 1
1248 */
1249 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest007, TestSize.Level1)
1250 {
1251 g_acm->notifyReq = UsbRawAllocRequest(NULL, 0, g_acm->notifyEp->maxPacketSize);
1252 EXPECT_EQ(nullptr, g_acm->notifyReq);
1253 }
1254
1255 /**
1256 * @tc.number : CheckRawSdkIfAllocRequest008
1257 * @tc.name :
1258 * @tc.type : PERFs
1259 * @tc.level : Level 1
1260 */
1261 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest008, TestSize.Level1)
1262 {
1263 g_acm->notifyReq = UsbRawAllocRequest(g_acm->devHandle, 0, g_acm->notifyEp->maxPacketSize);
1264 struct UsbHostRequest *tmp = reinterpret_cast<struct UsbHostRequest *>(g_acm->notifyReq);
1265 tmp->devHandle = reinterpret_cast<struct UsbDeviceHandle *>(g_acm->devHandle);
1266 EXPECT_NE(nullptr, g_acm->notifyReq);
1267 }
1268
1269 /**
1270 * @tc.number : CheckRawSdkIfFreeRequest001
1271 * @tc.name :
1272 * @tc.type : PERFs
1273 * @tc.level : Level 1
1274 */
1275 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFreeRequest001, TestSize.Level1)
1276 {
1277 int32_t ret;
1278 int32_t i;
1279
1280 for (i = 0; i < ACM_NW; i++) {
1281 ret = UsbRawFreeRequest(g_acm->wb[i].request);
1282 EXPECT_EQ(HDF_SUCCESS, ret);
1283 }
1284 }
1285
1286 /**
1287 * @tc.number : CheckRawSdkIfFreeRequest002
1288 * @tc.name :
1289 * @tc.type : PERFs
1290 * @tc.level : Level 1
1291 */
1292 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFreeRequest002, TestSize.Level1)
1293 {
1294 int32_t ret;
1295 int32_t i;
1296
1297 for (i = 0; i < ACM_NW; i++) {
1298 ret = UsbRawFreeRequest(g_acm->readReq[i]);
1299 EXPECT_EQ(HDF_SUCCESS, ret);
1300 }
1301 }
1302
1303 /**
1304 * @tc.number : CheckRawSdkIfFreeRequest003
1305 * @tc.name :
1306 * @tc.type : PERFs
1307 * @tc.level : Level 1
1308 */
1309 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFreeRequest003, TestSize.Level1)
1310 {
1311 int32_t ret;
1312
1313 ret = UsbRawFreeRequest(g_acm->ctrlReq);
1314 EXPECT_EQ(HDF_SUCCESS, ret);
1315 }
1316
1317 /**
1318 * @tc.number : CheckRawSdkIfFreeRequest004
1319 * @tc.name :
1320 * @tc.type : PERFs
1321 * @tc.level : Level 1
1322 */
1323 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFreeRequest004, TestSize.Level1)
1324 {
1325 int32_t ret;
1326
1327 ret = UsbRawFreeRequest(g_acm->notifyReq);
1328 EXPECT_EQ(HDF_SUCCESS, ret);
1329 }
1330
1331 /**
1332 * @tc.number : CheckRawSdkIfFreeRequest005
1333 * @tc.name :
1334 * @tc.type : PERFs
1335 * @tc.level : Level 1
1336 */
1337 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFreeRequest005, TestSize.Level1)
1338 {
1339 int32_t ret;
1340
1341 ret = UsbRawFreeRequest(NULL);
1342 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1343 }
1344
1345 /**
1346 * @tc.number : CheckRawSdkIfAllocRequest009
1347 * @tc.name :
1348 * @tc.type : PERFs
1349 * @tc.level : Level 1
1350 */
1351 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfAllocRequest009, TestSize.Level1)
1352 {
1353 int32_t i;
1354
1355 for (i = 0; i < ACM_NW; i++) {
1356 g_acm->wb[i].request = UsbRawAllocRequest(g_acm->devHandle, 0, g_acm->dataOutEp->maxPacketSize);
1357 g_acm->wb[i].instance = g_acm;
1358 EXPECT_NE(nullptr, g_acm->wb[i].request);
1359 }
1360
1361 for (i = 0; i < ACM_NR; i++) {
1362 g_acm->readReq[i] = UsbRawAllocRequest(g_acm->devHandle, 0, g_acm->dataInEp->maxPacketSize);
1363 EXPECT_NE(nullptr, g_acm->readReq[i]);
1364 }
1365
1366 g_acm->ctrlReq = UsbRawAllocRequest(g_acm->devHandle, 0, USB_CTRL_REQ_SIZE);
1367 EXPECT_NE(nullptr, g_acm->ctrlReq);
1368
1369 g_acm->notifyReq = UsbRawAllocRequest(g_acm->devHandle, 0, g_acm->notifyEp->maxPacketSize);
1370 EXPECT_NE(nullptr, g_acm->notifyReq);
1371 }
1372
1373 /**
1374 * @tc.number : CheckRawSdkIfGetDescriptor001
1375 * @tc.name :
1376 * @tc.type : PERF
1377 * @tc.level : Level 1
1378 */
1379 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor001, TestSize.Level1)
1380 {
1381 UsbRawDescriptorParam param;
1382 unsigned char data[100];
1383 int32_t ret;
1384
1385 ret = UsbRawGetDescriptor(NULL, g_acm->devHandle, ¶m, data);
1386 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1387 }
1388
1389 /**
1390 * @tc.number : CheckRawSdkIfGetDescriptor002
1391 * @tc.name :
1392 * @tc.type : PERF
1393 * @tc.level : Level 1
1394 */
1395 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor002, TestSize.Level1)
1396 {
1397 UsbRawDescriptorParam param;
1398 unsigned char data[100];
1399 int32_t ret;
1400
1401 ret = UsbRawGetDescriptor(g_acm->ctrlReq, NULL, ¶m, data);
1402 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1403 }
1404
1405 /**
1406 * @tc.number : CheckRawSdkIfGetDescriptor003
1407 * @tc.name :
1408 * @tc.type : PERF
1409 * @tc.level : Level 1
1410 */
1411 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor003, TestSize.Level1)
1412 {
1413 UsbRawDescriptorParam param;
1414 unsigned char data[100];
1415 int32_t ret;
1416
1417 ret = UsbRawGetDescriptor(NULL, NULL, ¶m, data);
1418 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1419 }
1420
1421 /**
1422 * @tc.number : CheckRawSdkIfGetDescriptor004
1423 * @tc.name :
1424 * @tc.type : PERF
1425 * @tc.level : Level 1
1426 */
1427 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor004, TestSize.Level1)
1428 {
1429 unsigned char data[100];
1430 int32_t ret;
1431
1432 ret = UsbRawGetDescriptor(g_acm->ctrlReq, g_acm->devHandle, NULL, data);
1433 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1434 }
1435
1436 /**
1437 * @tc.number : CheckRawSdkIfGetDescriptor005
1438 * @tc.name :
1439 * @tc.type : PERF
1440 * @tc.level : Level 1
1441 */
1442 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor005, TestSize.Level1)
1443 {
1444 UsbRawDescriptorParam param;
1445 int32_t ret;
1446
1447 ret = UsbRawGetDescriptor(g_acm->ctrlReq, g_acm->devHandle, ¶m, NULL);
1448 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1449 }
1450
1451 /**
1452 * @tc.number : CheckRawSdkIfGetDescriptor006
1453 * @tc.name :
1454 * @tc.type : PERF
1455 * @tc.level : Level 1
1456 */
1457 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor006, TestSize.Level1)
1458 {
1459 UsbRawDescriptorParam param;
1460 unsigned char data[100];
1461 int32_t ret;
1462
1463 param.descType = 0;
1464 param.descIndex = 0;
1465 param.length = sizeof(data);
1466
1467 ret = UsbRawGetDescriptor(g_acm->ctrlReq, g_acm->devHandle, ¶m, data);
1468 EXPECT_EQ(HDF_ERR_IO, ret);
1469 }
1470
1471 /**
1472 * @tc.number : CheckRawSdkIfGetDescriptor007
1473 * @tc.name :
1474 * @tc.type : PERF
1475 * @tc.level : Level 1
1476 */
1477 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor007, TestSize.Level1)
1478 {
1479 unsigned char data[100];
1480 int32_t ret;
1481
1482 ret = UsbRawGetDescriptor(g_acm->ctrlReq, NULL, NULL, data);
1483 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1484 }
1485
1486 /**
1487 * @tc.number : CheckRawSdkIfGetDescriptor008
1488 * @tc.name :
1489 * @tc.type : PERF
1490 * @tc.level : Level 1
1491 */
1492 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor008, TestSize.Level1)
1493 {
1494 int32_t ret;
1495
1496 ret = UsbRawGetDescriptor(g_acm->ctrlReq, g_acm->devHandle, NULL, NULL);
1497 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1498 }
1499
1500 /**
1501 * @tc.number : CheckRawSdkIfGetDescriptor009
1502 * @tc.name :
1503 * @tc.type : PERF
1504 * @tc.level : Level 1
1505 */
1506 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor009, TestSize.Level1)
1507 {
1508 unsigned char data[100];
1509 int32_t ret;
1510
1511 ret = UsbRawGetDescriptor(NULL, g_acm->devHandle, NULL, data);
1512 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1513 }
1514
1515 /**
1516 * @tc.number : CheckRawSdkIfGetDescriptor010
1517 * @tc.name :
1518 * @tc.type : PERF
1519 * @tc.level : Level 1
1520 */
1521 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor010, TestSize.Level1)
1522 {
1523 UsbRawDescriptorParam param;
1524 unsigned char data[100];
1525 int32_t ret;
1526
1527 param.descType = 0;
1528 param.descIndex = 0;
1529 param.length = sizeof(data);
1530
1531 ret = UsbRawGetDescriptor(NULL, g_acm->devHandle, ¶m, NULL);
1532 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1533 }
1534
1535 /**
1536 * @tc.number : CheckRawSdkIfGetDescriptor011
1537 * @tc.name :
1538 * @tc.type : PERF
1539 * @tc.level : Level 1
1540 */
1541 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor011, TestSize.Level1)
1542 {
1543 UsbRawDescriptorParam param;
1544 unsigned char data[100];
1545 int32_t ret;
1546
1547 param.descType = 0;
1548 param.descIndex = 0;
1549 param.length = sizeof(data);
1550
1551 ret = UsbRawGetDescriptor(g_acm->ctrlReq, NULL, ¶m, NULL);
1552 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1553 }
1554
1555 /**
1556 * @tc.number : CheckRawSdkIfGetDescriptor012
1557 * @tc.name :
1558 * @tc.type : PERF
1559 * @tc.level : Level 1
1560 */
1561 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor012, TestSize.Level1)
1562 {
1563 unsigned char data[100];
1564 int32_t ret;
1565
1566 ret = UsbRawGetDescriptor(NULL, NULL, NULL, data);
1567 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1568 }
1569
1570 /**
1571 * @tc.number : CheckRawSdkIfGetDescriptor013
1572 * @tc.name :
1573 * @tc.type : PERF
1574 * @tc.level : Level 1
1575 */
1576 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor013, TestSize.Level1)
1577 {
1578 UsbRawDescriptorParam param;
1579 unsigned char data[100];
1580 int32_t ret;
1581
1582 param.descType = 0;
1583 param.descIndex = 0;
1584 param.length = sizeof(data);
1585
1586 ret = UsbRawGetDescriptor(NULL, NULL, ¶m, NULL);
1587 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1588 }
1589
1590 /**
1591 * @tc.number : CheckRawSdkIfGetDescriptor014
1592 * @tc.name :
1593 * @tc.type : PERF
1594 * @tc.level : Level 1
1595 */
1596 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor014, TestSize.Level1)
1597 {
1598 int32_t ret;
1599
1600 ret = UsbRawGetDescriptor(NULL, g_acm->devHandle, NULL, NULL);
1601 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1602 }
1603
1604 /**
1605 * @tc.number : CheckRawSdkIfGetDescriptor015
1606 * @tc.name :
1607 * @tc.type : PERF
1608 * @tc.level : Level 1
1609 */
1610 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor015, TestSize.Level1)
1611 {
1612 int32_t ret;
1613
1614 ret = UsbRawGetDescriptor(g_acm->ctrlReq, NULL, NULL, NULL);
1615 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1616 }
1617
1618 /**
1619 * @tc.number : CheckRawSdkIfGetDescriptor016
1620 * @tc.name :
1621 * @tc.type : PERF
1622 * @tc.level : Level 1
1623 */
1624 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfGetDescriptor016, TestSize.Level1)
1625 {
1626 int32_t ret;
1627
1628 ret = UsbRawGetDescriptor(NULL, NULL, NULL, NULL);
1629 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1630 }
1631
1632 /**
1633 * @tc.number : CheckRawSdkIfFillBulkRequest001
1634 * @tc.name :
1635 * @tc.type : PERFs
1636 * @tc.level : Level 1
1637 */
1638 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillBulkRequest001, TestSize.Level1)
1639 {
1640 struct UsbRawFillRequestData reqData;
1641 int32_t ret;
1642 int32_t i;
1643 uint32_t size;
1644 char sendData[] = {"abcde\0"};
1645
1646 size = strlen(sendData) + 1;
1647
1648 size = (size > g_acm->dataOutEp->maxPacketSize) ? g_acm->dataOutEp->maxPacketSize : size;
1649
1650 for (i = 0; i < 1; i++) {
1651 AcmWb *snd = &g_acm->wb[i];
1652 snd->len = size;
1653 ret = memcpy_s(snd->buf, g_acm->dataOutEp->maxPacketSize, sendData, size);
1654 if (ret) {
1655 printf("memcpy_s fial");
1656 }
1657 g_acm->transmitting++;
1658
1659 reqData.endPoint = g_acm->dataOutEp->addr;
1660 reqData.numIsoPackets = 0;
1661 reqData.callback = AcmWriteBulkCallback;
1662 reqData.userData = (void *)snd;
1663 reqData.timeout = USB_CTRL_SET_TIMEOUT;
1664 reqData.buffer = snd->buf;
1665 reqData.length = snd->len;
1666
1667 ret = UsbRawFillBulkRequest(snd->request, g_acm->devHandle, &reqData);
1668 EXPECT_EQ(HDF_SUCCESS, ret);
1669 }
1670 }
1671
1672 /**
1673 * @tc.number : CheckRawSdkIfFillBulkRequest002
1674 * @tc.name :
1675 * @tc.type : PERFs
1676 * @tc.level : Level 1
1677 */
1678 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillBulkRequest002, TestSize.Level1)
1679 {
1680 struct UsbRawFillRequestData reqData;
1681 int32_t ret;
1682 int32_t i;
1683 uint32_t size = g_acm->dataInEp->maxPacketSize;
1684
1685 for (i = 0; i < 1; i++) {
1686 reqData.endPoint = g_acm->dataInEp->addr;
1687 reqData.numIsoPackets = 0;
1688 reqData.callback = AcmReadBulkCallback;
1689 reqData.userData = (void *)g_acm;
1690 reqData.timeout = USB_CTRL_SET_TIMEOUT;
1691 reqData.length = size;
1692
1693 ret = UsbRawFillBulkRequest(g_acm->readReq[i], g_acm->devHandle, &reqData);
1694 EXPECT_EQ(HDF_SUCCESS, ret);
1695 }
1696 }
1697
1698 /**
1699 * @tc.number : CheckRawSdkIfFillInterruptRequest001
1700 * @tc.name :
1701 * @tc.type : PERFs
1702 * @tc.level : Level 1
1703 */
1704 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillInterruptRequest001, TestSize.Level1)
1705 {
1706 struct UsbRawFillRequestData fillRequestData;
1707 int32_t ret;
1708 uint32_t size = g_acm->notifyEp->maxPacketSize;
1709
1710 fillRequestData.endPoint = g_acm->notifyEp->addr;
1711 fillRequestData.length = size;
1712 fillRequestData.numIsoPackets = 0;
1713 fillRequestData.callback = AcmNotifyReqCallback;
1714 fillRequestData.userData = (void *)g_acm;
1715 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1716
1717 ret = UsbRawFillInterruptRequest(g_acm->notifyReq, g_acm->devHandle, &fillRequestData);
1718 EXPECT_EQ(HDF_SUCCESS, ret);
1719 }
1720
1721 /**
1722 * @tc.number : CheckRawSdkIfFillInterruptRequest002
1723 * @tc.name :
1724 * @tc.type : PERFs
1725 * @tc.level : Level 1
1726 */
1727 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillInterruptRequest002, TestSize.Level1)
1728 {
1729 struct UsbRawFillRequestData fillRequestData;
1730 int32_t ret;
1731 uint32_t size = g_acm->notifyEp->maxPacketSize;
1732
1733 fillRequestData.endPoint = g_acm->notifyEp->addr;
1734 fillRequestData.length = size;
1735 fillRequestData.numIsoPackets = 0;
1736 fillRequestData.callback = AcmNotifyReqCallback;
1737 fillRequestData.userData = (void *)g_acm;
1738 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1739
1740 ret = UsbRawFillInterruptRequest(NULL, g_acm->devHandle, &fillRequestData);
1741 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1742 }
1743
1744 /**
1745 * @tc.number : CheckRawSdkIfFillInterruptRequest003
1746 * @tc.name :
1747 * @tc.type : PERFs
1748 * @tc.level : Level 1
1749 */
1750 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillInterruptRequest003, TestSize.Level1)
1751 {
1752 struct UsbRawFillRequestData fillRequestData;
1753 int32_t ret;
1754 uint32_t size = g_acm->notifyEp->maxPacketSize;
1755
1756 fillRequestData.endPoint = g_acm->notifyEp->addr;
1757 fillRequestData.length = size;
1758 fillRequestData.numIsoPackets = 0;
1759 fillRequestData.callback = AcmNotifyReqCallback;
1760 fillRequestData.userData = (void *)g_acm;
1761 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1762
1763 ret = UsbRawFillInterruptRequest(g_acm->notifyReq, NULL, &fillRequestData);
1764 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1765 }
1766
1767 /**
1768 * @tc.number : CheckRawSdkIfFillInterruptRequest004
1769 * @tc.name :
1770 * @tc.type : PERFs
1771 * @tc.level : Level 1
1772 */
1773 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillInterruptRequest004, TestSize.Level1)
1774 {
1775 struct UsbRawFillRequestData fillRequestData;
1776 int32_t ret;
1777 uint32_t size = g_acm->notifyEp->maxPacketSize;
1778
1779 fillRequestData.endPoint = g_acm->notifyEp->addr;
1780 fillRequestData.length = size;
1781 fillRequestData.numIsoPackets = 0;
1782 fillRequestData.callback = AcmNotifyReqCallback;
1783 fillRequestData.userData = (void *)g_acm;
1784 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1785
1786 ret = UsbRawFillInterruptRequest(g_acm->notifyReq, g_acm->devHandle, NULL);
1787 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1788 }
1789
1790 /**
1791 * @tc.number : CheckRawSdkIfFillControlRequest001
1792 * @tc.name :
1793 * @tc.type : PERFs
1794 * @tc.level : Level 1
1795 */
1796 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest001, TestSize.Level1)
1797 {
1798 struct UsbRawFillRequestData fillRequestData;
1799 int32_t ret;
1800 int32_t completed = 0;
1801
1802 fillRequestData.callback = AcmCtrlReqCallback;
1803 fillRequestData.userData = &completed;
1804 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1805
1806 ret = UsbRawFillControlRequest(g_acm->ctrlReq, g_acm->devHandle, &fillRequestData);
1807 EXPECT_EQ(HDF_SUCCESS, ret);
1808 }
1809
1810 /**
1811 * @tc.number : CheckRawSdkIfFillControlRequest002
1812 * @tc.name :
1813 * @tc.type : PERFs
1814 * @tc.level : Level 1
1815 */
1816 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest002, TestSize.Level1)
1817 {
1818 struct UsbRawFillRequestData fillRequestData;
1819 int32_t ret;
1820 int32_t completed = 0;
1821
1822 fillRequestData.callback = AcmCtrlReqCallback;
1823 fillRequestData.userData = &completed;
1824 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1825
1826 ret = UsbRawFillControlRequest(NULL, g_acm->devHandle, &fillRequestData);
1827 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1828 }
1829
1830 /**
1831 * @tc.number : CheckRawSdkIfFillControlRequest003
1832 * @tc.name :
1833 * @tc.type : PERFs
1834 * @tc.level : Level 1
1835 */
1836 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest003, TestSize.Level1)
1837 {
1838 struct UsbRawFillRequestData fillRequestData;
1839 int32_t ret;
1840 int32_t completed = 0;
1841
1842 fillRequestData.callback = AcmCtrlReqCallback;
1843 fillRequestData.userData = &completed;
1844 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1845
1846 ret = UsbRawFillControlRequest(g_acm->ctrlReq, NULL, &fillRequestData);
1847 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1848 }
1849
1850 /**
1851 * @tc.number : CheckRawSdkIfFillControlRequest004
1852 * @tc.name :
1853 * @tc.type : PERFs
1854 * @tc.level : Level 1
1855 */
1856 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest004, TestSize.Level1)
1857 {
1858 struct UsbRawFillRequestData fillRequestData;
1859 int32_t ret;
1860 int32_t completed = 0;
1861
1862 fillRequestData.callback = AcmCtrlReqCallback;
1863 fillRequestData.userData = &completed;
1864 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1865
1866 ret = UsbRawFillControlRequest(g_acm->ctrlReq, g_acm->devHandle, NULL);
1867 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1868 }
1869
1870 /**
1871 * @tc.number : CheckRawSdkIfFillControlRequest005
1872 * @tc.name :
1873 * @tc.type : PERFs
1874 * @tc.level : Level 1
1875 */
1876 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest005, TestSize.Level1)
1877 {
1878 struct UsbRawFillRequestData fillRequestData;
1879 int32_t ret;
1880 int32_t completed = 0;
1881
1882 fillRequestData.callback = AcmCtrlReqCallback;
1883 fillRequestData.userData = &completed;
1884 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1885
1886 ret = UsbRawFillControlRequest(NULL, g_acm->devHandle, NULL);
1887 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1888 }
1889
1890 /**
1891 * @tc.number : CheckRawSdkIfFillControlRequest006
1892 * @tc.name :
1893 * @tc.type : PERFs
1894 * @tc.level : Level 1
1895 */
1896 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest006, TestSize.Level1)
1897 {
1898 struct UsbRawFillRequestData fillRequestData;
1899 int32_t ret;
1900 int32_t completed = 0;
1901
1902 fillRequestData.callback = AcmCtrlReqCallback;
1903 fillRequestData.userData = &completed;
1904 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1905
1906 ret = UsbRawFillControlRequest(g_acm->ctrlReq, NULL, NULL);
1907 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1908 }
1909
1910 /**
1911 * @tc.number : CheckRawSdkIfFillControlRequest007
1912 * @tc.name :
1913 * @tc.type : PERFs
1914 * @tc.level : Level 1
1915 */
1916 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest007, TestSize.Level1)
1917 {
1918 struct UsbRawFillRequestData fillRequestData;
1919 int32_t ret;
1920 int32_t completed = 0;
1921
1922 fillRequestData.callback = AcmCtrlReqCallback;
1923 fillRequestData.userData = &completed;
1924 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1925
1926 ret = UsbRawFillControlRequest(NULL, NULL, NULL);
1927 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1928 }
1929
1930 /**
1931 * @tc.number : CheckRawSdkIfFillControlRequest008
1932 * @tc.name :
1933 * @tc.type : PERFs
1934 * @tc.level : Level 1
1935 */
1936 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlRequest008, TestSize.Level1)
1937 {
1938 struct UsbRawFillRequestData fillRequestData;
1939 int32_t ret;
1940 int32_t completed = 0;
1941
1942 fillRequestData.callback = AcmCtrlReqCallback;
1943 fillRequestData.userData = &completed;
1944 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
1945
1946 ret = UsbRawFillControlRequest(NULL, NULL, &fillRequestData);
1947 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1948 }
1949
1950 /**
1951 * @tc.number : CheckRawSdkIfFillIsoRequest001
1952 * @tc.name :
1953 * @tc.type : PERFs
1954 * @tc.level : Level 1
1955 */
1956 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillIsoRequest001, TestSize.Level1) {}
1957
1958 /**
1959 * @tc.number : CheckRawSdkIfFillControlSetup001
1960 * @tc.name :
1961 * @tc.type : PERFs
1962 * @tc.level : Level 1
1963 */
1964 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlSetup001, TestSize.Level1)
1965 {
1966 struct UsbControlRequestData ctrlReq;
1967 int32_t ret;
1968
1969 g_acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
1970 g_acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
1971 g_acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
1972 g_acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
1973
1974 ctrlReq.requestType = USB_DDK_DIR_OUT | USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE;
1975 ctrlReq.requestCmd = USB_DDK_CDC_REQ_SET_LINE_CODING;
1976 ctrlReq.value = CPU_TO_LE16(0);
1977 ctrlReq.index = 0;
1978 ctrlReq.data = (unsigned char *)&g_acm->lineCoding;
1979 ctrlReq.length = sizeof(struct UsbCdcLineCoding);
1980 ctrlReq.timeout = USB_CTRL_SET_TIMEOUT;
1981
1982 ret = UsbRawFillControlSetup(NULL, &ctrlReq);
1983 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1984 }
1985
1986 /**
1987 * @tc.number : CheckRawSdkIfFillControlSetup002
1988 * @tc.name :
1989 * @tc.type : PERFs
1990 * @tc.level : Level 1
1991 */
1992 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlSetup002, TestSize.Level1)
1993 {
1994 unsigned char setup[100] = {0};
1995 int32_t ret;
1996
1997 ret = UsbRawFillControlSetup(setup, NULL);
1998 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
1999 }
2000
2001 /**
2002 * @tc.number : CheckRawSdkIfFillControlSetup003
2003 * @tc.name :
2004 * @tc.type : PERFs
2005 * @tc.level : Level 1
2006 */
2007 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlSetup003, TestSize.Level1)
2008 {
2009 int32_t ret;
2010
2011 ret = UsbRawFillControlSetup(NULL, NULL);
2012 EXPECT_EQ(HDF_ERR_INVALID_PARAM, ret);
2013 }
2014
2015 /**
2016 * @tc.number : CheckRawSdkIfFillControlSetup004
2017 * @tc.name :
2018 * @tc.type : PERFs
2019 * @tc.level : Level 1
2020 */
2021 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillControlSetup004, TestSize.Level1)
2022 {
2023 struct UsbControlRequestData ctrlReq;
2024 unsigned char setup[100] = {0};
2025 int32_t ret;
2026
2027 g_acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
2028 g_acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
2029 g_acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
2030 g_acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
2031
2032 ctrlReq.requestType = USB_DDK_DIR_OUT | USB_DDK_TYPE_CLASS | USB_DDK_RECIP_INTERFACE;
2033 ctrlReq.requestCmd = USB_DDK_CDC_REQ_SET_LINE_CODING;
2034 ctrlReq.value = CPU_TO_LE16(0);
2035 ctrlReq.index = 0;
2036 ctrlReq.data = (unsigned char *)&g_acm->lineCoding;
2037 ctrlReq.length = sizeof(struct UsbCdcLineCoding);
2038 ctrlReq.timeout = USB_CTRL_SET_TIMEOUT;
2039
2040 ret = UsbRawFillControlSetup(setup, &ctrlReq);
2041 EXPECT_EQ(HDF_SUCCESS, ret);
2042 }
2043
2044 /**
2045 * @tc.number : CheckRawSdkIfFillBulkRequest004
2046 * @tc.name :
2047 * @tc.type : PERFs
2048 * @tc.level : Level 1
2049 */
2050 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillBulkRequest004, TestSize.Level1)
2051 {
2052 struct UsbRawFillRequestData reqData;
2053 int32_t ret;
2054 int32_t i;
2055 uint32_t size = g_acm->dataInEp->maxPacketSize;
2056
2057 for (i = 0; i < ACM_NW; i++) {
2058 reqData.endPoint = g_acm->dataInEp->addr;
2059 reqData.numIsoPackets = 0;
2060 reqData.callback = AcmReadBulkCallback;
2061 reqData.userData = (void *)g_acm;
2062 reqData.timeout = USB_CTRL_SET_TIMEOUT;
2063 reqData.length = size;
2064
2065 ret = UsbRawFillBulkRequest(g_acm->readReq[i], g_acm->devHandle, &reqData);
2066 EXPECT_EQ(HDF_SUCCESS, ret);
2067 }
2068 }
2069
2070 /**
2071 * @tc.number : CheckRawSdkIfFillInterruptRequest005
2072 * @tc.name :
2073 * @tc.type : PERFs
2074 * @tc.level : Level 1
2075 */
2076 HWTEST_F(UsbRawSdkIfTest, CheckRawSdkIfFillInterruptRequest005, TestSize.Level1)
2077 {
2078 struct UsbRawFillRequestData fillRequestData;
2079 int32_t ret;
2080 uint32_t size = g_acm->notifyEp->maxPacketSize;
2081
2082 fillRequestData.endPoint = g_acm->notifyEp->addr;
2083 fillRequestData.length = size;
2084 fillRequestData.numIsoPackets = 0;
2085 fillRequestData.callback = AcmNotifyReqCallback;
2086 fillRequestData.userData = (void *)g_acm;
2087 fillRequestData.timeout = USB_CTRL_SET_TIMEOUT;
2088
2089 ret = UsbRawFillInterruptRequest(g_acm->notifyReq, g_acm->devHandle, &fillRequestData);
2090 EXPECT_EQ(HDF_SUCCESS, ret);
2091 }
2092
2093 } // namespace
2094