• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <benchmark/benchmark.h>
17 #include <gtest/gtest.h>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 #include "hdf_log.h"
22 #include "securec.h"
23 #include "usbd_port.h"
24 #include "usbd_function.h"
25 #include "UsbSubscriberTest.h"
26 #include "v1_0/iusb_interface.h"
27 #include "v1_0/usb_types.h"
28 
29 using namespace benchmark::internal;
30 using namespace OHOS;
31 using namespace std;
32 using namespace OHOS::USB;
33 using namespace OHOS::HDI::Usb::V1_0;
34 
35 namespace {
36 sptr<IUsbInterface> g_usbInterface = nullptr;
37 struct UsbDev g_dev = {0, 0};
38 const int SLEEP_TIME = 3;
39 const uint8_t INTERFACEID_OK = 1;
40 const uint32_t MAX_BUFFER_LENGTH = 255;
41 const int32_t TRANSFER_TIME_OUT = 1000;
42 const int32_t ASHMEM_MAX_SIZE = 1024;
43 const uint8_t SAMPLE_DATA_1 = 1;
44 const uint8_t SAMPLE_DATA_2 = 2;
45 const uint8_t SAMPLE_DATA_3 = 3;
46 constexpr int32_t ITERATION_FREQUENCY = 100;
47 constexpr int32_t REPETITION_FREQUENCY = 3;
48 constexpr int32_t ITERATION_READ_FREQUENCY = 10;
49 constexpr int32_t ITERATION_WRITE_FREQUENCY = 20;
50 // data interface have 2 point : 1->bulk_out 2->bulk_in
51 const uint8_t POINTID_BULK_IN = USB_ENDPOINT_DIR_IN | 2;
52 const uint8_t POINTID_BULK_OUT = USB_ENDPOINT_DIR_OUT | 1;
53 
54 class HdfUsbdBenchmarkTransferTest : public benchmark::Fixture {
55 public:
56     void SetUp(const ::benchmark::State &state);
57     void TearDown(const ::benchmark::State &state);
58     void InitPara(const sptr<UsbSubscriberTest> &subscriber);
59     void ReleasePara(const sptr<UsbSubscriberTest> &subscriber);
60 };
61 
62 class UsbdBulkCallbackTest : public OHOS::HDI::Usb::V1_0::IUsbdBulkCallback {
63 public:
64     UsbdBulkCallbackTest() = default;
65     ~UsbdBulkCallbackTest() = default;
OnBulkWriteCallback(int32_t status,int32_t actLength)66     int32_t OnBulkWriteCallback(int32_t status, int32_t actLength) override
67     {
68         return 0;
69     };
OnBulkReadCallback(int32_t status,int32_t actLength)70     int32_t OnBulkReadCallback(int32_t status, int32_t actLength) override
71     {
72         return 0;
73     };
74 };
75 
InitAshmemOne(sptr<Ashmem> & asmptr,int32_t asmSize,uint8_t rflg)76 int32_t InitAshmemOne(sptr<Ashmem>& asmptr, int32_t asmSize, uint8_t rflg)
77 {
78     asmptr = Ashmem::CreateAshmem("ttashmem000", asmSize);
79     if (asmptr == nullptr) {
80         return HDF_FAILURE;
81     }
82 
83     asmptr->MapReadAndWriteAshmem();
84 
85     if (rflg == 0) {
86         uint8_t tdata[ASHMEM_MAX_SIZE];
87         int32_t offset = 0;
88         int32_t tlen = 0;
89 
90         int32_t retSafe = memset_s(tdata, sizeof(tdata), 'Y', ASHMEM_MAX_SIZE);
91         if (retSafe != EOK) {
92             return HDF_FAILURE;
93         }
94         while (offset < asmSize) {
95             tlen = (asmSize - offset) < ASHMEM_MAX_SIZE ? (asmSize - offset) : ASHMEM_MAX_SIZE;
96             asmptr->WriteToAshmem(tdata, tlen, offset);
97             offset += tlen;
98         }
99     }
100     return HDF_SUCCESS;
101 }
102 
SetUp(const::benchmark::State & state)103 void HdfUsbdBenchmarkTransferTest::SetUp(const ::benchmark::State& state)
104 {
105     g_usbInterface = IUsbInterface::Get();
106     ASSERT_NE(g_usbInterface, nullptr);
107     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
108     sleep(SLEEP_TIME);
109     EXPECT_EQ(0, ret);
110 }
111 
TearDown(const::benchmark::State & state)112 void HdfUsbdBenchmarkTransferTest::TearDown(const ::benchmark::State& state)
113 {}
114 
InitPara(const sptr<UsbSubscriberTest> & subscriber)115 void HdfUsbdBenchmarkTransferTest::InitPara(const sptr<UsbSubscriberTest> &subscriber)
116 {
117     if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
118         HDF_LOGW("HdfUsbdBenchmarkRequestTest::bind usbdsubscriber fail");
119     }
120     g_dev = {subscriber->busNum_, subscriber->devAddr_};
121     auto ret = g_usbInterface->OpenDevice(g_dev);
122     EXPECT_EQ(0, ret);
123 }
124 
ReleasePara(const sptr<UsbSubscriberTest> & subscriber)125 void HdfUsbdBenchmarkTransferTest::ReleasePara(const sptr<UsbSubscriberTest> &subscriber)
126 {
127     ASSERT_TRUE(g_usbInterface != nullptr);
128     auto ret = g_usbInterface->UnbindUsbdSubscriber(subscriber);
129     EXPECT_EQ(0, ret);
130     ret = g_usbInterface->CloseDevice(g_dev);
131     EXPECT_EQ(0, ret);
132 }
133 
134 /**
135  * @tc.name: ControlTransferRead
136  * @tc.desc: Benchmark test
137  * @tc.desc: Test functions to ControlTransferRead(const UsbDev &dev, UsbCtrlTransfer &ctrl,
138  * std::vector<uint8_t> &data);
139  * @tc.desc: Positive test: parameters correctly, standard request: get configuration
140  * @tc.type: FUNC
141  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,ControlTransferRead)142 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, ControlTransferRead)(benchmark::State& state)
143 {
144     ASSERT_TRUE(g_usbInterface != nullptr);
145     int32_t ret;
146     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
147     ASSERT_TRUE(subscriber != nullptr);
148     InitPara(subscriber);
149     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
150     struct UsbCtrlTransfer ctrlparmas = {USB_ENDPOINT_DIR_IN, USB_DDK_REQ_GET_CONFIGURATION, 0, 0, TRANSFER_TIME_OUT};
151     for (auto _ : state) {
152         ret = g_usbInterface->ControlTransferRead(g_dev, ctrlparmas, bufferData);
153     }
154     EXPECT_EQ(0, ret);
155     ReleasePara(subscriber);
156 }
157 
158 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, ControlTransferRead)->
159     Iterations(ITERATION_READ_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
160 
161 /**
162  * @tc.name: ControlTransferWrite
163  * @tc.desc: Benchmark test
164  * @tc.desc: Test functions to ControlTransferWrite(const UsbDev &dev, UsbCtrlTransfer &ctrl,
165  * std::vector<uint8_t> &data);
166  * @tc.desc: Positive test: parameters correctly
167  * @tc.type: FUNC
168  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,ControlTransferWrite)169 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, ControlTransferWrite)(benchmark::State& state)
170 {
171     ASSERT_TRUE(g_usbInterface != nullptr);
172     int32_t ret;
173     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
174     ASSERT_TRUE(subscriber != nullptr);
175     InitPara(subscriber);
176     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
177     bufferData.push_back(SAMPLE_DATA_1);
178     bufferData.push_back(SAMPLE_DATA_2);
179     bufferData.push_back(SAMPLE_DATA_3);
180     struct UsbCtrlTransfer ctrlparmas = {USB_ENDPOINT_DIR_OUT | USB_REQUEST_TARGET_INTERFACE,
181         USB_DDK_REQ_GET_CONFIGURATION, 0, 0, TRANSFER_TIME_OUT};
182     for (auto _ : state) {
183         ret = g_usbInterface->ControlTransferWrite(g_dev, ctrlparmas, bufferData);
184     }
185     EXPECT_EQ(0, ret);
186     ReleasePara(subscriber);
187 }
188 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, ControlTransferWrite)->
189     Iterations(ITERATION_WRITE_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
190 
191 /**
192  * @tc.name: BulkTransferRead
193  * @tc.desc: Benchmark test
194  * @tc.desc: Test functions to BulkTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
195  * std::vector<uint8_t> &data);
196  * @tc.desc: Positive test: parameters correctly
197  * @tc.type: FUNC
198  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,BulkTransferRead)199 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, BulkTransferRead)(benchmark::State& state)
200 {
201     ASSERT_TRUE(g_usbInterface != nullptr);
202     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
203     ASSERT_TRUE(subscriber != nullptr);
204     InitPara(subscriber);
205     uint8_t interfaceId = INTERFACEID_OK;
206     uint8_t pointid = POINTID_BULK_IN;
207     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
208     EXPECT_EQ(0, ret);
209     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
210     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
211     for (auto _ : state) {
212         ret = g_usbInterface->BulkTransferRead(g_dev, pipe, TRANSFER_TIME_OUT, bufferData);
213     }
214     EXPECT_EQ(0, ret);
215     ReleasePara(subscriber);
216 }
217 
218 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, BulkTransferRead)->
219     Iterations(ITERATION_READ_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
220 
221 /**
222  * @tc.name: BulkTransferWrite
223  * @tc.desc: Benchmark test
224  * @tc.desc: Test functions to BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
225  * std::vector<uint8_t> &data);
226  * @tc.desc: Positive test: parameters correctly
227  * @tc.type: FUNC
228  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,BulkTransferWrite)229 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, BulkTransferWrite)(benchmark::State& state)
230 {
231     ASSERT_TRUE(g_usbInterface != nullptr);
232     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
233     ASSERT_TRUE(subscriber != nullptr);
234     InitPara(subscriber);
235     uint8_t interfaceId = INTERFACEID_OK;
236     uint8_t pointid = POINTID_BULK_OUT;
237     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
238     EXPECT_EQ(0, ret);
239     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
240     std::vector<uint8_t> bufferData = {'b', 'u', 'l', 'k', 'w', 'r', 'i', 't', 'e', '0', '1'};
241     for (auto _ : state) {
242         ret = g_usbInterface->BulkTransferWrite(g_dev, pipe, TRANSFER_TIME_OUT, bufferData);
243     }
244     EXPECT_EQ(0, ret);
245     ReleasePara(subscriber);
246 }
247 
248 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, BulkTransferWrite)->
249     Iterations(ITERATION_WRITE_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
250 
251 /**
252  * @tc.name: InterruptTransferRead
253  * @tc.desc: Benchmark test
254  * @tc.desc: Test functions to InterruptTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
255  * std::vector<uint8_t> &data);
256  * @tc.desc: Positive test: parameters correctly
257  * @tc.type: FUNC
258  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,InterruptTransferRead)259 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, InterruptTransferRead)(benchmark::State& state)
260 {
261     ASSERT_TRUE(g_usbInterface != nullptr);
262     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
263     ASSERT_TRUE(subscriber != nullptr);
264     InitPara(subscriber);
265     uint8_t interfaceId = INTERFACEID_OK;
266     uint8_t pointid = POINTID_BULK_IN;
267     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
268     EXPECT_EQ(0, ret);
269     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
270     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
271     for (auto _ : state) {
272         ret = g_usbInterface->InterruptTransferRead(g_dev, pipe, TRANSFER_TIME_OUT, bufferData);
273     }
274     EXPECT_EQ(0, ret);
275     ReleasePara(subscriber);
276 }
277 
278 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, InterruptTransferRead)->
279     Iterations(ITERATION_READ_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
280 /**
281  * @tc.name: InterruptTransferWrite
282  * @tc.desc: Benchmark test
283  * @tc.desc: Test functions to InterruptTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
284  * std::vector<uint8_t> &data);
285  * @tc.desc: Positive test: parameters correctly
286  * @tc.type: FUNC
287  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,InterruptTransferWrite)288 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, InterruptTransferWrite)(benchmark::State& state)
289 {
290     ASSERT_TRUE(g_usbInterface != nullptr);
291     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
292     ASSERT_TRUE(subscriber != nullptr);
293     InitPara(subscriber);
294     uint8_t interfaceId = INTERFACEID_OK;
295     uint8_t pointid = POINTID_BULK_OUT;
296     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
297     EXPECT_EQ(0, ret);
298     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
299     std::vector<uint8_t> bufferData = {'i', 'n', 't', 'w', 'r', 'i', 't', 'e', '0', '1'};
300     for (auto _ : state) {
301         ret = g_usbInterface->InterruptTransferWrite(g_dev, pipe, TRANSFER_TIME_OUT, bufferData);
302     }
303     EXPECT_EQ(0, ret);
304     ReleasePara(subscriber);
305 }
306 
307 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, InterruptTransferWrite)->
308     Iterations(ITERATION_WRITE_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
309 /**
310  * @tc.name: IsoTransferRead
311  * @tc.desc: Benchmark test
312  * @tc.desc: Test functions to IsoTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
313  * std::vector<uint8_t> &data);
314  * @tc.desc: Positive test: parameters correctly
315  * @tc.type: FUNC
316  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,IsoTransferRead)317 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, IsoTransferRead)(benchmark::State& state)
318 {
319     ASSERT_TRUE(g_usbInterface != nullptr);
320     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
321     ASSERT_TRUE(subscriber != nullptr);
322     InitPara(subscriber);
323     uint8_t interfaceId = INTERFACEID_OK;
324     uint8_t pointid = POINTID_BULK_IN;
325     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
326     EXPECT_EQ(0, ret);
327     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
328     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
329     for (auto _ : state) {
330         ret = g_usbInterface->IsoTransferRead(g_dev, pipe, TRANSFER_TIME_OUT, bufferData);
331     }
332     EXPECT_EQ(0, ret);
333     ReleasePara(subscriber);
334 }
335 
336 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, IsoTransferRead)->
337     Iterations(ITERATION_READ_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
338 /**
339  * @tc.name: IsoTransferWrite
340  * @tc.desc: Benchmark test
341  * @tc.desc: Test functions to IsoTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
342  * std::vector<uint8_t> &data);
343  * @tc.desc: Positive test: parameters correctly
344  * @tc.type: FUNC
345  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,IsoTransferWrite)346 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, IsoTransferWrite)(benchmark::State& state)
347 {
348     ASSERT_TRUE(g_usbInterface != nullptr);
349     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
350     ASSERT_TRUE(subscriber != nullptr);
351     InitPara(subscriber);
352     uint8_t interfaceId = INTERFACEID_OK;
353     uint8_t pointid = POINTID_BULK_OUT;
354     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
355     EXPECT_EQ(0, ret);
356     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
357     std::vector<uint8_t> bufferData = {'i', 's', 'o', 'w', 'r', 'i', 't', 'e', '0', '1'};
358     for (auto _ : state) {
359         ret = g_usbInterface->IsoTransferWrite(g_dev, pipe, TRANSFER_TIME_OUT, bufferData);
360     }
361     EXPECT_EQ(0, ret);
362     ReleasePara(subscriber);
363 }
364 
365 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, IsoTransferWrite)->
366     Iterations(ITERATION_WRITE_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
367 
368 /**
369  * @tc.name: BulkRead
370  * @tc.desc: Benchmark test
371  * @tc.desc: Test functions to int32_t BulkRead(const UsbDev &dev, const UsbPipe &pipe, const sptr<Ashmem> &ashmem)
372  * @tc.desc: Positive test: parameters correctly
373  * @tc.type: FUNC
374  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,BulkRead)375 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, BulkRead)(benchmark::State& state)
376 {
377     ASSERT_TRUE(g_usbInterface != nullptr);
378     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
379     ASSERT_TRUE(subscriber != nullptr);
380     InitPara(subscriber);
381     sptr<Ashmem> ashmem;
382     uint8_t rflg = 0;
383     int32_t asmSize = MAX_BUFFER_LENGTH;
384     uint8_t interfaceId = INTERFACEID_OK;
385     uint8_t pointid = POINTID_BULK_IN;
386     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
387     EXPECT_EQ(0, ret);
388     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
389     (void)InitAshmemOne(ashmem, asmSize, rflg);
390     for (auto _ : state) {
391         ret = g_usbInterface->BulkRead(g_dev, pipe, ashmem);
392     }
393     EXPECT_EQ(ret, 0);
394     ReleasePara(subscriber);
395 }
396 
397 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, BulkRead)->
398     Iterations(ITERATION_READ_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
399 
400 /**
401  * @tc.name: BulkWrite
402  * @tc.desc: Benchmark test
403  * @tc.desc: Test functions to int32_t BulkWrite(const UsbDev &dev, const UsbPipe &pipe, const sptr<Ashmem> &ashmem)
404  * @tc.desc: Positive test: parameters correctly
405  * @tc.type: FUNC
406  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,BulkWrite)407 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, BulkWrite)(benchmark::State& state)
408 {
409     ASSERT_TRUE(g_usbInterface != nullptr);
410     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
411     ASSERT_TRUE(subscriber != nullptr);
412     InitPara(subscriber);
413     sptr<Ashmem> ashmem;
414     uint8_t rflg = 0;
415     int32_t asmSize = MAX_BUFFER_LENGTH;
416     uint8_t interfaceId = INTERFACEID_OK;
417     uint8_t pointid = POINTID_BULK_IN;
418     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
419     EXPECT_EQ(0, ret);
420     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
421     (void)InitAshmemOne(ashmem, asmSize, rflg);
422     for (auto _ : state) {
423         ret = g_usbInterface->BulkWrite(g_dev, pipe, ashmem);
424     }
425     EXPECT_EQ(ret, 0);
426     ReleasePara(subscriber);
427 }
428 
429 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, BulkWrite)->
430     Iterations(ITERATION_WRITE_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
431 
432 /**
433  * @tc.name: RegBulkCallback
434  * @tc.desc: Benchmark test
435  * @tc.desc: int32_t RegBulkCallback(const UsbDev &dev, const UsbPipe &pipe, const sptr<IUsbdBulkCallback> &cb)
436  * @tc.desc: Positive test: parameters correctly
437  * @tc.type: FUNC
438  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,RegBulkCallback)439 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, RegBulkCallback)(benchmark::State& state)
440 {
441     ASSERT_TRUE(g_usbInterface != nullptr);
442     int32_t ret;
443     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
444     ASSERT_TRUE(subscriber != nullptr);
445     InitPara(subscriber);
446     uint8_t interfaceId = INTERFACEID_OK;
447     uint8_t pointid = POINTID_BULK_OUT;
448     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
449     sptr<UsbdBulkCallbackTest> usbdBulkCallback = new UsbdBulkCallbackTest();
450     ASSERT_TRUE(usbdBulkCallback != nullptr);
451     for (auto _ : state) {
452         ret = g_usbInterface->RegBulkCallback(g_dev, pipe, usbdBulkCallback);
453     }
454     EXPECT_EQ(ret, 0);
455     ReleasePara(subscriber);
456 }
457 
458 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, RegBulkCallback)->
459     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
460 
461 /**
462  * @tc.name: UnRegBulkCallback
463  * @tc.desc: Benchmark test
464  * @tc.desc: Test functions to int32_t UnRegBulkCallback(const UsbDev &dev, const UsbPipe &pipe)
465  * @tc.desc: Positive test: parameters correctly
466  * @tc.type: FUNC
467  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,UnRegBulkCallback)468 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, UnRegBulkCallback)(benchmark::State& state)
469 {
470     ASSERT_TRUE(g_usbInterface != nullptr);
471     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
472     ASSERT_TRUE(subscriber != nullptr);
473     InitPara(subscriber);
474     uint8_t interfaceId = INTERFACEID_OK;
475     uint8_t pointid = POINTID_BULK_OUT;
476     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointid};
477     sptr<UsbdBulkCallbackTest> usbdBulkCallback = new UsbdBulkCallbackTest();
478     ASSERT_TRUE(usbdBulkCallback != nullptr);
479     auto ret = g_usbInterface->RegBulkCallback(g_dev, pipe, usbdBulkCallback);
480     EXPECT_EQ(ret, 0);
481     for (auto _ : state) {
482         ret = g_usbInterface->UnRegBulkCallback(g_dev, pipe);
483     }
484     EXPECT_EQ(ret, 0);
485     ReleasePara(subscriber);
486 }
487 
488 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, UnRegBulkCallback)->
489     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
490 
491 /**
492  * @tc.name: BindUsbdSubscriber
493  * @tc.desc: Benchmark test
494  * @tc.desc: Test functions to int32_t BindUsbdSubscriber(const sptr<IUsbdSubscriber> &subscriber)
495  * @tc.desc: Positive test: parameters correctly
496  * @tc.type: FUNC
497  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,BindUsbdSubscriber)498 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, BindUsbdSubscriber)(benchmark::State& state)
499 {
500     ASSERT_TRUE(g_usbInterface != nullptr);
501     int32_t ret;
502     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
503     ASSERT_TRUE(subscriber != nullptr);
504     InitPara(subscriber);
505     for (auto _ : state) {
506         ret = g_usbInterface->BindUsbdSubscriber(subscriber);
507     }
508     EXPECT_EQ(0, ret);
509     ReleasePara(subscriber);
510 }
511 
512 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, BindUsbdSubscriber)->
513     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
514 /**
515  * @tc.name: UnbindUsbdSubscriber
516  * @tc.desc: Benchmark test
517  * @tc.desc: Test functions to int32_t UnbindUsbdSubscriber(const sptr<IUsbdSubscriber> &subscriber)
518  * @tc.desc: Positive test: parameters correctly
519  * @tc.type: FUNC
520  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,UnbindUsbdSubscriber)521 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, UnbindUsbdSubscriber)(benchmark::State& state)
522 {
523     ASSERT_TRUE(g_usbInterface != nullptr);
524     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
525     ASSERT_NE(subscriber, nullptr);
526     if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
527         HDF_LOGW("%{public}s: bind usbd subscriber failed\n", __func__);
528     }
529     g_dev = {subscriber->busNum_, subscriber->devAddr_};
530     auto ret = g_usbInterface->OpenDevice(g_dev);
531     EXPECT_EQ(ret, 0);
532     for (auto _ : state) {
533         ret = g_usbInterface->UnbindUsbdSubscriber(subscriber);
534     }
535     ret = g_usbInterface->CloseDevice(g_dev);
536     EXPECT_EQ(0, ret);
537 }
538 
539 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, UnbindUsbdSubscriber)->
540     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
541 } // namespace
542 
543 BENCHMARK_MAIN();
544