• 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 #include <benchmark/benchmark.h>
16 #include "open_camera_test.h"
17 #include "camera_preview_test.h"
18 #include <string>
19 #include <vector>
20 
21 using namespace OHOS;
22 using namespace std;
23 using namespace testing::ext;
24 using namespace OHOS::Camera;
25 
26 class wlanBenchmarkTest : public benchmark::Fixture {
27 public:
28     void SetUp(const ::benchmark::State &state);
29     void TearDown(const ::benchmark::State &state);
30 };
31 
32 class CameraBenchmarkTest :  public benchmark::Fixture {
33 public:
34     void SetUp(const ::benchmark::State &state);
35     void TearDown(const ::benchmark::State &state);
36     std::shared_ptr<TestDisplay> display_ = nullptr;
37 };
38 
SetUp(const::benchmark::State & state)39 void CameraBenchmarkTest::SetUp(const ::benchmark::State &state)
40 {
41     std::cout << "==========[test log] CameraBenchmarkTest::SetUp.display_0: "<<display_<< std::endl;
42     if (display_ == nullptr) {
43         std::cout << "==========[test log] CameraBenchmarkTest::SetUp.display_1: "<<display_<< std::endl;
44         display_ = std::make_shared<TestDisplay>();
45         std::cout << "==========[test log] CameraBenchmarkTest::SetUp.display_2: "<<display_<< std::endl;
46         std::cout << "==========[test log] CameraBenchmarkTest::SetUp.display_3: "<<display_<< std::endl;
47         display_->Init();
48         std::cout << "==========[test log] CameraBenchmarkTest::SetUp.display_4: "<<display_<< std::endl;
49     }
50 }
TearDown(const::benchmark::State & state)51 void CameraBenchmarkTest::TearDown(const ::benchmark::State &state)
52 {
53     display_->Close();
54 }
55 
56 /**
57   * @tc.name: OpenCamera
58   * @tc.desc: OpenCamera, benchmark.
59   * @tc.level: Level0
60   * @tc.size: MediumTest
61   * @tc.type: Function
62   */
BENCHMARK_F(CameraBenchmarkTest,SUB_OpenCamera_benchmark_0010)63 BENCHMARK_F(CameraBenchmarkTest, SUB_OpenCamera_benchmark_0010)(
64     benchmark::State &st)
65 {
66    // std::cout << "==========[test log] OpenCamera, success."<< std::endl;
67     std::vector<std::string> cameraIds;
68     display_->cameraHost->GetCameraIds(cameraIds);
69     for (auto &cameraId : cameraIds) {
70      //   std::cout << "cameraId = " << cameraId << std::endl;
71     }
72     std::string cameraId = cameraIds.front();
73     const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
74     OHOS::sptr<ICameraDevice> cameraDevice;
75     for (auto _ : st) {
76     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, cameraDevice);
77     }
78     //EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
79 }
80 BENCHMARK_REGISTER_F(CameraBenchmarkTest, SUB_OpenCamera_benchmark_0010)->Iterations(100)->
81     Repetitions(3)->ReportAggregatesOnly();
82 
83 /**
84   * @tc.name: GetCameraIds
85   * @tc.desc: GetCameraIds, benchmark.
86   * @tc.level: Level0
87   * @tc.size: MediumTest
88   * @tc.type: Function
89   */
BENCHMARK_F(CameraBenchmarkTest,SUB_GetCameraIds_benchmark_0010)90 BENCHMARK_F(CameraBenchmarkTest, SUB_GetCameraIds_benchmark_0010)(
91     benchmark::State &st)
92 {
93     //std::cout << "==========[test log] GetCameraIds, success."<< std::endl;
94     std::vector<std::string> cameraIds;
95     for (auto _ : st) {
96     display_->cameraHost->GetCameraIds(cameraIds);
97     }
98 }
99 BENCHMARK_REGISTER_F(CameraBenchmarkTest, SUB_GetCameraIds_benchmark_0010)->Iterations(100)->
100     Repetitions(3)->ReportAggregatesOnly();
101 /**
102   * @tc.name: GetStreamOperator
103   * @tc.desc: GetStreamOperator, benchmark.
104   * @tc.level: Level0
105   * @tc.size: MediumTest
106   * @tc.type: Function
107   */
BENCHMARK_F(CameraBenchmarkTest,SUB_GetStreamOperator_benchmark_0010)108 BENCHMARK_F(CameraBenchmarkTest, SUB_GetStreamOperator_benchmark_0010)(
109     benchmark::State &st)
110 {
111     //std::cout << "==========[test log] GetStreamOperator, input nullptr." << std::endl;
112     // Get the configured cameraId
113     display_->cameraHost->GetCameraIds(display_->cameraIds);
114     std::cout << "cameraIds.front() = " << display_->cameraIds.front() << std::endl;
115     // Open the camera device and get the device
116     const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
117     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(display_->cameraIds.front(),
118         callback, display_->cameraDevice);
119    // std::cout << "OpenCamera's RetCode = " << display_->rc << std::endl;
120     EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
121     // Create and get streamOperator information
122     OHOS::sptr<IStreamOperatorCallback> streamOperatorCallback = new DemoStreamOperatorCallback();
123     for (auto _ : st) {
124     display_->rc = (CamRetCode)display_->cameraDevice->GetStreamOperator(streamOperatorCallback,
125         display_->streamOperator);
126     }
127    // std::cout << "GetStreamOperator's RetCode = " << display_->rc << std::endl;
128    // EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, display_->rc);
129 }
130 BENCHMARK_REGISTER_F(CameraBenchmarkTest, SUB_GetStreamOperator_benchmark_0010)->Iterations(100)->
131     Repetitions(3)->ReportAggregatesOnly();
132 
133 BENCHMARK_MAIN();
134