From cc441e0dff6ebecf8f65dff4dc7c8255a5104958 Mon Sep 17 00:00:00 2001 From: liuhonggang123 Date: Sat, 26 Feb 2022 16:43:25 +0800 Subject: [PATCH] usb test Signed-off-by: liuhonggang123 Change-Id: Ibcb7ded3675db1b15a96d5228ba6b1c760b680d3 --- hdf/usb/BUILD.gn | 25 + hdf/usb/deviceTest/BUILD.gn | 47 + hdf/usb/deviceTest/Test.json | 18 + .../deviceTest/common/usbd_device_test.cpp | 125 +++ hdf/usb/deviceTest/include/usbd_device_test.h | 27 + hdf/usb/functionTest/BUILD.gn | 46 + hdf/usb/functionTest/Test.json | 18 + .../common/usbd_function_test.cpp | 234 +++++ .../functionTest/include/usbd_function_test.h | 27 + hdf/usb/requestTest/BUILD.gn | 47 + hdf/usb/requestTest/Test.json | 18 + .../requestTest/common/usbd_request_test.cpp | 944 ++++++++++++++++++ .../requestTest/include/usbd_request_test.h | 27 + hdf/usb/transferTest/BUILD.gn | 47 + hdf/usb/transferTest/Test.json | 18 + .../common/usbd_transfer_test.cpp | 588 +++++++++++ .../transferTest/include/usbd_transfer_test.h | 27 + 17 files changed, 2283 insertions(+) create mode 100644 hdf/usb/BUILD.gn create mode 100644 hdf/usb/deviceTest/BUILD.gn create mode 100644 hdf/usb/deviceTest/Test.json create mode 100644 hdf/usb/deviceTest/common/usbd_device_test.cpp create mode 100644 hdf/usb/deviceTest/include/usbd_device_test.h create mode 100644 hdf/usb/functionTest/BUILD.gn create mode 100644 hdf/usb/functionTest/Test.json create mode 100644 hdf/usb/functionTest/common/usbd_function_test.cpp create mode 100644 hdf/usb/functionTest/include/usbd_function_test.h create mode 100644 hdf/usb/requestTest/BUILD.gn create mode 100644 hdf/usb/requestTest/Test.json create mode 100644 hdf/usb/requestTest/common/usbd_request_test.cpp create mode 100644 hdf/usb/requestTest/include/usbd_request_test.h create mode 100644 hdf/usb/transferTest/BUILD.gn create mode 100644 hdf/usb/transferTest/Test.json create mode 100644 hdf/usb/transferTest/common/usbd_transfer_test.cpp create mode 100644 hdf/usb/transferTest/include/usbd_transfer_test.h diff --git a/hdf/usb/BUILD.gn b/hdf/usb/BUILD.gn new file mode 100644 index 00000000..0fef2875 --- /dev/null +++ b/hdf/usb/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +group("HatsHdfUsbTest") { + testonly = true + deps = [ + "deviceTest:HatsHdfUsbDeviceTest", + "functionTest:HatsHdfUsbFunctionTest", + "requestTest:HatsHdfUsbRequestTest", + "transferTest:HatsHdfUsbTransferTest", + ] +} diff --git a/hdf/usb/deviceTest/BUILD.gn b/hdf/usb/deviceTest/BUILD.gn new file mode 100644 index 00000000..d4dc5bd5 --- /dev/null +++ b/hdf/usb/deviceTest/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +module_output_path = "hdf/usb" + +ohos_moduletest_suite("HatsHdfUsbDeviceTest") { + module_out_path = module_output_path + sources = [ "./common/usbd_device_test.cpp" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//drivers/peripheral/usb/hal/client/include", + ] + + deps = [ + "//drivers/peripheral/usb/ddk:libusb_core", + "//drivers/peripheral/usb/hal/client:usbd_client", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "ces_standard:cesfwk_innerkits", + "device_driver_framework:libhdf_utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] +} diff --git a/hdf/usb/deviceTest/Test.json b/hdf/usb/deviceTest/Test.json new file mode 100644 index 00000000..8f992df3 --- /dev/null +++ b/hdf/usb/deviceTest/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "HatsHdfUsbDeviceTest->/data/local/tmp/HatsHdfUsbDeviceTest" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "HatsHdfUsbDeviceTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for HatsHdfUsbDeviceTest Tests" +} \ No newline at end of file diff --git a/hdf/usb/deviceTest/common/usbd_device_test.cpp b/hdf/usb/deviceTest/common/usbd_device_test.cpp new file mode 100644 index 00000000..b6eac880 --- /dev/null +++ b/hdf/usb/deviceTest/common/usbd_device_test.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "usbd_device_test.h" +#include +#include +#include "hdf_log.h" +#include "usb_param.h" +#include "usbd_client.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::USB; +using namespace std; + +const int SLEEP_TIME = 3; +const uint8_t BUS_NUM_1 = 1; +const uint8_t DEV_ADDR_2 = 2; +const uint8_t BUS_NUM_255 = 255; + +void UsbdDeviceTest::SetUpTestCase(void) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 1); + sleep(SLEEP_TIME); + HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + if (ret != 0) { + exit(0); + } + std::cout << "please connect device, press enter to continue" << std::endl; + int c; + while ((c = getchar()) != '\n' && c != EOF) { + } +} + +void UsbdDeviceTest::TearDownTestCase(void) {} + +void UsbdDeviceTest::SetUp(void) {} + +void UsbdDeviceTest::TearDown(void) {} + +/** + * @tc.name: UsbdDevice001 + * @tc.desc: Test functions to OpenDevice + * @tc.desc: int32_t OpenDevice(const UsbDev &dev); + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceTest, UsbdOpenDevice001, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_1; + uint8_t devAddr = DEV_ADDR_2; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().OpenDevice(dev); + HDF_LOGI("UsbdDeviceTest:: Line:%{public}d OpenDevice result =%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDevice002 + * @tc.desc: Test functions to OpenDevice + * @tc.desc: int32_t OpenDevice(const UsbDev &dev); + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceTest, UsbdOpenDevice002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_255; + uint8_t devAddr = DEV_ADDR_2; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().OpenDevice(dev); + HDF_LOGI("UsbdDeviceTest:: Line:%{public}d OpenDevice result=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdDevice011 + * @tc.desc: Test functions to CloseDevice + * @tc.desc: int32_t CloseDevice(const UsbDev &dev); + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceTest, UsbdCloseDevice001, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_1; + uint8_t devAddr = DEV_ADDR_2; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().OpenDevice(dev); + HDF_LOGI("UsbdDeviceTest:: Line:%{public}d OpenDevice result=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + ret = UsbdClient::GetInstance().CloseDevice(dev); + HDF_LOGI("UsbdDeviceTest:: Line:%{public}d Close result=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDevice012 + * @tc.desc: Test functions to CloseDevice + * @tc.desc: int32_t CloseDevice(const UsbDev &dev); + * @tc.type: FUNC + */ +HWTEST_F(UsbdDeviceTest, UsbdCloseDevice002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_1; + uint8_t devAddr = DEV_ADDR_2; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().OpenDevice(dev); + HDF_LOGI("UsbdDeviceTest:: Line:%{public}d OpenDevice result=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_255; + ret = UsbdClient::GetInstance().CloseDevice(dev); + HDF_LOGI("UsbdDeviceTest:: Line:%{public}d Close result=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); + dev.busNum = BUS_NUM_1; + UsbdClient::GetInstance().CloseDevice(dev); +} + diff --git a/hdf/usb/deviceTest/include/usbd_device_test.h b/hdf/usb/deviceTest/include/usbd_device_test.h new file mode 100644 index 00000000..3418d0d8 --- /dev/null +++ b/hdf/usb/deviceTest/include/usbd_device_test.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USBD_DEVICE_TEST_H +#define USBD_DEVICE_TEST_H + +#include + +class UsbdDeviceTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +#endif // USBD_DEVICE_TEST_H \ No newline at end of file diff --git a/hdf/usb/functionTest/BUILD.gn b/hdf/usb/functionTest/BUILD.gn new file mode 100644 index 00000000..6e9899f3 --- /dev/null +++ b/hdf/usb/functionTest/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +module_output_path = "hdf/usb" + +ohos_moduletest_suite("HatsHdfUsbFunctionTest") { + module_out_path = module_output_path + sources = [ "./common/usbd_function_test.cpp" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//drivers/peripheral/usb/hal/client/include", + ] + + deps = [ + "//drivers/peripheral/usb/hal/client:usbd_client", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "ces_standard:cesfwk_innerkits", + "device_driver_framework:libhdf_utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] +} diff --git a/hdf/usb/functionTest/Test.json b/hdf/usb/functionTest/Test.json new file mode 100644 index 00000000..0e38f61d --- /dev/null +++ b/hdf/usb/functionTest/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "HatsHdfUsbFunctionTest->/data/local/tmp/HatsHdfUsbFunctionTest" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "HatsHdfUsbFunctionTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for HatsHdfUsbFunctionTest Tests" +} \ No newline at end of file diff --git a/hdf/usb/functionTest/common/usbd_function_test.cpp b/hdf/usb/functionTest/common/usbd_function_test.cpp new file mode 100644 index 00000000..ca4e2a22 --- /dev/null +++ b/hdf/usb/functionTest/common/usbd_function_test.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "usbd_function_test.h" +#include +#include "hdf_log.h" +#include "if_system_ability_manager.h" +#include "system_ability_definition.h" +#include "usbd_client.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::USB; +using namespace std; + +const int SLEEP_TIME = 3; +const int TEST_PORT_ID = 1; +const int TEST_POWER_ROLE = 2; +const int TEST_DATAR_ROLE = 2; +const int USB_FUNCTION_ACM = 1; +const int USB_FUNCTION_ECM = 2; +const int USB_FUNCTION_HDC = 4; + +void UsbdFunctionTest::SetUpTestCase(void) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(TEST_PORT_ID, TEST_POWER_ROLE, TEST_DATAR_ROLE); + sleep(SLEEP_TIME); + HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + if (ret != 0) { + exit(0); + } +} + +void UsbdFunctionTest::TearDownTestCase(void) {} + +void UsbdFunctionTest::SetUp(void) {} + +void UsbdFunctionTest::TearDown(void) {} + +/** + * @tc.name: UsbdGetCurrentFunctions001 + * @tc.desc: Test functions to GetCurrentFunctions + * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs); + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions001, Function | MediumTest | Level1) +{ + int32_t funcs = 0; + auto ret = UsbdClient::GetInstance().GetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdGetCurrentFunctions001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdGetCurrentFunctions002 + * @tc.desc: Test functions to GetCurrentFunctions + * @tc.desc: int32_t GetCurrentFunctions(int32_t &funcs); + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdGetCurrentFunctions002, Function | MediumTest | Level1) +{ + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(1); + HDF_LOGI("UsbdFunctionTest::UsbdFunction011 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + int32_t funcs = 1; + ret = UsbdClient::GetInstance().GetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdFunction001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetCurrentFunctions001 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions001, Function | MediumTest | Level1) +{ + int32_t funcs = 1; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions001 %{public}d SetCurrentFunctions=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetCurrentFunctions002 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions002, Function | MediumTest | Level1) +{ + int32_t funcs = -1; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdFunction002 %{public}d, ret=%{public}d, funcs=%{public}d", __LINE__, ret, funcs); + ASSERT_TRUE(ret != 0); +} +/** + * @tc.name: UsbdSetCurrentFunctions003 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions003, Function | MediumTest | Level1) +{ + int32_t funcs = USB_FUNCTION_ECM; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions003 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetCurrentFunctions004 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions004, Function | MediumTest | Level1) +{ + int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_ECM; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions004 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetCurrentFunctions005 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions005, Function | MediumTest | Level1) +{ + int32_t funcs = USB_FUNCTION_HDC; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions005 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetCurrentFunctions006 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions006, Function | MediumTest | Level1) +{ + int32_t funcs = USB_FUNCTION_ACM | USB_FUNCTION_HDC; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions006 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetCurrentFunctions007 + * @tc.desc: Test functions to SetCurrentFunctions + * @tc.desc: int32_t SetCurrentFunctions(int32_t funcs) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetCurrentFunctions007, Function | MediumTest | Level1) +{ + int32_t funcs = USB_FUNCTION_ECM | USB_FUNCTION_HDC; + auto ret = UsbdClient::GetInstance().SetCurrentFunctions(funcs); + HDF_LOGI("UsbdFunctionTest::UsbdSetCurrentFunctions007 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetPortRole001 + * @tc.desc: Test functions to SetPortRole + * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetPortRole001, Function | MediumTest | Level1) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 1); + HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetPortRole002 + * @tc.desc: Test functions to SetPortRole + * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, UsbdSetPortRole002, Function | MediumTest | Level1) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(2, 1, 1); + HDF_LOGI("UsbdFunctionTest::UsbdSetPortRole002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: SetPortRole009 + * @tc.desc: Test functions to SetPortRole + * @tc.desc: int32_t SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole) + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, SetPortRole09, Function | MediumTest | Level1) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(1, 2, 2); + HDF_LOGI("UsbdFunctionTest::SetPortRole09 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: QueryPort001 + * @tc.desc: Test functions to QueryPort + * @tc.desc: int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode); + * @tc.type: FUNC + */ +HWTEST_F(UsbdFunctionTest, QueryPort001, Function | MediumTest | Level1) +{ + int32_t portId = 0; + int32_t powerRole = 0; + int32_t dataRole = 0; + int32_t mode = 0; + auto ret = UsbdClient::GetInstance().QueryPort(portId, powerRole, dataRole, mode); + HDF_LOGI("UsbdFunctionTest::QueryPort001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} diff --git a/hdf/usb/functionTest/include/usbd_function_test.h b/hdf/usb/functionTest/include/usbd_function_test.h new file mode 100644 index 00000000..97e460b8 --- /dev/null +++ b/hdf/usb/functionTest/include/usbd_function_test.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USBD_FUNCTION_TEST_H +#define USBD_FUNCTION_TEST_H + +#include + +class UsbdFunctionTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +#endif // USBD_FUNCTION_TEST_H \ No newline at end of file diff --git a/hdf/usb/requestTest/BUILD.gn b/hdf/usb/requestTest/BUILD.gn new file mode 100644 index 00000000..56f833ee --- /dev/null +++ b/hdf/usb/requestTest/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +module_output_path = "hdf/usb" + +ohos_moduletest_suite("HatsHdfUsbRequestTest") { + module_out_path = module_output_path + sources = [ "./common/usbd_request_test.cpp" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//drivers/peripheral/usb/hal/client/include", + ] + + deps = [ + "//drivers/peripheral/usb/ddk:libusb_core", + "//drivers/peripheral/usb/hal/client:usbd_client", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "ces_standard:cesfwk_innerkits", + "device_driver_framework:libhdf_utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] +} diff --git a/hdf/usb/requestTest/Test.json b/hdf/usb/requestTest/Test.json new file mode 100644 index 00000000..9f204ae8 --- /dev/null +++ b/hdf/usb/requestTest/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "HatsHdfUsbRequestTest->/data/local/tmp/HatsHdfUsbRequestTest" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "HatsHdfUsbRequestTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for HatsHdfUsbRequestTest Tests" +} \ No newline at end of file diff --git a/hdf/usb/requestTest/common/usbd_request_test.cpp b/hdf/usb/requestTest/common/usbd_request_test.cpp new file mode 100644 index 00000000..3c26c972 --- /dev/null +++ b/hdf/usb/requestTest/common/usbd_request_test.cpp @@ -0,0 +1,944 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "usbd_request_test.h" +#include +#include +#include "hdf_log.h" +#include "usb_param.h" +#include "usbd_client.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::USB; +using namespace std; + +const int SLEEP_TIME = 3; +const uint8_t BUS_NUM_1 = 1; +const uint8_t DEV_ADDR_2 = 2; +const uint8_t BUS_NUM_255 = 255; +const uint8_t DEV_ADDR_255 = 255; +const uint8_t BUS_NUM_222 = 222; +const uint8_t DEV_ADDR_222 = 222; +const uint32_t LENGTH_NUM_255 = 255; +const uint32_t TAG_LENGTH_NUM_1000 = 1000; +const int TAG_NUM_10 = 10; +const int TAG_NUM_11 = 11; +const uint8_t INTERFACEID_1 = 1; +const uint8_t POINTID_1 = 1; +const uint8_t POINTID_129 = 129; + +void UsbdRequestTest::SetUpTestCase(void) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 1); + sleep(SLEEP_TIME); + HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + if (ret != 0) { + exit(0); + } + std::cout << "please connect device, press enter to continue" << std::endl; + int c; + while ((c = getchar()) != '\n' && c != EOF) { + } + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + ret = UsbdClient::GetInstance().OpenDevice(dev); + HDF_LOGI("UsbdRequestTest:: %{public}d OpenDevice=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +void UsbdRequestTest::TearDownTestCase(void) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + auto ret = UsbdClient::GetInstance().CloseDevice(dev); + HDF_LOGI("UsbdRequestTest:: %{public}d Close=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +void UsbdRequestTest::SetUp(void) {} + +void UsbdRequestTest::TearDown(void) {} + +/** + * @tc.name: UsbdConfig001 + * @tc.desc: Test functions to SetConfig + * @tc.desc: int32_t SetConfig(const UsbDev &dev, uint8_t configIndex); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdSetConfig001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t configIndex = 1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().SetConfig(dev, configIndex); + HDF_LOGI("UsbdRequestTest::UsbdSetConfigConfig001 %{public}d SetConfig=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdConfig002 + * @tc.desc: Test functions to SetConfig + * @tc.desc: int32_t SetConfig(const UsbDev &dev, uint8_t configIndex); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdSetConfig002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_222; + uint8_t devAddr = 2; + uint8_t configIndex = 1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().SetConfig(dev, configIndex); + HDF_LOGI("UsbdRequestTest::UsbdSetConfig002 %{public}d SetConfig=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdConfig001 + * @tc.desc: Test functions to GetConfig + * @tc.desc: int32_t GetConfig(const UsbDev &dev, uint8_t &configIndex); + * @tc.desc: 正向测试:参数正确 + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetConfig001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t configIndex = 1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().GetConfig(dev, configIndex); + HDF_LOGI("UsbdRequestTest::UsbdGetConfig001 %{public}d GetConfig=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdConfig002 + * @tc.desc: Test functions to GetConfig + * @tc.desc: int32_t GetConfig(const UsbDev &dev, uint8_t &configIndex); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetConfig002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_222; + uint8_t devAddr = 2; + uint8_t configIndex = 1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().GetConfig(dev, configIndex); + HDF_LOGI("UsbdRequestTest::UsbdGetConfig002 %{public}d GetConfig=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdClaimInterface001 + * @tc.desc: Test functions to ClaimInterface + * @tc.desc: int32_t ClaimInterface(const UsbDev &dev, uint8_t interfaceId); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdClaimInterface001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdClaimInterface001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdClaimInterface002 + * @tc.desc: Test functions to ClaimInterface + * @tc.desc: int32_t ClaimInterface(const UsbDev &dev, uint8_t interfaceId); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdClaimInterface002, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {busNum, devAddr}; + dev.busNum = 20; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdClaimInterface002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdSetInterface001 + * @tc.desc: Test functions to SetInterface + * @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdSetInterface001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t altIndex = 0; + + struct UsbDev dev = {busNum, devAddr}; + + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdClaimInterface001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + ret = UsbdClient::GetInstance().SetInterface(dev, interfaceId, altIndex); + HDF_LOGI("UsbdRequestTest::UsbdSetInterface001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdSetInterface002 + * @tc.desc: Test functions to SetInterface + * @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdSetInterface002, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t interfaceId = INTERFACEID_1; + + uint8_t altIndex = 0; + struct UsbDev dev = {busNum, devAddr}; + + + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdSetInterface002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_222; + ret = UsbdClient::GetInstance().SetInterface(dev, interfaceId, altIndex); + HDF_LOGI("UsbdRequestTest::UsbdSetInterface002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdDescriptor001 + * @tc.desc: Test functions to GetDeviceDescriptor + * @tc.desc: int32_t GetDeviceDescriptor(const UsbDev &dev, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetDeviceDescriptor001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = {0}; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetDeviceDescriptor(dev, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetDeviceDescriptor001 %{public}d ret=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::UsbdGetDeviceDescriptor001 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDescriptor002 + * @tc.desc: Test functions to GetDeviceDescriptor + * @tc.desc: int32_t GetDeviceDescriptor(const UsbDev &dev, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetDeviceDescriptor002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_222; + uint8_t devAddr = 2; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetDeviceDescriptor(dev, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetDeviceDescriptor002 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetDeviceDescriptor002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdDescriptor004 + * @tc.desc: Test functions to GetDeviceDescriptor + * @tc.desc: int32_t GetDeviceDescriptor(const UsbDev &dev, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetDeviceDescriptor004, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t buffer[LENGTH_NUM_255] = {}; + uint32_t length = 0; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetDeviceDescriptor(dev, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetDeviceDescriptor004 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetDeviceDescriptor004 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDescriptor001 + * @tc.desc: Test functions to GetStringDescriptor + * @tc.desc: int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetStringDescriptor001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t stringId = 0; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetStringDescriptor(dev, stringId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor001 %{public}d ret=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor001 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDescriptor002 + * @tc.desc: Test functions to GetStringDescriptor + * @tc.desc: int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetStringDescriptor002, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t stringId = 1; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetStringDescriptor(dev, stringId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor002 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDescriptor003 + * @tc.desc: Test functions to GetStringDescriptor + * @tc.desc: int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetStringDescriptor003, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t stringId = 222; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetStringDescriptor(dev, stringId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor003 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor003 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDescriptor004 + * @tc.desc: Test functions to GetStringDescriptor + * @tc.desc: int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetStringDescriptor004, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 255; + uint8_t stringId = 0; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = 8; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetStringDescriptor(dev, stringId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor004 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetStringDescriptor004 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdDescriptor001 + * @tc.desc: Test functions to GetConfigDescriptor + * @tc.desc: int32_t GetConfigDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetConfigDescriptor001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t configId = 0; + uint8_t buffer[LENGTH_NUM_255] = {}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetConfigDescriptor(dev, configId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetConfigDescriptor001 %{public}d ret=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::UsbdGetConfigDescriptor001 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdDescriptor002 + * @tc.desc: Test functions to GetConfigDescriptor + * @tc.desc: int32_t GetConfigDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetConfigDescriptor002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_222; + uint8_t devAddr = 2; + uint8_t configId = 1; + uint8_t buffer[LENGTH_NUM_255] = {}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetConfigDescriptor(dev, configId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetConfigDescriptor002 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetConfigDescriptor002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdDescriptor004 + * @tc.desc: Test functions to GetConfigDescriptor + * @tc.desc: int32_t GetConfigDescriptor(const UsbDev &dev, uint8_t descId, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetConfigDescriptor004, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t configId = 1; + uint8_t buffer[LENGTH_NUM_255] = {}; + uint32_t length = LENGTH_NUM_255; + struct UsbDev dev = {busNum, devAddr}; + std::vector devdata(buffer, buffer + length); + auto ret = UsbdClient::GetInstance().GetConfigDescriptor(dev, configId, devdata); + HDF_LOGI("UsbdRequestTest::UsbdGetConfigDescriptor004 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + devdata.size(), sizeof(devdata)); + HDF_LOGI("UsbdRequestTest::UsbdGetConfigDescriptor004 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdGetRawDescriptor001 + * @tc.desc: Test functions to GetRawDescriptor + * @tc.desc: int32_t GetRawDescriptor(const UsbDev &dev, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetRawDescriptor001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + struct UsbDev dev = {busNum, devAddr}; + std::vector rawData; + auto ret = UsbdClient::GetInstance().GetRawDescriptor(dev, rawData); + HDF_LOGI("UsbdRequestTest::UsbdGetRawDescriptor001 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + rawData.size(), sizeof(rawData)); + HDF_LOGI("UsbdRequestTest::UsbdGetRawDescriptor001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdGetRawDescriptor002 + * @tc.desc: Test functions to GetRawDescriptor + * @tc.desc: int32_t GetRawDescriptor(const UsbDev &dev, std::vector &decriptor); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdGetRawDescriptor002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_222; + uint8_t devAddr = 2; + struct UsbDev dev = {busNum, devAddr}; + std::vector rawData; + auto ret = UsbdClient::GetInstance().GetRawDescriptor(dev, rawData); + HDF_LOGI("UsbdRequestTest::UsbdGetRawDescriptor002 %{public}d length=%{public}d buffer=%{public}d", __LINE__, + rawData.size(), sizeof(rawData)); + HDF_LOGI("UsbdRequestTest::UsbdGetRawDescriptor002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: GetFileDescriptor001 + * @tc.desc: Test functions to GetFileDescriptor + * @tc.desc: int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, GetFileDescriptor001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + struct UsbDev dev = {busNum, devAddr}; + int32_t fd = 0; + auto ret = UsbdClient::GetInstance().GetFileDescriptor(dev, fd); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor001 %{public}d GetFileDescriptor=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor001 %{public}d fd=%{public}d", __LINE__, fd); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: GetFileDescriptor002 + * @tc.desc: Test functions to GetFileDescriptor + * @tc.desc: int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, GetFileDescriptor002, Function | MediumTest | Level1) +{ + uint8_t busNum = BUS_NUM_222; + uint8_t devAddr = 2; + struct UsbDev dev = {busNum, devAddr}; + int32_t fd = 0; + auto ret = UsbdClient::GetInstance().GetFileDescriptor(dev, fd); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor002 %{public}d GetFileDescriptor=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor002 %{public}d fd=%{public}d", __LINE__, fd); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: GetFileDescriptor003 + * @tc.desc: Test functions to GetFileDescriptor + * @tc.desc: int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, GetFileDescriptor003, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = DEV_ADDR_222; + struct UsbDev dev = {busNum, devAddr}; + int32_t fd = 0; + auto ret = UsbdClient::GetInstance().GetFileDescriptor(dev, fd); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor003 %{public}d GetFileDescriptor=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor003 %{public}d fd=%{public}d", __LINE__, fd); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: GetFileDescriptor004 + * @tc.desc: Test functions to GetFileDescriptor + * @tc.desc: int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, GetFileDescriptor004, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + struct UsbDev dev = {busNum, devAddr}; + int32_t fd = LENGTH_NUM_255; + auto ret = UsbdClient::GetInstance().GetFileDescriptor(dev, fd); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor004 %{public}d GetFileDescriptor=%{public}d", __LINE__, ret); + HDF_LOGI("UsbdRequestTest::GetFileDescriptor004 %{public}d fd=%{public}d", __LINE__, fd); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdRequest001 + * @tc.desc: Test functions to RequestQueue + * @tc.desc: int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, std::vector &clientData, + std::vector &buffer); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestQueue001, Function | MediumTest | Level1) +{ + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue001 %{public}d interfaceId=%{public}d pointid=%{public}d", __LINE__, + interfaceId, pointid); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue001 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdRequest002 + * @tc.desc: Test functions to RequestQueue + * @tc.desc: int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, std::vector &clientData, + std::vector &buffer); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestQueue002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.devAddr = DEV_ADDR_2; + dev.busNum = BUS_NUM_1; + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + dev = {222, 222}; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue002 %{public}d interfaceId=%{public}d pointid=%{public}d", __LINE__, + interfaceId, pointid); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue002 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdRequest007 + * @tc.desc: Test functions to RequestQueue + * @tc.desc: int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, std::vector &clientData, + std::vector &buffer); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestQueue007, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t buffer[LENGTH_NUM_255] = "request 007"; + uint32_t length = LENGTH_NUM_255; + uint8_t pointid = POINTID_1; + uint8_t interfaceId = INTERFACEID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue007 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue write"; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_11}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestQueue007 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdRequest001 + * @tc.desc: Test functions to RequestWait + * @tc.desc: int32_t RequestWait(const UsbDev &dev, std::vector &clientData, std::vector &buffer, + * int32_t timeout); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestWait001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t buffer[LENGTH_NUM_255] = {}; + uint32_t length = LENGTH_NUM_255; + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait001 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t *clientObj = new uint8_t[10]; + std::vector waitdata = {clientObj, clientObj + 10}; + ret = UsbdClient::GetInstance().RequestWait(dev, waitdata, bufferdata, 10000); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait001 %{public}d RequestWait=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + delete[] clientObj; + clientObj = nullptr; +} + +/** + * @tc.name: UsbdRequest002 + * @tc.desc: Test functions to RequestWait + * @tc.desc: int32_t RequestWait(const UsbDev &dev, std::vector &clientData, std::vector &buffer, + * int32_t timeout); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestWait002, Function | MediumTest | Level1) +{ + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t buffer[LENGTH_NUM_255] = {}; + uint32_t length = LENGTH_NUM_255; + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbPipe pipe = {interfaceId, pointid}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait002 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_222; + uint8_t *clientObj = new uint8_t[10]; + std::vector waitdata = {clientObj, clientObj + 10}; + ret = UsbdClient::GetInstance().RequestWait(dev, waitdata, bufferdata, 10000); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait002 %{public}d RequestWait=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); + delete[] clientObj; + clientObj = nullptr; +} + +/** + * @tc.name: UsbdRequest004 + * @tc.desc: Test functions to RequestWait + * @tc.desc: int32_t RequestWait(const UsbDev &dev, std::vector &clientData, std::vector &buffer, + * int32_t timeout); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestWait004, Function | MediumTest | Level1) +{ + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait004 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t buffer[LENGTH_NUM_255] = {}; + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + uint32_t length = LENGTH_NUM_255; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait004 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t *clientObj = new uint8_t[10]; + std::vector waitdata = {clientObj, clientObj + 10}; + ret = UsbdClient::GetInstance().RequestWait(dev, waitdata, bufferdata, -10000); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait004 %{public}d RequestWait=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + delete[] clientObj; + clientObj = nullptr; +} + +/** + * @tc.name: UsbdRequest005 + * @tc.desc: Test functions to RequestWait + * @tc.desc: int32_t RequestWait(const UsbDev &dev, std::vector &clientData, std::vector &buffer, + * int32_t timeout); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestWait005, Function | MediumTest | Level1) +{ + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait005 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint32_t length = LENGTH_NUM_255; + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + uint8_t buffer[LENGTH_NUM_255] = {}; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait005 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t *clientObj = new uint8_t[10]; + std::vector waitdata = {clientObj, clientObj + 10}; + dev.devAddr = DEV_ADDR_255; + dev.busNum = BUS_NUM_255; + ret = UsbdClient::GetInstance().RequestWait(dev, waitdata, bufferdata, 10000); + HDF_LOGI("UsbdRequestTest::UsbdRequestWait005 %{public}d RequestWait=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); + delete[] clientObj; + clientObj = nullptr; +} + +/** + * @tc.name: UsbdRequest001 + * @tc.desc: Test functions to RequestCancel + * @tc.desc: int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestCancel001, Function | MediumTest | Level1) +{ + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t buffer[LENGTH_NUM_255] = "request001"; + uint32_t length = LENGTH_NUM_255; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + EXPECT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel001 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + ret = UsbdClient::GetInstance().RequestCancel(dev, pipe); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel001 %{public}d RequestCancel=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdRequest002 + * @tc.desc: Test functions to RequestCancel + * @tc.desc: int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestCancel002, Function | MediumTest | Level1) +{ + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + uint8_t buffer[LENGTH_NUM_255] = "request002"; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + EXPECT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel002 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_222; + ret = UsbdClient::GetInstance().RequestCancel(dev, pipe); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel002 %{public}d RequestCancel=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); + dev.busNum = BUS_NUM_1; + ret = UsbdClient::GetInstance().RequestCancel(dev, pipe); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdRequest004 + * @tc.desc: Test functions to RequestCancel + * @tc.desc: int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestCancel004, Function | MediumTest | Level1) +{ + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue read"; + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = "request004"; + uint8_t pointid = POINTID_129; + uint8_t interfaceId = INTERFACEID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel004 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + EXPECT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector clientdata = {tag, tag + TAG_NUM_10}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel004 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + pipe.interfaceId = 222; + pipe.endpointId = 222; + ret = UsbdClient::GetInstance().RequestCancel(dev, pipe); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel004 %{public}d RequestCancel=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdRequest005 + * @tc.desc: Test functions to RequestCancel + * @tc.desc: int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdRequestCancel005, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t buffer[LENGTH_NUM_255] = "request005"; + uint32_t length = LENGTH_NUM_255; + uint8_t pointid = POINTID_1; + uint8_t interfaceId = INTERFACEID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel005 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + EXPECT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + uint8_t tag[TAG_LENGTH_NUM_1000] = "queue Write"; + std::vector clientdata = {tag, tag + TAG_NUM_11}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().RequestQueue(dev, pipe, clientdata, bufferdata); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel005 %{public}d RequestQueue=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + ret = UsbdClient::GetInstance().RequestCancel(dev, pipe); + HDF_LOGI("UsbdRequestTest::UsbdRequestCancel005 %{public}d RequestCancel=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdReleaseInterface001 + * @tc.desc: Test functions to ReleaseInterface + * @tc.desc: int32_t ReleaseInterface(const UsbDev &dev, uint8_t interfaceId); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdReleaseInterface001, Function | MediumTest | Level1) +{ + uint8_t busNum = 1; + uint8_t devAddr = 2; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().ReleaseInterface(dev, interfaceId); + HDF_LOGI("UsbdRequestTest::UsbdReleaseInterface001 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdReleaseInterface002 + * @tc.desc: Test functions to ReleaseInterface + * @tc.desc: int32_t ReleaseInterface(const UsbDev &dev, uint8_t interfaceId); + * @tc.type: FUNC + */ +HWTEST_F(UsbdRequestTest, UsbdReleaseInterface002, Function | MediumTest | Level1) +{ + uint8_t busNum = 25; + uint8_t devAddr = 2; + uint8_t interfaceId = INTERFACEID_1; + struct UsbDev dev = {busNum, devAddr}; + auto ret = UsbdClient::GetInstance().ReleaseInterface(dev, interfaceId); + HDF_LOGI("UsbdRequestTest::UsbdReleaseInterface002 %{public}d ret=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} diff --git a/hdf/usb/requestTest/include/usbd_request_test.h b/hdf/usb/requestTest/include/usbd_request_test.h new file mode 100644 index 00000000..b86ea32b --- /dev/null +++ b/hdf/usb/requestTest/include/usbd_request_test.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USBD_Request_TEST_H +#define USBD_Request_TEST_H + +#include + +class UsbdRequestTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +#endif // USBD_Request_TEST_H \ No newline at end of file diff --git a/hdf/usb/transferTest/BUILD.gn b/hdf/usb/transferTest/BUILD.gn new file mode 100644 index 00000000..4a13e14f --- /dev/null +++ b/hdf/usb/transferTest/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +module_output_path = "hdf/usb" + +ohos_moduletest_suite("HatsHdfUsbTransferTest") { + module_out_path = module_output_path + sources = [ "./common/usbd_transfer_test.cpp" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//drivers/peripheral/usb/hal/client/include", + ] + + deps = [ + "//drivers/peripheral/usb/ddk:libusb_core", + "//drivers/peripheral/usb/hal/client:usbd_client", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "ces_standard:cesfwk_innerkits", + "device_driver_framework:libhdf_utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] +} diff --git a/hdf/usb/transferTest/Test.json b/hdf/usb/transferTest/Test.json new file mode 100644 index 00000000..a6efe9fa --- /dev/null +++ b/hdf/usb/transferTest/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "HatsHdfUsbTransferTest->/data/local/tmp/HatsHdfUsbTransferTest" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "HatsHdfUsbTransferTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for HatsHdfUsbTransferTest Tests" +} \ No newline at end of file diff --git a/hdf/usb/transferTest/common/usbd_transfer_test.cpp b/hdf/usb/transferTest/common/usbd_transfer_test.cpp new file mode 100644 index 00000000..2de0fb38 --- /dev/null +++ b/hdf/usb/transferTest/common/usbd_transfer_test.cpp @@ -0,0 +1,588 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "usbd_transfer_test.h" +#include +#include +#include "hdf_log.h" +#include "usb_param.h" +#include "usbd_client.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::USB; +using namespace std; + +const int SLEEP_TIME = 3; +const uint8_t BUS_NUM_1 = 1; +const uint8_t DEV_ADDR_2 = 2; +const uint8_t BUS_NUM_255 = 255; +const uint8_t BUS_NUM_222 = 222; +const uint32_t LENGTH_NUM_255 = 255; +const uint8_t INTERFACEID_1 = 1; +const uint8_t POINTID_1 = 1; +const uint8_t POINTID_129 = 129; + +void UsbdTransferTest::SetUpTestCase(void) +{ + auto ret = UsbdClient::GetInstance().SetPortRole(1, 1, 1); + sleep(SLEEP_TIME); + HDF_LOGI("UsbdFunctionTest::[Device] %{public}d SetPortRole=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + if (ret != 0) { + exit(0); + } + std::cout << "please connect device, press enter to continue" << std::endl; + int c; + while ((c = getchar()) != '\n' && c != EOF) { + } + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + ret = UsbdClient::GetInstance().OpenDevice(dev); + HDF_LOGI("UsbdTransferTest:: %{public}d OpenDevice=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +void UsbdTransferTest::TearDownTestCase(void) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + auto ret = UsbdClient::GetInstance().CloseDevice(dev); + HDF_LOGI("UsbdTransferTest:: %{public}d Close=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +void UsbdTransferTest::SetUp(void) {} + +void UsbdTransferTest::TearDown(void) {} + +/** + * @tc.name: UsbdControlTransfer001 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000000, 8, 0, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer001 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdControlTransfer002 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_255; + dev.devAddr = DEV_ADDR_2; + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000000, 8, 0, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer002 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdControlTransfer004 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer004, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = {0}; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000000, 6, 0x100, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer004 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdControlTransfer010 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer010, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = {0}; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000000, 0, 0, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer010 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdControlTransfer013 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer013, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = {0}; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000001, 0, 0, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer013 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdControlTransfer016 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer016, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = {0}; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000010, 0, 0, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer016 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdControlTransfer019 + * @tc.desc: Test functions to ControlTransfer(const UsbDev &dev, UsbCtrlTransfer &ctrl, std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdControlTransfer019, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint32_t length = LENGTH_NUM_255; + uint8_t buffer[LENGTH_NUM_255] = {}; + std::vector bufferdata = {buffer, buffer + length}; + struct UsbCtrlTransfer ctrlparmas = {0b10000010, 0X0C, 0, 0, 1000}; + auto ret = UsbdClient::GetInstance().ControlTransfer(dev, ctrlparmas, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdControlTransfer019 %{public}d ControlTransfer=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdBulkTransferRead001 + * @tc.desc: Test functions to BulkTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdBulkTransferRead001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_129; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferRead001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().BulkTransferRead(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferRead001 %{public}d UsbdBulkTransferRead=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdBulkTransferRead002 + * @tc.desc: Test functions to BulkTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdBulkTransferRead002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_129; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferRead002 %{public}d ReleaseInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_222; + uint32_t length = 100; + uint8_t buffer[100] = {0}; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().BulkTransferRead(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferRead002 %{public}d UsbdBulkTransferRead=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdBulkTransferWrite001 + * @tc.desc: Test functions to BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdBulkTransferWrite001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferWrite001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint32_t length = 100; + uint8_t buffer[100] = "hello world bulk writ01"; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().BulkTransferWrite(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferWrite001 %{public}d BulkTransferWrite=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdBulkTransferWrite002 + * @tc.desc: Test functions to BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdBulkTransferWrite002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferWrite002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + dev.busNum = 99; + uint32_t length = 100; + uint8_t buffer[100] = "hello world bulk writ02"; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().BulkTransferWrite(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferWrite002 %{public}d BulkTransferWrite=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdBulkTransferWrite008 + * @tc.desc: Test functions to BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdBulkTransferWrite008, Function | MediumTest | Level1) +{ + HDF_LOGI("Case Start : UsbdBulkTransferWrite008 : BulkTransferWrite"); + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferWrite008 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + uint32_t length = 100; + uint8_t buffer[100] = "hello world bulk writ08"; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().BulkTransferWrite(dev, pipe, -1, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdBulkTransferWrite008 %{public}d BulkTransferWrite=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: InterruptTransferRead001 + * @tc.desc: Test functions to InterruptTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdInterruptTransferRead001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_129; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferRead001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().InterruptTransferRead(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferRead001 %{public}d UsbdInterruptTransferRead=%{public}d", __LINE__, + ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdInterruptTransferRead002 + * @tc.desc: Test functions to InterruptTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdInterruptTransferRead002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_129; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferRead002 %{public}d ReleaseInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_222; + uint32_t length = 100; + uint8_t buffer[100] = {0}; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().InterruptTransferRead(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferRead002 %{public}d UsbdInterruptTransferRead=%{public}d", __LINE__, + ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdInterruptTransferWrite001 + * @tc.desc: Test functions to InterruptTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdInterruptTransferWrite001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferWrite001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint32_t length = 100; + uint8_t buffer[100] = "hello world Interrupt writ01"; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().InterruptTransferWrite(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferWrite001 %{public}d InterruptTransferWrite=%{public}d", __LINE__, + ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdInterruptTransferWrite002 + * @tc.desc: Test functions to InterruptTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdInterruptTransferWrite002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferWrite002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + dev.busNum = 99; + uint32_t length = 100; + uint8_t buffer[100] = "hello world Interrupt writ02"; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().InterruptTransferWrite(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferWrite002 %{public}d InterruptTransferWrite=%{public}d", __LINE__, + ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdInterruptTransferWrite008 + * @tc.desc: Test functions to InterruptTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdInterruptTransferWrite008, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferWrite008 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + uint32_t length = 100; + uint8_t buffer[100] = "hello world Interrupt writ08"; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().InterruptTransferWrite(dev, pipe, -1, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdInterruptTransferWrite008 %{public}d InterruptTransferWrite=%{public}d", __LINE__, + ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdIsoTransferRead001 + * @tc.desc: Test functions to IsoTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdIsoTransferRead001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_129; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferRead001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint8_t buffer[LENGTH_NUM_255] = {0}; + uint32_t length = LENGTH_NUM_255; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().IsoTransferRead(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferRead001 %{public}d UsbdIsoTransferRead=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdIsoTransferRead002 + * @tc.desc: Test functions to IsoTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdIsoTransferRead002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_129; + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferRead002 %{public}d interfaceId=%{public}d", __LINE__, interfaceId); + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferRead002 %{public}d ReleaseInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + dev.busNum = BUS_NUM_222; + uint32_t length = 100; + uint8_t buffer[100] = {0}; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().IsoTransferRead(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferRead002 %{public}d UsbdIsoTransferRead=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdIsoTransferWrite001 + * @tc.desc: Test functions to IsoTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdIsoTransferWrite001, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferWrite001 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + uint32_t length = 100; + uint8_t buffer[100] = "hello world Iso writ01"; + struct UsbPipe pipe = {interfaceId, pointid}; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().IsoTransferWrite(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferWrite001 %{public}d IsoTransferWrite=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} + +/** + * @tc.name: UsbdIsoTransferWrite002 + * @tc.desc: Test functions to IsoTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdIsoTransferWrite002, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferWrite002 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + dev.busNum = 99; + uint32_t length = 100; + uint8_t buffer[100] = "hello world Iso writ02"; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().IsoTransferWrite(dev, pipe, 1000, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferWrite002 %{public}d IsoTransferWrite=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret != 0); +} + +/** + * @tc.name: UsbdIsoTransferWrite008 + * @tc.desc: Test functions to IsoTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + * std::vector &data); + * @tc.type: FUNC + */ +HWTEST_F(UsbdTransferTest, UsbdIsoTransferWrite008, Function | MediumTest | Level1) +{ + struct UsbDev dev = {BUS_NUM_1, DEV_ADDR_2}; + dev.busNum = BUS_NUM_1; + dev.devAddr = DEV_ADDR_2; + uint8_t interfaceId = INTERFACEID_1; + uint8_t pointid = POINTID_1; + auto ret = UsbdClient::GetInstance().ClaimInterface(dev, interfaceId, true); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferWrite008 %{public}d ClaimInterface=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); + struct UsbPipe pipe = {interfaceId, pointid}; + uint32_t length = 100; + uint8_t buffer[100] = "hello world Iso writ08"; + std::vector bufferdata = {buffer, buffer + length}; + ret = UsbdClient::GetInstance().IsoTransferWrite(dev, pipe, -1, bufferdata); + HDF_LOGI("UsbdTransferTest::UsbdIsoTransferWrite008 %{public}d IsoTransferWrite=%{public}d", __LINE__, ret); + ASSERT_TRUE(ret == 0); +} diff --git a/hdf/usb/transferTest/include/usbd_transfer_test.h b/hdf/usb/transferTest/include/usbd_transfer_test.h new file mode 100644 index 00000000..3947520f --- /dev/null +++ b/hdf/usb/transferTest/include/usbd_transfer_test.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef USBD_TRANSFER_TEST_H +#define USBD_TRANSFER_TEST_H + +#include + +class UsbdTransferTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +#endif // USBD_TRANSFER_TEST_H \ No newline at end of file