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 "ability_info.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: BenchmarkTestForReadFromParcel
27      * @tc.desc: Testcase for testing 'ReadFromParcel' function.
28      * @tc.type: FUNC
29      * @tc.require: Issue Number
30      */
BenchmarkTestForReadFromParcel(benchmark::State & state)31     static void BenchmarkTestForReadFromParcel(benchmark::State &state)
32     {
33         AbilityInfo info;
34         info.name = "allLogAbility";
35         info.description = "dataability_description";
36         info.iconPath = "$media:icon";
37         info.labelId = 0;
38         info.descriptionId = 0;
39         info.iconId = 0;
40         info.kind = "data";
41         info.deviceTypes = {"smartVision"};
42         info.uri = "dataability://com.ohos.callogability";
43         info.readPermission = "ohos.permission.READ_CALL_LOG";
44         info.writePermission = "ohos.permission.WRITE_CALL_LOG";
45         info.package = "com.ohos.contactsdataability";
46         info.bundleName = "com.ohos.contactsdataability";
47         info.moduleName = "entry";
48         info.applicationName = "com.ohos.contactsdataability";
49         info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\
50             "/com.ohos.contactsdataability/assets/entry/resources.index";
51         info.versionName = "1.0";
52         info.applicationInfo.name = "com.ohos.contactsdataability";
53         info.applicationInfo.description = "dataability_description";
54         info.applicationInfo.cpuAbi = "armeabi";
55         Parcel parcel;
56         info.Marshalling(parcel);
57         for (auto _ : state) {
58             /* @tc.steps: step1.call ReadFromParcel in loop */
59             info.ReadFromParcel(parcel);
60         }
61     }
62 
63     /**
64      * @tc.name: BenchmarkTestForMarshalling
65      * @tc.desc: Testcase for testing 'Marshalling' function.
66      * @tc.type: FUNC
67      * @tc.require: Issue Number
68      */
BenchmarkTestForMarshalling(benchmark::State & state)69     static void BenchmarkTestForMarshalling(benchmark::State &state)
70     {
71         AbilityInfo info;
72         info.name = "allLogAbility";
73         info.description = "dataability_description";
74         info.iconPath = "$media:icon";
75         info.labelId = 0;
76         info.descriptionId = 0;
77         info.iconId = 0;
78         info.kind = "data";
79         info.deviceTypes = {"smartVision"};
80         info.uri = "dataability://com.ohos.callogability";
81         info.readPermission = "ohos.permission.READ_CALL_LOG";
82         info.writePermission = "ohos.permission.WRITE_CALL_LOG";
83         info.package = "com.ohos.contactsdataability";
84         info.bundleName = "com.ohos.contactsdataability";
85         info.moduleName = "entry";
86         info.applicationName = "com.ohos.contactsdataability";
87         info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\
88             "/com.ohos.contactsdataability/assets/entry/resources.index";
89         info.versionName = "1.0";
90         info.applicationInfo.name = "com.ohos.contactsdataability";
91         info.applicationInfo.description = "dataability_description";
92         info.applicationInfo.cpuAbi = "armeabi";
93         Parcel parcel;
94         for (auto _ : state) {
95             /* @tc.steps: step1.call Marshalling in loop */
96             info.Marshalling(parcel);
97         }
98     }
99 
100     /**
101      * @tc.name: BenchmarkTestForUnmarshalling
102      * @tc.desc: Testcase for testing 'Unmarshalling' function.
103      * @tc.type: FUNC
104      * @tc.require: Issue Number
105      */
BenchmarkTestForUnmarshalling(benchmark::State & state)106     static void BenchmarkTestForUnmarshalling(benchmark::State &state)
107     {
108         AbilityInfo info;
109         info.name = "allLogAbility";
110         info.description = "dataability_description";
111         info.iconPath = "$media:icon";
112         info.labelId = 0;
113         info.descriptionId = 0;
114         info.iconId = 0;
115         info.kind = "data";
116         info.deviceTypes = {"smartVision"};
117         info.uri = "dataability://com.ohos.callogability";
118         info.readPermission = "ohos.permission.READ_CALL_LOG";
119         info.writePermission = "ohos.permission.WRITE_CALL_LOG";
120         info.package = "com.ohos.contactsdataability";
121         info.bundleName = "com.ohos.contactsdataability";
122         info.moduleName = "entry";
123         info.applicationName = "com.ohos.contactsdataability";
124         info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\
125             "/com.ohos.contactsdataability/assets/entry/resources.index";
126         info.versionName = "1.0";
127         info.applicationInfo.name = "com.ohos.contactsdataability";
128         info.applicationInfo.description = "dataability_description";
129         info.applicationInfo.cpuAbi = "armeabi";
130         Parcel parcel;
131         info.Marshalling(parcel);
132         for (auto _ : state) {
133             /* @tc.steps: step1.call Unmarshalling in loop */
134             info.Unmarshalling(parcel);
135         }
136     }
137 
138     BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000);
139     BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000);
140     BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000);
141 }
142 
143 BENCHMARK_MAIN();