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 "hap_module_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 HapModuleInfo info; 34 info.name = "com.ohos.contactsdataability"; 35 info.moduleName = "entry"; 36 info.description = "dataability_description"; 37 info.iconPath = "$media:icon"; 38 info.deviceTypes = {"smartVision"}; 39 info.bundleName = "com.ohos.contactsdataability"; 40 info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\ 41 "/com.ohos.contactsdataability/assets/entry/resources.index"; 42 Parcel parcel; 43 info.Marshalling(parcel); 44 for (auto _ : state) { 45 /* @tc.steps: step1.call ReadFromParcel in loop */ 46 info.ReadFromParcel(parcel); 47 } 48 } 49 50 /** 51 * @tc.name: BenchmarkTestForMarshalling 52 * @tc.desc: Testcase for testing 'Marshalling' function. 53 * @tc.type: FUNC 54 * @tc.require: Issue Number 55 */ BenchmarkTestForMarshalling(benchmark::State & state)56 static void BenchmarkTestForMarshalling(benchmark::State &state) 57 { 58 HapModuleInfo info; 59 info.name = "com.ohos.contactsdataability"; 60 info.moduleName = "entry"; 61 info.description = "dataability_description"; 62 info.iconPath = "$media:icon"; 63 info.deviceTypes = {"smartVision"}; 64 info.bundleName = "com.ohos.contactsdataability"; 65 info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\ 66 "/com.ohos.contactsdataability/assets/entry/resources.index"; 67 Parcel parcel; 68 for (auto _ : state) { 69 /* @tc.steps: step1.call Marshalling in loop */ 70 info.Marshalling(parcel); 71 } 72 } 73 74 /** 75 * @tc.name: BenchmarkTestForUnmarshalling 76 * @tc.desc: Testcase for testing 'Unmarshalling' function. 77 * @tc.type: FUNC 78 * @tc.require: Issue Number 79 */ BenchmarkTestForUnmarshalling(benchmark::State & state)80 static void BenchmarkTestForUnmarshalling(benchmark::State &state) 81 { 82 HapModuleInfo info; 83 info.name = "com.ohos.contactsdataability"; 84 info.moduleName = "entry"; 85 info.description = "dataability_description"; 86 info.iconPath = "$media:icon"; 87 info.deviceTypes = {"smartVision"}; 88 info.bundleName = "com.ohos.contactsdataability"; 89 info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\ 90 "/com.ohos.contactsdataability/assets/entry/resources.index"; 91 Parcel parcel; 92 info.Marshalling(parcel); 93 for (auto _ : state) { 94 /* @tc.steps: step1.call Unmarshalling in loop */ 95 info.Unmarshalling(parcel); 96 } 97 } 98 99 BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000); 100 BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000); 101 BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000); 102 } 103 104 BENCHMARK_MAIN();