• 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 #include <benchmark/benchmark.h>
16 #include <gtest/gtest.h>
17 #include <iostream>
18 #include <vector>
19 #include "hdf_log.h"
20 #include "usbd_port.h"
21 #include "UsbSubscriberTest.h"
22 #include "v1_0/iusb_interface.h"
23 #include "v1_0/iusbd_bulk_callback.h"
24 #include "v1_0/usb_types.h"
25 
26 using namespace benchmark::internal;
27 using namespace OHOS;
28 using namespace OHOS::USB;
29 using namespace std;
30 using namespace OHOS::HDI::Usb::V1_0;
31 
32 namespace {
33 sptr<IUsbInterface> g_usbInterface = nullptr;
34 struct UsbDev g_dev = {0, 0};
35 
36 const int SLEEP_TIME = 3;
37 const uint8_t INDEX_0 = 0;
38 const uint8_t INDEX_1 = 1;
39 const int TAG_NUM_10 = 10;
40 const uint8_t CONFIG_ID_0 = 0;
41 const uint8_t INTERFACEID_OK = 1;
42 const uint32_t MAX_BUFFER_LENGTH = 255;
43 constexpr int32_t ITERATION_FREQUENCY = 100;
44 constexpr int32_t REPETITION_FREQUENCY = 3;
45 const uint32_t TIME_WAIT = 10000;
46 // data interface have 2 point : 1->bulk_out 2->bulk_in
47 const uint8_t POINTID_DIR_IN = USB_ENDPOINT_DIR_IN | 2;
48 
49 class HdfUsbdBenchmarkRequestTest : public benchmark::Fixture {
50 public:
51     void InitPara(const sptr<UsbSubscriberTest> &subscriber);
52     void ReleasePara(const sptr<UsbSubscriberTest> &subscriber);
53     void SetUp(const ::benchmark::State &state);
54     void TearDown(const ::benchmark::State &state);
55 };
56 
57 
58 class UsbdBulkCallbackTest : public OHOS::HDI::Usb::V1_0::IUsbdBulkCallback {
59 public:
60     UsbdBulkCallbackTest() = default;
61     ~UsbdBulkCallbackTest() = default;
OnBulkWriteCallback(int32_t status,int32_t actLength)62     int32_t OnBulkWriteCallback(int32_t status, int32_t actLength) override
63     {
64         return 0;
65     };
OnBulkReadCallback(int32_t status,int32_t actLength)66     int32_t OnBulkReadCallback(int32_t status, int32_t actLength) override
67     {
68         return 0;
69     };
70 };
71 
SetUp(const::benchmark::State & state)72 void HdfUsbdBenchmarkRequestTest::SetUp(const ::benchmark::State& state)
73 {
74     g_usbInterface = IUsbInterface::Get();
75     ASSERT_TRUE(g_usbInterface != nullptr);
76     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SOURCE, DATA_ROLE_HOST);
77     sleep(SLEEP_TIME);
78     EXPECT_EQ(0, ret);
79 }
80 
TearDown(const::benchmark::State & state)81 void HdfUsbdBenchmarkRequestTest::TearDown(const ::benchmark::State& state) {}
82 
InitPara(const sptr<UsbSubscriberTest> & subscriber)83 void HdfUsbdBenchmarkRequestTest::InitPara(const sptr<UsbSubscriberTest> &subscriber)
84 {
85     if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
86         HDF_LOGW("HdfUsbdBenchmarkRequestTest::bind usbdsubscriber fail");
87     }
88     g_dev = {subscriber->busNum_, subscriber->devAddr_};
89     auto ret = g_usbInterface->OpenDevice(g_dev);
90     EXPECT_EQ(0, ret);
91 }
92 
ReleasePara(const sptr<UsbSubscriberTest> & subscriber)93 void HdfUsbdBenchmarkRequestTest::ReleasePara(const sptr<UsbSubscriberTest> &subscriber)
94 {
95     ASSERT_TRUE(g_usbInterface != nullptr);
96     auto ret = g_usbInterface->UnbindUsbdSubscriber(subscriber);
97     EXPECT_EQ(0, ret);
98     ret = g_usbInterface->CloseDevice(g_dev);
99     EXPECT_EQ(0, ret);
100 }
101 /**
102  * @tc.name: SetConfig
103  * @tc.desc: Test functions to SetConfig benchmark test
104  * @tc.desc: int32_t SetConfig(const UsbDev &dev, uint8_t configIndex);
105  * @tc.desc: Positive test: parameters correctly
106  * @tc.type: FUNC
107  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,SetConfig)108 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, SetConfig)(benchmark::State& state)
109 {
110     ASSERT_TRUE(g_usbInterface != nullptr);
111     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
112     ASSERT_TRUE(subscriber != nullptr);
113     uint8_t configIndex = INDEX_1;
114     InitPara(subscriber);
115     auto ret = 0;
116     for (auto _ : state) {
117         ret = g_usbInterface->SetConfig(g_dev, configIndex);
118     }
119     ASSERT_EQ(0, ret);
120     ReleasePara(subscriber);
121 }
122 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, SetConfig)->
123     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
124 
125 /**
126  * @tc.name: GetConfig
127  * @tc.desc: Test functions to GetConfig benchmark test
128  * @tc.desc: int32_t GetConfig(const UsbDev &dev, uint8_t &configIndex);
129  * @tc.desc: Positive test: parameters correctly
130  * @tc.type: FUNC
131  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,GetConfig)132 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, GetConfig)(benchmark::State& state)
133 {
134     ASSERT_TRUE(g_usbInterface != nullptr);
135     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
136     ASSERT_TRUE(subscriber != nullptr);
137     uint8_t configIndex = INDEX_1;
138     InitPara(subscriber);
139     auto ret = 0;
140     for (auto _ : state) {
141         ret = g_usbInterface->GetConfig(g_dev, configIndex);
142     }
143     EXPECT_EQ(0, ret);
144     ReleasePara(subscriber);
145 }
146 
147 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, GetConfig)->
148     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
149 
150 /**
151  * @tc.name: ClaimInterface
152  * @tc.desc: Test functions to ClaimInterface benchmark test
153  * @tc.desc: int32_t  ClaimInterface(const UsbDev &dev, uint8_t interfaceId);
154  * @tc.desc: Positive test: parameters correctly
155  * @tc.type: FUNC
156  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,ClaimInterface)157 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, ClaimInterface)(benchmark::State& state)
158 {
159     ASSERT_TRUE(g_usbInterface != nullptr);
160     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
161     ASSERT_TRUE(subscriber != nullptr);
162     uint8_t interfaceId = INTERFACEID_OK;
163     InitPara(subscriber);
164     auto ret = 0;
165     for (auto _ : state) {
166         ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
167     }
168     EXPECT_EQ(0, ret);
169     ReleasePara(subscriber);
170 }
171 
172 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, ClaimInterface)->
173     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
174 
175 /**
176  * @tc.name: SetInterface
177  * @tc.desc: Test functions to SetInterface benchmark test
178  * @tc.desc: int32_t SetInterface(const UsbDev &dev, uint8_t interfaceId, uint8_t altIndex);
179  * @tc.desc: Positive test: parameters correctly
180  * @tc.type: FUNC
181  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,SetInterface)182 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, SetInterface)(benchmark::State& state)
183 {
184     ASSERT_TRUE(g_usbInterface != nullptr);
185     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
186     ASSERT_TRUE(subscriber != nullptr);
187     InitPara(subscriber);
188     uint8_t interfaceId = INTERFACEID_OK;
189     uint8_t altIndex = INDEX_0;
190     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
191     EXPECT_EQ(0, ret);
192     for (auto _ : state) {
193         ret = g_usbInterface->SetInterface(g_dev, interfaceId, altIndex);
194     }
195     EXPECT_EQ(0, ret);
196     ReleasePara(subscriber);
197 }
198 
199 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, SetInterface)->
200     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
201 
202 /**
203  * @tc.name: GetDeviceDescriptor
204  * @tc.desc: Test functions to GetDeviceDescriptor benchmark test
205  * @tc.desc: int32_t GetDeviceDescriptor(const UsbDev &dev, std::vector<uint8_t> &descriptor);
206  * @tc.desc: Positive test: parameters correctly
207  * @tc.type: FUNC
208  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,GetDeviceDescriptor)209 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, GetDeviceDescriptor)(benchmark::State& state)
210 {
211     ASSERT_TRUE(g_usbInterface != nullptr);
212     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
213     ASSERT_TRUE(subscriber != nullptr);
214     InitPara(subscriber);
215     std::vector<uint8_t> devData(MAX_BUFFER_LENGTH);
216     auto ret = 0;
217     for (auto _ : state) {
218         ret = g_usbInterface->GetDeviceDescriptor(g_dev, devData);
219     }
220     EXPECT_EQ(0, ret);
221     ReleasePara(subscriber);
222 }
223 
224 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, GetDeviceDescriptor)->
225     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
226 
227 /**
228  * @tc.name: GetStringDescriptor
229  * @tc.desc: Test functions to GetStringDescriptor benchmark test
230  * @tc.desc: int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector<uint8_t> &descriptor);
231  * @tc.desc: Positive test: parameters correctly
232  * @tc.type: FUNC
233  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,GetStringDescriptor)234 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, GetStringDescriptor)(benchmark::State& state)
235 {
236     ASSERT_TRUE(g_usbInterface != nullptr);
237     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
238     ASSERT_TRUE(subscriber != nullptr);
239     InitPara(subscriber);
240     uint8_t stringId = 0;
241     std::vector<uint8_t> devData(MAX_BUFFER_LENGTH);
242     auto ret = 0;
243     for (auto _ : state) {
244         ret = g_usbInterface->GetStringDescriptor(g_dev, stringId, devData);
245     }
246     EXPECT_EQ(0, ret);
247     ReleasePara(subscriber);
248 }
249 
250 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, GetStringDescriptor)->
251     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
252 
253 /**
254  * @tc.name: GetConfigDescriptor
255  * @tc.desc: Test functions to GetConfigDescriptor benchmark test
256  * @tc.desc: int32_t GetConfigDescriptor(const UsbDev &dev, uint8_t descId, std::vector<uint8_t> &descriptor);
257  * @tc.desc: Positive test: parameters correctly
258  * @tc.type: FUNC
259  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,GetConfigDescriptor)260 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, GetConfigDescriptor)(benchmark::State& state)
261 {
262     ASSERT_TRUE(g_usbInterface != nullptr);
263     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
264     ASSERT_TRUE(subscriber != nullptr);
265     InitPara(subscriber);
266     uint8_t configId = CONFIG_ID_0;
267     std::vector<uint8_t> devData(MAX_BUFFER_LENGTH);
268     auto ret = 0;
269     for (auto _ : state) {
270         ret = g_usbInterface->GetConfigDescriptor(g_dev, configId, devData);
271     }
272     EXPECT_EQ(0, ret);
273     ReleasePara(subscriber);
274 }
275 
276 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, GetConfigDescriptor)->
277     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
278 
279 /**
280  * @tc.name: GetRawDescriptor
281  * @tc.desc: Test functions to GetRawDescriptor benchmark test
282  * @tc.desc: int32_t GetRawDescriptor(const UsbDev &dev, std::vector<uint8_t> &descriptor);
283  * @tc.desc: Positive test: parameters correctly
284  * @tc.type: FUNC
285  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,GetRawDescriptor)286 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, GetRawDescriptor)(benchmark::State& state)
287 {
288     ASSERT_TRUE(g_usbInterface != nullptr);
289     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
290     ASSERT_TRUE(subscriber != nullptr);
291     InitPara(subscriber);
292     std::vector<uint8_t> rawData;
293     auto ret = 0;
294     for (auto _ : state) {
295         ret = g_usbInterface->GetRawDescriptor(g_dev, rawData);
296     }
297     EXPECT_EQ(0, ret);
298     ReleasePara(subscriber);
299 }
300 
301 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, GetRawDescriptor)->
302     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
303 
304 /**
305  * @tc.name: GetFileDescriptor
306  * @tc.desc: Test functions to GetFileDescriptor benchmark test
307  * @tc.desc: int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd);
308  * @tc.desc: Positive test: parameters correctly
309  * @tc.type: FUNC
310  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,GetFileDescriptor)311 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, GetFileDescriptor)(benchmark::State& state)
312 {
313     ASSERT_TRUE(g_usbInterface != nullptr);
314     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
315     ASSERT_TRUE(subscriber != nullptr);
316     InitPara(subscriber);
317     int32_t fd = 0;
318     auto ret = 0;
319     for (auto _ : state) {
320         ret = g_usbInterface->GetFileDescriptor(g_dev, fd);
321     }
322     EXPECT_EQ(0, ret);
323     ReleasePara(subscriber);
324 }
325 
326 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, GetFileDescriptor)->
327     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
328 
329 /**
330  * @tc.name: RequestQueue
331  * @tc.desc: Test functions to RequestQueue benchmark test
332  * @tc.desc: int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, std::vector<uint8_t> &clientData,
333         std::vector<uint8_t> &buffer);
334  * @tc.desc: Positive test: parameters correctly
335  * @tc.type: FUNC
336  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,RequestQueue)337 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, RequestQueue)(benchmark::State& state)
338 {
339     ASSERT_TRUE(g_usbInterface != nullptr);
340     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
341     ASSERT_TRUE(subscriber != nullptr);
342     InitPara(subscriber);
343     uint8_t interfaceId = INTERFACEID_OK;
344     uint8_t pointId = POINTID_DIR_IN;
345     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
346     EXPECT_EQ(0, ret);
347     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointId};
348     std::vector<uint8_t> clientData = {'q', 'u', 'e', 'u', 'e', 'r', 'e', 'a', 'd'};
349     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
350     for (auto _ : state) {
351         ret = g_usbInterface->RequestQueue(g_dev, pipe, clientData, bufferData);
352     }
353     ReleasePara(subscriber);
354 }
355 
356 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, RequestQueue)->
357     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
358 
359 /**
360  * @tc.name: RequestWait
361  * @tc.desc: Test functions to RequestWait benchmark test
362  * @tc.desc: int32_t RequestWait(const UsbDev &dev, std::vector<uint8_t> &clientData, std::vector<uint8_t> &buffer,
363  * int32_t timeout);
364  * @tc.desc: Positive test: parameters correctly
365  * @tc.type: FUNC
366  */
367 
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,RequestWait)368 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, RequestWait)(benchmark::State& state)
369 {
370     ASSERT_TRUE(g_usbInterface != nullptr);
371     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
372     ASSERT_TRUE(subscriber != nullptr);
373     InitPara(subscriber);
374     uint8_t pointId = POINTID_DIR_IN;
375     uint8_t interfaceId = INTERFACEID_OK;
376     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
377     EXPECT_EQ(0, ret);
378     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointId};
379     std::vector<uint8_t> clientData = {'q', 'u', 'e', 'u', 'e', 'r', 'e', 'a', 'd'};
380     std::vector<uint8_t> bufferData(MAX_BUFFER_LENGTH);
381     ret = g_usbInterface->RequestQueue(g_dev, pipe, clientData, bufferData);
382     std::vector<uint8_t> waitData(TAG_NUM_10);
383     for (auto _ : state) {
384         ret = g_usbInterface->RequestWait(g_dev, waitData, bufferData, TIME_WAIT);
385     }
386     ReleasePara(subscriber);
387 }
388 
389 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, RequestWait)->
390     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
391 
392 /**
393  * @tc.name: RequestCancel
394  * @tc.desc: Test functions to RequestCancel benchmark test
395  * @tc.desc: int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe);
396  * @tc.desc: Positive test: parameters correctly
397  * @tc.type: FUNC
398  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,RequestCancel)399 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, RequestCancel)(benchmark::State& state)
400 {
401     ASSERT_TRUE(g_usbInterface != nullptr);
402     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
403     ASSERT_TRUE(subscriber != nullptr);
404     InitPara(subscriber);
405     uint8_t pointId = POINTID_DIR_IN;
406     uint8_t interfaceId = INTERFACEID_OK;
407     auto ret = g_usbInterface->ClaimInterface(g_dev, interfaceId, 1);
408     EXPECT_EQ(0, ret);
409     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointId};
410     std::vector<uint8_t> clientData = {'q', 'u', 'e', 'u', 'e', 'r', 'e', 'a', 'd'};
411     std::vector<uint8_t> bufferData = {'r', 'e', 'q', 'u', 'e', 's', 't', '0', '0', '1'};
412     ret = g_usbInterface->RequestQueue(g_dev, pipe, clientData, bufferData);
413     EXPECT_EQ(0, ret);
414     for (auto _ : state) {
415         ret = g_usbInterface->RequestCancel(g_dev, pipe);
416     }
417     EXPECT_EQ(0, ret);
418     ReleasePara(subscriber);
419 }
420 
421 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, RequestCancel)->
422     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
423 
424 /**
425  * @tc.name: ReleaseInterface
426  * @tc.desc: Test functions to ReleaseInterface benchmark test
427  * @tc.desc: int32_t ReleaseInterface(const UsbDev &dev, uint8_t interfaceId);
428  * @tc.desc: Positive test: parameters correctly
429  * @tc.type: FUNC
430  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,ReleaseInterface)431 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, ReleaseInterface)(benchmark::State& state)
432 {
433     ASSERT_TRUE(g_usbInterface != nullptr);
434     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
435     ASSERT_TRUE(subscriber != nullptr);
436     InitPara(subscriber);
437     uint8_t interfaceId = INTERFACEID_OK;
438     auto ret = 0;
439     for (auto _ : state) {
440         ret = g_usbInterface->ReleaseInterface(g_dev, interfaceId);
441     }
442     EXPECT_EQ(0, ret);
443     ReleasePara(subscriber);
444 }
445 
446 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, ReleaseInterface)->
447     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
448 
449 /**
450  * @tc.name: BulkCancel
451  * @tc.desc: Test functions to BulkCancel benchmark test
452  * @tc.desc: int32_t BulkCancel(const UsbDev &dev, const UsbPipe &pipe);
453  * @tc.desc: Positive test: parameters correctly
454  * @tc.type: FUNC
455  */
BENCHMARK_F(HdfUsbdBenchmarkRequestTest,BulkCancel)456 BENCHMARK_F(HdfUsbdBenchmarkRequestTest, BulkCancel)(benchmark::State& state)
457 {
458     ASSERT_TRUE(g_usbInterface != nullptr);
459     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
460     ASSERT_TRUE(subscriber != nullptr);
461     InitPara(subscriber);
462     uint8_t interfaceId = INTERFACEID_OK;
463     uint8_t pointId = POINTID_DIR_IN;
464     OHOS::HDI::Usb::V1_0::UsbPipe pipe = {interfaceId, pointId};
465     sptr<UsbdBulkCallbackTest> usbdBulkCallback = new UsbdBulkCallbackTest();
466     auto ret = g_usbInterface->RegBulkCallback(g_dev, pipe, usbdBulkCallback);
467     EXPECT_EQ(ret, 0);
468     for (auto _ : state) {
469         ret = g_usbInterface->BulkCancel(g_dev, pipe);
470     }
471     EXPECT_EQ(0, ret);
472     ret = g_usbInterface->UnRegBulkCallback(g_dev, pipe);
473     EXPECT_EQ(ret, 0);
474     ReleasePara(subscriber);
475 }
476 
477 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkRequestTest, BulkCancel)->
478     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
479 } // namespace
480 
481 BENCHMARK_MAIN();
482