• 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 
16 #include <benchmark/benchmark.h>
17 
18 #include "bundle_constants.h"
19 #include "bundle_mgr_interface.h"
20 #include "bundle_mgr_proxy.h"
21 #include "bundle_status_callback_host.h"
22 #include "clean_cache_callback_host.h"
23 #include "common_tool.h"
24 #include "iservice_registry.h"
25 #include "status_receiver_host.h"
26 #include "system_ability_definition.h"
27 
28 using OHOS::AAFwk::Want;
29 using namespace std::chrono_literals;
30 using namespace OHOS;
31 using namespace OHOS::AppExecFwk;
32 
33 namespace {
34 const std::string SYSTEM_SETTINGS_BUNDLE_NAME = "com.ohos.settings";
35 const std::string BUNDLE_NAME = "com.ohos.contactsdataability";
36 const std::string ABILITY_NAME = "com.ohos.contactsdataability.MainAbility";
37 const std::string HAP_FILE = "/data/test/benchmark/test.hap";
38 const std::string MODULE_NAME_TEST = "entry";
39 const std::string COMMON_EVENT_EVENT = "usual.event.PACKAGE_ADDED";
40 constexpr int32_t DEFAULT_USERID = 100;
41 constexpr int32_t BENCHMARK_TIMES = 1000;
42 
43 class BundleStatusCallbackImpl : public BundleStatusCallbackHost {
44 public:
45     BundleStatusCallbackImpl() = default;
~BundleStatusCallbackImpl()46     virtual ~BundleStatusCallbackImpl() override {};
47     virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg,
48         const std::string &bundleName) override;
OnBundleAdded(const std::string & bundleName,const int userId)49     virtual void OnBundleAdded(const std::string &bundleName, const int userId) override {};
OnBundleUpdated(const std::string & bundleName,const int userId)50     virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override {};
OnBundleRemoved(const std::string & bundleName,const int userId)51     virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override {};
52 
53 private:
54     DISALLOW_COPY_AND_MOVE(BundleStatusCallbackImpl);
55 };
56 
OnBundleStateChanged(const uint8_t installType,const int32_t resultCode,const std::string & resultMsg,const std::string & bundleName)57 void BundleStatusCallbackImpl::OnBundleStateChanged(
58     const uint8_t installType, const int32_t resultCode, const std::string &resultMsg, const std::string &bundleName)
59 {}
60 
61 class CleanCacheCallBackImpl : public CleanCacheCallbackHost {
62 public:
63     CleanCacheCallBackImpl() = default;
~CleanCacheCallBackImpl()64     virtual ~CleanCacheCallBackImpl() override {};
OnCleanCacheFinished(bool succeeded)65     virtual void OnCleanCacheFinished(bool succeeded) override {};
66 
67 private:
68     DISALLOW_COPY_AND_MOVE(CleanCacheCallBackImpl);
69 };
70 
71 class StatusReceiverImpl : public StatusReceiverHost {
72 public:
73     StatusReceiverImpl() = default;
~StatusReceiverImpl()74     virtual ~StatusReceiverImpl() {};
OnStatusNotify(const int progress)75     virtual void OnStatusNotify(const int progress) override {};
OnFinished(const int32_t resultCode,const std::string & resultMsg)76     virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override {};
77 
78 private:
79     DISALLOW_COPY_AND_MOVE(StatusReceiverImpl);
80 };
81 
82 class BundleMgrProxyTest {
83 public:
84     static sptr<IBundleMgr> GetBundleMgrProxy();
85 };
86 
GetBundleMgrProxy()87 sptr<IBundleMgr> BundleMgrProxyTest::GetBundleMgrProxy()
88 {
89     sptr<ISystemAbilityManager> systemAbilityManager =
90         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
91     if (!systemAbilityManager) {
92         return nullptr;
93     }
94 
95     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
96     if (!remoteObject) {
97         return nullptr;
98     }
99 
100     return iface_cast<IBundleMgr>(remoteObject);
101 }
102 
103 /**
104  * @tc.name: BenchmarkTestGetApplicationInfo
105  * @tc.desc: Testcase for testing GetApplicationInfo.
106  * @tc.type: FUNC
107  * @tc.require: Issue Number
108  */
109 
BenchmarkTestGetApplicationInfoByFlag(benchmark::State & state)110 static void BenchmarkTestGetApplicationInfoByFlag(benchmark::State &state)
111 {
112     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
113     ApplicationInfo appInfo;
114 
115     for (auto _ : state) {
116         if (bundleMgrProxy == nullptr) {
117             break;
118         }
119         /* @tc.steps: step1.call GetApplicationInfo in loop */
120         bundleMgrProxy->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO,
121             Constants::DEFAULT_USERID, appInfo);
122     }
123 }
124 
125 /**
126  * @tc.name: BenchmarkTestGetApplicationInfo
127  * @tc.desc: Testcase for testing GetApplicationInfo.
128  * @tc.type: FUNC
129  * @tc.require: Issue Number
130  */
BenchmarkTestGetApplicationInfoByUserId(benchmark::State & state)131 static void BenchmarkTestGetApplicationInfoByUserId(benchmark::State &state)
132 {
133     int32_t flags = 0;
134     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
135     ApplicationInfo appInfo;
136 
137     for (auto _ : state) {
138         if (bundleMgrProxy == nullptr) {
139             break;
140         }
141         /* @tc.steps: step1.call GetApplicationInfo in loop */
142         bundleMgrProxy->GetApplicationInfo(BUNDLE_NAME, flags, DEFAULT_USERID, appInfo);
143     }
144 }
145 
146 /**
147  * @tc.name: BenchmarkTestGetApplicationInfosByApplicationFlag
148  * @tc.desc: Testcase for testing GetApplicationInfos.
149  * @tc.type: FUNC
150  * @tc.require: Issue Number
151  */
152 
BenchmarkTestGetApplicationInfosByApplicationFlag(benchmark::State & state)153 static void BenchmarkTestGetApplicationInfosByApplicationFlag(benchmark::State &state)
154 {
155     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
156     std::vector<ApplicationInfo> appInfos;
157 
158     for (auto _ : state) {
159         if (bundleMgrProxy == nullptr) {
160             break;
161         }
162         /* @tc.steps: step1.call GetApplicationInfos in loop */
163         bundleMgrProxy->GetApplicationInfos(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, DEFAULT_USERID,
164             appInfos);
165     }
166 }
167 
168 /**
169  * @tc.name: BenchmarkTestGetApplicationInfosByFlags
170  * @tc.desc: Testcase for testing GetApplicationInfos.
171  * @tc.type: FUNC
172  * @tc.require: Issue Number
173  */
174 
BenchmarkTestGetApplicationInfosByFlags(benchmark::State & state)175 static void BenchmarkTestGetApplicationInfosByFlags(benchmark::State &state)
176 {
177     int32_t flags = 0;
178     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
179     std::vector<ApplicationInfo> appInfos;
180 
181     for (auto _ : state) {
182         if (bundleMgrProxy == nullptr) {
183             break;
184         }
185         /* @tc.steps: step1.call GetApplicationInfos in loop */
186         bundleMgrProxy->GetApplicationInfos(flags, DEFAULT_USERID, appInfos);
187     }
188 }
189 
190 /**
191  * @tc.name: BenchmarkTestGetBundleInfoByBundleFlag
192  * @tc.desc: Testcase for testing GetBundleInfo.
193  * @tc.type: FUNC
194  * @tc.require: Issue Number
195  */
196 
BenchmarkTestGetBundleInfoByBundleFlag(benchmark::State & state)197 static void BenchmarkTestGetBundleInfoByBundleFlag(benchmark::State &state)
198 {
199     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
200     BundleInfo info;
201 
202     for (auto _ : state) {
203         if (bundleMgrProxy == nullptr) {
204             break;
205         }
206         /* @tc.steps: step1.call GetBundleInfo in loop */
207         bundleMgrProxy->GetBundleInfo(BUNDLE_NAME, BundleFlag::GET_BUNDLE_DEFAULT, info);
208     }
209 }
210 
211 /**
212  * @tc.name: BenchmarkTestGetBundleInfoByFlags
213  * @tc.desc: Testcase for testing GetBundleInfo.
214  * @tc.type: FUNC
215  * @tc.require: Issue Number
216  */
BenchmarkTestGetBundleInfoByFlags(benchmark::State & state)217 static void BenchmarkTestGetBundleInfoByFlags(benchmark::State &state)
218 {
219     int32_t flags = 0;
220     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
221     BundleInfo info;
222 
223     for (auto _ : state) {
224         if (bundleMgrProxy == nullptr) {
225             break;
226         }
227         /* @tc.steps: step1.call GetBundleInfo in loop */
228         bundleMgrProxy->GetBundleInfo(BUNDLE_NAME, flags, info);
229     }
230 }
231 
232 /**
233  * @tc.name: BenchmarkTestGetBundleInfosByBundleFlag
234  * @tc.desc: Testcase for testing GetBundleInfos.
235  * @tc.type: FUNC
236  * @tc.require: Issue Number
237  */
238 
BenchmarkTestGetBundleInfosByBundleFlag(benchmark::State & state)239 static void BenchmarkTestGetBundleInfosByBundleFlag(benchmark::State &state)
240 {
241     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
242     std::vector<BundleInfo> bundleInfos;
243 
244     for (auto _ : state) {
245         if (bundleMgrProxy == nullptr) {
246             break;
247         }
248         /* @tc.steps: step1.call GetBundleInfos in loop */
249         bundleMgrProxy->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos);
250     }
251 }
252 
253 /**
254  * @tc.name: BenchmarkTestGetBundleInfosByFlags
255  * @tc.desc: Testcase for testing GetBundleInfos.
256  * @tc.type: FUNC
257  * @tc.require: Issue Number
258  */
259 
BenchmarkTestGetBundleInfosByFlags(benchmark::State & state)260 static void BenchmarkTestGetBundleInfosByFlags(benchmark::State &state)
261 {
262     int32_t flags = 0;
263     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
264     std::vector<BundleInfo> bundleInfos;
265 
266     for (auto _ : state) {
267         if (bundleMgrProxy == nullptr) {
268             break;
269         }
270         /* @tc.steps: step1.call GetBundleInfos in loop */
271         bundleMgrProxy->GetBundleInfos(flags, bundleInfos);
272     }
273 }
274 
275 /**
276  * @tc.name: BenchmarkTestGetUidByBundleName
277  * @tc.desc: Obtains the application ID based on the given bundle name and user ID.
278  * @tc.type: FUNC
279  * @tc.require: Issue Number
280  */
281 
BenchmarkTestGetUidByBundleName(benchmark::State & state)282 static void BenchmarkTestGetUidByBundleName(benchmark::State &state)
283 {
284     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
285     for (auto _ : state) {
286         if (bundleMgrProxy == nullptr) {
287             break;
288         }
289         /* @tc.steps: step1.call GetUidByBundleName in loop */
290         bundleMgrProxy->GetUidByBundleName(BUNDLE_NAME, DEFAULT_USERID);
291     }
292 }
293 
294 /**
295  * @tc.name: BenchmarkTestGetAppIdByBundleName
296  * @tc.desc: Obtains the application ID based on the given bundle name and user ID.
297  * @tc.type: FUNC
298  * @tc.require: Issue Number
299  */
BenchmarkTestGetAppIdByBundleName(benchmark::State & state)300 static void BenchmarkTestGetAppIdByBundleName(benchmark::State &state)
301 {
302     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
303     for (auto _ : state) {
304         if (bundleMgrProxy == nullptr) {
305             break;
306         }
307         /* @tc.steps: step1.call GetAppIdByBundleName in loop */
308         bundleMgrProxy->GetAppIdByBundleName(BUNDLE_NAME, DEFAULT_USERID);
309     }
310 }
311 
312 /**
313  * @tc.name: BenchmarkTestGetBundleNameForUid
314  * @tc.desc: Testcase for testing GetBundleNameForUid.
315  * @tc.type: FUNC
316  * @tc.require: Issue Number
317  */
BenchmarkTestGetBundleNameForUid(benchmark::State & state)318 static void BenchmarkTestGetBundleNameForUid(benchmark::State &state)
319 {
320     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
321     std::string bundleName;
322     for (auto _ : state) {
323         if (bundleMgrProxy == nullptr) {
324             break;
325         }
326         /* @tc.steps: step1.call GetBundleNameForUid in loop */
327         bundleMgrProxy->GetBundleNameForUid(Constants::INVALID_UID, bundleName);
328     }
329 }
330 
331 /**
332  * @tc.name: BenchmarkTestGetBundlesForUid
333  * @tc.desc: Testcase for testing GetBundlesForUid.
334  * @tc.type: FUNC
335  * @tc.require: Issue Number
336  */
BenchmarkTestGetBundlesForUid(benchmark::State & state)337 static void BenchmarkTestGetBundlesForUid(benchmark::State &state)
338 {
339     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
340     std::vector<std::string> bundleNames;
341 
342     for (auto _ : state) {
343         if (bundleMgrProxy == nullptr) {
344             break;
345         }
346         /* @tc.steps: step1.call GetBundlesForUid in loop */
347         bundleMgrProxy->GetBundlesForUid(Constants::INVALID_UID, bundleNames);
348     }
349 }
350 
351 /**
352  * @tc.name: BenchmarkTestGetNameForUid
353  * @tc.desc: Testcase for testing GetNameForUid.
354  * @tc.type: FUNC
355  * @tc.require: Issue Number
356  */
BenchmarkTestGetNameForUid(benchmark::State & state)357 static void BenchmarkTestGetNameForUid(benchmark::State &state)
358 {
359     std::string name;
360     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
361     for (auto _ : state) {
362         if (bundleMgrProxy == nullptr) {
363             break;
364         }
365         /* @tc.steps: step1.call GetNameForUid in loop */
366         bundleMgrProxy->GetNameForUid(Constants::INVALID_UID, name);
367     }
368 }
369 
370 /**
371  * @tc.name: BenchmarkTestGetAppType
372  * @tc.desc: Testcase for testing GetAppType.
373  * @tc.type: FUNC
374  * @tc.require: Issue Number
375  */
376 
BenchmarkTestGetAppType(benchmark::State & state)377 static void BenchmarkTestGetAppType(benchmark::State &state)
378 {
379     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
380     for (auto _ : state) {
381         if (bundleMgrProxy == nullptr) {
382             break;
383         }
384         /* @tc.steps: step1.call GetAppType in loop */
385         bundleMgrProxy->GetAppType(SYSTEM_SETTINGS_BUNDLE_NAME);
386     }
387 }
388 
389 /**
390  * @tc.name: BenchmarkTestCheckIsSystemAppByUid
391  * @tc.desc: Testcase for testing CheckIsSystemAppByUid.
392  * @tc.type: FUNC
393  * @tc.require: Issue Number
394  */
395 
BenchmarkTestCheckIsSystemAppByUid(benchmark::State & state)396 static void BenchmarkTestCheckIsSystemAppByUid(benchmark::State &state)
397 {
398     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
399     for (auto _ : state) {
400         if (bundleMgrProxy == nullptr) {
401             break;
402         }
403         /* @tc.steps: step1.call CheckIsSystemAppByUid in loop */
404         bundleMgrProxy->CheckIsSystemAppByUid(Constants::INVALID_UID);
405     }
406 }
407 
408 /**
409  * @tc.name: BenchmarkTestGetBundleInfosByMetaData
410  * @tc.desc: Testcase for testing GetBundleInfosByMetaData.
411  * @tc.type: FUNC
412  * @tc.require: Issue Number
413  */
414 
BenchmarkTestGetBundleInfosByMetaData(benchmark::State & state)415 static void BenchmarkTestGetBundleInfosByMetaData(benchmark::State &state)
416 {
417     std::vector<BundleInfo> bundleInfos;
418     std::string metadata = "string";
419     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
420     for (auto _ : state) {
421         if (bundleMgrProxy == nullptr) {
422             break;
423         }
424         /* @tc.steps: step1.call GetBundleInfosByMetaData in loop */
425         bundleMgrProxy->GetBundleInfosByMetaData(metadata, bundleInfos);
426     }
427 }
428 
429 /**
430  * @tc.name: BenchmarkTestQueryAbilityInfo
431  * @tc.desc: Testcase for testing QueryAbilityInfo.
432  * @tc.type: FUNC
433  * @tc.require: Issue Number
434  */
435 
BenchmarkTestQueryAbilityInfo(benchmark::State & state)436 static void BenchmarkTestQueryAbilityInfo(benchmark::State &state)
437 {
438     Want want;
439     ElementName name;
440     name.SetAbilityName(ABILITY_NAME);
441     name.SetBundleName(BUNDLE_NAME);
442     want.SetElement(name);
443     AbilityInfo info;
444     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
445 
446     for (auto _ : state) {
447         /* @tc.steps: step1.call QueryAbilityInfo in loop */
448         bundleMgrProxy->QueryAbilityInfo(want, info);
449     }
450 }
451 
452 /**
453  * @tc.name: BenchmarkTestQueryAbilityInfoByFlags
454  * @tc.desc: Testcase for testing QueryAbilityInfo.
455  * @tc.type: FUNC
456  * @tc.require: Issue Number
457  */
458 
BenchmarkTestQueryAbilityInfoByFlags(benchmark::State & state)459 static void BenchmarkTestQueryAbilityInfoByFlags(benchmark::State &state)
460 {
461     Want want;
462     ElementName name;
463     name.SetAbilityName(ABILITY_NAME);
464     name.SetBundleName(BUNDLE_NAME);
465     want.SetElement(name);
466 
467     AbilityInfo info;
468 
469     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
470     for (auto _ : state) {
471         if (bundleMgrProxy == nullptr) {
472             break;
473         }
474         /* @tc.steps: step1.call QueryAbilityInfo in loop */
475         bundleMgrProxy->QueryAbilityInfo(want, 0, DEFAULT_USERID, info);
476     }
477 }
478 
479 /**
480  * @tc.name: BenchmarkTestQueryAbilityInfos
481  * @tc.desc: Testcase for testing QueryAbilityInfos.
482  * @tc.type: FUNC
483  * @tc.require: Issue Number
484  */
485 
BenchmarkTestQueryAbilityInfos(benchmark::State & state)486 static void BenchmarkTestQueryAbilityInfos(benchmark::State &state)
487 {
488     Want want;
489     ElementName name;
490     name.SetAbilityName(ABILITY_NAME);
491     name.SetBundleName(BUNDLE_NAME);
492     want.SetElement(name);
493 
494     std::vector<AbilityInfo> abilityInfos;
495 
496     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
497     for (auto _ : state) {
498         if (bundleMgrProxy == nullptr) {
499             break;
500         }
501         /* @tc.steps: step1.call QueryAbilityInfos in loop */
502         bundleMgrProxy->QueryAbilityInfos(want, abilityInfos);
503     }
504 }
505 
506 /**
507  * @tc.name: BenchmarkTestQueryAbilityInfosByFlags
508  * @tc.desc: Testcase for testing QueryAbilityInfos.
509  * @tc.type: FUNC
510  * @tc.require: Issue Number
511  */
512 
BenchmarkTestQueryAbilityInfosByFlags(benchmark::State & state)513 static void BenchmarkTestQueryAbilityInfosByFlags(benchmark::State &state)
514 {
515     Want want;
516     ElementName name;
517     name.SetAbilityName(ABILITY_NAME);
518     name.SetBundleName(BUNDLE_NAME);
519     want.SetElement(name);
520 
521     std::vector<AbilityInfo> abilityInfos;
522     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
523     for (auto _ : state) {
524         if (bundleMgrProxy == nullptr) {
525             break;
526         }
527         /* @tc.steps: step1.call QueryAbilityInfos in loop */
528         bundleMgrProxy->QueryAbilityInfos(want, 0, DEFAULT_USERID, abilityInfos);
529     }
530 }
531 
532 /**
533  * @tc.name: BenchmarkTestQueryAbilityInfosById
534  * @tc.desc: Testcase for testing QueryAllAbilityInfos.
535  * @tc.type: FUNC
536  * @tc.require: Issue Number
537  */
538 
BenchmarkTestQueryAbilityInfosById(benchmark::State & state)539 static void BenchmarkTestQueryAbilityInfosById(benchmark::State &state)
540 {
541     Want want;
542     ElementName name;
543     name.SetAbilityName(ABILITY_NAME);
544     name.SetBundleName(BUNDLE_NAME);
545     want.SetElement(name);
546 
547     std::vector<AbilityInfo> abilityInfos;
548 
549     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
550     for (auto _ : state) {
551         if (bundleMgrProxy == nullptr) {
552             break;
553         }
554         /* @tc.steps: step1.call QueryAllAbilityInfos in loop */
555         bundleMgrProxy->QueryAllAbilityInfos(want, 0, abilityInfos);
556     }
557 }
558 
559 /**
560  * @tc.name: BenchmarkTestQueryAbilityInfoByUri
561  * @tc.desc: Testcase for testing QueryAbilityInfoByUri.
562  * @tc.type: FUNC
563  * @tc.require: Issue Number
564  */
565 
BenchmarkTestQueryAbilityInfoByUri(benchmark::State & state)566 static void BenchmarkTestQueryAbilityInfoByUri(benchmark::State &state)
567 {
568     std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility";
569     AbilityInfo info;
570 
571     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
572     for (auto _ : state) {
573         if (bundleMgrProxy == nullptr) {
574             break;
575         }
576         /* @tc.steps: step1.call QueryAbilityInfoByUri in loop */
577         bundleMgrProxy->QueryAbilityInfoByUri(abilityUri, info);
578     }
579 }
580 
581 /**
582  * @tc.name: BenchmarkTestQueryAbilityInfoByUriAndId
583  * @tc.desc: Testcase for testing QueryAbilityInfoByUri.
584  * @tc.type: FUNC
585  * @tc.require: Issue Number
586  */
587 
BenchmarkTestQueryAbilityInfoByUriAndId(benchmark::State & state)588 static void BenchmarkTestQueryAbilityInfoByUriAndId(benchmark::State &state)
589 {
590     std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility";
591     AbilityInfo info;
592 
593     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
594     for (auto _ : state) {
595         if (bundleMgrProxy == nullptr) {
596             break;
597         }
598         /* @tc.steps: step1.call QueryAbilityInfoByUri in loop */
599         bundleMgrProxy->QueryAbilityInfoByUri(abilityUri, DEFAULT_USERID, info);
600     }
601 }
602 
603 /**
604  * @tc.name: BenchmarkTestQueryAbilityInfosByUri
605  * @tc.desc: Testcase for testing QueryAbilityInfosByUri.
606  * @tc.type: FUNC
607  * @tc.require: Issue Number
608  */
609 
BenchmarkTestQueryAbilityInfosByUri(benchmark::State & state)610 static void BenchmarkTestQueryAbilityInfosByUri(benchmark::State &state)
611 {
612     std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility";
613     std::vector<AbilityInfo> abilityInfos;
614 
615     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
616     for (auto _ : state) {
617         if (bundleMgrProxy == nullptr) {
618             break;
619         }
620         /* @tc.steps: step1.call QueryAbilityInfosByUri in loop */
621         bundleMgrProxy->QueryAbilityInfosByUri(abilityUri, abilityInfos);
622     }
623 }
624 
625 /**
626  * @tc.name: BenchmarkTestQueryKeepAliveBundleInfos
627  * @tc.desc: Testcase for testing QueryKeepAliveBundleInfos.
628  * @tc.type: FUNC
629  * @tc.require: Issue Number
630  */
631 
BenchmarkTestQueryKeepAliveBundleInfos(benchmark::State & state)632 static void BenchmarkTestQueryKeepAliveBundleInfos(benchmark::State &state)
633 {
634     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
635     std::vector<BundleInfo> bundleInfos;
636 
637     for (auto _ : state) {
638         if (bundleMgrProxy == nullptr) {
639             break;
640         }
641         /* @tc.steps: step1.call QueryKeepAliveBundleInfos in loop */
642         bundleMgrProxy->QueryKeepAliveBundleInfos(bundleInfos);
643     }
644 }
645 
646 /**
647  * @tc.name: BenchmarkTestGetAbilityLabel
648  * @tc.desc: Testcase for testing GetAbilityLabel.
649  * @tc.type: FUNC
650  * @tc.require: Issue Number
651  */
652 
BenchmarkTestGetAbilityLabel(benchmark::State & state)653 static void BenchmarkTestGetAbilityLabel(benchmark::State &state)
654 {
655     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
656     for (auto _ : state) {
657         if (bundleMgrProxy == nullptr) {
658             break;
659         }
660         /* @tc.steps: step1.call GetAbilityLabel in loop */
661         bundleMgrProxy->GetAbilityLabel(BUNDLE_NAME, ABILITY_NAME);
662     }
663 }
664 
665 /**
666  * @tc.name: BenchmarkTestGetBundleArchiveInfo
667  * @tc.desc: Testcase for testing GetBundleArchiveInfo.
668  * @tc.type: FUNC
669  * @tc.require: Issue Number
670  */
671 
BenchmarkTestGetBundleArchiveInfo(benchmark::State & state)672 static void BenchmarkTestGetBundleArchiveInfo(benchmark::State &state)
673 {
674     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
675     BundleInfo info;
676     for (auto _ : state) {
677         if (bundleMgrProxy == nullptr) {
678             break;
679         }
680         /* @tc.steps: step1.call GetBundleArchiveInfo in loop */
681         bundleMgrProxy->GetBundleArchiveInfo(HAP_FILE, 0, info);
682     }
683 }
684 
685 /**
686  * @tc.name: BenchmarkTestGetBundleArchiveInfoByFlag
687  * @tc.desc: Testcase for testing GetBundleArchiveInfo.
688  * @tc.type: FUNC
689  * @tc.require: Issue Number
690  */
691 
BenchmarkTestGetBundleArchiveInfoByFlag(benchmark::State & state)692 static void BenchmarkTestGetBundleArchiveInfoByFlag(benchmark::State &state)
693 {
694     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
695     BundleInfo info;
696     for (auto _ : state) {
697         if (bundleMgrProxy == nullptr) {
698             break;
699         }
700         /* @tc.steps: step1.call GetBundleArchiveInfo in loop */
701         bundleMgrProxy->GetBundleArchiveInfo(HAP_FILE, BundleFlag::GET_BUNDLE_DEFAULT, info);
702     }
703 }
704 
705 /**
706  * @tc.name: BenchmarkTestGetLaunchWantForBundle
707  * @tc.desc: Testcase for testing GetLaunchWantForBundle.
708  * @tc.type: FUNC
709  * @tc.require: Issue Number
710  */
711 
BenchmarkTestGetLaunchWantForBundle(benchmark::State & state)712 static void BenchmarkTestGetLaunchWantForBundle(benchmark::State &state)
713 {
714     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
715     Want want;
716     for (auto _ : state) {
717         if (bundleMgrProxy == nullptr) {
718             break;
719         }
720         /* @tc.steps: step1.call GetLaunchWantForBundle in loop */
721         bundleMgrProxy->GetLaunchWantForBundle(BUNDLE_NAME, want);
722     }
723 }
724 
725 /**
726  * @tc.name: BenchmarkTestGetPermissionDef
727  * @tc.desc: Testcase for testing GetPermissionDef.
728  * @tc.type: FUNC
729  * @tc.require: Issue Number
730  */
731 
BenchmarkTestGetPermissionDef(benchmark::State & state)732 static void BenchmarkTestGetPermissionDef(benchmark::State &state)
733 {
734     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
735     std::string permissionName;
736     PermissionDef info;
737 
738     for (auto _ : state) {
739         if (bundleMgrProxy == nullptr) {
740             break;
741         }
742         /* @tc.steps: step1.call GetPermissionDef in loop */
743         bundleMgrProxy->GetPermissionDef(permissionName, info);
744     }
745 }
746 
747 /**
748  * @tc.name: BenchmarkTestCleanBundleDataFiles
749  * @tc.desc: Testcase for testing CleanBundleDataFiles.
750  * @tc.type: FUNC
751  * @tc.require: Issue Number
752  */
753 
BenchmarkTestCleanBundleDataFiles(benchmark::State & state)754 static void BenchmarkTestCleanBundleDataFiles(benchmark::State &state)
755 {
756     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
757     for (auto _ : state) {
758         if (bundleMgrProxy == nullptr) {
759             break;
760         }
761         /* @tc.steps: step1.call CleanBundleDataFiles in loop */
762         bundleMgrProxy->CleanBundleDataFiles(BUNDLE_NAME, 0);
763     }
764 }
765 
766 /**
767  * @tc.name: BenchmarkTestRegisterBundleStatusCallback
768  * @tc.desc: Testcase for testing RegisterBundleStatusCallback.
769  * @tc.type: FUNC
770  * @tc.require: Issue Number
771  */
772 
BenchmarkTestRegisterBundleStatusCallback(benchmark::State & state)773 static void BenchmarkTestRegisterBundleStatusCallback(benchmark::State &state)
774 {
775     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
776     sptr<BundleStatusCallbackImpl> bundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl());
777     bundleStatusCallback->SetBundleName(BUNDLE_NAME);
778     for (auto _ : state) {
779         if (bundleMgrProxy == nullptr) {
780             break;
781         }
782         /* @tc.steps: step1.call RegisterBundleStatusCallback in loop */
783         bundleMgrProxy->RegisterBundleStatusCallback(bundleStatusCallback);
784     }
785 }
786 
787 /**
788  * @tc.name: BenchmarkTestClearBundleStatusCallback
789  * @tc.desc: Testcase for testing ClearBundleStatusCallback.
790  * @tc.type: FUNC
791  * @tc.require: Issue Number
792  */
793 
BenchmarkTestClearBundleStatusCallback(benchmark::State & state)794 static void BenchmarkTestClearBundleStatusCallback(benchmark::State &state)
795 {
796     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
797     sptr<BundleStatusCallbackImpl> bundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl());
798     bundleStatusCallback->SetBundleName(BUNDLE_NAME);
799     for (auto _ : state) {
800         if (bundleMgrProxy == nullptr) {
801             break;
802         }
803         /* @tc.steps: step1.call ClearBundleStatusCallback in loop */
804         bundleMgrProxy->ClearBundleStatusCallback(bundleStatusCallback);
805     }
806 }
807 
808 /**
809  * @tc.name: BenchmarkTestUnregisterBundleStatusCallback
810  * @tc.desc: Testcase for testing UnregisterBundleStatusCallback.
811  * @tc.type: FUNC
812  * @tc.require: Issue Number
813  */
814 
BenchmarkTestUnregisterBundleStatusCallback(benchmark::State & state)815 static void BenchmarkTestUnregisterBundleStatusCallback(benchmark::State &state)
816 {
817     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
818     for (auto _ : state) {
819         if (bundleMgrProxy == nullptr) {
820             break;
821         }
822         /* @tc.steps: step1.call UnregisterBundleStatusCallback in loop */
823         bundleMgrProxy->UnregisterBundleStatusCallback();
824     }
825 }
826 
827 /**
828  * @tc.name: BenchmarkTestDumpInfos
829  * @tc.desc: Testcase for testing DumpInfos.
830  * @tc.type: FUNC
831  * @tc.require: Issue Number
832  */
833 
BenchmarkTestDumpInfos(benchmark::State & state)834 static void BenchmarkTestDumpInfos(benchmark::State &state)
835 {
836     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
837     const std::string EMPTY_STRING = "";
838     std::string bundleNames;
839     for (auto _ : state) {
840         if (bundleMgrProxy == nullptr) {
841             break;
842         }
843         /* @tc.steps: step1.call DumpInfos in loop */
844         bundleMgrProxy->DumpInfos(
845             DumpFlag::DUMP_BUNDLE_LIST, EMPTY_STRING, DEFAULT_USERID, bundleNames);
846     }
847 }
848 
849 /**
850  * @tc.name: BenchmarkTestIsApplicationEnabled
851  * @tc.desc: Testcase for testing IsApplicationEnabled.
852  * @tc.type: FUNC
853  * @tc.require: Issue Number
854  */
855 
BenchmarkTestIsApplicationEnabled(benchmark::State & state)856 static void BenchmarkTestIsApplicationEnabled(benchmark::State &state)
857 {
858     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
859     for (auto _ : state) {
860         if (bundleMgrProxy == nullptr) {
861             break;
862         }
863         /* @tc.steps: step1.call IsApplicationEnabled in loop */
864         bool isEnable = false;
865         bundleMgrProxy->IsApplicationEnabled(BUNDLE_NAME, isEnable);
866     }
867 }
868 
869 /**
870  * @tc.name: BenchmarkTestSetApplicationEnabled
871  * @tc.desc: Testcase for testing SetApplicationEnabled.
872  * @tc.type: FUNC
873  * @tc.require: Issue Number
874  */
875 
BenchmarkTestSetApplicationEnabled(benchmark::State & state)876 static void BenchmarkTestSetApplicationEnabled(benchmark::State &state)
877 {
878     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
879     for (auto _ : state) {
880         if (bundleMgrProxy == nullptr) {
881             break;
882         }
883         /* @tc.steps: step1.call SetApplicationEnabled in loop */
884         bundleMgrProxy->SetApplicationEnabled(BUNDLE_NAME, false);
885     }
886 }
887 
888 /**
889  * @tc.name: BenchmarkTestIsAbilityEnabled
890  * @tc.desc: Testcase for testing IsAbilityEnabled.
891  * @tc.type: FUNC
892  * @tc.require: Issue Number
893  */
894 
BenchmarkTestIsAbilityEnabled(benchmark::State & state)895 static void BenchmarkTestIsAbilityEnabled(benchmark::State &state)
896 {
897     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
898     AbilityInfo info;
899 
900     for (auto _ : state) {
901         if (bundleMgrProxy == nullptr) {
902             break;
903         }
904         /* @tc.steps: step1.call IsAbilityEnabled in loop */
905         bool isEnable = false;
906         bundleMgrProxy->IsAbilityEnabled(info, isEnable);
907     }
908 }
909 
910 /**
911  * @tc.name: BenchmarkTestSetAbilityEnabled
912  * @tc.desc: Testcase for testing SetAbilityEnabled.
913  * @tc.type: FUNC
914  * @tc.require: Issue Number
915  */
916 
BenchmarkTestSetAbilityEnabled(benchmark::State & state)917 static void BenchmarkTestSetAbilityEnabled(benchmark::State &state)
918 {
919     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
920     AbilityInfo info;
921 
922     for (auto _ : state) {
923         if (bundleMgrProxy == nullptr) {
924             break;
925         }
926         /* @tc.steps: step1.call SetAbilityEnabled in loop */
927         bundleMgrProxy->SetAbilityEnabled(info, false);
928     }
929 }
930 
931 /**
932  * @tc.name: BenchmarkTestGetBundleInstaller
933  * @tc.desc: Testcase for testing GetBundleInstaller.
934  * @tc.type: FUNC
935  * @tc.require: Issue Number
936  */
937 
BenchmarkTestGetBundleInstaller(benchmark::State & state)938 static void BenchmarkTestGetBundleInstaller(benchmark::State &state)
939 {
940     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
941     for (auto _ : state) {
942         if (bundleMgrProxy == nullptr) {
943             break;
944         }
945         /* @tc.steps: step1.call GetBundleInstaller in loop */
946         bundleMgrProxy->GetBundleInstaller();
947     }
948 }
949 
950 /**
951  * @tc.name: BenchmarkTestGetBundleUserMgr
952  * @tc.desc: Testcase for testing GetBundleUserMgr.
953  * @tc.type: FUNC
954  * @tc.require: Issue Number
955  */
956 
BenchmarkTestGetBundleUserMgr(benchmark::State & state)957 static void BenchmarkTestGetBundleUserMgr(benchmark::State &state)
958 {
959     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
960     for (auto _ : state) {
961         if (bundleMgrProxy == nullptr) {
962             break;
963         }
964         /* @tc.steps: step1.call GetBundleUserMgr in loop */
965         bundleMgrProxy->GetBundleUserMgr();
966     }
967 }
968 
969 /**
970  * @tc.name: BenchmarkTestGetAllFormsInfo
971  * @tc.desc: Testcase for testing GetAllFormsInfo.
972  * @tc.type: FUNC
973  * @tc.require: Issue Number
974  */
975 
BenchmarkTestGetAllFormsInfo(benchmark::State & state)976 static void BenchmarkTestGetAllFormsInfo(benchmark::State &state)
977 {
978     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
979     std::vector<FormInfo> formInfos;
980 
981     for (auto _ : state) {
982         if (bundleMgrProxy == nullptr) {
983             break;
984         }
985         /* @tc.steps: step1.call GetAllFormsInfo in loop */
986         bundleMgrProxy->GetAllFormsInfo(formInfos);
987     }
988 }
989 
990 /**
991  * @tc.name: BenchmarkTestGetFormsInfoByApp
992  * @tc.desc: Testcase for testing GetFormsInfoByApp.
993  * @tc.type: FUNC
994  * @tc.require: Issue Number
995  */
996 
BenchmarkTestGetFormsInfoByApp(benchmark::State & state)997 static void BenchmarkTestGetFormsInfoByApp(benchmark::State &state)
998 {
999     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1000     std::vector<FormInfo> formInfos;
1001 
1002     for (auto _ : state) {
1003         if (bundleMgrProxy == nullptr) {
1004             break;
1005         }
1006         /* @tc.steps: step1.call GetFormsInfoByApp in loop */
1007         bundleMgrProxy->GetFormsInfoByApp(BUNDLE_NAME, formInfos);
1008     }
1009 }
1010 
1011 /**
1012  * @tc.name: BenchmarkTestGetFormsInfoByModule
1013  * @tc.desc: Testcase for testing GetFormsInfoByModule.
1014  * @tc.type: FUNC
1015  * @tc.require: Issue Number
1016  */
1017 
BenchmarkTestGetFormsInfoByModule(benchmark::State & state)1018 static void BenchmarkTestGetFormsInfoByModule(benchmark::State &state)
1019 {
1020     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1021     std::vector<FormInfo> formInfos;
1022 
1023     for (auto _ : state) {
1024         if (bundleMgrProxy == nullptr) {
1025             break;
1026         }
1027         /* @tc.steps: step1.call GetFormsInfoByModule in loop */
1028         bundleMgrProxy->GetFormsInfoByModule(BUNDLE_NAME, MODULE_NAME_TEST, formInfos);
1029     }
1030 }
1031 
1032 /**
1033  * @tc.name: BenchmarkTestGetShortcutInfos
1034  * @tc.desc: Testcase for testing GetShortcutInfos.
1035  * @tc.type: FUNC
1036  * @tc.require: Issue Number
1037  */
1038 
BenchmarkTestGetShortcutInfos(benchmark::State & state)1039 static void BenchmarkTestGetShortcutInfos(benchmark::State &state)
1040 {
1041     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1042     std::vector<ShortcutInfo> shortcutInfos;
1043 
1044     for (auto _ : state) {
1045         if (bundleMgrProxy == nullptr) {
1046             break;
1047         }
1048         /* @tc.steps: step1.call GetShortcutInfos in loop */
1049         bundleMgrProxy->GetShortcutInfos(BUNDLE_NAME, shortcutInfos);
1050     }
1051 }
1052 
1053 /**
1054  * @tc.name: BenchmarkTestGetAllCommonEventInfo
1055  * @tc.desc: Testcase for testing GetAllCommonEventInfo.
1056  * @tc.type: FUNC
1057  * @tc.require: Issue Number
1058  */
1059 
BenchmarkTestGetAllCommonEventInfo(benchmark::State & state)1060 static void BenchmarkTestGetAllCommonEventInfo(benchmark::State &state)
1061 {
1062     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1063     std::vector<CommonEventInfo> commonEventInfos;
1064 
1065     for (auto _ : state) {
1066         if (bundleMgrProxy == nullptr) {
1067             break;
1068         }
1069         /* @tc.steps: step1.call GetAllCommonEventInfo in loop */
1070         bundleMgrProxy->GetAllCommonEventInfo(COMMON_EVENT_EVENT, commonEventInfos);
1071     }
1072 }
1073 
1074 /**
1075  * @tc.name: BenchmarkTestGetDistributedBundleInfo
1076  * @tc.desc: Testcase for testing GetDistributedBundleInfo.
1077  * @tc.type: FUNC
1078  * @tc.require: Issue Number
1079  */
1080 
BenchmarkTestGetDistributedBundleInfo(benchmark::State & state)1081 static void BenchmarkTestGetDistributedBundleInfo(benchmark::State &state)
1082 {
1083     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1084     std::string networkId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm"\
1085         "/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM=";
1086     DistributedBundleInfo distributedBundleInfo;
1087 
1088     for (auto _ : state) {
1089         if (bundleMgrProxy == nullptr) {
1090             break;
1091         }
1092         /* @tc.steps: step1.call GetDistributedBundleInfo in loop */
1093         bundleMgrProxy->GetDistributedBundleInfo(networkId, BUNDLE_NAME, distributedBundleInfo);
1094     }
1095 }
1096 
1097 /**
1098  * @tc.name: BenchmarkTestGetAppPrivilegeLevel
1099  * @tc.desc: Testcase for testing GetAppPrivilegeLevel.
1100  * @tc.type: FUNC
1101  * @tc.require: Issue Number
1102  */
1103 
BenchmarkTestGetAppPrivilegeLevel(benchmark::State & state)1104 static void BenchmarkTestGetAppPrivilegeLevel(benchmark::State &state)
1105 {
1106     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1107     for (auto _ : state) {
1108         if (bundleMgrProxy == nullptr) {
1109             break;
1110         }
1111         /* @tc.steps: step1.call GetAppPrivilegeLevel in loop */
1112         bundleMgrProxy->GetAppPrivilegeLevel(BUNDLE_NAME);
1113     }
1114 }
1115 
1116 /**
1117  * @tc.name: BenchmarkTestQueryExtensionAbilityInfosByWant
1118  * @tc.desc: Testcase for testing QueryExtensionAbilityInfos.
1119  * @tc.type: FUNC
1120  * @tc.require: Issue Number
1121  */
1122 
BenchmarkTestQueryExtensionAbilityInfosByWant(benchmark::State & state)1123 static void BenchmarkTestQueryExtensionAbilityInfosByWant(benchmark::State &state)
1124 {
1125     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1126     Want want;
1127     ElementName name;
1128     name.SetAbilityName(ABILITY_NAME);
1129     name.SetBundleName(BUNDLE_NAME);
1130     want.SetElement(name);
1131     int32_t flags = 0;
1132     std::vector<ExtensionAbilityInfo> infos;
1133     for (auto _ : state) {
1134         if (bundleMgrProxy == nullptr) {
1135             break;
1136         }
1137         /* @tc.steps: step1.call QueryExtensionAbilityInfos in loop */
1138         bundleMgrProxy->QueryExtensionAbilityInfos(want, flags, DEFAULT_USERID, infos);
1139     }
1140 }
1141 
1142 /**
1143  * @tc.name: BenchmarkTestQueryExtensionAbilityInfosByType
1144  * @tc.desc: Testcase for testing QueryExtensionAbilityInfos.
1145  * @tc.type: FUNC
1146  * @tc.require: Issue Number
1147  */
1148 
BenchmarkTestQueryExtensionAbilityInfosByType(benchmark::State & state)1149 static void BenchmarkTestQueryExtensionAbilityInfosByType(benchmark::State &state)
1150 {
1151     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1152     std::vector<ExtensionAbilityInfo> infos;
1153     for (auto _ : state) {
1154         if (bundleMgrProxy == nullptr) {
1155             break;
1156         }
1157         /* @tc.steps: step1.call QueryExtensionAbilityInfos in loop */
1158         bundleMgrProxy->QueryExtensionAbilityInfos(ExtensionAbilityType::FORM, DEFAULT_USERID, infos);
1159     }
1160 }
1161 
1162 /**
1163  * @tc.name: BenchmarkTestQueryExtensionAbilityInfos
1164  * @tc.desc: Testcase for testing QueryExtensionAbilityInfos.
1165  * @tc.type: FUNC
1166  * @tc.require: Issue Number
1167  */
1168 
BenchmarkTestQueryExtensionAbilityInfos(benchmark::State & state)1169 static void BenchmarkTestQueryExtensionAbilityInfos(benchmark::State &state)
1170 {
1171     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1172     Want want;
1173     ElementName name;
1174     name.SetAbilityName(ABILITY_NAME);
1175     name.SetBundleName(BUNDLE_NAME);
1176     want.SetElement(name);
1177     int32_t flags = 0;
1178     std::vector<ExtensionAbilityInfo> infos;
1179     for (auto _ : state) {
1180         if (bundleMgrProxy == nullptr) {
1181             break;
1182         }
1183         /* @tc.steps: step1.call QueryExtensionAbilityInfos in loop */
1184         bundleMgrProxy->QueryExtensionAbilityInfos(want, ExtensionAbilityType::FORM, flags, DEFAULT_USERID, infos);
1185     }
1186 }
1187 
1188 /**
1189  * @tc.name: BenchmarkTestVerifyCallingPermission
1190  * @tc.desc: Testcase for testing VerifyCallingPermission.
1191  * @tc.type: FUNC
1192  * @tc.require: Issue Number
1193  */
1194 
BenchmarkTestVerifyCallingPermission(benchmark::State & state)1195 static void BenchmarkTestVerifyCallingPermission(benchmark::State &state)
1196 {
1197     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1198     std::string appPermission = "USER_GRANT";
1199     for (auto _ : state) {
1200         if (bundleMgrProxy == nullptr) {
1201             break;
1202         }
1203         /* @tc.steps: step1.call VerifyCallingPermission in loop */
1204         bundleMgrProxy->VerifyCallingPermission(appPermission);
1205     }
1206 }
1207 
1208 /**
1209  * @tc.name: BenchmarkTestQueryExtensionAbilityInfoByUri
1210  * @tc.desc: Testcase for testing QueryExtensionAbilityInfoByUri.
1211  * @tc.type: FUNC
1212  * @tc.require: Issue Number
1213  */
1214 
BenchmarkTestQueryExtensionAbilityInfoByUri(benchmark::State & state)1215 static void BenchmarkTestQueryExtensionAbilityInfoByUri(benchmark::State &state)
1216 {
1217     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1218     ExtensionAbilityInfo info;
1219     const std::string URI = "dataability://com.example.hiworld.himusic.UserADataAbility";
1220     for (auto _ : state) {
1221         if (bundleMgrProxy == nullptr) {
1222             break;
1223         }
1224         /* @tc.steps: step1.call QueryExtensionAbilityInfoByUri in loop */
1225         bundleMgrProxy->QueryExtensionAbilityInfoByUri(URI, DEFAULT_USERID, info);
1226     }
1227 }
1228 
1229 /**
1230  * @tc.name: BenchmarkTestImplicitQueryInfoByPriority
1231  * @tc.desc: Testcase for testing ImplicitQueryInfoByPriority.
1232  * @tc.type: FUNC
1233  * @tc.require: Issue Number
1234  */
1235 
BenchmarkTestImplicitQueryInfoByPriority(benchmark::State & state)1236 static void BenchmarkTestImplicitQueryInfoByPriority(benchmark::State &state)
1237 {
1238     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1239     Want want;
1240     ElementName name;
1241     name.SetAbilityName(ABILITY_NAME);
1242     name.SetBundleName(BUNDLE_NAME);
1243     want.SetElement(name);
1244     int32_t flags = 0;
1245     AbilityInfo abilityInfo;
1246     ExtensionAbilityInfo extensionInfo;
1247     for (auto _ : state) {
1248         if (bundleMgrProxy == nullptr) {
1249             break;
1250         }
1251         /* @tc.steps: step1.call ImplicitQueryInfoByPriority in loop */
1252         bundleMgrProxy->ImplicitQueryInfoByPriority(want, flags, DEFAULT_USERID, abilityInfo, extensionInfo);
1253     }
1254 }
1255 
1256 /**
1257  * @tc.name: BenchmarkTestGetSandboxBundleInfo
1258  * @tc.desc: Testcase for testing GetSandboxBundleInfo.
1259  * @tc.type: FUNC
1260  * @tc.require: Issue Number
1261  */
1262 
BenchmarkTestGetSandboxBundleInfo(benchmark::State & state)1263 static void BenchmarkTestGetSandboxBundleInfo(benchmark::State &state)
1264 {
1265     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1266     BundleInfo info;
1267     for (auto _ : state) {
1268         if (bundleMgrProxy == nullptr) {
1269             break;
1270         }
1271         /* @tc.steps: step1.call GetSandboxBundleInfo in loop */
1272         bundleMgrProxy->GetSandboxBundleInfo(BUNDLE_NAME, 0, DEFAULT_USERID, info);
1273     }
1274 }
1275 
1276 /**
1277  * @tc.name: BenchmarkTestGetAbilityInfo
1278  * @tc.desc: Testcase for testing GetAbilityInfo.
1279  * @tc.type: FUNC
1280  * @tc.require: Issue Number
1281  */
1282 
BenchmarkTestGetAbilityInfo(benchmark::State & state)1283 static void BenchmarkTestGetAbilityInfo(benchmark::State &state)
1284 {
1285     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1286     AbilityInfo info;
1287     for (auto _ : state) {
1288         if (bundleMgrProxy == nullptr) {
1289             break;
1290         }
1291 
1292         /* @tc.steps: step1.call GetAbilityInfo in loop */
1293         bundleMgrProxy->GetAbilityInfo(BUNDLE_NAME, ABILITY_NAME, info);
1294     }
1295 }
1296 
1297 /**
1298  * @tc.name: BenchmarkTestGetAbilityInfoByModuleName
1299  * @tc.desc: Testcase for testing GetAbilityInfo.
1300  * @tc.type: FUNC
1301  * @tc.require: Issue Number
1302  */
1303 
BenchmarkTestGetAbilityInfoByModuleName(benchmark::State & state)1304 static void BenchmarkTestGetAbilityInfoByModuleName(benchmark::State &state)
1305 {
1306     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1307     AbilityInfo info;
1308     for (auto _ : state) {
1309         if (bundleMgrProxy == nullptr) {
1310             break;
1311         }
1312         /* @tc.steps: step1.call GetAbilityInfo in loop */
1313         bundleMgrProxy->GetAbilityInfo(BUNDLE_NAME, MODULE_NAME_TEST, ABILITY_NAME, info);
1314     }
1315 }
1316 
1317 /**
1318  * @tc.name: BenchmarkTestGetAllDependentModuleNames
1319  * @tc.desc: Testcase for testing GetAllDependentModuleNames.
1320  * @tc.type: FUNC
1321  * @tc.require: Issue Number
1322  */
1323 
BenchmarkTestGetAllDependentModuleNames(benchmark::State & state)1324 static void BenchmarkTestGetAllDependentModuleNames(benchmark::State &state)
1325 {
1326     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1327     std::vector<std::string> dependentModuleNames;
1328     for (auto _ : state) {
1329         if (bundleMgrProxy == nullptr) {
1330             break;
1331         }
1332         /* @tc.steps: step1.call GetAllDependentModuleNames in loop */
1333         bundleMgrProxy->GetAllDependentModuleNames(BUNDLE_NAME, MODULE_NAME_TEST, dependentModuleNames);
1334     }
1335 }
1336 
1337 /**
1338  * @tc.name: BenchmarkTestObtainCallingBundleName
1339  * @tc.desc: Testcase for testing ObtainCallingBundleName.
1340  * @tc.type: FUNC
1341  * @tc.require: Issue Number
1342  */
1343 
BenchmarkTestObtainCallingBundleName(benchmark::State & state)1344 static void BenchmarkTestObtainCallingBundleName(benchmark::State &state)
1345 {
1346     sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1347     std::string bundleName;
1348 
1349     for (auto _ : state) {
1350         if (bundleMgrProxy == nullptr) {
1351             break;
1352         }
1353         /* @tc.steps: step1.call ObtainCallingBundleName in loop */
1354         bundleMgrProxy->ObtainCallingBundleName(bundleName);
1355     }
1356 }
1357 
1358 BENCHMARK(BenchmarkTestGetApplicationInfoByFlag)->Iterations(BENCHMARK_TIMES);
1359 BENCHMARK(BenchmarkTestGetApplicationInfoByUserId)->Iterations(BENCHMARK_TIMES);
1360 BENCHMARK(BenchmarkTestGetApplicationInfosByApplicationFlag)->Iterations(BENCHMARK_TIMES);
1361 BENCHMARK(BenchmarkTestGetApplicationInfosByFlags)->Iterations(BENCHMARK_TIMES);
1362 BENCHMARK(BenchmarkTestGetBundleInfoByBundleFlag)->Iterations(BENCHMARK_TIMES);
1363 BENCHMARK(BenchmarkTestGetBundleInfoByFlags)->Iterations(BENCHMARK_TIMES);
1364 BENCHMARK(BenchmarkTestGetBundleInfosByBundleFlag)->Iterations(BENCHMARK_TIMES);
1365 BENCHMARK(BenchmarkTestGetBundleInfosByFlags)->Iterations(BENCHMARK_TIMES);
1366 BENCHMARK(BenchmarkTestGetUidByBundleName)->Iterations(BENCHMARK_TIMES);
1367 BENCHMARK(BenchmarkTestGetAppIdByBundleName)->Iterations(BENCHMARK_TIMES);
1368 BENCHMARK(BenchmarkTestGetBundleNameForUid)->Iterations(BENCHMARK_TIMES);
1369 BENCHMARK(BenchmarkTestGetBundlesForUid)->Iterations(BENCHMARK_TIMES);
1370 BENCHMARK(BenchmarkTestGetNameForUid)->Iterations(BENCHMARK_TIMES);
1371 BENCHMARK(BenchmarkTestGetAppType)->Iterations(BENCHMARK_TIMES);
1372 BENCHMARK(BenchmarkTestCheckIsSystemAppByUid)->Iterations(BENCHMARK_TIMES);
1373 BENCHMARK(BenchmarkTestGetBundleInfosByMetaData)->Iterations(BENCHMARK_TIMES);
1374 BENCHMARK(BenchmarkTestQueryAbilityInfo)->Iterations(BENCHMARK_TIMES);
1375 BENCHMARK(BenchmarkTestQueryAbilityInfoByFlags)->Iterations(BENCHMARK_TIMES);
1376 BENCHMARK(BenchmarkTestQueryAbilityInfos)->Iterations(BENCHMARK_TIMES);
1377 BENCHMARK(BenchmarkTestQueryAbilityInfosByFlags)->Iterations(BENCHMARK_TIMES);
1378 BENCHMARK(BenchmarkTestQueryAbilityInfosById)->Iterations(BENCHMARK_TIMES);
1379 BENCHMARK(BenchmarkTestQueryAbilityInfoByUriAndId)->Iterations(BENCHMARK_TIMES);
1380 BENCHMARK(BenchmarkTestQueryAbilityInfoByUri)->Iterations(BENCHMARK_TIMES);
1381 BENCHMARK(BenchmarkTestQueryAbilityInfosByUri)->Iterations(BENCHMARK_TIMES);
1382 BENCHMARK(BenchmarkTestQueryKeepAliveBundleInfos)->Iterations(BENCHMARK_TIMES);
1383 BENCHMARK(BenchmarkTestGetAbilityLabel)->Iterations(BENCHMARK_TIMES);
1384 BENCHMARK(BenchmarkTestGetBundleArchiveInfo)->Iterations(BENCHMARK_TIMES);
1385 BENCHMARK(BenchmarkTestGetBundleArchiveInfoByFlag)->Iterations(BENCHMARK_TIMES);
1386 BENCHMARK(BenchmarkTestGetLaunchWantForBundle)->Iterations(BENCHMARK_TIMES);
1387 BENCHMARK(BenchmarkTestGetPermissionDef)->Iterations(BENCHMARK_TIMES);
1388 BENCHMARK(BenchmarkTestCleanBundleDataFiles)->Iterations(BENCHMARK_TIMES);
1389 BENCHMARK(BenchmarkTestRegisterBundleStatusCallback)->Iterations(BENCHMARK_TIMES);
1390 BENCHMARK(BenchmarkTestClearBundleStatusCallback)->Iterations(BENCHMARK_TIMES);
1391 BENCHMARK(BenchmarkTestUnregisterBundleStatusCallback)->Iterations(BENCHMARK_TIMES);
1392 BENCHMARK(BenchmarkTestDumpInfos)->Iterations(BENCHMARK_TIMES);
1393 BENCHMARK(BenchmarkTestIsApplicationEnabled)->Iterations(BENCHMARK_TIMES);
1394 BENCHMARK(BenchmarkTestSetApplicationEnabled)->Iterations(BENCHMARK_TIMES);
1395 BENCHMARK(BenchmarkTestIsAbilityEnabled)->Iterations(BENCHMARK_TIMES);
1396 BENCHMARK(BenchmarkTestSetAbilityEnabled)->Iterations(BENCHMARK_TIMES);
1397 BENCHMARK(BenchmarkTestGetBundleInstaller)->Iterations(BENCHMARK_TIMES);
1398 BENCHMARK(BenchmarkTestGetBundleUserMgr)->Iterations(BENCHMARK_TIMES);
1399 BENCHMARK(BenchmarkTestGetAllFormsInfo)->Iterations(BENCHMARK_TIMES);
1400 BENCHMARK(BenchmarkTestGetFormsInfoByApp)->Iterations(BENCHMARK_TIMES);
1401 BENCHMARK(BenchmarkTestGetFormsInfoByModule)->Iterations(BENCHMARK_TIMES);
1402 BENCHMARK(BenchmarkTestGetShortcutInfos)->Iterations(BENCHMARK_TIMES);
1403 BENCHMARK(BenchmarkTestGetAllCommonEventInfo)->Iterations(BENCHMARK_TIMES);
1404 BENCHMARK(BenchmarkTestGetDistributedBundleInfo)->Iterations(BENCHMARK_TIMES);
1405 BENCHMARK(BenchmarkTestGetAppPrivilegeLevel)->Iterations(BENCHMARK_TIMES);
1406 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfosByWant)->Iterations(BENCHMARK_TIMES);
1407 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfos)->Iterations(BENCHMARK_TIMES);
1408 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfosByType)->Iterations(BENCHMARK_TIMES);
1409 BENCHMARK(BenchmarkTestVerifyCallingPermission)->Iterations(BENCHMARK_TIMES);
1410 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfoByUri)->Iterations(BENCHMARK_TIMES);
1411 BENCHMARK(BenchmarkTestImplicitQueryInfoByPriority)->Iterations(BENCHMARK_TIMES);
1412 BENCHMARK(BenchmarkTestGetSandboxBundleInfo)->Iterations(BENCHMARK_TIMES);
1413 BENCHMARK(BenchmarkTestGetAbilityInfo)->Iterations(BENCHMARK_TIMES);
1414 BENCHMARK(BenchmarkTestGetAbilityInfoByModuleName)->Iterations(BENCHMARK_TIMES);
1415 BENCHMARK(BenchmarkTestGetAllDependentModuleNames)->Iterations(BENCHMARK_TIMES);;
1416 BENCHMARK(BenchmarkTestObtainCallingBundleName)->Iterations(BENCHMARK_TIMES);
1417 }  // namespace
1418 
1419 BENCHMARK_MAIN();