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