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     /**
27      * @tc.name: BenchmarkTestForGetBundleInfo
28      * @tc.desc: Testcase for testing 'GetBundleInfo' function.
29      * @tc.type: FUNC
30      * @tc.require: Issue Number
31      */
BenchmarkTestForGetBundleInfo(benchmark::State & state)32     static void BenchmarkTestForGetBundleInfo(benchmark::State &state)
33     {
34         BundleMgrClient client;
35         std::string bundleName = "ohos.global.systemres";
36         BundleInfo bundleInfo;
37         Parcel parcel;
38         bundleInfo.Marshalling(parcel);
39         for (auto _ : state) {
40             /* @tc.steps: step1.call GetBundleInfo in loop */
41             client.GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo);
42         }
43     }
44 
45     /**
46      * @tc.name: BenchmarkTestForGetHapModuleInfo
47      * @tc.desc: Testcase for testing 'GetHapModuleInfo' function.
48      * @tc.type: FUNC
49      * @tc.require: Issue Number
50      */
BenchmarkTestForGetHapModuleInfo(benchmark::State & state)51     static void BenchmarkTestForGetHapModuleInfo(benchmark::State &state)
52     {
53         BundleMgrClient client;
54         std::string bundleName = "ohos.global.systemres";
55         std::string hapName = "ohos_global_systemres";
56         HapModuleInfo hapModuleInfo;
57         Parcel parcel;
58         hapModuleInfo.Marshalling(parcel);
59         for (auto _ : state) {
60             /* @tc.steps: step1.call GetHapModuleInfo in loop */
61             client.GetHapModuleInfo(bundleName, hapName, hapModuleInfo);
62         }
63     }
64 
65     /**
66      * @tc.name: BenchmarkTestForGetResConfigFile1
67      * @tc.desc: Testcase for testing 'GetResConfigFile' function.
68      * @tc.type: FUNC
69      * @tc.require: Issue Number
70      */
BenchmarkTestForGetResConfigFile1(benchmark::State & state)71     static void BenchmarkTestForGetResConfigFile1(benchmark::State &state)
72     {
73         BundleMgrClient client;
74         HapModuleInfo hapModuleInfo;
75         Parcel parcel;
76         hapModuleInfo.Marshalling(parcel);
77         std::string metadataName = "";
78         std::vector<std::string> profileInfos;
79         for (auto _ : state) {
80             /* @tc.steps: step1.call GetResConfigFile in loop */
81             client.GetResConfigFile(hapModuleInfo, metadataName, profileInfos);
82         }
83     }
84 
85     /**
86      * @tc.name: BenchmarkTestForGetResConfigFile2
87      * @tc.desc: Testcase for testing 'GetResConfigFile' function.
88      * @tc.type: FUNC
89      * @tc.require: Issue Number
90      */
BenchmarkTestForGetResConfigFile2(benchmark::State & state)91     static void BenchmarkTestForGetResConfigFile2(benchmark::State &state)
92     {
93         BundleMgrClient client;
94         ExtensionAbilityInfo extensionInfo;
95         Parcel parcel;
96         extensionInfo.Marshalling(parcel);
97         std::string metadataName = "";
98         std::vector<std::string> profileInfos;
99         for (auto _ : state) {
100             /* @tc.steps: step1.call GetResConfigFile in loop */
101             client.GetResConfigFile(extensionInfo, metadataName, profileInfos);
102         }
103     }
104 
105     /**
106      * @tc.name: BenchmarkTestForGetResConfigFile3
107      * @tc.desc: Testcase for testing 'GetResConfigFile' function.
108      * @tc.type: FUNC
109      * @tc.require: Issue Number
110      */
BenchmarkTestForGetResConfigFile3(benchmark::State & state)111     static void BenchmarkTestForGetResConfigFile3(benchmark::State &state)
112     {
113         BundleMgrClient client;
114         AbilityInfo abilityInfo;
115         Parcel parcel;
116         abilityInfo.Marshalling(parcel);
117         std::string metadataName = "";
118         std::vector<std::string> profileInfos;
119         for (auto _ : state) {
120             /* @tc.steps: step1.call GetResConfigFile in loop */
121             client.GetResConfigFile(abilityInfo, metadataName, profileInfos);
122         }
123     }
124 
125     BENCHMARK(BenchmarkTestForGetBundleInfo)->Iterations(1000);
126     BENCHMARK(BenchmarkTestForGetHapModuleInfo)->Iterations(1000);
127     BENCHMARK(BenchmarkTestForGetResConfigFile1)->Iterations(1000);
128     BENCHMARK(BenchmarkTestForGetResConfigFile2)->Iterations(1000);
129     BENCHMARK(BenchmarkTestForGetResConfigFile3)->Iterations(1000);
130 }
131 
132 BENCHMARK_MAIN();