1 /*
2  * Copyright (c) 2024 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 "usbd_device_status_test.h"
17 
18 #include <iostream>
19 #include <vector>
20 
21 #include "UsbSubscriberTest.h"
22 #include "hdf_log.h"
23 #include "v1_1/iusb_interface.h"
24 
25 const int SLEEP_TIME = 3;
26 const uint8_t BUS_NUM_INVALID = 255;
27 const uint8_t DEV_ADDR_INVALID = 255;
28 const uint8_t INTERFACEID_OK = 1;
29 const uint8_t INTERFACEID_OK_NEW = 0;
30 const uint8_t INTERFACEID_INVALID = 255;
31 const uint8_t POINTID_DIR_IN = USB_ENDPOINT_DIR_IN | 2;
32 
33 using namespace testing::ext;
34 using namespace OHOS;
35 using namespace OHOS::USB;
36 using namespace std;
37 using namespace OHOS::HDI::Usb::V1_1;
38 namespace OHOS {
39 namespace USB {
40 UsbDev UsbdDeviceStatusTest::dev_ = {0, 0};
41 sptr<UsbSubscriberTest> UsbdDeviceStatusTest::subscriber_ = nullptr;
42 sptr<OHOS::HDI::Usb::V1_1::IUsbInterface> g_usbInterface = nullptr;
43 
SwitchErrCode(int32_t ret)44 int32_t SwitchErrCode(int32_t ret)
45 {
46     return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret;
47 }
48 
SetUpTestCase(void)49 void UsbdDeviceStatusTest::SetUpTestCase(void)
50 {
51     g_usbInterface = OHOS::HDI::Usb::V1_1::IUsbInterface::Get();
52     if (g_usbInterface == nullptr) {
53         HDF_LOGE("%{public}s:IUsbInterface::Get() failed.", __func__);
54         exit(0);
55     }
56     auto ret = g_usbInterface->SetPortRole(1, 1, 1);
57     sleep(SLEEP_TIME);
58     HDF_LOGI("UsbdDeviceStatusTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret);
59     ret = SwitchErrCode(ret);
60     ASSERT_EQ(0, ret);
61     if (ret != 0) {
62         exit(0);
63     }
64 
65     subscriber_ = new UsbSubscriberTest();
66     if (g_usbInterface->BindUsbdSubscriber(subscriber_) != HDF_SUCCESS) {
67         HDF_LOGE("%{public}s: bind usbd subscriber_ failed", __func__);
68         exit(0);
69     }
70 
71     std::cout << "please connect device, press enter to continue" << std::endl;
72     int c;
73     while ((c = getchar()) != '\n' && c != EOF) {}
74     dev_ = {subscriber_->busNum_, subscriber_->devAddr_};
75 
76     ret = g_usbInterface->OpenDevice(dev_);
77     HDF_LOGI("UsbdDeviceStatusTest::%{public}d OpenDevice=%{public}d", __LINE__, ret);
78     ASSERT_EQ(0, ret);
79 }
80 
TearDownTestCase(void)81 void UsbdDeviceStatusTest::TearDownTestCase(void)
82 {
83     g_usbInterface->UnbindUsbdSubscriber(subscriber_);
84     dev_ = {subscriber_->busNum_, subscriber_->devAddr_};
85     auto ret = g_usbInterface->CloseDevice(dev_);
86     HDF_LOGI("UsbdDeviceStatusTest::%{public}d Close=%{public}d", __LINE__, ret);
87     ASSERT_EQ(0, ret);
88 }
89 
SetUp(void)90 void UsbdDeviceStatusTest::SetUp(void) {}
91 
TearDown(void)92 void UsbdDeviceStatusTest::TearDown(void) {}
93 
94 /**
95  * @tc.name: SUB_USB_HostManager_HDI_Func_1000
96  * @tc.desc: Test functions to GetDeviceSpeed
97  * @tc.desc: int32_t  GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
98  * @tc.desc: Positive test: parameters correctly
99  * @tc.type: FUNC
100  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed001, Function | MediumTest | Level1)101 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed001, Function | MediumTest | Level1)
102 {
103     struct UsbDev dev = dev_;
104     int32_t ret = -1;
105     uint8_t speed = 0;
106     ret = g_usbInterface->GetDeviceSpeed(dev, speed);
107     HDF_LOGI("UsbdGetDeviceSpeed001 %{public}d GetDeviceSpeed=%{public}d, speed=%{public}d", __LINE__, ret, speed);
108     ASSERT_EQ(0, ret);
109 }
110 
111 /**
112  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8000
113  * @tc.desc: Test functions to GetDeviceSpeed
114  * @tc.desc: int32_t  GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
115  * @tc.desc: Negative test: parameters exception, busNum error
116  * @tc.type: FUNC
117  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed002, Function | MediumTest | Level1)118 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed002, Function | MediumTest | Level1)
119 {
120     struct UsbDev dev = dev_;
121     dev.busNum = BUS_NUM_INVALID;
122     uint8_t speed = 0;
123     auto ret = g_usbInterface->GetDeviceSpeed(dev, speed);
124     HDF_LOGI("UsbdGetDeviceSpeed002 %{public}d ret=%{public}d, speed=%{public}d", __LINE__, ret, speed);
125     ASSERT_NE(ret, 0);
126 }
127 
128 
129 /**
130  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8100
131  * @tc.desc: Test functions to GetDeviceSpeed
132  * @tc.desc: int32_t  GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
133  * @tc.desc: Negative test: parameters exception, devAddr error
134  * @tc.type: FUNC
135  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed003, Function | MediumTest | Level1)136 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed003, Function | MediumTest | Level1)
137 {
138     struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID};
139     uint8_t speed = 0;
140     auto ret = g_usbInterface->GetDeviceSpeed(dev, speed);
141     HDF_LOGI("UsbdGetDeviceSpeed003 %{public}d, ret=%{public}d, speed=%{public}d", __LINE__, ret, speed);
142     ASSERT_NE(ret, 0);
143 }
144 
145 /**
146  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8200
147  * @tc.desc: Test functions to GetDeviceSpeed
148  * @tc.desc: int32_t  GetDeviceSpeed(const UsbDev &dev, uint8_t interfaceId, uint8_t speed);
149  * @tc.desc: Negative test: parameters exception, busNum && devAddr error
150  * @tc.type: FUNC
151  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed004, Function | MediumTest | Level1)152 HWTEST_F(UsbdDeviceStatusTest, UsbdGetDeviceSpeed004, Function | MediumTest | Level1)
153 {
154     uint8_t speed = 0;
155     struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID};
156     auto ret = g_usbInterface->GetDeviceSpeed(dev, speed);
157     HDF_LOGI("UsbdGetDeviceSpeed004 %{public}d, ret=%{public}d, speed=%{public}d", __LINE__, ret, speed);
158     ASSERT_NE(ret, 0);
159 }
160 
161 /**
162  * @tc.name: SUB_USB_HostManager_HDI_Func_1100
163  * @tc.desc: Test functions to GetInterfaceActiveStatus
164  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
165  * @tc.desc: Positive test: parameters correctly
166  * @tc.type: FUNC
167  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus001, Function | MediumTest | Level1)168 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus001, Function | MediumTest | Level1)
169 {
170     uint8_t interfaceId = INTERFACEID_OK_NEW;
171     struct UsbDev dev = dev_;
172     int32_t ret = -1;
173     bool unactived = 1;
174     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
175     HDF_LOGI("UsbdDeviceStatusTest::UsbdGetInterfaceActiveStatus %{public}d ClaimInterface=%{public}d", __LINE__, ret);
176     ASSERT_EQ(0, ret);
177     for (; interfaceId < INTERFACEID_INVALID; interfaceId++) {
178         ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
179         if (ret == 0) {
180             break;
181         }
182     }
183     HDF_LOGI("UsbdGetInterfaceActiveStatus001 %{public}d GetInterfaceActiveStatus=%{public}d, unactived=%{public}d",
184         __LINE__, ret, unactived);
185     ASSERT_EQ(0, ret);
186 }
187 
188 /**
189  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8300
190  * @tc.desc: Test functions to GetInterfaceActiveStatus
191  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
192  * @tc.desc: Negative test: parameters exception, busNum error
193  * @tc.type: FUNC
194  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus002, Function | MediumTest | Level1)195 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus002, Function | MediumTest | Level1)
196 {
197     uint8_t interfaceId = INTERFACEID_OK;
198     struct UsbDev dev = dev_;
199     dev.busNum = BUS_NUM_INVALID;
200     bool unactived = 1;
201     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
202     HDF_LOGI("UsbdGetInterfaceActiveStatus002 %{public}d ret=%{public}d, unactived=%{public}d",
203         __LINE__, ret, unactived);
204     ASSERT_NE(ret, 0);
205 }
206 
207 /**
208  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8400
209  * @tc.desc: Test functions to GetInterfaceActiveStatus
210  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
211  * @tc.desc: Negative test: parameters exception, devAddr error
212  * @tc.type: FUNC
213  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus003, Function | MediumTest | Level1)214 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus003, Function | MediumTest | Level1)
215 {
216     uint8_t interfaceId = INTERFACEID_OK;
217     struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID};
218     bool unactived = 1;
219     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
220     HDF_LOGI("UsbdGetInterfaceActiveStatus003 %{public}d, ret=%{public}d, unactived=%{public}d",
221         __LINE__, ret, unactived);
222     ASSERT_NE(ret, 0);
223 }
224 
225 /**
226  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8500
227  * @tc.desc: Test functions to GetInterfaceActiveStatus
228  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
229  * @tc.desc: Negative test: parameters exception, interfaceid error
230  * @tc.type: FUNC
231  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus004, Function | MediumTest | Level1)232 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus004, Function | MediumTest | Level1)
233 {
234     uint8_t interfaceId = INTERFACEID_OK;
235     struct UsbDev dev = dev_;
236     interfaceId = INTERFACEID_INVALID;
237     bool unactived = 1;
238     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
239     HDF_LOGI("UsbdGetInterfaceActiveStatus004 %{public}d, ret=%{public}d, unactived=%{public}d",
240         __LINE__, ret, unactived);
241     ASSERT_NE(ret, 0);
242 }
243 
244 /**
245  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8600
246  * @tc.desc: Test functions to GetInterfaceActiveStatus
247  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
248  * @tc.desc: Negative test: parameters exception, busNum && devAddr error
249  * @tc.type: FUNC
250  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus005, Function | MediumTest | Level1)251 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus005, Function | MediumTest | Level1)
252 {
253     uint8_t interfaceId = INTERFACEID_OK;
254     bool unactived = 1;
255     struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID};
256     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
257     HDF_LOGI("UsbdGetInterfaceActiveStatus005 %{public}d, ret=%{public}d, unactived=%{public}d",
258         __LINE__, ret, unactived);
259     ASSERT_NE(ret, 0);
260 }
261 
262 /**
263  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8700
264  * @tc.desc: Test functions to GetInterfaceActiveStatus
265  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
266  * @tc.desc: Negative test: parameters exception, busNum && interfaceid error
267  * @tc.type: FUNC
268  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus006, Function | MediumTest | Level1)269 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus006, Function | MediumTest | Level1)
270 {
271     uint8_t interfaceId = INTERFACEID_INVALID;
272     bool unactived = 1;
273     struct UsbDev dev = {BUS_NUM_INVALID, dev_.devAddr};
274     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
275     HDF_LOGI("UsbdGetInterfaceActiveStatus006 %{public}d, ret=%{public}d, unactived=%{public}d",
276         __LINE__, ret, unactived);
277     ASSERT_NE(ret, 0);
278 }
279 
280 /**
281  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8800
282  * @tc.desc: Test functions to GetInterfaceActiveStatus
283  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
284  * @tc.desc: Negative test: parameters exception, devAddr && interfaceid error
285  * @tc.type: FUNC
286  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus007, Function | MediumTest | Level1)287 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus007, Function | MediumTest | Level1)
288 {
289     uint8_t interfaceId = INTERFACEID_INVALID;
290     bool unactived = 1;
291     struct UsbDev dev = {dev_.busNum, DEV_ADDR_INVALID};
292     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
293     HDF_LOGI("UsbdGetInterfaceActiveStatus007 %{public}d, ret=%{public}d, unactived=%{public}d",
294         __LINE__, ret, unactived);
295     ASSERT_NE(ret, 0);
296 }
297 
298 /**
299  * @tc.name: SUB_USB_HostManager_HDI_Compatibility_8900
300  * @tc.desc: Test functions to GetInterfaceActiveStatus
301  * @tc.desc: int32_t  GetInterfaceActiveStatus(const UsbDev &dev, uint8_t interfaceId, bool unactived);
302  * @tc.desc: Negative test: parameters exception, busNum && devAddr && interfaceid error
303  * @tc.type: FUNC
304  */
HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus008, Function | MediumTest | Level1)305 HWTEST_F(UsbdDeviceStatusTest, UsbdGetInterfaceActiveStatus008, Function | MediumTest | Level1)
306 {
307     uint8_t interfaceId = INTERFACEID_INVALID;
308     bool unactived = 1;
309     struct UsbDev dev = {BUS_NUM_INVALID, DEV_ADDR_INVALID};
310     auto ret = g_usbInterface->GetInterfaceActiveStatus(dev, interfaceId, unactived);
311     HDF_LOGI("UsbdGetInterfaceActiveStatus008 %{public}d, ret=%{public}d, unactived=%{public}d",
312         __LINE__, ret, unactived);
313     ASSERT_NE(ret, 0);
314 }
315 
316 /**
317  * @tc.number   : SUB_USB_HostManager_HDI_Func_2000
318  * @tc.name     : UsbdClearHalt001
319  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
320  * @tc.desc     : Positive test: parameters correctly
321  * @tc.size     : MediumTest
322  * @tc.type     : Function
323  * @tc.level    : Level 3
324  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt001, Function | MediumTest | Level1)325 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt001, Function | MediumTest | Level1)
326 {
327     struct UsbDev dev = dev_;
328     int32_t ret = -1;
329     uint8_t interfaceId = INTERFACEID_OK;
330     uint8_t pointId = POINTID_DIR_IN;
331     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
332     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt001 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
333     ASSERT_EQ(0, ret);
334     struct UsbPipe pipe = {interfaceId, pointId};
335     ret = g_usbInterface->ClearHalt(dev, pipe);
336     HDF_LOGI("UsbdClearHalt001 %{public}d ClearHalt=%{public}d", __LINE__, ret);
337 }
338 
339 /**
340  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9300
341  * @tc.name     : UsbdClearHalt002
342  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
343  * @tc.desc     : Negative test: parameters exception, busNum error
344  * @tc.size     : MediumTest
345  * @tc.type     : Function
346  * @tc.level    : Level 3
347  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt002, Function | MediumTest | Level1)348 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt002, Function | MediumTest | Level1)
349 {
350     struct UsbDev dev = dev_;
351     int32_t ret = -1;
352     uint8_t interfaceId = INTERFACEID_OK;
353     uint8_t pointId = POINTID_DIR_IN;
354     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
355     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt002 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
356     ASSERT_EQ(0, ret);
357     struct UsbPipe pipe = {interfaceId, pointId};
358     dev.busNum = BUS_NUM_INVALID;
359     ret = g_usbInterface->ClearHalt(dev, pipe);
360     HDF_LOGI("UsbdClearHalt002 %{public}d ClearHalt=%{public}d", __LINE__, ret);
361     ASSERT_NE(0, ret);
362 }
363 
364 /**
365  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9400
366  * @tc.name     : UsbdClearHalt003
367  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
368  * @tc.desc     : Negative test: parameters exception, devAddr error
369  * @tc.size     : MediumTest
370  * @tc.type     : Function
371  * @tc.level    : Level 3
372  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt003, Function | MediumTest | Level1)373 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt003, Function | MediumTest | Level1)
374 {
375     struct UsbDev dev = dev_;
376     int32_t ret = -1;
377     uint8_t interfaceId = INTERFACEID_OK;
378     uint8_t pointId = POINTID_DIR_IN;
379     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
380     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt003 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
381     ASSERT_EQ(0, ret);
382     struct UsbPipe pipe = {interfaceId, pointId};
383     dev.devAddr = DEV_ADDR_INVALID;
384     ret = g_usbInterface->ClearHalt(dev, pipe);
385     HDF_LOGI("UsbdClearHalt003 %{public}d ClearHalt=%{public}d", __LINE__, ret);
386     ASSERT_NE(0, ret);
387 }
388 
389 /**
390  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9500
391  * @tc.name     : UsbdClearHalt004
392  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
393  * @tc.desc     : Negative test: parameters exception, interfaceid error
394  * @tc.size     : MediumTest
395  * @tc.type     : Function
396  * @tc.level    : Level 3
397  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt004, Function | MediumTest | Level1)398 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt004, Function | MediumTest | Level1)
399 {
400     struct UsbDev dev = dev_;
401     int32_t ret = -1;
402     uint8_t interfaceId = INTERFACEID_INVALID;
403     uint8_t pointId = POINTID_DIR_IN;
404     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
405     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt004 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
406     ASSERT_NE(0, ret);
407     struct UsbPipe pipe = {interfaceId, pointId};
408     ret = g_usbInterface->ClearHalt(dev, pipe);
409     HDF_LOGI("UsbdClearHalt004 %{public}d ClearHalt=%{public}d", __LINE__, ret);
410     ASSERT_NE(0, ret);
411 }
412 
413 /**
414  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9600
415  * @tc.name     : UsbdClearHalt005
416  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
417  * @tc.desc     : Negative test: parameters exception, busNum && devAddr error
418  * @tc.size     : MediumTest
419  * @tc.type     : Function
420  * @tc.level    : Level 3
421  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt005, Function | MediumTest | Level1)422 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt005, Function | MediumTest | Level1)
423 {
424     struct UsbDev dev = dev_;
425     int32_t ret = -1;
426     uint8_t interfaceId = INTERFACEID_OK;
427     uint8_t pointId = POINTID_DIR_IN;
428     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
429     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt005 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
430     ASSERT_EQ(0, ret);
431     struct UsbPipe pipe = {interfaceId, pointId};
432     dev.busNum = BUS_NUM_INVALID;
433     dev.devAddr = DEV_ADDR_INVALID;
434     ret = g_usbInterface->ClearHalt(dev, pipe);
435     HDF_LOGI("UsbdClearHalt005 %{public}d ClearHalt=%{public}d", __LINE__, ret);
436     ASSERT_NE(0, ret);
437 }
438 
439 /**
440  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9700
441  * @tc.name     : UsbdClearHalt006
442  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
443  * @tc.desc     : Negative test: parameters exception, busNum && interfaceid error
444  * @tc.size     : MediumTest
445  * @tc.type     : Function
446  * @tc.level    : Level 3
447  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt006, Function | MediumTest | Level1)448 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt006, Function | MediumTest | Level1)
449 {
450     struct UsbDev dev = dev_;
451     int32_t ret = -1;
452     uint8_t interfaceId = INTERFACEID_INVALID;
453     uint8_t pointId = POINTID_DIR_IN;
454     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
455     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt006 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
456     ASSERT_NE(0, ret);
457     struct UsbPipe pipe = {interfaceId, pointId};
458     dev.busNum = BUS_NUM_INVALID;
459     ret = g_usbInterface->ClearHalt(dev, pipe);
460     HDF_LOGI("UsbdClearHalt006 %{public}d ClearHalt=%{public}d", __LINE__, ret);
461     ASSERT_NE(0, ret);
462 }
463 
464 /**
465  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9800
466  * @tc.name     : UsbdClearHalt007
467  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
468  * @tc.desc     : Negative test: parameters exception, devAddr && interfaceid error
469  * @tc.size     : MediumTest
470  * @tc.type     : Function
471  * @tc.level    : Level 3
472  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt007, Function | MediumTest | Level1)473 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt007, Function | MediumTest | Level1)
474 {
475     struct UsbDev dev = dev_;
476     int32_t ret = -1;
477     uint8_t interfaceId = INTERFACEID_INVALID;
478     uint8_t pointId = POINTID_DIR_IN;
479     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
480     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt007 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
481     ASSERT_NE(0, ret);
482     struct UsbPipe pipe = {interfaceId, pointId};
483     dev.devAddr = DEV_ADDR_INVALID;
484     ret = g_usbInterface->ClearHalt(dev, pipe);
485     HDF_LOGI("UsbdClearHalt005 %{public}d ClearHalt=%{public}d", __LINE__, ret);
486     ASSERT_NE(0, ret);
487 }
488 
489 /**
490  * @tc.number   : SUB_USB_HostManager_HDI_Compatibility_9900
491  * @tc.name     : UsbdClearHalt008
492  * @tc.desc     : int32_t ClearHalt(const UsbDev &dev, const UsbPipe &pipe)
493  * @tc.desc     : Negative test: parameters exception, busNum && devAddr && interfaceid error
494  * @tc.size     : MediumTest
495  * @tc.type     : Function
496  * @tc.level    : Level 3
497  */
HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt008, Function | MediumTest | Level1)498 HWTEST_F(UsbdDeviceStatusTest, UsbdClearHalt008, Function | MediumTest | Level1)
499 {
500     struct UsbDev dev = dev_;
501     int32_t ret = -1;
502     uint8_t interfaceId = INTERFACEID_INVALID;
503     uint8_t pointId = POINTID_DIR_IN;
504     ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
505     HDF_LOGI("UsbdDeviceStatusTest::UsbdClearHalt008 %{public}d ClaimInterface=%{public}d", __LINE__, ret);
506     ASSERT_NE(0, ret);
507     struct UsbPipe pipe = {interfaceId, pointId};
508     dev.busNum = BUS_NUM_INVALID;
509     dev.devAddr = DEV_ADDR_INVALID;
510     ret = g_usbInterface->ClearHalt(dev, pipe);
511     HDF_LOGI("UsbdClearHalt008 %{public}d ClearHalt=%{public}d", __LINE__, ret);
512     ASSERT_NE(0, ret);
513 }
514 } // USB
515 } // OHOS
516