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 "form_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 FormInfo info; 34 info.package = "com.ohos.contactsdataability"; 35 info.bundleName = "com.ohos.contactsdataability"; 36 info.moduleName = "entry"; 37 info.name = "com.ohos.contactsdataability"; 38 info.description = "dataability_description"; 39 Parcel parcel; 40 info.Marshalling(parcel); 41 for (auto _ : state) { 42 /* @tc.steps: step1.call ReadFromParcel in loop */ 43 info.ReadFromParcel(parcel); 44 } 45 } 46 47 /** 48 * @tc.name: BenchmarkTestForMarshalling 49 * @tc.desc: Testcase for testing 'Marshalling' function. 50 * @tc.type: FUNC 51 * @tc.require: Issue Number 52 */ BenchmarkTestForMarshalling(benchmark::State & state)53 static void BenchmarkTestForMarshalling(benchmark::State &state) 54 { 55 FormInfo info; 56 info.package = "com.ohos.contactsdataability"; 57 info.bundleName = "com.ohos.contactsdataability"; 58 info.moduleName = "entry"; 59 info.name = "com.ohos.contactsdataability"; 60 info.description = "dataability_description"; 61 Parcel parcel; 62 for (auto _ : state) { 63 /* @tc.steps: step1.call Marshalling in loop */ 64 info.Marshalling(parcel); 65 } 66 } 67 68 /** 69 * @tc.name: BenchmarkTestForUnmarshalling 70 * @tc.desc: Testcase for testing 'Unmarshalling' function. 71 * @tc.type: FUNC 72 * @tc.require: Issue Number 73 */ BenchmarkTestForUnmarshalling(benchmark::State & state)74 static void BenchmarkTestForUnmarshalling(benchmark::State &state) 75 { 76 FormInfo info; 77 info.package = "com.ohos.contactsdataability"; 78 info.bundleName = "com.ohos.contactsdataability"; 79 info.moduleName = "entry"; 80 info.name = "com.ohos.contactsdataability"; 81 info.description = "dataability_description"; 82 Parcel parcel; 83 info.Marshalling(parcel); 84 for (auto _ : state) { 85 /* @tc.steps: step1.call Unmarshalling in loop */ 86 info.Unmarshalling(parcel); 87 } 88 } 89 90 /** 91 * @tc.name: BenchmarkTestForIsValid 92 * @tc.desc: Testcase for testing 'IsValid' function. 93 * @tc.type: FUNC 94 * @tc.require: Issue Number 95 */ BenchmarkTestForIsValid(benchmark::State & state)96 static void BenchmarkTestForIsValid(benchmark::State &state) 97 { 98 FormInfo info; 99 info.package = "com.ohos.contactsdataability"; 100 info.bundleName = "com.ohos.contactsdataability"; 101 info.moduleName = "entry"; 102 info.name = "com.ohos.contactsdataability"; 103 info.description = "dataability_description"; 104 for (auto _ : state) { 105 /* @tc.steps: step1.call IsValid in loop */ 106 info.IsValid(); 107 } 108 } 109 110 BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000); 111 BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000); 112 BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000); 113 BENCHMARK(BenchmarkTestForIsValid)->Iterations(1000); 114 } 115 116 BENCHMARK_MAIN();