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: BenchmarkTestGetBundlesForUid
314 * @tc.desc: Testcase for testing GetBundlesForUid.
315 * @tc.type: FUNC
316 * @tc.require: Issue Number
317 */
BenchmarkTestGetBundlesForUid(benchmark::State & state)318 static void BenchmarkTestGetBundlesForUid(benchmark::State &state)
319 {
320 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
321 std::vector<std::string> bundleNames;
322
323 for (auto _ : state) {
324 if (bundleMgrProxy == nullptr) {
325 break;
326 }
327 /* @tc.steps: step1.call GetBundlesForUid in loop */
328 bundleMgrProxy->GetBundlesForUid(Constants::INVALID_UID, bundleNames);
329 }
330 }
331
332 /**
333 * @tc.name: BenchmarkTestGetNameForUid
334 * @tc.desc: Testcase for testing GetNameForUid.
335 * @tc.type: FUNC
336 * @tc.require: Issue Number
337 */
BenchmarkTestGetNameForUid(benchmark::State & state)338 static void BenchmarkTestGetNameForUid(benchmark::State &state)
339 {
340 std::string name;
341 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
342 for (auto _ : state) {
343 if (bundleMgrProxy == nullptr) {
344 break;
345 }
346 /* @tc.steps: step1.call GetNameForUid in loop */
347 bundleMgrProxy->GetNameForUid(Constants::INVALID_UID, name);
348 }
349 }
350
351 /**
352 * @tc.name: BenchmarkTestGetAppType
353 * @tc.desc: Testcase for testing GetAppType.
354 * @tc.type: FUNC
355 * @tc.require: Issue Number
356 */
357
BenchmarkTestGetAppType(benchmark::State & state)358 static void BenchmarkTestGetAppType(benchmark::State &state)
359 {
360 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
361 for (auto _ : state) {
362 if (bundleMgrProxy == nullptr) {
363 break;
364 }
365 /* @tc.steps: step1.call GetAppType in loop */
366 bundleMgrProxy->GetAppType(SYSTEM_SETTINGS_BUNDLE_NAME);
367 }
368 }
369
370 /**
371 * @tc.name: BenchmarkTestCheckIsSystemAppByUid
372 * @tc.desc: Testcase for testing CheckIsSystemAppByUid.
373 * @tc.type: FUNC
374 * @tc.require: Issue Number
375 */
376
BenchmarkTestCheckIsSystemAppByUid(benchmark::State & state)377 static void BenchmarkTestCheckIsSystemAppByUid(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 CheckIsSystemAppByUid in loop */
385 bundleMgrProxy->CheckIsSystemAppByUid(Constants::INVALID_UID);
386 }
387 }
388
389 /**
390 * @tc.name: BenchmarkTestGetBundleInfosByMetaData
391 * @tc.desc: Testcase for testing GetBundleInfosByMetaData.
392 * @tc.type: FUNC
393 * @tc.require: Issue Number
394 */
395
BenchmarkTestGetBundleInfosByMetaData(benchmark::State & state)396 static void BenchmarkTestGetBundleInfosByMetaData(benchmark::State &state)
397 {
398 std::vector<BundleInfo> bundleInfos;
399 std::string metadata = "string";
400 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
401 for (auto _ : state) {
402 if (bundleMgrProxy == nullptr) {
403 break;
404 }
405 /* @tc.steps: step1.call GetBundleInfosByMetaData in loop */
406 bundleMgrProxy->GetBundleInfosByMetaData(metadata, bundleInfos);
407 }
408 }
409
410 /**
411 * @tc.name: BenchmarkTestQueryAbilityInfo
412 * @tc.desc: Testcase for testing QueryAbilityInfo.
413 * @tc.type: FUNC
414 * @tc.require: Issue Number
415 */
416
BenchmarkTestQueryAbilityInfo(benchmark::State & state)417 static void BenchmarkTestQueryAbilityInfo(benchmark::State &state)
418 {
419 Want want;
420 ElementName name;
421 name.SetAbilityName(ABILITY_NAME);
422 name.SetBundleName(BUNDLE_NAME);
423 want.SetElement(name);
424 AbilityInfo info;
425 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
426
427 for (auto _ : state) {
428 /* @tc.steps: step1.call QueryAbilityInfo in loop */
429 bundleMgrProxy->QueryAbilityInfo(want, info);
430 }
431 }
432
433 /**
434 * @tc.name: BenchmarkTestQueryAbilityInfoByFlags
435 * @tc.desc: Testcase for testing QueryAbilityInfo.
436 * @tc.type: FUNC
437 * @tc.require: Issue Number
438 */
439
BenchmarkTestQueryAbilityInfoByFlags(benchmark::State & state)440 static void BenchmarkTestQueryAbilityInfoByFlags(benchmark::State &state)
441 {
442 Want want;
443 ElementName name;
444 name.SetAbilityName(ABILITY_NAME);
445 name.SetBundleName(BUNDLE_NAME);
446 want.SetElement(name);
447
448 AbilityInfo info;
449
450 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
451 for (auto _ : state) {
452 if (bundleMgrProxy == nullptr) {
453 break;
454 }
455 /* @tc.steps: step1.call QueryAbilityInfo in loop */
456 bundleMgrProxy->QueryAbilityInfo(want, 0, DEFAULT_USERID, info);
457 }
458 }
459
460 /**
461 * @tc.name: BenchmarkTestQueryAbilityInfos
462 * @tc.desc: Testcase for testing QueryAbilityInfos.
463 * @tc.type: FUNC
464 * @tc.require: Issue Number
465 */
466
BenchmarkTestQueryAbilityInfos(benchmark::State & state)467 static void BenchmarkTestQueryAbilityInfos(benchmark::State &state)
468 {
469 Want want;
470 ElementName name;
471 name.SetAbilityName(ABILITY_NAME);
472 name.SetBundleName(BUNDLE_NAME);
473 want.SetElement(name);
474
475 std::vector<AbilityInfo> abilityInfos;
476
477 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
478 for (auto _ : state) {
479 if (bundleMgrProxy == nullptr) {
480 break;
481 }
482 /* @tc.steps: step1.call QueryAbilityInfos in loop */
483 bundleMgrProxy->QueryAbilityInfos(want, abilityInfos);
484 }
485 }
486
487 /**
488 * @tc.name: BenchmarkTestQueryAbilityInfosByFlags
489 * @tc.desc: Testcase for testing QueryAbilityInfos.
490 * @tc.type: FUNC
491 * @tc.require: Issue Number
492 */
493
BenchmarkTestQueryAbilityInfosByFlags(benchmark::State & state)494 static void BenchmarkTestQueryAbilityInfosByFlags(benchmark::State &state)
495 {
496 Want want;
497 ElementName name;
498 name.SetAbilityName(ABILITY_NAME);
499 name.SetBundleName(BUNDLE_NAME);
500 want.SetElement(name);
501
502 std::vector<AbilityInfo> abilityInfos;
503 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
504 for (auto _ : state) {
505 if (bundleMgrProxy == nullptr) {
506 break;
507 }
508 /* @tc.steps: step1.call QueryAbilityInfos in loop */
509 bundleMgrProxy->QueryAbilityInfos(want, 0, DEFAULT_USERID, abilityInfos);
510 }
511 }
512
513 /**
514 * @tc.name: BenchmarkTestQueryAbilityInfosById
515 * @tc.desc: Testcase for testing QueryAllAbilityInfos.
516 * @tc.type: FUNC
517 * @tc.require: Issue Number
518 */
519
BenchmarkTestQueryAbilityInfosById(benchmark::State & state)520 static void BenchmarkTestQueryAbilityInfosById(benchmark::State &state)
521 {
522 Want want;
523 ElementName name;
524 name.SetAbilityName(ABILITY_NAME);
525 name.SetBundleName(BUNDLE_NAME);
526 want.SetElement(name);
527
528 std::vector<AbilityInfo> abilityInfos;
529
530 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
531 for (auto _ : state) {
532 if (bundleMgrProxy == nullptr) {
533 break;
534 }
535 /* @tc.steps: step1.call QueryAllAbilityInfos in loop */
536 bundleMgrProxy->QueryAllAbilityInfos(want, 0, abilityInfos);
537 }
538 }
539
540 /**
541 * @tc.name: BenchmarkTestQueryAbilityInfoByUri
542 * @tc.desc: Testcase for testing QueryAbilityInfoByUri.
543 * @tc.type: FUNC
544 * @tc.require: Issue Number
545 */
546
BenchmarkTestQueryAbilityInfoByUri(benchmark::State & state)547 static void BenchmarkTestQueryAbilityInfoByUri(benchmark::State &state)
548 {
549 std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility";
550 AbilityInfo info;
551
552 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
553 for (auto _ : state) {
554 if (bundleMgrProxy == nullptr) {
555 break;
556 }
557 /* @tc.steps: step1.call QueryAbilityInfoByUri in loop */
558 bundleMgrProxy->QueryAbilityInfoByUri(abilityUri, info);
559 }
560 }
561
562 /**
563 * @tc.name: BenchmarkTestQueryAbilityInfoByUriAndId
564 * @tc.desc: Testcase for testing QueryAbilityInfoByUri.
565 * @tc.type: FUNC
566 * @tc.require: Issue Number
567 */
568
BenchmarkTestQueryAbilityInfoByUriAndId(benchmark::State & state)569 static void BenchmarkTestQueryAbilityInfoByUriAndId(benchmark::State &state)
570 {
571 std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility";
572 AbilityInfo info;
573
574 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
575 for (auto _ : state) {
576 if (bundleMgrProxy == nullptr) {
577 break;
578 }
579 /* @tc.steps: step1.call QueryAbilityInfoByUri in loop */
580 bundleMgrProxy->QueryAbilityInfoByUri(abilityUri, DEFAULT_USERID, info);
581 }
582 }
583
584 /**
585 * @tc.name: BenchmarkTestQueryAbilityInfosByUri
586 * @tc.desc: Testcase for testing QueryAbilityInfosByUri.
587 * @tc.type: FUNC
588 * @tc.require: Issue Number
589 */
590
BenchmarkTestQueryAbilityInfosByUri(benchmark::State & state)591 static void BenchmarkTestQueryAbilityInfosByUri(benchmark::State &state)
592 {
593 std::string abilityUri = "err://com.test.demo.weatherfa.UserADataAbility";
594 std::vector<AbilityInfo> abilityInfos;
595
596 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
597 for (auto _ : state) {
598 if (bundleMgrProxy == nullptr) {
599 break;
600 }
601 /* @tc.steps: step1.call QueryAbilityInfosByUri in loop */
602 bundleMgrProxy->QueryAbilityInfosByUri(abilityUri, abilityInfos);
603 }
604 }
605
606 /**
607 * @tc.name: BenchmarkTestQueryKeepAliveBundleInfos
608 * @tc.desc: Testcase for testing QueryKeepAliveBundleInfos.
609 * @tc.type: FUNC
610 * @tc.require: Issue Number
611 */
612
BenchmarkTestQueryKeepAliveBundleInfos(benchmark::State & state)613 static void BenchmarkTestQueryKeepAliveBundleInfos(benchmark::State &state)
614 {
615 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
616 std::vector<BundleInfo> bundleInfos;
617
618 for (auto _ : state) {
619 if (bundleMgrProxy == nullptr) {
620 break;
621 }
622 /* @tc.steps: step1.call QueryKeepAliveBundleInfos in loop */
623 bundleMgrProxy->QueryKeepAliveBundleInfos(bundleInfos);
624 }
625 }
626
627 /**
628 * @tc.name: BenchmarkTestGetAbilityLabel
629 * @tc.desc: Testcase for testing GetAbilityLabel.
630 * @tc.type: FUNC
631 * @tc.require: Issue Number
632 */
633
BenchmarkTestGetAbilityLabel(benchmark::State & state)634 static void BenchmarkTestGetAbilityLabel(benchmark::State &state)
635 {
636 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
637 for (auto _ : state) {
638 if (bundleMgrProxy == nullptr) {
639 break;
640 }
641 /* @tc.steps: step1.call GetAbilityLabel in loop */
642 bundleMgrProxy->GetAbilityLabel(BUNDLE_NAME, ABILITY_NAME);
643 }
644 }
645
646 /**
647 * @tc.name: BenchmarkTestGetBundleArchiveInfo
648 * @tc.desc: Testcase for testing GetBundleArchiveInfo.
649 * @tc.type: FUNC
650 * @tc.require: Issue Number
651 */
652
BenchmarkTestGetBundleArchiveInfo(benchmark::State & state)653 static void BenchmarkTestGetBundleArchiveInfo(benchmark::State &state)
654 {
655 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
656 BundleInfo info;
657 for (auto _ : state) {
658 if (bundleMgrProxy == nullptr) {
659 break;
660 }
661 /* @tc.steps: step1.call GetBundleArchiveInfo in loop */
662 bundleMgrProxy->GetBundleArchiveInfo(HAP_FILE, 0, info);
663 }
664 }
665
666 /**
667 * @tc.name: BenchmarkTestGetBundleArchiveInfoByFlag
668 * @tc.desc: Testcase for testing GetBundleArchiveInfo.
669 * @tc.type: FUNC
670 * @tc.require: Issue Number
671 */
672
BenchmarkTestGetBundleArchiveInfoByFlag(benchmark::State & state)673 static void BenchmarkTestGetBundleArchiveInfoByFlag(benchmark::State &state)
674 {
675 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
676 BundleInfo info;
677 for (auto _ : state) {
678 if (bundleMgrProxy == nullptr) {
679 break;
680 }
681 /* @tc.steps: step1.call GetBundleArchiveInfo in loop */
682 bundleMgrProxy->GetBundleArchiveInfo(HAP_FILE, BundleFlag::GET_BUNDLE_DEFAULT, info);
683 }
684 }
685
686 /**
687 * @tc.name: BenchmarkTestGetLaunchWantForBundle
688 * @tc.desc: Testcase for testing GetLaunchWantForBundle.
689 * @tc.type: FUNC
690 * @tc.require: Issue Number
691 */
692
BenchmarkTestGetLaunchWantForBundle(benchmark::State & state)693 static void BenchmarkTestGetLaunchWantForBundle(benchmark::State &state)
694 {
695 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
696 Want want;
697 for (auto _ : state) {
698 if (bundleMgrProxy == nullptr) {
699 break;
700 }
701 /* @tc.steps: step1.call GetLaunchWantForBundle in loop */
702 bundleMgrProxy->GetLaunchWantForBundle(BUNDLE_NAME, want);
703 }
704 }
705
706 /**
707 * @tc.name: BenchmarkTestGetPermissionDef
708 * @tc.desc: Testcase for testing GetPermissionDef.
709 * @tc.type: FUNC
710 * @tc.require: Issue Number
711 */
712
BenchmarkTestGetPermissionDef(benchmark::State & state)713 static void BenchmarkTestGetPermissionDef(benchmark::State &state)
714 {
715 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
716 std::string permissionName;
717 PermissionDef info;
718
719 for (auto _ : state) {
720 if (bundleMgrProxy == nullptr) {
721 break;
722 }
723 /* @tc.steps: step1.call GetPermissionDef in loop */
724 bundleMgrProxy->GetPermissionDef(permissionName, info);
725 }
726 }
727
728 /**
729 * @tc.name: BenchmarkTestCleanBundleDataFiles
730 * @tc.desc: Testcase for testing CleanBundleDataFiles.
731 * @tc.type: FUNC
732 * @tc.require: Issue Number
733 */
734
BenchmarkTestCleanBundleDataFiles(benchmark::State & state)735 static void BenchmarkTestCleanBundleDataFiles(benchmark::State &state)
736 {
737 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
738 for (auto _ : state) {
739 if (bundleMgrProxy == nullptr) {
740 break;
741 }
742 /* @tc.steps: step1.call CleanBundleDataFiles in loop */
743 bundleMgrProxy->CleanBundleDataFiles(BUNDLE_NAME, 0);
744 }
745 }
746
747 /**
748 * @tc.name: BenchmarkTestRegisterBundleStatusCallback
749 * @tc.desc: Testcase for testing RegisterBundleStatusCallback.
750 * @tc.type: FUNC
751 * @tc.require: Issue Number
752 */
753
BenchmarkTestRegisterBundleStatusCallback(benchmark::State & state)754 static void BenchmarkTestRegisterBundleStatusCallback(benchmark::State &state)
755 {
756 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
757 sptr<BundleStatusCallbackImpl> bundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl());
758 bundleStatusCallback->SetBundleName(BUNDLE_NAME);
759 for (auto _ : state) {
760 if (bundleMgrProxy == nullptr) {
761 break;
762 }
763 /* @tc.steps: step1.call RegisterBundleStatusCallback in loop */
764 bundleMgrProxy->RegisterBundleStatusCallback(bundleStatusCallback);
765 }
766 }
767
768 /**
769 * @tc.name: BenchmarkTestClearBundleStatusCallback
770 * @tc.desc: Testcase for testing ClearBundleStatusCallback.
771 * @tc.type: FUNC
772 * @tc.require: Issue Number
773 */
774
BenchmarkTestClearBundleStatusCallback(benchmark::State & state)775 static void BenchmarkTestClearBundleStatusCallback(benchmark::State &state)
776 {
777 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
778 sptr<BundleStatusCallbackImpl> bundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl());
779 bundleStatusCallback->SetBundleName(BUNDLE_NAME);
780 for (auto _ : state) {
781 if (bundleMgrProxy == nullptr) {
782 break;
783 }
784 /* @tc.steps: step1.call ClearBundleStatusCallback in loop */
785 bundleMgrProxy->ClearBundleStatusCallback(bundleStatusCallback);
786 }
787 }
788
789 /**
790 * @tc.name: BenchmarkTestUnregisterBundleStatusCallback
791 * @tc.desc: Testcase for testing UnregisterBundleStatusCallback.
792 * @tc.type: FUNC
793 * @tc.require: Issue Number
794 */
795
BenchmarkTestUnregisterBundleStatusCallback(benchmark::State & state)796 static void BenchmarkTestUnregisterBundleStatusCallback(benchmark::State &state)
797 {
798 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
799 for (auto _ : state) {
800 if (bundleMgrProxy == nullptr) {
801 break;
802 }
803 /* @tc.steps: step1.call UnregisterBundleStatusCallback in loop */
804 bundleMgrProxy->UnregisterBundleStatusCallback();
805 }
806 }
807
808 /**
809 * @tc.name: BenchmarkTestDumpInfos
810 * @tc.desc: Testcase for testing DumpInfos.
811 * @tc.type: FUNC
812 * @tc.require: Issue Number
813 */
814
BenchmarkTestDumpInfos(benchmark::State & state)815 static void BenchmarkTestDumpInfos(benchmark::State &state)
816 {
817 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
818 const std::string EMPTY_STRING = "";
819 std::string bundleNames;
820 for (auto _ : state) {
821 if (bundleMgrProxy == nullptr) {
822 break;
823 }
824 /* @tc.steps: step1.call DumpInfos in loop */
825 bundleMgrProxy->DumpInfos(
826 DumpFlag::DUMP_BUNDLE_LIST, EMPTY_STRING, DEFAULT_USERID, bundleNames);
827 }
828 }
829
830 /**
831 * @tc.name: BenchmarkTestIsApplicationEnabled
832 * @tc.desc: Testcase for testing IsApplicationEnabled.
833 * @tc.type: FUNC
834 * @tc.require: Issue Number
835 */
836
BenchmarkTestIsApplicationEnabled(benchmark::State & state)837 static void BenchmarkTestIsApplicationEnabled(benchmark::State &state)
838 {
839 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
840 for (auto _ : state) {
841 if (bundleMgrProxy == nullptr) {
842 break;
843 }
844 /* @tc.steps: step1.call IsApplicationEnabled in loop */
845 bool isEnable = false;
846 bundleMgrProxy->IsApplicationEnabled(BUNDLE_NAME, isEnable);
847 }
848 }
849
850 /**
851 * @tc.name: BenchmarkTestSetApplicationEnabled
852 * @tc.desc: Testcase for testing SetApplicationEnabled.
853 * @tc.type: FUNC
854 * @tc.require: Issue Number
855 */
856
BenchmarkTestSetApplicationEnabled(benchmark::State & state)857 static void BenchmarkTestSetApplicationEnabled(benchmark::State &state)
858 {
859 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
860 for (auto _ : state) {
861 if (bundleMgrProxy == nullptr) {
862 break;
863 }
864 /* @tc.steps: step1.call SetApplicationEnabled in loop */
865 bundleMgrProxy->SetApplicationEnabled(BUNDLE_NAME, false);
866 }
867 }
868
869 /**
870 * @tc.name: BenchmarkTestIsAbilityEnabled
871 * @tc.desc: Testcase for testing IsAbilityEnabled.
872 * @tc.type: FUNC
873 * @tc.require: Issue Number
874 */
875
BenchmarkTestIsAbilityEnabled(benchmark::State & state)876 static void BenchmarkTestIsAbilityEnabled(benchmark::State &state)
877 {
878 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
879 AbilityInfo info;
880
881 for (auto _ : state) {
882 if (bundleMgrProxy == nullptr) {
883 break;
884 }
885 /* @tc.steps: step1.call IsAbilityEnabled in loop */
886 bool isEnable = false;
887 bundleMgrProxy->IsAbilityEnabled(info, isEnable);
888 }
889 }
890
891 /**
892 * @tc.name: BenchmarkTestSetAbilityEnabled
893 * @tc.desc: Testcase for testing SetAbilityEnabled.
894 * @tc.type: FUNC
895 * @tc.require: Issue Number
896 */
897
BenchmarkTestSetAbilityEnabled(benchmark::State & state)898 static void BenchmarkTestSetAbilityEnabled(benchmark::State &state)
899 {
900 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
901 AbilityInfo info;
902
903 for (auto _ : state) {
904 if (bundleMgrProxy == nullptr) {
905 break;
906 }
907 /* @tc.steps: step1.call SetAbilityEnabled in loop */
908 bundleMgrProxy->SetAbilityEnabled(info, false);
909 }
910 }
911
912 /**
913 * @tc.name: BenchmarkTestGetBundleInstaller
914 * @tc.desc: Testcase for testing GetBundleInstaller.
915 * @tc.type: FUNC
916 * @tc.require: Issue Number
917 */
918
BenchmarkTestGetBundleInstaller(benchmark::State & state)919 static void BenchmarkTestGetBundleInstaller(benchmark::State &state)
920 {
921 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
922 for (auto _ : state) {
923 if (bundleMgrProxy == nullptr) {
924 break;
925 }
926 /* @tc.steps: step1.call GetBundleInstaller in loop */
927 bundleMgrProxy->GetBundleInstaller();
928 }
929 }
930
931 /**
932 * @tc.name: BenchmarkTestGetBundleUserMgr
933 * @tc.desc: Testcase for testing GetBundleUserMgr.
934 * @tc.type: FUNC
935 * @tc.require: Issue Number
936 */
937
BenchmarkTestGetBundleUserMgr(benchmark::State & state)938 static void BenchmarkTestGetBundleUserMgr(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 GetBundleUserMgr in loop */
946 bundleMgrProxy->GetBundleUserMgr();
947 }
948 }
949
950 /**
951 * @tc.name: BenchmarkTestGetAllFormsInfo
952 * @tc.desc: Testcase for testing GetAllFormsInfo.
953 * @tc.type: FUNC
954 * @tc.require: Issue Number
955 */
956
BenchmarkTestGetAllFormsInfo(benchmark::State & state)957 static void BenchmarkTestGetAllFormsInfo(benchmark::State &state)
958 {
959 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
960 std::vector<FormInfo> formInfos;
961
962 for (auto _ : state) {
963 if (bundleMgrProxy == nullptr) {
964 break;
965 }
966 /* @tc.steps: step1.call GetAllFormsInfo in loop */
967 bundleMgrProxy->GetAllFormsInfo(formInfos);
968 }
969 }
970
971 /**
972 * @tc.name: BenchmarkTestGetFormsInfoByApp
973 * @tc.desc: Testcase for testing GetFormsInfoByApp.
974 * @tc.type: FUNC
975 * @tc.require: Issue Number
976 */
977
BenchmarkTestGetFormsInfoByApp(benchmark::State & state)978 static void BenchmarkTestGetFormsInfoByApp(benchmark::State &state)
979 {
980 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
981 std::vector<FormInfo> formInfos;
982
983 for (auto _ : state) {
984 if (bundleMgrProxy == nullptr) {
985 break;
986 }
987 /* @tc.steps: step1.call GetFormsInfoByApp in loop */
988 bundleMgrProxy->GetFormsInfoByApp(BUNDLE_NAME, formInfos);
989 }
990 }
991
992 /**
993 * @tc.name: BenchmarkTestGetFormsInfoByModule
994 * @tc.desc: Testcase for testing GetFormsInfoByModule.
995 * @tc.type: FUNC
996 * @tc.require: Issue Number
997 */
998
BenchmarkTestGetFormsInfoByModule(benchmark::State & state)999 static void BenchmarkTestGetFormsInfoByModule(benchmark::State &state)
1000 {
1001 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1002 std::vector<FormInfo> formInfos;
1003
1004 for (auto _ : state) {
1005 if (bundleMgrProxy == nullptr) {
1006 break;
1007 }
1008 /* @tc.steps: step1.call GetFormsInfoByModule in loop */
1009 bundleMgrProxy->GetFormsInfoByModule(BUNDLE_NAME, MODULE_NAME_TEST, formInfos);
1010 }
1011 }
1012
1013 /**
1014 * @tc.name: BenchmarkTestGetShortcutInfos
1015 * @tc.desc: Testcase for testing GetShortcutInfos.
1016 * @tc.type: FUNC
1017 * @tc.require: Issue Number
1018 */
1019
BenchmarkTestGetShortcutInfos(benchmark::State & state)1020 static void BenchmarkTestGetShortcutInfos(benchmark::State &state)
1021 {
1022 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1023 std::vector<ShortcutInfo> shortcutInfos;
1024
1025 for (auto _ : state) {
1026 if (bundleMgrProxy == nullptr) {
1027 break;
1028 }
1029 /* @tc.steps: step1.call GetShortcutInfos in loop */
1030 bundleMgrProxy->GetShortcutInfos(BUNDLE_NAME, shortcutInfos);
1031 }
1032 }
1033
1034 /**
1035 * @tc.name: BenchmarkTestGetAllCommonEventInfo
1036 * @tc.desc: Testcase for testing GetAllCommonEventInfo.
1037 * @tc.type: FUNC
1038 * @tc.require: Issue Number
1039 */
1040
BenchmarkTestGetAllCommonEventInfo(benchmark::State & state)1041 static void BenchmarkTestGetAllCommonEventInfo(benchmark::State &state)
1042 {
1043 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1044 std::vector<CommonEventInfo> commonEventInfos;
1045
1046 for (auto _ : state) {
1047 if (bundleMgrProxy == nullptr) {
1048 break;
1049 }
1050 /* @tc.steps: step1.call GetAllCommonEventInfo in loop */
1051 bundleMgrProxy->GetAllCommonEventInfo(COMMON_EVENT_EVENT, commonEventInfos);
1052 }
1053 }
1054
1055 /**
1056 * @tc.name: BenchmarkTestGetDistributedBundleInfo
1057 * @tc.desc: Testcase for testing GetDistributedBundleInfo.
1058 * @tc.type: FUNC
1059 * @tc.require: Issue Number
1060 */
1061
BenchmarkTestGetDistributedBundleInfo(benchmark::State & state)1062 static void BenchmarkTestGetDistributedBundleInfo(benchmark::State &state)
1063 {
1064 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1065 std::string networkId = "com.ohos.contactsdataability_BNtg4JBClbl92Rgc3jm"\
1066 "/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM=";
1067 DistributedBundleInfo distributedBundleInfo;
1068
1069 for (auto _ : state) {
1070 if (bundleMgrProxy == nullptr) {
1071 break;
1072 }
1073 /* @tc.steps: step1.call GetDistributedBundleInfo in loop */
1074 bundleMgrProxy->GetDistributedBundleInfo(networkId, BUNDLE_NAME, distributedBundleInfo);
1075 }
1076 }
1077
1078 /**
1079 * @tc.name: BenchmarkTestGetAppPrivilegeLevel
1080 * @tc.desc: Testcase for testing GetAppPrivilegeLevel.
1081 * @tc.type: FUNC
1082 * @tc.require: Issue Number
1083 */
1084
BenchmarkTestGetAppPrivilegeLevel(benchmark::State & state)1085 static void BenchmarkTestGetAppPrivilegeLevel(benchmark::State &state)
1086 {
1087 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1088 for (auto _ : state) {
1089 if (bundleMgrProxy == nullptr) {
1090 break;
1091 }
1092 /* @tc.steps: step1.call GetAppPrivilegeLevel in loop */
1093 bundleMgrProxy->GetAppPrivilegeLevel(BUNDLE_NAME);
1094 }
1095 }
1096
1097 /**
1098 * @tc.name: BenchmarkTestQueryExtensionAbilityInfosByWant
1099 * @tc.desc: Testcase for testing QueryExtensionAbilityInfos.
1100 * @tc.type: FUNC
1101 * @tc.require: Issue Number
1102 */
1103
BenchmarkTestQueryExtensionAbilityInfosByWant(benchmark::State & state)1104 static void BenchmarkTestQueryExtensionAbilityInfosByWant(benchmark::State &state)
1105 {
1106 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1107 Want want;
1108 ElementName name;
1109 name.SetAbilityName(ABILITY_NAME);
1110 name.SetBundleName(BUNDLE_NAME);
1111 want.SetElement(name);
1112 int32_t flags = 0;
1113 std::vector<ExtensionAbilityInfo> infos;
1114 for (auto _ : state) {
1115 if (bundleMgrProxy == nullptr) {
1116 break;
1117 }
1118 /* @tc.steps: step1.call QueryExtensionAbilityInfos in loop */
1119 bundleMgrProxy->QueryExtensionAbilityInfos(want, flags, DEFAULT_USERID, infos);
1120 }
1121 }
1122
1123 /**
1124 * @tc.name: BenchmarkTestQueryExtensionAbilityInfosByType
1125 * @tc.desc: Testcase for testing QueryExtensionAbilityInfos.
1126 * @tc.type: FUNC
1127 * @tc.require: Issue Number
1128 */
1129
BenchmarkTestQueryExtensionAbilityInfosByType(benchmark::State & state)1130 static void BenchmarkTestQueryExtensionAbilityInfosByType(benchmark::State &state)
1131 {
1132 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1133 std::vector<ExtensionAbilityInfo> infos;
1134 for (auto _ : state) {
1135 if (bundleMgrProxy == nullptr) {
1136 break;
1137 }
1138 /* @tc.steps: step1.call QueryExtensionAbilityInfos in loop */
1139 bundleMgrProxy->QueryExtensionAbilityInfos(ExtensionAbilityType::FORM, DEFAULT_USERID, infos);
1140 }
1141 }
1142
1143 /**
1144 * @tc.name: BenchmarkTestQueryExtensionAbilityInfos
1145 * @tc.desc: Testcase for testing QueryExtensionAbilityInfos.
1146 * @tc.type: FUNC
1147 * @tc.require: Issue Number
1148 */
1149
BenchmarkTestQueryExtensionAbilityInfos(benchmark::State & state)1150 static void BenchmarkTestQueryExtensionAbilityInfos(benchmark::State &state)
1151 {
1152 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1153 Want want;
1154 ElementName name;
1155 name.SetAbilityName(ABILITY_NAME);
1156 name.SetBundleName(BUNDLE_NAME);
1157 want.SetElement(name);
1158 int32_t flags = 0;
1159 std::vector<ExtensionAbilityInfo> infos;
1160 for (auto _ : state) {
1161 if (bundleMgrProxy == nullptr) {
1162 break;
1163 }
1164 /* @tc.steps: step1.call QueryExtensionAbilityInfos in loop */
1165 bundleMgrProxy->QueryExtensionAbilityInfos(want, ExtensionAbilityType::FORM, flags, DEFAULT_USERID, infos);
1166 }
1167 }
1168
1169 /**
1170 * @tc.name: BenchmarkTestVerifyCallingPermission
1171 * @tc.desc: Testcase for testing VerifyCallingPermission.
1172 * @tc.type: FUNC
1173 * @tc.require: Issue Number
1174 */
1175
BenchmarkTestVerifyCallingPermission(benchmark::State & state)1176 static void BenchmarkTestVerifyCallingPermission(benchmark::State &state)
1177 {
1178 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1179 std::string appPermission = "USER_GRANT";
1180 for (auto _ : state) {
1181 if (bundleMgrProxy == nullptr) {
1182 break;
1183 }
1184 /* @tc.steps: step1.call VerifyCallingPermission in loop */
1185 bundleMgrProxy->VerifyCallingPermission(appPermission);
1186 }
1187 }
1188
1189 /**
1190 * @tc.name: BenchmarkTestQueryExtensionAbilityInfoByUri
1191 * @tc.desc: Testcase for testing QueryExtensionAbilityInfoByUri.
1192 * @tc.type: FUNC
1193 * @tc.require: Issue Number
1194 */
1195
BenchmarkTestQueryExtensionAbilityInfoByUri(benchmark::State & state)1196 static void BenchmarkTestQueryExtensionAbilityInfoByUri(benchmark::State &state)
1197 {
1198 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1199 ExtensionAbilityInfo info;
1200 const std::string URI = "dataability://com.example.hiworld.himusic.UserADataAbility";
1201 for (auto _ : state) {
1202 if (bundleMgrProxy == nullptr) {
1203 break;
1204 }
1205 /* @tc.steps: step1.call QueryExtensionAbilityInfoByUri in loop */
1206 bundleMgrProxy->QueryExtensionAbilityInfoByUri(URI, DEFAULT_USERID, info);
1207 }
1208 }
1209
1210 /**
1211 * @tc.name: BenchmarkTestImplicitQueryInfoByPriority
1212 * @tc.desc: Testcase for testing ImplicitQueryInfoByPriority.
1213 * @tc.type: FUNC
1214 * @tc.require: Issue Number
1215 */
1216
BenchmarkTestImplicitQueryInfoByPriority(benchmark::State & state)1217 static void BenchmarkTestImplicitQueryInfoByPriority(benchmark::State &state)
1218 {
1219 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1220 Want want;
1221 ElementName name;
1222 name.SetAbilityName(ABILITY_NAME);
1223 name.SetBundleName(BUNDLE_NAME);
1224 want.SetElement(name);
1225 int32_t flags = 0;
1226 AbilityInfo abilityInfo;
1227 ExtensionAbilityInfo extensionInfo;
1228 for (auto _ : state) {
1229 if (bundleMgrProxy == nullptr) {
1230 break;
1231 }
1232 /* @tc.steps: step1.call ImplicitQueryInfoByPriority in loop */
1233 bundleMgrProxy->ImplicitQueryInfoByPriority(want, flags, DEFAULT_USERID, abilityInfo, extensionInfo);
1234 }
1235 }
1236
1237 /**
1238 * @tc.name: BenchmarkTestGetSandboxBundleInfo
1239 * @tc.desc: Testcase for testing GetSandboxBundleInfo.
1240 * @tc.type: FUNC
1241 * @tc.require: Issue Number
1242 */
1243
BenchmarkTestGetSandboxBundleInfo(benchmark::State & state)1244 static void BenchmarkTestGetSandboxBundleInfo(benchmark::State &state)
1245 {
1246 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1247 BundleInfo info;
1248 for (auto _ : state) {
1249 if (bundleMgrProxy == nullptr) {
1250 break;
1251 }
1252 /* @tc.steps: step1.call GetSandboxBundleInfo in loop */
1253 bundleMgrProxy->GetSandboxBundleInfo(BUNDLE_NAME, 0, DEFAULT_USERID, info);
1254 }
1255 }
1256
1257 /**
1258 * @tc.name: BenchmarkTestGetAbilityInfo
1259 * @tc.desc: Testcase for testing GetAbilityInfo.
1260 * @tc.type: FUNC
1261 * @tc.require: Issue Number
1262 */
1263
BenchmarkTestGetAbilityInfo(benchmark::State & state)1264 static void BenchmarkTestGetAbilityInfo(benchmark::State &state)
1265 {
1266 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1267 AbilityInfo info;
1268 for (auto _ : state) {
1269 if (bundleMgrProxy == nullptr) {
1270 break;
1271 }
1272
1273 /* @tc.steps: step1.call GetAbilityInfo in loop */
1274 bundleMgrProxy->GetAbilityInfo(BUNDLE_NAME, ABILITY_NAME, info);
1275 }
1276 }
1277
1278 /**
1279 * @tc.name: BenchmarkTestGetAbilityInfoByModuleName
1280 * @tc.desc: Testcase for testing GetAbilityInfo.
1281 * @tc.type: FUNC
1282 * @tc.require: Issue Number
1283 */
1284
BenchmarkTestGetAbilityInfoByModuleName(benchmark::State & state)1285 static void BenchmarkTestGetAbilityInfoByModuleName(benchmark::State &state)
1286 {
1287 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1288 AbilityInfo info;
1289 for (auto _ : state) {
1290 if (bundleMgrProxy == nullptr) {
1291 break;
1292 }
1293 /* @tc.steps: step1.call GetAbilityInfo in loop */
1294 bundleMgrProxy->GetAbilityInfo(BUNDLE_NAME, MODULE_NAME_TEST, ABILITY_NAME, info);
1295 }
1296 }
1297
1298 /**
1299 * @tc.name: BenchmarkTestGetAllDependentModuleNames
1300 * @tc.desc: Testcase for testing GetAllDependentModuleNames.
1301 * @tc.type: FUNC
1302 * @tc.require: Issue Number
1303 */
1304
BenchmarkTestGetAllDependentModuleNames(benchmark::State & state)1305 static void BenchmarkTestGetAllDependentModuleNames(benchmark::State &state)
1306 {
1307 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1308 std::vector<std::string> dependentModuleNames;
1309 for (auto _ : state) {
1310 if (bundleMgrProxy == nullptr) {
1311 break;
1312 }
1313 /* @tc.steps: step1.call GetAllDependentModuleNames in loop */
1314 bundleMgrProxy->GetAllDependentModuleNames(BUNDLE_NAME, MODULE_NAME_TEST, dependentModuleNames);
1315 }
1316 }
1317
1318 /**
1319 * @tc.name: BenchmarkTestObtainCallingBundleName
1320 * @tc.desc: Testcase for testing ObtainCallingBundleName.
1321 * @tc.type: FUNC
1322 * @tc.require: Issue Number
1323 */
1324
BenchmarkTestObtainCallingBundleName(benchmark::State & state)1325 static void BenchmarkTestObtainCallingBundleName(benchmark::State &state)
1326 {
1327 sptr<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
1328 std::string bundleName;
1329
1330 for (auto _ : state) {
1331 if (bundleMgrProxy == nullptr) {
1332 break;
1333 }
1334 /* @tc.steps: step1.call ObtainCallingBundleName in loop */
1335 bundleMgrProxy->ObtainCallingBundleName(bundleName);
1336 }
1337 }
1338
1339 BENCHMARK(BenchmarkTestGetApplicationInfoByFlag)->Iterations(BENCHMARK_TIMES);
1340 BENCHMARK(BenchmarkTestGetApplicationInfoByUserId)->Iterations(BENCHMARK_TIMES);
1341 BENCHMARK(BenchmarkTestGetApplicationInfosByApplicationFlag)->Iterations(BENCHMARK_TIMES);
1342 BENCHMARK(BenchmarkTestGetApplicationInfosByFlags)->Iterations(BENCHMARK_TIMES);
1343 BENCHMARK(BenchmarkTestGetBundleInfoByBundleFlag)->Iterations(BENCHMARK_TIMES);
1344 BENCHMARK(BenchmarkTestGetBundleInfoByFlags)->Iterations(BENCHMARK_TIMES);
1345 BENCHMARK(BenchmarkTestGetBundleInfosByBundleFlag)->Iterations(BENCHMARK_TIMES);
1346 BENCHMARK(BenchmarkTestGetBundleInfosByFlags)->Iterations(BENCHMARK_TIMES);
1347 BENCHMARK(BenchmarkTestGetUidByBundleName)->Iterations(BENCHMARK_TIMES);
1348 BENCHMARK(BenchmarkTestGetAppIdByBundleName)->Iterations(BENCHMARK_TIMES);
1349 BENCHMARK(BenchmarkTestGetBundlesForUid)->Iterations(BENCHMARK_TIMES);
1350 BENCHMARK(BenchmarkTestGetNameForUid)->Iterations(BENCHMARK_TIMES);
1351 BENCHMARK(BenchmarkTestGetAppType)->Iterations(BENCHMARK_TIMES);
1352 BENCHMARK(BenchmarkTestCheckIsSystemAppByUid)->Iterations(BENCHMARK_TIMES);
1353 BENCHMARK(BenchmarkTestGetBundleInfosByMetaData)->Iterations(BENCHMARK_TIMES);
1354 BENCHMARK(BenchmarkTestQueryAbilityInfo)->Iterations(BENCHMARK_TIMES);
1355 BENCHMARK(BenchmarkTestQueryAbilityInfoByFlags)->Iterations(BENCHMARK_TIMES);
1356 BENCHMARK(BenchmarkTestQueryAbilityInfos)->Iterations(BENCHMARK_TIMES);
1357 BENCHMARK(BenchmarkTestQueryAbilityInfosByFlags)->Iterations(BENCHMARK_TIMES);
1358 BENCHMARK(BenchmarkTestQueryAbilityInfosById)->Iterations(BENCHMARK_TIMES);
1359 BENCHMARK(BenchmarkTestQueryAbilityInfoByUriAndId)->Iterations(BENCHMARK_TIMES);
1360 BENCHMARK(BenchmarkTestQueryAbilityInfoByUri)->Iterations(BENCHMARK_TIMES);
1361 BENCHMARK(BenchmarkTestQueryAbilityInfosByUri)->Iterations(BENCHMARK_TIMES);
1362 BENCHMARK(BenchmarkTestQueryKeepAliveBundleInfos)->Iterations(BENCHMARK_TIMES);
1363 BENCHMARK(BenchmarkTestGetAbilityLabel)->Iterations(BENCHMARK_TIMES);
1364 BENCHMARK(BenchmarkTestGetBundleArchiveInfo)->Iterations(BENCHMARK_TIMES);
1365 BENCHMARK(BenchmarkTestGetBundleArchiveInfoByFlag)->Iterations(BENCHMARK_TIMES);
1366 BENCHMARK(BenchmarkTestGetLaunchWantForBundle)->Iterations(BENCHMARK_TIMES);
1367 BENCHMARK(BenchmarkTestGetPermissionDef)->Iterations(BENCHMARK_TIMES);
1368 BENCHMARK(BenchmarkTestCleanBundleDataFiles)->Iterations(BENCHMARK_TIMES);
1369 BENCHMARK(BenchmarkTestRegisterBundleStatusCallback)->Iterations(BENCHMARK_TIMES);
1370 BENCHMARK(BenchmarkTestClearBundleStatusCallback)->Iterations(BENCHMARK_TIMES);
1371 BENCHMARK(BenchmarkTestUnregisterBundleStatusCallback)->Iterations(BENCHMARK_TIMES);
1372 BENCHMARK(BenchmarkTestDumpInfos)->Iterations(BENCHMARK_TIMES);
1373 BENCHMARK(BenchmarkTestIsApplicationEnabled)->Iterations(BENCHMARK_TIMES);
1374 BENCHMARK(BenchmarkTestSetApplicationEnabled)->Iterations(BENCHMARK_TIMES);
1375 BENCHMARK(BenchmarkTestIsAbilityEnabled)->Iterations(BENCHMARK_TIMES);
1376 BENCHMARK(BenchmarkTestSetAbilityEnabled)->Iterations(BENCHMARK_TIMES);
1377 BENCHMARK(BenchmarkTestGetBundleInstaller)->Iterations(BENCHMARK_TIMES);
1378 BENCHMARK(BenchmarkTestGetBundleUserMgr)->Iterations(BENCHMARK_TIMES);
1379 BENCHMARK(BenchmarkTestGetAllFormsInfo)->Iterations(BENCHMARK_TIMES);
1380 BENCHMARK(BenchmarkTestGetFormsInfoByApp)->Iterations(BENCHMARK_TIMES);
1381 BENCHMARK(BenchmarkTestGetFormsInfoByModule)->Iterations(BENCHMARK_TIMES);
1382 BENCHMARK(BenchmarkTestGetShortcutInfos)->Iterations(BENCHMARK_TIMES);
1383 BENCHMARK(BenchmarkTestGetAllCommonEventInfo)->Iterations(BENCHMARK_TIMES);
1384 BENCHMARK(BenchmarkTestGetDistributedBundleInfo)->Iterations(BENCHMARK_TIMES);
1385 BENCHMARK(BenchmarkTestGetAppPrivilegeLevel)->Iterations(BENCHMARK_TIMES);
1386 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfosByWant)->Iterations(BENCHMARK_TIMES);
1387 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfos)->Iterations(BENCHMARK_TIMES);
1388 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfosByType)->Iterations(BENCHMARK_TIMES);
1389 BENCHMARK(BenchmarkTestVerifyCallingPermission)->Iterations(BENCHMARK_TIMES);
1390 BENCHMARK(BenchmarkTestQueryExtensionAbilityInfoByUri)->Iterations(BENCHMARK_TIMES);
1391 BENCHMARK(BenchmarkTestImplicitQueryInfoByPriority)->Iterations(BENCHMARK_TIMES);
1392 BENCHMARK(BenchmarkTestGetSandboxBundleInfo)->Iterations(BENCHMARK_TIMES);
1393 BENCHMARK(BenchmarkTestGetAbilityInfo)->Iterations(BENCHMARK_TIMES);
1394 BENCHMARK(BenchmarkTestGetAbilityInfoByModuleName)->Iterations(BENCHMARK_TIMES);
1395 BENCHMARK(BenchmarkTestGetAllDependentModuleNames)->Iterations(BENCHMARK_TIMES);;
1396 BENCHMARK(BenchmarkTestObtainCallingBundleName)->Iterations(BENCHMARK_TIMES);
1397 } // namespace
1398
1399 BENCHMARK_MAIN();