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 "application_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         ApplicationInfo info;
34         info.name = "com.ohos.contactsdataability";
35         info.bundleName = "com.ohos.contactsdataability";
36         info.versionName = "1.0";
37         info.iconPath = "$media:icon";
38         info.description = "dataability_description";
39         info.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability";
40         info.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability";
41         info.apiReleaseType = "Release";
42         info.deviceId = "PHONE-001";
43         info.entityType = "unsppecified";
44         info.vendor = "ohos";
45         info.nativeLibraryPath = "libs/arm";
46         Parcel parcel;
47         info.Marshalling(parcel);
48         for (auto _ : state) {
49             /* @tc.steps: step1.call ReadFromParcel in loop */
50             info.ReadFromParcel(parcel);
51         }
52     }
53 
54     /**
55      * @tc.name: BenchmarkTestForReadMetaDataFromParcel
56      * @tc.desc: Testcase for testing 'ReadMetaDataFromParcel' function.
57      * @tc.type: FUNC
58      * @tc.require: Issue Number
59      */
BenchmarkTestForReadMetaDataFromParcel(benchmark::State & state)60     static void BenchmarkTestForReadMetaDataFromParcel(benchmark::State &state)
61     {
62         ApplicationInfo info;
63         info.name = "com.ohos.contactsdataability";
64         info.bundleName = "com.ohos.contactsdataability";
65         info.versionName = "1.0";
66         info.iconPath = "$media:icon";
67         info.description = "dataability_description";
68         info.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability";
69         info.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability";
70         info.apiReleaseType = "Release";
71         info.deviceId = "PHONE-001";
72         info.entityType = "unsppecified";
73         info.vendor = "ohos";
74         info.nativeLibraryPath = "libs/arm";
75         Parcel parcel;
76         info.Marshalling(parcel);
77         for (auto _ : state) {
78             /* @tc.steps: step1.call ReadMetaDataFromParcel in loop */
79             info.ReadMetaDataFromParcel(parcel);
80         }
81     }
82 
83     /**
84      * @tc.name: BenchmarkTestForMarshalling
85      * @tc.desc: Testcase for testing 'Marshalling' function.
86      * @tc.type: FUNC
87      * @tc.require: Issue Number
88      */
BenchmarkTestForMarshalling(benchmark::State & state)89     static void BenchmarkTestForMarshalling(benchmark::State &state)
90     {
91         ApplicationInfo info;
92         info.name = "com.ohos.contactsdataability";
93         info.bundleName = "com.ohos.contactsdataability";
94         info.versionName = "1.0";
95         info.iconPath = "$media:icon";
96         info.description = "dataability_description";
97         info.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability";
98         info.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability";
99         info.apiReleaseType = "Release";
100         info.deviceId = "PHONE-001";
101         info.entityType = "unsppecified";
102         info.vendor = "ohos";
103         info.nativeLibraryPath = "libs/arm";
104         Parcel parcel;
105         for (auto _ : state) {
106             /* @tc.steps: step1.call Marshalling in loop */
107             info.Marshalling(parcel);
108         }
109     }
110 
111     /**
112      * @tc.name: BenchmarkTestForUnmarshalling
113      * @tc.desc: Testcase for testing 'Unmarshalling' function.
114      * @tc.type: FUNC
115      * @tc.require: Issue Number
116      */
BenchmarkTestForUnmarshalling(benchmark::State & state)117     static void BenchmarkTestForUnmarshalling(benchmark::State &state)
118     {
119         ApplicationInfo info;
120         info.name = "com.ohos.contactsdataability";
121         info.bundleName = "com.ohos.contactsdataability";
122         info.versionName = "1.0";
123         info.iconPath = "$media:icon";
124         info.description = "dataability_description";
125         info.codePath = "/data/app/el1/budle/public/com.ohos.contactsdataability";
126         info.dataBaseDir = "/data/app/el2/database/com.ohos.contactsdataability";
127         info.apiReleaseType = "Release";
128         info.deviceId = "PHONE-001";
129         info.entityType = "unsppecified";
130         info.vendor = "ohos";
131         info.nativeLibraryPath = "libs/arm";
132         Parcel parcel;
133         info.Marshalling(parcel);
134         for (auto _ : state) {
135             /* @tc.steps: step1.call Unmarshalling in loop */
136             info.Unmarshalling(parcel);
137         }
138     }
139 
140     BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000);
141     BENCHMARK(BenchmarkTestForReadMetaDataFromParcel)->Iterations(1000);
142     BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000);
143     BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000);
144 }
145 
146 BENCHMARK_MAIN();