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