1 /*
2 * Copyright (c) 2021 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 "usb_host_serial_func_test.h"
17 #include <cstdio>
18 #include <cstring>
19 #include <gtest/gtest.h>
20 #include <unistd.h>
21 #include "securec.h"
22 #include "usbhost_ddk_test.h"
23
24 using namespace std;
25 using namespace testing::ext;
26
27 namespace {
28
29 class UsbHostSerialFuncTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 };
34
SetUpTestCase()35 void UsbHostSerialFuncTest::SetUpTestCase()
36 {
37 printf("------start UsbHostSerialFuncTest------\n");
38 const char *apiType = "-SDK";
39 UsbHostDdkTestInit(const_cast<char*>(apiType));
40 }
41
TearDownTestCase()42 void UsbHostSerialFuncTest::TearDownTestCase()
43 {
44 const char *apiType = "-SDK";
45 UsbHostDdkTestInit(const_cast<char*>(apiType));
46 char writeBuf[] = "q";
47 UsbHostDdkTestOpen(HOST_ACM_ASYNC_WRITE);
48 UsbHostDdkTestAsyncWrite(writeBuf);
49 UsbHostDdkTestClose(HOST_ACM_ASYNC_WRITE);
50 TestExit();
51 printf("------end UsbHostSerialFuncTest------\n");
52 }
53
54 /**
55 * @tc.number : H_Lx_H_Sub_usb_IOread_write_001,H_Lx_H_Sub_usb_IOread_write_003
56 * @tc.name : USB串口同步数据读写
57 * @tc.size : MEDIUM
58 * @tc.type : FUNC
59 * @tc.level : Level 1
60 */
61 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadSync_001, TestSize.Level1)
62 {
63 printf("------start UsbSerialReadSync_001------\n");
64 char writeBuf[DATA_MAX_LEN] = "abc";
65 char readBuf[DATA_MAX_LEN] = {0};
66 UsbHostDdkTestOpen(HOST_ACM_SYNC_WRITE);
67 UsbHostDdkTestSyncWrite(writeBuf);
68 UsbHostDdkTestClose(HOST_ACM_SYNC_WRITE);
69 UsbHostDdkTestOpen(HOST_ACM_SYNC_READ);
70 UsbHostDdkTestSyncRead(readBuf);
71 UsbHostDdkTestClose(HOST_ACM_SYNC_READ);
72 EXPECT_EQ(strcmp(writeBuf, readBuf), 0);
73 printf("------end UsbSerialReadSync_001------\n");
74 }
75
76 /**
77 * @tc.number : H_Lx_H_Sub_usb_IOread_write_001,H_Lx_H_Sub_usb_IOread_write_006
78 * @tc.name : USB串口同步读+异步写
79 * @tc.size : MEDIUM
80 * @tc.type : FUNC
81 * @tc.level : Level 1
82 */
83 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadSync_002, TestSize.Level1)
84 {
85 printf("------start UsbSerialReadSync_002------\n");
86 char writeBuf[DATA_MAX_LEN] = "abc";
87 char readBuf[DATA_MAX_LEN] = {0};
88 UsbHostDdkTestOpen(HOST_ACM_ASYNC_WRITE);
89 UsbHostDdkTestAsyncWrite(writeBuf);
90 UsbHostDdkTestClose(HOST_ACM_ASYNC_WRITE);
91 UsbHostDdkTestOpen(HOST_ACM_SYNC_READ);
92 UsbHostDdkTestSyncRead(readBuf);
93 UsbHostDdkTestClose(HOST_ACM_SYNC_READ);
94 EXPECT_EQ(strcmp(writeBuf, readBuf), 0);
95 printf("------end UsbSerialReadSync_002------\n");
96 }
97
98 /**
99 * @tc.number : H_Lx_H_Sub_usb_IOread_write_001,H_Lx_H_Sub_usb_IOread_write_003
100 * @tc.name : USB串口同步数据读写
101 * @tc.size : MEDIUM
102 * @tc.type : FUNC
103 * @tc.level : Level 1
104 */
105 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadSync_003, TestSize.Level1)
106 {
107 printf("------start UsbSerialReadSync_003------\n");
108 const char *data[] = {
109 "0123456789",
110 "Z",
111 "0!a@1#b$2%c^3&D*4(E)5-F_",
112 ""
113 };
114 char readBuf[DATA_MAX_LEN] = {0};
115 for (int32_t i = 0; strlen(data[i]) > 0; i++) {
116 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
117 UsbHostDdkTestOpen(HOST_ACM_SYNC_WRITE);
118 UsbHostDdkTestSyncWrite(const_cast<char *>(data[i]));
119 UsbHostDdkTestClose(HOST_ACM_SYNC_WRITE);
120 UsbHostDdkTestOpen(HOST_ACM_SYNC_READ);
121 UsbHostDdkTestSyncRead(readBuf);
122 UsbHostDdkTestClose(HOST_ACM_SYNC_READ);
123 EXPECT_EQ(strcmp(const_cast<char *>(data[i]), readBuf), 0);
124 }
125 printf("------end UsbSerialReadSync_003------\n");
126 }
127
128 /**
129 * @tc.number : H_Lx_H_Sub_usb_IOread_write_001,H_Lx_H_Sub_usb_IOread_write_006
130 * @tc.name : USB串口同步读+异步写
131 * @tc.size : MEDIUM
132 * @tc.type : FUNC
133 * @tc.level : Level 1
134 */
135 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadSync_004, TestSize.Level1)
136 {
137 printf("------start UsbSerialReadSync_004------\n");
138 const char *data[] = {
139 "0123456789",
140 "Z",
141 "0!a@1#b$2%c^3&D*4(E)5-F_",
142 ""
143 };
144 char readBuf[DATA_MAX_LEN] = {0};
145 for (int32_t i = 0; strlen(data[i]) > 0; i++) {
146 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
147 UsbHostDdkTestOpen(HOST_ACM_ASYNC_WRITE);
148 UsbHostDdkTestAsyncWrite(const_cast<char *>(data[i]));
149 UsbHostDdkTestClose(HOST_ACM_ASYNC_WRITE);
150 UsbHostDdkTestOpen(HOST_ACM_SYNC_READ);
151 UsbHostDdkTestSyncRead(readBuf);
152 UsbHostDdkTestClose(HOST_ACM_SYNC_READ);
153 EXPECT_EQ(strcmp(const_cast<char *>(data[i]), readBuf), 0);
154 }
155 printf("------end UsbSerialReadSync_004------\n");
156 }
157
158 /**
159 * @tc.number : H_Lx_H_Sub_usb_IOread_write_001,H_Lx_H_Sub_usb_IOread_write_003
160 * @tc.name : USB串口同步读写1KB数据
161 * @tc.size : MEDIUM
162 * @tc.type : FUNC
163 * @tc.level : Level 2
164 */
165 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadSync_005, TestSize.Level2)
166 {
167 printf("------start UsbSerialReadSync_005------\n");
168 const string s = "0123456789abcdef";
169 string data;
170 int32_t totalSize = 1024;
171 int32_t writeCnt = 8;
172 unsigned int n = 0;
173 while (n < totalSize / writeCnt / s.size()) {
174 data += s;
175 n++;
176 }
177 char readBuf[DATA_MAX_LEN] = {0};
178 char writeBuf[DATA_MAX_LEN] = {0};
179 strcpy_s(writeBuf, sizeof(writeBuf), data.c_str());
180 for (int32_t i = 0; i < writeCnt; i++) {
181 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
182 UsbHostDdkTestOpen(HOST_ACM_SYNC_WRITE);
183 UsbHostDdkTestSyncWrite(writeBuf);
184 UsbHostDdkTestClose(HOST_ACM_SYNC_WRITE);
185 UsbHostDdkTestOpen(HOST_ACM_SYNC_READ);
186 UsbHostDdkTestSyncRead(readBuf);
187 UsbHostDdkTestClose(HOST_ACM_SYNC_READ);
188 EXPECT_EQ(strcmp(writeBuf, readBuf), 0);
189 }
190 printf("------end UsbSerialReadSync_005------\n");
191 }
192
193 extern "C" {
TestAsyncRead(char * readBuf,int32_t timeout)194 static void TestAsyncRead(char *readBuf, int32_t timeout)
195 {
196 printf("------TestAsyncRead start-----\n");
197 if (strlen(readBuf) > 0) {
198 memset_s(readBuf, strlen(readBuf), 0, strlen(readBuf));
199 }
200 timeout = timeout * 1000;
201 UsbHostDdkTestOpen(HOST_ACM_ASYNC_READ);
202 while (timeout-- > 0) {
203 UsbHostDdkTestAsyncRead(readBuf);
204 if (strlen(readBuf) > 0) {
205 break;
206 }
207 usleep(1000);
208 }
209 printf("------TestAsyncRead end-----");
210 }
211 }
212
213 /**
214 * @tc.number : H_Lx_H_Sub_usb_IOread_write_005, H_Lx_H_Sub_usb_IOread_write_006
215 * @tc.name : USB串口异步数据读写
216 * @tc.size : MEDIUM
217 * @tc.type : FUNC
218 * @tc.level : Level 1
219 */
220 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadAsync_001, TestSize.Level1)
221 {
222 printf("------start UsbSerialReadAsync_001------\n");
223 char writeBuf[DATA_MAX_LEN] = "abc";
224 char readBuf[DATA_MAX_LEN] = {0};
225 UsbHostDdkTestOpen(HOST_ACM_ASYNC_WRITE);
226 UsbHostDdkTestAsyncWrite(writeBuf);
227 UsbHostDdkTestClose(HOST_ACM_ASYNC_WRITE);
228 TestAsyncRead(readBuf, 5);
229 EXPECT_EQ(strcmp(writeBuf, readBuf), 0);
230 printf("------end UsbSerialReadAsync_001------\n");
231 }
232
233 /**
234 * @tc.number : H_Lx_H_Sub_usb_IOread_write_005, H_Lx_H_Sub_usb_IOread_write_003
235 * @tc.name : USB串口异步读+同步写
236 * @tc.size : MEDIUM
237 * @tc.type : FUNC
238 * @tc.level : Level 1
239 */
240 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadAsync_002, TestSize.Level1)
241 {
242 printf("------start UsbSerialReadAsync_002------\n");
243 char writeBuf[DATA_MAX_LEN] = "abc";
244 char readBuf[DATA_MAX_LEN] = {0};
245 UsbHostDdkTestOpen(HOST_ACM_SYNC_WRITE);
246 UsbHostDdkTestSyncWrite(writeBuf);
247 UsbHostDdkTestClose(HOST_ACM_SYNC_WRITE);
248 TestAsyncRead(readBuf, 5);
249 EXPECT_EQ(strcmp(writeBuf, readBuf), 0);
250 printf("------end UsbSerialReadAsync_002------\n");
251 }
252
253 /**
254 * @tc.number : H_Lx_H_Sub_usb_IOread_write_005, H_Lx_H_Sub_usb_IOread_write_006
255 * @tc.name : USB串口异步数据读写
256 * @tc.size : MEDIUM
257 * @tc.type : FUNC
258 * @tc.level : Level 1
259 */
260 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadAsync_003, TestSize.Level1)
261 {
262 printf("------start UsbSerialReadAsync_003------\n");
263 const char *data[] = {
264 "0123456789",
265 "Z",
266 "0!a@1#b$2%c^3&D*4(E)5-F_",
267 ""
268 };
269 char readBuf[DATA_MAX_LEN] = {0};
270 for (int32_t i = 0; strlen(data[i]) > 0; i++) {
271 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
272 UsbHostDdkTestOpen(HOST_ACM_ASYNC_WRITE);
273 UsbHostDdkTestAsyncWrite(const_cast<char *>(data[i]));
274 UsbHostDdkTestClose(HOST_ACM_ASYNC_WRITE);
275 TestAsyncRead(readBuf, 5);
276 EXPECT_EQ(strcmp(const_cast<char *>(data[i]), readBuf), 0);
277 }
278 printf("------end UsbSerialReadAsync_003------\n");
279 }
280
281 /**
282 * @tc.number : H_Lx_H_Sub_usb_IOread_write_005, H_Lx_H_Sub_usb_IOread_write_003
283 * @tc.name : USB串口异步读+同步写
284 * @tc.size : MEDIUM
285 * @tc.type : FUNC
286 * @tc.level : Level 1
287 */
288 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadAsync_004, TestSize.Level1)
289 {
290 printf("------start UsbSerialReadAsync_004------\n");
291 const char *data[] = {
292 "0123456789",
293 "Z",
294 "0!a@1#b$2%c^3&D*4(E)5-F_",
295 ""
296 };
297 char readBuf[DATA_MAX_LEN] = {0};
298 for (int32_t i = 0; strlen(data[i]) > 0; i++) {
299 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
300 UsbHostDdkTestOpen(HOST_ACM_SYNC_WRITE);
301 UsbHostDdkTestSyncWrite(const_cast<char *>(data[i]));
302 UsbHostDdkTestClose(HOST_ACM_SYNC_WRITE);
303 TestAsyncRead(readBuf, 5);
304 EXPECT_EQ(strcmp(const_cast<char *>(data[i]), readBuf), 0);
305 }
306 printf("------end UsbSerialReadAsync_004------\n");
307 }
308
309 /**
310 * @tc.number : H_Lx_H_Sub_usb_IOread_write_005, H_Lx_H_Sub_usb_IOread_write_006
311 * @tc.name : USB串口异步读写1KB数据
312 * @tc.size : MEDIUM
313 * @tc.type : FUNC
314 * @tc.level : Level 2
315 */
316 HWTEST_F(UsbHostSerialFuncTest, UsbSerialReadAsync_005, TestSize.Level2)
317 {
318 printf("------start UsbSerialReadAsync_005------\n");
319 const string s = "0123456789abcdef";
320 string data;
321 unsigned int totalSize = 1024;
322 unsigned int writeCnt = 8;
323 unsigned int n = 0;
324 while (n < totalSize / writeCnt / s.size()) {
325 data += s;
326 n++;
327 }
328 char readBuf[DATA_MAX_LEN] = {0};
329 char writeBuf[DATA_MAX_LEN] = {0};
330 strcpy_s(writeBuf, sizeof(writeBuf), data.c_str());
331 for (unsigned int i = 0; i < writeCnt; i++) {
332 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
333 UsbHostDdkTestOpen(HOST_ACM_ASYNC_WRITE);
334 UsbHostDdkTestAsyncWrite(writeBuf);
335 UsbHostDdkTestClose(HOST_ACM_ASYNC_WRITE);
336 TestAsyncRead(readBuf, 5);
337 EXPECT_EQ(strcmp(writeBuf, readBuf), 0);
338 }
339 printf("------end UsbSerialReadAsync_005------\n");
340 }
341
342 /**
343 * @tc.number : H_Lx_H_Sub_usb_Control_001
344 * @tc.name : USB串口标准控制命令的同步处理
345 * @tc.size : MEDIUM
346 * @tc.type : FUNC
347 * @tc.level : Level 1
348 */
349 HWTEST_F(UsbHostSerialFuncTest, UsbSerialStdCtrlCmdSync_001, TestSize.Level1)
350 {
351 printf("------start UsbSerialStdCtrlCmdSync_001------\n");
352 char readBuf[DATA_MAX_LEN] = {0};
353 UsbHostDdkTestOpen(HOST_ACM_CTRL_SYNC_DESCRIPTOR);
354 UsbHostDdkTestStdGetDes(readBuf);
355 UsbHostDdkTestClose(HOST_ACM_CTRL_SYNC_DESCRIPTOR);
356 EXPECT_NE(strlen(readBuf), 0);
357 printf("------end UsbSerialStdCtrlCmdSync_001------\n");
358 }
359
360 /**
361 * @tc.number : H_Lx_H_Sub_usb_Control_001
362 * @tc.name : USB串口标准控制命令的同步处理
363 * @tc.size : MEDIUM
364 * @tc.type : FUNC
365 * @tc.level : Level 1
366 */
367 HWTEST_F(UsbHostSerialFuncTest, UsbSerialStdCtrlCmdSync_002, TestSize.Level1)
368 {
369 printf("------start UsbSerialStdCtrlCmdSync_002------\n");
370 char readBuf[DATA_MAX_LEN] = {0};
371 UsbHostDdkTestOpen(HOST_ACM_CTRL_GET_STATUS);
372 UsbHostDdkTestStdGetStatus(readBuf);
373 UsbHostDdkTestClose(HOST_ACM_CTRL_GET_STATUS);
374 EXPECT_NE(strlen(readBuf), 0);
375 printf("------end UsbSerialStdCtrlCmdSync_002------\n");
376 }
377
378
379 /**
380 * @tc.number : H_Lx_H_Sub_usb_Control_001
381 * @tc.name : USB串口标准控制命令的同步处理
382 * @tc.size : MEDIUM
383 * @tc.type : FUNC
384 * @tc.level : Level 2
385 */
386 HWTEST_F(UsbHostSerialFuncTest, UsbSerialStdCtrlCmdSync_003, TestSize.Level2)
387 {
388 printf("------start UsbSerialStdCtrlCmdSync_003------\n");
389 char readBuf[DATA_MAX_LEN] = {0};
390 for (int32_t i=0; i < TEST_COUNT; i++) {
391 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
392 UsbHostDdkTestOpen(HOST_ACM_CTRL_SYNC_DESCRIPTOR);
393 UsbHostDdkTestStdGetDes(readBuf);
394 UsbHostDdkTestClose(HOST_ACM_CTRL_SYNC_DESCRIPTOR);
395 EXPECT_NE(strlen(readBuf), 0);
396 }
397 printf("------end UsbSerialStdCtrlCmdSync_003------\n");
398 }
399
400 /**
401 * @tc.number : H_Lx_H_Sub_usb_Control_002
402 * @tc.name : USB串口类控制命令的同步处理
403 * @tc.size : MEDIUM
404 * @tc.type : FUNC
405 * @tc.level : Level 1
406 */
407 HWTEST_F(UsbHostSerialFuncTest, UsbSerialClsCtrlCmdSync_001, TestSize.Level1)
408 {
409 printf("------start UsbSerialClsCtrlCmdSync_001------\n");
410 char readBuf[DATA_MAX_LEN] = {0};
411 UsbHostDdkTestOpen(HOST_ACM_CTRL_CLASS_SYNC);
412 UsbHostDdkTestCtrlClass(readBuf);
413 UsbHostDdkTestClose(HOST_ACM_CTRL_CLASS_SYNC);
414 EXPECT_NE(strlen(readBuf), 0);
415 printf("------end UsbSerialClsCtrlCmdSync_001------\n");
416 }
417
418 /**
419 * @tc.number : H_Lx_H_Sub_usb_Control_002
420 * @tc.name : USB串口类控制命令的同步处理
421 * @tc.size : MEDIUM
422 * @tc.type : FUNC
423 * @tc.level : Level 2
424 */
425 HWTEST_F(UsbHostSerialFuncTest, UsbSerialClsCtrlCmdSync_002, TestSize.Level2)
426 {
427 printf("------start UsbSerialClsCtrlCmdSync_002------\n");
428 char readBuf[DATA_MAX_LEN] = {0};
429 for (int32_t i = 0; i < TEST_COUNT; i++) {
430 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
431 UsbHostDdkTestOpen(HOST_ACM_CTRL_CLASS_SYNC);
432 UsbHostDdkTestCtrlClass(readBuf);
433 UsbHostDdkTestClose(HOST_ACM_CTRL_CLASS_SYNC);
434 EXPECT_NE(strlen(readBuf), 0);
435 }
436 printf("------end UsbSerialClsCtrlCmdSync_002------\n");
437 }
438
439 /**
440 * @tc.number : H_Lx_H_Sub_usb_Control_004, H_Lx_H_Sub_usb_Control_005, H_Lx_H_Sub_usb_Control_006
441 * @tc.name : USB串口控制命令的异步处理
442 * @tc.size : MEDIUM
443 * @tc.type : FUNC
444 * @tc.level : Level 1
445 */
446 HWTEST_F(UsbHostSerialFuncTest, UsbSerialCtrlCmdAsync_001, TestSize.Level1)
447 {
448 printf("------start UsbSerialCtrlCmdAsync_001------\n");
449 char readBuf[DATA_MAX_LEN] = {0};
450 UsbHostDdkTestOpen(HOST_ACM_CTRL_ASYNC_DESCRIPTOR);
451 UsbHostDdkTestStdGetDesAsync(readBuf);
452 UsbHostDdkTestClose(HOST_ACM_CTRL_ASYNC_DESCRIPTOR);
453 printf("readBuf==>%s\n", readBuf);
454 EXPECT_NE(strlen(readBuf), 0);
455 printf("------end UsbSerialCtrlCmdAsync_001------\n");
456 }
457
458 /**
459 * @tc.number : H_Lx_H_Sub_usb_Control_004, H_Lx_H_Sub_usb_Control_005, H_Lx_H_Sub_usb_Control_006
460 * @tc.name : USB串口控制命令的异步处理
461 * @tc.size : MEDIUM
462 * @tc.type : FUNC
463 * @tc.level : Level 2
464 */
465 HWTEST_F(UsbHostSerialFuncTest, UsbSerialCtrlCmdAsync_002, TestSize.Level2)
466 {
467 printf("------start UsbSerialCtrlCmdAsync_002------\n");
468 char readBuf[DATA_MAX_LEN] = {0};
469 for (int32_t i = 0; i < TEST_COUNT; i++) {
470 memset_s(readBuf, sizeof(readBuf), 0, sizeof(readBuf));
471 UsbHostDdkTestOpen(HOST_ACM_CTRL_ASYNC_DESCRIPTOR);
472 UsbHostDdkTestStdGetDesAsync(readBuf);
473 UsbHostDdkTestClose(HOST_ACM_CTRL_ASYNC_DESCRIPTOR);
474 printf("readBuf==>%s\n", readBuf);
475 EXPECT_NE(strlen(readBuf), 0);
476 }
477 printf("------end UsbSerialCtrlCmdAsync_002------\n");
478 }
479
480 /**
481 * @tc.number : H_Lx_D_Sub_usb_Instance_001, H_Lx_D_Sub_usb_Descriptor_002, H_Lx_D_Sub_usb_Descriptor_001
482 * @tc.name : 动态实例化USB串口设备, 支持通用属性可配置, 从HCS导入属性及默认值
483 * @tc.type : FUNC
484 * @tc.level : Level 1
485 */
486 HWTEST_F(UsbHostSerialFuncTest, UsbSerialGetDeviceInfo_001, TestSize.Level1)
487 {
488 printf("------start UsbSerialGetDeviceInfo_001------\n");
489 const char *idVendor = "0x12d1";
490 const char *idProduct = "0x5000";
491 const char *bDeviceClass = "0x00";
492 const char *bDeviceSubClass = "0x00";
493 const char *bDeviceProtocol = "0x00";
494 const int32_t logMaxLen = 256;
495 char targetLog[logMaxLen] = {0};
496 const char *fmt = "device descriptor info:[%s %s %s %s %s]\n";
497 if (snprintf_s(targetLog, logMaxLen, logMaxLen -1, fmt, \
498 idVendor, idProduct, bDeviceClass, bDeviceSubClass, bDeviceProtocol) < 0) {
499 printf("UsbSerialGetDeviceInfo_001 snprintf_s failed\n");
500 }
501 printf("targetLog==>%s-%d\n", targetLog, strlen(targetLog));
502 char readBuf[DATA_MAX_LEN] = {0};
503 UsbHostDdkTestOpen(HOST_ACM_CTRL_SYNC_DESCRIPTOR);
504 UsbHostDdkTestStdGetDes(readBuf);
505 UsbHostDdkTestClose(HOST_ACM_CTRL_SYNC_DESCRIPTOR);
506 printf("readBuf==>%s-%d\n", readBuf, strlen(readBuf));
507 EXPECT_EQ(strcmp(targetLog, readBuf), 0);
508 printf("------end UsbSerialGetDeviceInfo_001------\n");
509 }
510
511 /**
512 * @tc.number : add/remove interface
513 * @tc.name : add/remove interface
514 * @tc.size : MEDIUM
515 * @tc.type : FUNC
516 * @tc.level : Level 2
517 */
518 HWTEST_F(UsbHostSerialFuncTest, UsbSerialAddOrRemoveInterface_001, TestSize.Level2)
519 {
520 printf("------start UsbSerialAddOrRemoveInterface_001------\n");
521 const char *ecmApiType = "-ECM";
522 const char *acmApiType = "-SDK";
523 TestExit();
524 UsbHostDdkTestInit(const_cast<char*>(ecmApiType));
525 int32_t acmInterface = 2;
526 UsbHostDdkTestOpen(HOST_ACM_REMOVE_INTERFACE);
527 UsbHostDdkTestRemoveInterface(acmInterface);
528 TestExit();
529 sleep(2);
530 int32_t status = 0;
531 status = UsbHostDdkTestInit(const_cast<char*>(acmApiType));
532 printf("acm init status=>%d\n", status);
533 EXPECT_NE(status, 0);
534 printf("------end UsbSerialAddOrRemoveInterface_001------\n");
535 }
536
537 /**
538 * @tc.number : add/remove interface
539 * @tc.name : add/remove interface
540 * @tc.size : MEDIUM
541 * @tc.type : FUNC
542 * @tc.level : Level 2
543 */
544 HWTEST_F(UsbHostSerialFuncTest, UsbSerialAddOrRemoveInterface_002, TestSize.Level2)
545 {
546 printf("------start UsbSerialAddOrRemoveInterface_002------\n");
547 const char *ecmApiType = "-ECM";
548 const char *acmApiType = "-SDK";
549 int32_t acmInterface = 2;
550 UsbHostDdkTestInit(const_cast<char*>(ecmApiType));
551 UsbHostDdkTestOpen(HOST_ACM_ADD_INTERFACE);
552 UsbHostDdkTestAddInterface(acmInterface);
553 TestExit();
554 sleep(2);
555 int32_t status = 0;
556 status = UsbHostDdkTestInit(const_cast<char*>(acmApiType));
557 printf("acm init status=>%d\n", status);
558 EXPECT_EQ(status, 0);
559 TestExit();
560 printf("------end UsbSerialAddOrRemoveInterface_002------\n");
561 }
562
563 /**
564 * @tc.number : add/remove interface
565 * @tc.name : add/remove interface
566 * @tc.size : MEDIUM
567 * @tc.type : FUNC
568 * @tc.level : Level 2
569 */
570 HWTEST_F(UsbHostSerialFuncTest, UsbSerialAddOrRemoveInterface_003, TestSize.Level2)
571 {
572 printf("------start UsbSerialAddOrRemoveInterface_003------\n");
573 const char *ecmApiType = "-ECM";
574 const char *acmApiType = "-SDK";
575 int32_t acmInterface = 3;
576 UsbHostDdkTestInit(const_cast<char*>(ecmApiType));
577 UsbHostDdkTestOpen(HOST_ACM_REMOVE_INTERFACE);
578 UsbHostDdkTestRemoveInterface(acmInterface);
579 TestExit();
580 sleep(2);
581 int32_t status = 0;
582 status = UsbHostDdkTestInit(const_cast<char*>(acmApiType));
583 printf("acm init status=>%d\n", status);
584 EXPECT_NE(status, 0);
585 printf("------end UsbSerialAddOrRemoveInterface_003------\n");
586 }
587
588 /**
589 * @tc.number : add/remove interface
590 * @tc.name : add/remove interface
591 * @tc.size : MEDIUM
592 * @tc.type : FUNC
593 * @tc.level : Level 2
594 */
595 HWTEST_F(UsbHostSerialFuncTest, UsbSerialAddOrRemoveInterface_004, TestSize.Level2)
596 {
597 printf("------start UsbSerialAddOrRemoveInterface_004------\n");
598 const char *ecmApiType = "-ECM";
599 const char *acmApiType = "-SDK";
600 int32_t acmInterface = 3;
601 UsbHostDdkTestInit(const_cast<char*>(ecmApiType));
602 UsbHostDdkTestOpen(HOST_ACM_ADD_INTERFACE);
603 UsbHostDdkTestAddInterface(acmInterface);
604 TestExit();
605 sleep(2);
606 int32_t status = 0;
607 status = UsbHostDdkTestInit(const_cast<char*>(acmApiType));
608 printf("acm init status=>%d\n", status);
609 EXPECT_EQ(status, 0);
610 TestExit();
611 printf("------end UsbSerialAddOrRemoveInterface_004------\n");
612 }
613
614 /**
615 * @tc.number : add/remove interface
616 * @tc.name : add/remove interface
617 * @tc.size : MEDIUM
618 * @tc.type : FUNC
619 * @tc.level : Level 2
620 */
621 HWTEST_F(UsbHostSerialFuncTest, UsbSerialAddOrRemoveInterface_005, TestSize.Level2)
622 {
623 printf("------start UsbSerialAddOrRemoveInterface_005------\n");
624 const char *ecmApiType = "-ECM";
625 const char *acmApiType = "-SDK";
626 int32_t ecmInterface = 0;
627 UsbHostDdkTestInit(const_cast<char*>(acmApiType));
628 UsbHostDdkTestOpen(HOST_ACM_REMOVE_INTERFACE);
629 UsbHostDdkTestRemoveInterface(ecmInterface);
630 TestExit();
631 sleep(2);
632 int32_t status = 0;
633 status = UsbHostDdkTestInit(const_cast<char*>(ecmApiType));
634 printf("ecm init status=>%d\n", status);
635 EXPECT_NE(status, 0);
636 printf("------end UsbSerialAddOrRemoveInterface_005------\n");
637 }
638
639 /**
640 * @tc.number : add/remove interface
641 * @tc.name : add/remove interface
642 * @tc.size : MEDIUM
643 * @tc.type : FUNC
644 * @tc.level : Level 2
645 */
646 HWTEST_F(UsbHostSerialFuncTest, UsbSerialAddOrRemoveInterface_006, TestSize.Level2)
647 {
648 printf("------start UsbSerialAddOrRemoveInterface_006------\n");
649 const char *ecmApiType = "-ECM";
650 const char *acmApiType = "-SDK";
651 int32_t ecmInterface = 0;
652 UsbHostDdkTestInit(const_cast<char*>(acmApiType));
653 UsbHostDdkTestOpen(HOST_ACM_ADD_INTERFACE);
654 UsbHostDdkTestAddInterface(ecmInterface);
655 TestExit();
656 sleep(2);
657 int32_t status = 0;
658 status = UsbHostDdkTestInit(const_cast<char*>(ecmApiType));
659 printf("ecm init status=>%d\n", status);
660 EXPECT_EQ(status, 0);
661 printf("------end UsbSerialAddOrRemoveInterface_006------\n");
662 }
663 }
664