From deea2c4ae2a9d59ab344474c6cddb73eb21cd770 Mon Sep 17 00:00:00 2001 From: zhangquanchao Date: Mon, 7 Jul 2025 11:10:54 +0800 Subject: [PATCH] test read,write and transfer Signed-off-by: zhangquanchao --- .../src/usb_device_pipe_test.cpp | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/test/native/service_unittest/src/usb_device_pipe_test.cpp b/test/native/service_unittest/src/usb_device_pipe_test.cpp index 21d5a3b9..d2950bb3 100644 --- a/test/native/service_unittest/src/usb_device_pipe_test.cpp +++ b/test/native/service_unittest/src/usb_device_pipe_test.cpp @@ -4361,6 +4361,80 @@ HWTEST_F(UsbDevicePipeTest, GetFileDescriptors003, TestSize.Level1) EXPECT_TRUE(ret); USB_HILOGI(MODULE_USB_SERVICE, "Case End : GetFileDescriptors003 : ControlTransfer"); } + +/** + * @tc.name: UsbBulkRead001 + * @tc.desc: Test functions to int32_t UsbSrvClient::BulkRead(USBDevicePipe &pipe, const USBEndpoint &endpoint, sptr &ashmem) + * @tc.type: FUNC + */ +HWTEST_F(UsbDevicePipeTest, UsbBulkRead001, TestSize.Level1) +{ + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] Case Start : UsbBulkRead001"); + USBEndpoint point; + point.SetAddr(BUFFER_SIZE); + + USBDevicePipe pipe; + pipe.SetBusNum(BUFFER_SIZE); + pipe.SetDevAddr(1); + + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] start to execute BulkRead"); + sptr ashmem = new Ashmem(1, 1); + auto &UsbSrvClient = UsbSrvClient::GetInstance(); + auto ret = UsbSrvClient.BulkRead(pipe, point,ashmem); + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] UsbBulkRead001 %{public}d BulkRead=%{public}d", __LINE__, + ret); + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] Case End : UsbBulkRead001"); + sleep(SLEEP_TIME); +} + +/** + * @tc.name: UsbBulkWrite001 + * @tc.desc: Test functions to int32_t UsbService::BulkWrite(uint8_t busNum, uint8_t devAddr, const USBEndpoint &ep, int32_t fd, int32_t memSize) + * @tc.type: FUNC + */ +HWTEST_F(UsbDevicePipeTest, UsbBulkWrite001, TestSize.Level1) +{ + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] Case Start : UsbBulkWrite001"); + USBEndpoint point; + point.SetAddr(BUFFER_SIZE); + + USBDevicePipe pipe; + pipe.SetBusNum(BUFFER_SIZE); + pipe.SetDevAddr(1); + + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] start to execute BulkWrite"); + sptr ashmem = new Ashmem(1, 1); + auto &UsbSrvClient = UsbSrvClient::GetInstance(); + auto ret = UsbSrvClient.BulkWrite(pipe, point,ashmem); + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] UsbBulkWrite001 %{public}d BulkWrite=%{public}d", __LINE__, + ret); + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] Case End : UsbBulkWrite001"); + sleep(SLEEP_TIME); +} + +/** + * @tc.name: Usbcontrolstansfer099 + * @tc.desc: Test functions to int32_t UsbService::ControlTransfer(uint8_t busNum, uint8_t devAddr, + * const UsbCtlSetUp& ctrlParams, std::vector &bufferData) + * @tc.type: FUNC + */ +HWTEST_F(UsbDevicePipeTest, Usbcontrolstansfer099, TestSize.Level1) +{ + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] Case Start : Usbcontrolstansfer099 : ControlTransfer"); + uint32_t len = BUFFER_SIZE; + uint8_t buffer[BUFFER_SIZE] = {0}; + USBDevicePipe pipe; + pipe.SetDevAddr(BUFFER_SIZE); + struct UsbCtrlTransfer ctrldata = {0b10000010, 0X0C, 0, 0, 5}; + std::vector ctrlbuffer = {buffer, buffer + len}; + auto &UsbSrvClient = UsbSrvClient::GetInstance(); + auto ret = UsbSrvClient.ControlTransfer(pipe, ctrldata, ctrlbuffer); + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] UsbDevicePipeTest::Usbcontrolstansfer099 %{public}d ControlTransfer=%{public}d", + __LINE__, ret); + + USB_HILOGI(MODULE_USB_SERVICE, "[wjg] Case End : Usbcontrolstansfer099 : ControlTransfer"); + sleep(SLEEP_TIME); +} } // DevicePipe } // USB } // OHOS -- Gitee