• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <iostream>
16 #include <string>
17 #include <vector>
18 
19 #include "UsbSubscriberTest.h"
20 #include "hdf_log.h"
21 #include "securec.h"
22 #include "v1_0/iusb_interface.h"
23 #include "v1_0/usb_types.h"
24 #include "HdfUsbdBenchmarkTransferTest.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 const int SLEEP_TIME = 3;
33 uint8_t BUS_NUM_1 = 0;
34 uint8_t DEV_ADDR_2 = 0;
35 const uint32_t LENGTH_NUM_255 = 255;
36 const uint8_t INTERFACEID_1 = 1;
37 const uint8_t POINTID_1 = 1;
38 const uint8_t POINTID_129 = 130;
39 const uint8_t POINTID_BULK_IN = 0x82;
40 const uint8_t POINTID_BULK_OUT = 0x01;
41 const int32_t ASHMEM_MAX_SIZE = 1024;
42 const uint8_t SAMPLE_DATA_1 = 1;
43 const uint8_t SAMPLE_DATA_2 = 2;
44 const uint8_t SAMPLE_DATA_3 = 3;
45 UsbDev HdfUsbdBenchmarkTransferTest::dev_ = { 0, 0 };
46 
47 namespace {
48 sptr<IUsbInterface> g_usbInterface = nullptr;
49 
InitAshmemOne(sptr<Ashmem> & asmptr,int32_t asmSize,uint8_t rflg)50 int32_t InitAshmemOne(sptr<Ashmem>& asmptr, int32_t asmSize, uint8_t rflg)
51 {
52     asmptr = Ashmem::CreateAshmem("ttashmem000", asmSize);
53     if (asmptr == nullptr) {
54         return HDF_FAILURE;
55     }
56 
57     asmptr->MapReadAndWriteAshmem();
58 
59     if (rflg == 0) {
60         uint8_t tdata[ASHMEM_MAX_SIZE];
61         int32_t offset = 0;
62         int32_t tlen = 0;
63 
64         int32_t retSafe = memset_s(tdata, sizeof(tdata), 'Y', ASHMEM_MAX_SIZE);
65         if (retSafe != EOK) {
66             return HDF_FAILURE;
67         }
68         while (offset < asmSize) {
69             tlen = (asmSize - offset) < ASHMEM_MAX_SIZE ? (asmSize - offset) : ASHMEM_MAX_SIZE;
70             asmptr->WriteToAshmem(tdata, tlen, offset);
71             offset += tlen;
72         }
73     }
74     return HDF_SUCCESS;
75 }
76 
SetUp(const::benchmark::State & state)77 void HdfUsbdBenchmarkTransferTest::SetUp(const ::benchmark::State& state)
78 {
79     g_usbInterface = IUsbInterface::Get();
80     if (g_usbInterface == nullptr) {
81         exit(0);
82     }
83     const int32_t DEFAULT_PORT_ID = 1;
84     const int32_t DEFAULT_ROLE_HOST = 1;
85     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, DEFAULT_ROLE_HOST, DEFAULT_ROLE_HOST);
86     sleep(SLEEP_TIME);
87     ASSERT_EQ(0, ret);
88     if (ret != 0) {
89         exit(0);
90     }
91 
92     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
93     if (subscriber == nullptr) {
94         exit(0);
95     }
96     if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
97         exit(0);
98     }
99     dev_ = { subscriber->busNum_, subscriber->devAddr_ };
100     ret = g_usbInterface->OpenDevice(dev_);
101     ASSERT_EQ(0, ret);
102 }
103 
TearDown(const::benchmark::State & state)104 void HdfUsbdBenchmarkTransferTest::TearDown(const ::benchmark::State& state)
105 {
106     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
107     if (subscriber == nullptr) {
108         exit(0);
109     }
110     if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
111         exit(0);
112     }
113     dev_ = { subscriber->busNum_, subscriber->devAddr_ };
114     auto ret = g_usbInterface->CloseDevice(dev_);
115     ASSERT_EQ(0, ret);
116 }
117 
118 /**
119  * @tc.name: SUB_USB_HDI_Benchmark_0200
120  * @tc.desc: Benchmark test
121  * @tc.desc: Test functions to ControlTransferRead(const UsbDev &dev, UsbCtrlTransfer &ctrl,
122  * std::vector<uint8_t> &data);
123  * @tc.desc: Positive test: parameters correctly, standard request: get configuration
124  * @tc.type: FUNC
125  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0200)126 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0200)
127 (benchmark::State& st)
128 {
129     struct UsbDev dev = dev_;
130     uint8_t buffer[LENGTH_NUM_255] = { 0 };
131     uint32_t length = LENGTH_NUM_255;
132     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
133     struct UsbCtrlTransfer ctrlparmas = { 0b10000000, 8, 0, 0, 1000 };
134     auto ret = 0;
135     for (auto _ : st) {
136         ret = g_usbInterface->ControlTransferRead(dev, ctrlparmas, bufferdata);
137     }
138     ASSERT_EQ(0, ret);
139 }
140 
141 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0200)
142     ->Iterations(100)
143     ->Repetitions(3)
144     ->ReportAggregatesOnly();
145 
146 /**
147  * @tc.name: SUB_USB_HDI_Benchmark_0270
148  * @tc.desc: Benchmark test
149  * @tc.desc: Test functions to ControlTransferWrite(const UsbDev &dev, UsbCtrlTransfer &ctrl,
150  * std::vector<uint8_t> &data);
151  * @tc.desc: Positive test: parameters correctly
152  * @tc.type: FUNC
153  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0270)154 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0270)
155 (benchmark::State& st)
156 {
157     struct UsbDev dev = dev_;
158     std::vector<uint8_t> bufferdata(LENGTH_NUM_255);
159     bufferdata.push_back(SAMPLE_DATA_1);
160     bufferdata.push_back(SAMPLE_DATA_2);
161     bufferdata.push_back(SAMPLE_DATA_3);
162     struct UsbCtrlTransfer ctrlparmas = {0b0001, 8, 0, 0, 1000};
163     auto ret = 0;
164     for (auto _ : st) {
165         ret = g_usbInterface->ControlTransferWrite(dev, ctrlparmas, bufferdata);
166     }
167     ASSERT_EQ(0, ret);
168 }
169 
170 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0270)
171     ->Iterations(100)
172     ->Repetitions(3)
173     ->ReportAggregatesOnly();
174 
175 /**
176  * @tc.name: SUB_USB_HDI_Benchmark_0210
177  * @tc.desc: Benchmark test
178  * @tc.desc: Test functions to BulkTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
179  * std::vector<uint8_t> &data);
180  * @tc.desc: Positive test: parameters correctly
181  * @tc.type: FUNC
182  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0210)183 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0210)
184 (benchmark::State& st)
185 {
186     struct UsbDev dev = dev_;
187     uint8_t interfaceId = INTERFACEID_1;
188     uint8_t pointid = POINTID_BULK_IN;
189     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
190     ASSERT_EQ(0, ret);
191     uint8_t buffer[LENGTH_NUM_255] = { 0 };
192     uint32_t length = LENGTH_NUM_255;
193     struct UsbPipe pipe = { interfaceId, pointid };
194     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
195     for (auto _ : st) {
196         ret = g_usbInterface->BulkTransferRead(dev, pipe, 1000, bufferdata);
197     }
198     ASSERT_EQ(0, ret);
199 }
200 
201 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0210)
202     ->Iterations(100)
203     ->Repetitions(3)
204     ->ReportAggregatesOnly();
205 
206 /**
207  * @tc.name: SUB_USB_HDI_Benchmark_0220
208  * @tc.desc: Benchmark test
209  * @tc.desc: Test functions to BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
210  * std::vector<uint8_t> &data);
211  * @tc.desc: Positive test: parameters correctly
212  * @tc.type: FUNC
213  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0220)214 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0220)
215 (benchmark::State& st)
216 {
217     struct UsbDev dev = dev_;
218     uint8_t interfaceId = INTERFACEID_1;
219     uint8_t pointid = POINTID_1;
220     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
221     ASSERT_EQ(0, ret);
222     uint32_t length = 100;
223     uint8_t buffer[100] = "hello world bulk writ01";
224     struct UsbPipe pipe = { interfaceId, pointid };
225     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
226     for (auto _ : st) {
227         ret = g_usbInterface->BulkTransferWrite(dev, pipe, 1000, bufferdata);
228     }
229     ASSERT_EQ(0, ret);
230 }
231 
232 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0220)
233     ->Iterations(100)
234     ->Repetitions(3)
235     ->ReportAggregatesOnly();
236 
237 /**
238  * @tc.name: SUB_USB_HDI_Benchmark_0230
239  * @tc.desc: Benchmark test
240  * @tc.desc: Test functions to InterruptTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
241  * std::vector<uint8_t> &data);
242  * @tc.desc: Positive test: parameters correctly
243  * @tc.type: FUNC
244  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0230)245 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0230)
246 (benchmark::State& st)
247 {
248     struct UsbDev dev = dev_;
249     uint8_t interfaceId = INTERFACEID_1;
250     uint8_t pointid = POINTID_129;
251     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
252     ASSERT_EQ(0, ret);
253     uint8_t buffer[LENGTH_NUM_255] = { 0 };
254     uint32_t length = LENGTH_NUM_255;
255     struct UsbPipe pipe = { interfaceId, pointid };
256     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
257     for (auto _ : st) {
258         ret = g_usbInterface->InterruptTransferRead(dev, pipe, 1000, bufferdata);
259     }
260     ASSERT_EQ(0, ret);
261 }
262 
263 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0230)
264     ->Iterations(100)
265     ->Repetitions(3)
266     ->ReportAggregatesOnly();
267 
268 /**
269  * @tc.name: SUB_USB_HDI_Benchmark_0240
270  * @tc.desc: Benchmark test
271  * @tc.desc: Test functions to InterruptTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
272  * std::vector<uint8_t> &data);
273  * @tc.desc: Positive test: parameters correctly
274  * @tc.type: FUNC
275  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0240)276 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0240)
277 (benchmark::State& st)
278 {
279     struct UsbDev dev = dev_;
280     uint8_t interfaceId = INTERFACEID_1;
281     uint8_t pointid = POINTID_1;
282     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
283     ASSERT_EQ(0, ret);
284     uint32_t length = 100;
285     uint8_t buffer[100] = "hello world Interrupt writ01";
286     struct UsbPipe pipe = { interfaceId, pointid };
287     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
288     for (auto _ : st) {
289         ret = g_usbInterface->InterruptTransferWrite(dev, pipe, 1000, bufferdata);
290     }
291     ASSERT_EQ(0, ret);
292 }
293 
294 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0240)
295     ->Iterations(100)
296     ->Repetitions(3)
297     ->ReportAggregatesOnly();
298 
299 /**
300  * @tc.name: SUB_USB_HDI_Benchmark_0250
301  * @tc.desc: Benchmark test
302  * @tc.desc: Test functions to IsoTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
303  * std::vector<uint8_t> &data);
304  * @tc.desc: Positive test: parameters correctly
305  * @tc.type: FUNC
306  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0250)307 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0250)
308 (benchmark::State& st)
309 {
310     struct UsbDev dev = dev_;
311     uint8_t interfaceId = INTERFACEID_1;
312     uint8_t pointid = POINTID_129;
313     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
314     ASSERT_EQ(0, ret);
315     uint8_t buffer[LENGTH_NUM_255] = { 0 };
316     uint32_t length = LENGTH_NUM_255;
317     struct UsbPipe pipe = { interfaceId, pointid };
318     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
319     for (auto _ : st) {
320         ret = g_usbInterface->IsoTransferRead(dev, pipe, 1000, bufferdata);
321     }
322     ASSERT_EQ(0, ret);
323 }
324 
325 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0250)
326     ->Iterations(100)
327     ->Repetitions(3)
328     ->ReportAggregatesOnly();
329 
330 /**
331  * @tc.name: SUB_USB_HDI_Benchmark_0260
332  * @tc.desc: Benchmark test
333  * @tc.desc: Test functions to IsoTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout,
334  * std::vector<uint8_t> &data);
335  * @tc.desc: Positive test: parameters correctly
336  * @tc.type: FUNC
337  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0260)338 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0260)
339 (benchmark::State& st)
340 {
341     struct UsbDev dev = dev_;
342     uint8_t interfaceId = INTERFACEID_1;
343     uint8_t pointid = POINTID_1;
344     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
345     ASSERT_EQ(0, ret);
346     uint32_t length = 100;
347     uint8_t buffer[100] = "hello world Iso writ01";
348     struct UsbPipe pipe = { interfaceId, pointid };
349     std::vector<uint8_t> bufferdata = { buffer, buffer + length };
350     for (auto _ : st) {
351         ret = g_usbInterface->IsoTransferWrite(dev, pipe, 1000, bufferdata);
352     }
353     ASSERT_EQ(0, ret);
354 }
355 
356 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0260)
357     ->Iterations(100)
358     ->Repetitions(3)
359     ->ReportAggregatesOnly();
360 
361 /**
362  * @tc.name: SUB_USB_HDI_Benchmark_0290
363  * @tc.desc: Benchmark test
364  * @tc.desc: Test functions to int32_t BulkWrite(const UsbDev &dev, const UsbPipe &pipe, const sptr<Ashmem> &ashmem)
365  * @tc.desc: Positive test: parameters correctly
366  * @tc.type: FUNC
367  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0290)368 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0290)
369 (benchmark::State& st)
370 {
371     sptr<Ashmem> ashmem;
372     uint8_t rflg = 0;
373     int32_t asmSize = LENGTH_NUM_255;
374     struct UsbDev dev = dev_;
375     uint8_t interfaceId = INTERFACEID_1;
376     uint8_t pointid = POINTID_129;
377     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
378     ASSERT_EQ(0, ret);
379     struct UsbPipe pipe = { interfaceId, pointid };
380     (void)InitAshmemOne(ashmem, asmSize, rflg);
381     for (auto _ : st) {
382         ret = g_usbInterface->BulkWrite(dev, pipe, ashmem);
383     }
384     ASSERT_EQ(ret, 0);
385 }
386 
387 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0290)
388     ->Iterations(100)
389     ->Repetitions(3)
390     ->ReportAggregatesOnly();
391 
392 /**
393  * @tc.name: SUB_USB_HDI_Benchmark_0300
394  * @tc.desc: Benchmark test
395  * @tc.desc: Test functions to int32_t BulkRead(const UsbDev &dev, const UsbPipe &pipe, const sptr<Ashmem> &ashmem)
396  * @tc.desc: Positive test: parameters correctly
397  * @tc.type: FUNC
398  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0300)399 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0300)
400 (benchmark::State& st)
401 {
402     sptr<Ashmem> ashmem;
403     uint8_t rflg = 0;
404     int32_t asmSize = LENGTH_NUM_255;
405     struct UsbDev dev = dev_;
406     uint8_t interfaceId = INTERFACEID_1;
407     uint8_t pointid = POINTID_129;
408     auto ret = g_usbInterface->ClaimInterface(dev, interfaceId, 1);
409     ASSERT_EQ(0, ret);
410     struct UsbPipe pipe = { interfaceId, pointid };
411     (void)InitAshmemOne(ashmem, asmSize, rflg);
412     for (auto _ : st) {
413         ret = g_usbInterface->BulkRead(dev, pipe, ashmem);
414     }
415     ASSERT_EQ(ret, 0);
416 }
417 
418 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0300)
419     ->Iterations(100)
420     ->Repetitions(3)
421     ->ReportAggregatesOnly();
422 
423 /**
424  * @tc.name: SUB_USB_HDI_Benchmark_0310
425  * @tc.desc: Benchmark test
426  * @tc.desc: int32_t RegBulkCallback(const UsbDev &dev, const UsbPipe &pipe, const sptr<IUsbdBulkCallback> &cb)
427  * @tc.desc: Positive test: parameters correctly
428  * @tc.type: FUNC
429  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0310)430 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0310)
431 (benchmark::State& st)
432 {
433     struct UsbDev dev = dev_;
434     uint8_t interfaceId = INTERFACEID_1;
435     uint8_t pointid = POINTID_BULK_OUT;
436     struct UsbPipe pipe = {interfaceId, pointid};
437     sptr<UsbdBulkCallbackTest> usbdBulkCallback = new UsbdBulkCallbackTest();
438     if (usbdBulkCallback == nullptr) {
439         exit(0);
440     }
441     auto ret = 0;
442     for (auto _ : st) {
443         ret = g_usbInterface->RegBulkCallback(dev, pipe, usbdBulkCallback);
444     }
445     ASSERT_EQ(ret, 0);
446 }
447 
448 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0310)
449     ->Iterations(100)
450     ->Repetitions(3)
451     ->ReportAggregatesOnly();
452 
453 /**
454  * @tc.name: SUB_USB_HDI_Benchmark_0320
455  * @tc.desc: Benchmark test
456  * @tc.desc: Test functions to int32_t UnRegBulkCallback(const UsbDev &dev, const UsbPipe &pipe)
457  * @tc.desc: Positive test: parameters correctly
458  * @tc.type: FUNC
459  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0320)460 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0320)
461 (benchmark::State& st)
462 {
463     struct UsbDev dev = dev_;
464     uint8_t interfaceId = INTERFACEID_1;
465     uint8_t pointid = POINTID_1;
466     struct UsbPipe pipe = {interfaceId, pointid};
467     sptr<UsbdBulkCallbackTest> usbdBulkCallback = new UsbdBulkCallbackTest();
468     if (usbdBulkCallback == nullptr) {
469         exit(0);
470     }
471     auto ret = g_usbInterface->RegBulkCallback(dev, pipe, usbdBulkCallback);
472     ASSERT_EQ(ret, 0);
473     for (auto _ : st) {
474         ret = g_usbInterface->UnRegBulkCallback(dev, pipe);
475     }
476     ASSERT_EQ(ret, 0);
477 }
478 
479 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0320)
480     ->Iterations(100)
481     ->Repetitions(3)
482     ->ReportAggregatesOnly();
483 
484 /**
485  * @tc.name: SUB_USB_HDI_Benchmark_0330
486  * @tc.desc: Benchmark test
487  * @tc.desc: Test functions to int32_t BindUsbdSubscriber(const sptr<IUsbdSubscriber> &subscriber)
488  * @tc.desc: Positive test: parameters correctly
489  * @tc.type: FUNC
490  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0330)491 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0330)
492 (benchmark::State& st)
493 {
494     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
495     if (subscriber == nullptr) {
496         exit(0);
497     }
498     auto ret = 0;
499     for (auto _ : st) {
500         ret = g_usbInterface->BindUsbdSubscriber(subscriber);
501     }
502     ASSERT_EQ(ret, 0);
503 }
504 
505 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0330)
506     ->Iterations(100)
507     ->Repetitions(3)
508     ->ReportAggregatesOnly();
509 
510 /**
511  * @tc.name: SUB_USB_HDI_Benchmark_0340
512  * @tc.desc: Benchmark test
513  * @tc.desc: Test functions to int32_t UnbindUsbdSubscriber(const sptr<IUsbdSubscriber> &subscriber)
514  * @tc.desc: Positive test: parameters correctly
515  * @tc.type: FUNC
516  */
BENCHMARK_F(HdfUsbdBenchmarkTransferTest,SUB_USB_HDI_Benchmark_0340)517 BENCHMARK_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0340)
518 (benchmark::State& st)
519 {
520     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
521     if (subscriber == nullptr) {
522         exit(0);
523     }
524     auto ret = g_usbInterface->BindUsbdSubscriber(subscriber);
525     ASSERT_EQ(0, ret);
526     ret = 0;
527     for (auto _ : st) {
528         ret = g_usbInterface->UnbindUsbdSubscriber(subscriber);
529     }
530     ASSERT_EQ(ret, 0);
531 }
532 
533 BENCHMARK_REGISTER_F(HdfUsbdBenchmarkTransferTest, SUB_USB_HDI_Benchmark_0340)
534     ->Iterations(100)
535     ->Repetitions(3)
536     ->ReportAggregatesOnly();
537 } // namespace
538 
539 BENCHMARK_MAIN();
540