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 "permission_define.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 PermissionDef info; 34 info.bundleName = "com.ohos.contactsdataability"; 35 info.description = "dataability_description"; 36 Parcel parcel; 37 info.Marshalling(parcel); 38 for (auto _ : state) { 39 /* @tc.steps: step1.call ReadFromParcel in loop */ 40 info.ReadFromParcel(parcel); 41 } 42 } 43 44 /** 45 * @tc.name: BenchmarkTestForMarshalling 46 * @tc.desc: Testcase for testing 'Marshalling' function. 47 * @tc.type: FUNC 48 * @tc.require: Issue Number 49 */ BenchmarkTestForMarshalling(benchmark::State & state)50 static void BenchmarkTestForMarshalling(benchmark::State &state) 51 { 52 PermissionDef info; 53 info.bundleName = "com.ohos.contactsdataability"; 54 info.description = "dataability_description"; 55 Parcel parcel; 56 for (auto _ : state) { 57 /* @tc.steps: step1.call Marshalling in loop */ 58 info.Marshalling(parcel); 59 } 60 } 61 62 /** 63 * @tc.name: BenchmarkTestForUnmarshalling 64 * @tc.desc: Testcase for testing 'Unmarshalling' function. 65 * @tc.type: FUNC 66 * @tc.require: Issue Number 67 */ BenchmarkTestForUnmarshalling(benchmark::State & state)68 static void BenchmarkTestForUnmarshalling(benchmark::State &state) 69 { 70 PermissionDef info; 71 info.bundleName = "com.ohos.contactsdataability"; 72 info.description = "dataability_description"; 73 Parcel parcel; 74 info.Marshalling(parcel); 75 for (auto _ : state) { 76 /* @tc.steps: step1.call Unmarshalling in loop */ 77 info.Unmarshalling(parcel); 78 } 79 } 80 81 BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000); 82 BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000); 83 BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000); 84 } 85 86 BENCHMARK_MAIN();