• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <benchmark/benchmark.h>
17 #include <unistd.h>
18 #include <vector>
19 
20 #include "ability_manager_client.h"
21 
22 using namespace std;
23 using namespace OHOS;
24 using namespace OHOS::AAFwk;
25 
26 namespace {
27 class AbilityContextTest : public benchmark::Fixture {
28 public:
AbilityContextTest()29     AbilityContextTest()
30     {
31         Iterations(iterations);
32         Repetitions(repetitions);
33         ReportAggregatesOnly();
34     }
35 
36     ~AbilityContextTest() override = default;
37 
SetUp(const::benchmark::State & state)38     void SetUp(const ::benchmark::State &state) override
39     {
40         sleep(1);
41         AbilityManagerClient::GetInstance()->CleanAllMissions();
42         sleep(1);
43     }
44 
TearDown(const::benchmark::State & state)45     void TearDown(const ::benchmark::State &state) override
46     {
47     }
48 
49 protected:
50     const string deviceId;
51     const string bundleName = "ohos.samples.FormApplication";
52     const string abilityName = "ohos.samples.FormApplication.MainAbility";
53     const int32_t repetitions = 16;
54     const int32_t iterations = 1;
55 };
56 
57 // StartAbility
BENCHMARK_F(AbilityContextTest,StartAbilityTestCase)58 BENCHMARK_F(AbilityContextTest, StartAbilityTestCase)(
59     benchmark::State &state)
60 {
61     while (state.KeepRunning()) {
62         Want want;
63         want.SetElementName(deviceId, bundleName, abilityName);
64         ErrCode errCode = AbilityManagerClient::GetInstance()->StartAbility(want);
65         if (errCode != ERR_OK) {
66             state.SkipWithError("StartAbilityTestCase failed.");
67         }
68     }
69 }
70 }
71 
72 // Run the benchmark
73 BENCHMARK_MAIN();
74