1 /* 2 * Copyright (c) 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 "bundle_mgr_client.h" 17 18 #include <benchmark/benchmark.h> 19 20 using namespace std; 21 using namespace OHOS; 22 using namespace OHOS::AppExecFwk; 23 24 namespace { 25 /** 26 * @tc.name: BenchmarkTestForGetBundleNameForUid 27 * @tc.desc: Testcase for testing 'GetBundleNameForUid' function. 28 * @tc.type: FUNC 29 * @tc.require: Issue Number 30 */ BenchmarkTestForGetBundleNameForUid(benchmark::State & state)31 static void BenchmarkTestForGetBundleNameForUid(benchmark::State &state) 32 { 33 BundleMgrClient client; 34 int uid = 100; 35 std::string bundleName = "ohos.global.systemres"; 36 for (auto _ : state) { 37 /* @tc.steps: step1.call GetBundleNameForUid in loop */ 38 client.GetBundleNameForUid(uid, bundleName); 39 } 40 } 41 42 /** 43 * @tc.name: BenchmarkTestForGetBundleInfo 44 * @tc.desc: Testcase for testing 'GetBundleInfo' function. 45 * @tc.type: FUNC 46 * @tc.require: Issue Number 47 */ BenchmarkTestForGetBundleInfo(benchmark::State & state)48 static void BenchmarkTestForGetBundleInfo(benchmark::State &state) 49 { 50 BundleMgrClient client; 51 std::string bundleName = "ohos.global.systemres"; 52 BundleInfo bundleInfo; 53 Parcel parcel; 54 bundleInfo.Marshalling(parcel); 55 for (auto _ : state) { 56 /* @tc.steps: step1.call GetBundleInfo in loop */ 57 client.GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo); 58 } 59 } 60 61 /** 62 * @tc.name: BenchmarkTestForGetHapModuleInfo 63 * @tc.desc: Testcase for testing 'GetHapModuleInfo' function. 64 * @tc.type: FUNC 65 * @tc.require: Issue Number 66 */ BenchmarkTestForGetHapModuleInfo(benchmark::State & state)67 static void BenchmarkTestForGetHapModuleInfo(benchmark::State &state) 68 { 69 BundleMgrClient client; 70 std::string bundleName = "ohos.global.systemres"; 71 std::string hapName = "ohos_global_systemres"; 72 HapModuleInfo hapModuleInfo; 73 Parcel parcel; 74 hapModuleInfo.Marshalling(parcel); 75 for (auto _ : state) { 76 /* @tc.steps: step1.call GetHapModuleInfo in loop */ 77 client.GetHapModuleInfo(bundleName, hapName, hapModuleInfo); 78 } 79 } 80 81 /** 82 * @tc.name: BenchmarkTestForGetResConfigFile1 83 * @tc.desc: Testcase for testing 'GetResConfigFile' function. 84 * @tc.type: FUNC 85 * @tc.require: Issue Number 86 */ BenchmarkTestForGetResConfigFile1(benchmark::State & state)87 static void BenchmarkTestForGetResConfigFile1(benchmark::State &state) 88 { 89 BundleMgrClient client; 90 HapModuleInfo hapModuleInfo; 91 Parcel parcel; 92 hapModuleInfo.Marshalling(parcel); 93 std::string metadataName = ""; 94 std::vector<std::string> profileInfos; 95 for (auto _ : state) { 96 /* @tc.steps: step1.call GetResConfigFile in loop */ 97 client.GetResConfigFile(hapModuleInfo, metadataName, profileInfos); 98 } 99 } 100 101 /** 102 * @tc.name: BenchmarkTestForGetResConfigFile2 103 * @tc.desc: Testcase for testing 'GetResConfigFile' function. 104 * @tc.type: FUNC 105 * @tc.require: Issue Number 106 */ BenchmarkTestForGetResConfigFile2(benchmark::State & state)107 static void BenchmarkTestForGetResConfigFile2(benchmark::State &state) 108 { 109 BundleMgrClient client; 110 ExtensionAbilityInfo extensionInfo; 111 Parcel parcel; 112 extensionInfo.Marshalling(parcel); 113 std::string metadataName = ""; 114 std::vector<std::string> profileInfos; 115 for (auto _ : state) { 116 /* @tc.steps: step1.call GetResConfigFile in loop */ 117 client.GetResConfigFile(extensionInfo, metadataName, profileInfos); 118 } 119 } 120 121 /** 122 * @tc.name: BenchmarkTestForGetResConfigFile3 123 * @tc.desc: Testcase for testing 'GetResConfigFile' function. 124 * @tc.type: FUNC 125 * @tc.require: Issue Number 126 */ BenchmarkTestForGetResConfigFile3(benchmark::State & state)127 static void BenchmarkTestForGetResConfigFile3(benchmark::State &state) 128 { 129 BundleMgrClient client; 130 AbilityInfo abilityInfo; 131 Parcel parcel; 132 abilityInfo.Marshalling(parcel); 133 std::string metadataName = ""; 134 std::vector<std::string> profileInfos; 135 for (auto _ : state) { 136 /* @tc.steps: step1.call GetResConfigFile in loop */ 137 client.GetResConfigFile(abilityInfo, metadataName, profileInfos); 138 } 139 } 140 141 /** 142 * @tc.name: BenchmarkTestForGetAccessibleAppCodePaths 143 * @tc.desc: Testcase for testing 'GetAccessibleAppCodePaths' function. 144 * @tc.type: FUNC 145 * @tc.require: Issue Number 146 */ BenchmarkTestForGetAccessibleAppCodePaths(benchmark::State & state)147 static void BenchmarkTestForGetAccessibleAppCodePaths(benchmark::State &state) 148 { 149 BundleMgrClient client; 150 int32_t userId = 100; 151 for (auto _ : state) { 152 /* @tc.steps: step1.call GetAccessibleAppCodePaths in loop */ 153 client.GetAccessibleAppCodePaths(userId); 154 } 155 } 156 157 BENCHMARK(BenchmarkTestForGetBundleNameForUid)->Iterations(1000); 158 BENCHMARK(BenchmarkTestForGetBundleInfo)->Iterations(1000); 159 BENCHMARK(BenchmarkTestForGetHapModuleInfo)->Iterations(1000); 160 BENCHMARK(BenchmarkTestForGetResConfigFile1)->Iterations(1000); 161 BENCHMARK(BenchmarkTestForGetResConfigFile2)->Iterations(1000); 162 BENCHMARK(BenchmarkTestForGetResConfigFile3)->Iterations(1000); 163 BENCHMARK(BenchmarkTestForGetAccessibleAppCodePaths)->Iterations(1000); 164 } 165 166 BENCHMARK_MAIN();