1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file expected in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#include "stability_test.h"
17094332d3Sopenharmony_ci
18094332d3Sopenharmony_ciusing namespace OHOS;
19094332d3Sopenharmony_ciusing namespace std;
20094332d3Sopenharmony_ciusing namespace testing::ext;
21094332d3Sopenharmony_ciusing namespace OHOS::Camera;
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_civoid StabilityTest::SetUpTestCase(void) {}
24094332d3Sopenharmony_civoid StabilityTest::TearDownTestCase(void) {}
25094332d3Sopenharmony_civoid StabilityTest::SetUp(void)
26094332d3Sopenharmony_ci{
27094332d3Sopenharmony_ci    Test_ = std::make_shared<OHOS::Camera::Test>();
28094332d3Sopenharmony_ci    Test_->Init();
29094332d3Sopenharmony_ci}
30094332d3Sopenharmony_civoid StabilityTest::TearDown(void)
31094332d3Sopenharmony_ci{
32094332d3Sopenharmony_ci    Test_->Close();
33094332d3Sopenharmony_ci}
34094332d3Sopenharmony_ci
35094332d3Sopenharmony_ci/**
36094332d3Sopenharmony_ci  * @tc.name: OpenCamera
37094332d3Sopenharmony_ci  * @tc.desc: OpenCamera, 100 times.
38094332d3Sopenharmony_ci  * @tc.size: MediumTest
39094332d3Sopenharmony_ci  * @tc.type: Function
40094332d3Sopenharmony_ci  */
41094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Open_0001, TestSize.Level3)
42094332d3Sopenharmony_ci{
43094332d3Sopenharmony_ci    if (Test_->cameraDevice == nullptr) {
44094332d3Sopenharmony_ci        std::cout << "==========[test log] Check Performance: OpenCamera, 100 times."<< std::endl;
45094332d3Sopenharmony_ci        std::vector<int> FailTimes;
46094332d3Sopenharmony_ci        Test_->service->GetCameraIds(Test_->cameraIds);
47094332d3Sopenharmony_ci        Test_->CreateDeviceCallback();
48094332d3Sopenharmony_ci        for (int i = 0; i < 100; i++) {
49094332d3Sopenharmony_ci            std::cout << "Running " << i << " time" << std::endl;
50094332d3Sopenharmony_ci            Test_->rc =
51094332d3Sopenharmony_ci                Test_->service->OpenCamera(Test_->cameraIds.front(), Test_->deviceCallback, Test_->cameraDevice);
52094332d3Sopenharmony_ci            EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
53094332d3Sopenharmony_ci            EXPECT_EQ(true, Test_->cameraDevice != nullptr);
54094332d3Sopenharmony_ci            if (Test_->rc != Camera::NO_ERROR) {
55094332d3Sopenharmony_ci                FailTimes.push_back(i);
56094332d3Sopenharmony_ci            }
57094332d3Sopenharmony_ci        }
58094332d3Sopenharmony_ci        std::cout << "Total fail times: "<< FailTimes.size() << ", at :" << std::endl;
59094332d3Sopenharmony_ci        for (auto it = FailTimes.begin(); it != FailTimes.end(); ++it) {
60094332d3Sopenharmony_ci            std::cout << *it << std::endl;
61094332d3Sopenharmony_ci        }
62094332d3Sopenharmony_ci    }
63094332d3Sopenharmony_ci}
64094332d3Sopenharmony_ci
65094332d3Sopenharmony_ci/**
66094332d3Sopenharmony_ci  * @tc.name: Preview
67094332d3Sopenharmony_ci  * @tc.desc: Preview for 100 times.
68094332d3Sopenharmony_ci  * @tc.size: MediumTest
69094332d3Sopenharmony_ci  * @tc.type: Function
70094332d3Sopenharmony_ci  */
71094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Preview_0001, TestSize.Level3)
72094332d3Sopenharmony_ci{
73094332d3Sopenharmony_ci    std::cout << "==========[test log] Check Performance: Preview for 100 times." << std::endl;
74094332d3Sopenharmony_ci    for (int i = 1; i < 101; i++) {
75094332d3Sopenharmony_ci        std::cout << "Running " << i << " time" << std::endl;
76094332d3Sopenharmony_ci        std::cout << "==========[test log] Check Performance: Preview: " << i << " times. " << std::endl;
77094332d3Sopenharmony_ci        // Turn on the camera
78094332d3Sopenharmony_ci        Test_->Open();
79094332d3Sopenharmony_ci        // Configure two streams of information
80094332d3Sopenharmony_ci        Test_->intents = {Camera::PREVIEW};
81094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
82094332d3Sopenharmony_ci        // Capture preview stream
83094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
84094332d3Sopenharmony_ci        // post-processing
85094332d3Sopenharmony_ci        Test_->captureIds = {Test_->captureId_preview};
86094332d3Sopenharmony_ci        Test_->streamIds = {Test_->streamId_preview};
87094332d3Sopenharmony_ci        Test_->StopStream(Test_->captureIds, Test_->streamIds);
88094332d3Sopenharmony_ci        Test_->StopConsumer(Test_->intents);
89094332d3Sopenharmony_ci    }
90094332d3Sopenharmony_ci    Test_->Close();
91094332d3Sopenharmony_ci}
92094332d3Sopenharmony_ci
93094332d3Sopenharmony_ci/**
94094332d3Sopenharmony_ci  * @tc.name: preview and capture stream, for 100 times.
95094332d3Sopenharmony_ci  * @tc.desc: Commit 2 streams together, Preview and still_capture streams, for 100 times.
96094332d3Sopenharmony_ci  * @tc.size: MediumTest
97094332d3Sopenharmony_ci  * @tc.type: Function
98094332d3Sopenharmony_ci  */
99094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Capture_0001, TestSize.Level3)
100094332d3Sopenharmony_ci{
101094332d3Sopenharmony_ci    std::cout << "==========[test log] Commit 2 streams together, Preview and still_capture streams,";
102094332d3Sopenharmony_ci    std::cout << " for 100 times." << std::endl;
103094332d3Sopenharmony_ci    // Turn on the camera
104094332d3Sopenharmony_ci    Test_->Open();
105094332d3Sopenharmony_ci    for (int i = 1; i < 101; i++) {
106094332d3Sopenharmony_ci        std::cout << "Running " << i << " time" << std::endl;
107094332d3Sopenharmony_ci        // Configure two streams of information
108094332d3Sopenharmony_ci        Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
109094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
110094332d3Sopenharmony_ci        // Capture preview stream
111094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
112094332d3Sopenharmony_ci        // Circulate the camera stream to capture 100 times
113094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, false);
114094332d3Sopenharmony_ci        // post-processing
115094332d3Sopenharmony_ci        Test_->captureIds = {Test_->captureId_preview};
116094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_preview);
117094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_capture);
118094332d3Sopenharmony_ci        Test_->StopStream(Test_->captureIds, Test_->streamIds);
119094332d3Sopenharmony_ci        Test_->StopConsumer(Test_->intents);
120094332d3Sopenharmony_ci    }
121094332d3Sopenharmony_ci    Test_->Close();
122094332d3Sopenharmony_ci}
123094332d3Sopenharmony_ci
124094332d3Sopenharmony_ci/**
125094332d3Sopenharmony_ci  * @tc.name: preview and capture
126094332d3Sopenharmony_ci  * @tc.desc: Dynamic capture start&stop, Preview and still_capture streams.
127094332d3Sopenharmony_ci  * @tc.size: MediumTest
128094332d3Sopenharmony_ci  * @tc.type: Function
129094332d3Sopenharmony_ci  */
130094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Capture_0002, TestSize.Level3)
131094332d3Sopenharmony_ci{
132094332d3Sopenharmony_ci    std::cout << "==========[test log] Dynamic capture start&stop, ";
133094332d3Sopenharmony_ci    std::cout << "Preview and still_capture streams for 100 times." << std::endl;
134094332d3Sopenharmony_ci    // Turn on the camera
135094332d3Sopenharmony_ci    Test_->Open();
136094332d3Sopenharmony_ci    for (int i = 1; i < 101; i++) {
137094332d3Sopenharmony_ci        std::cout << "Running " << i << " time" << std::endl;
138094332d3Sopenharmony_ci        // start preview stream
139094332d3Sopenharmony_ci        Test_->intents = {Camera::PREVIEW};
140094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
141094332d3Sopenharmony_ci        // Get preview
142094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
143094332d3Sopenharmony_ci        // start stream
144094332d3Sopenharmony_ci        Test_->intents = {Camera::STILL_CAPTURE};
145094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
146094332d3Sopenharmony_ci        // Start capture
147094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
148094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
149094332d3Sopenharmony_ci        // release stream
150094332d3Sopenharmony_ci        Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
151094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_preview);
152094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_capture);
153094332d3Sopenharmony_ci        Test_->StopStream(Test_->captureIds, Test_->streamIds);
154094332d3Sopenharmony_ci        Test_->StopConsumer({Camera::PREVIEW, Camera::STILL_CAPTURE});
155094332d3Sopenharmony_ci    }
156094332d3Sopenharmony_ci    Test_->Close();
157094332d3Sopenharmony_ci}
158094332d3Sopenharmony_ci
159094332d3Sopenharmony_ci/**
160094332d3Sopenharmony_ci  * @tc.name: Preview + Video stream, for 100 times.
161094332d3Sopenharmony_ci  * @tc.desc: Preview + video, commit together, for 100 times.
162094332d3Sopenharmony_ci  * @tc.size: MediumTest
163094332d3Sopenharmony_ci  * @tc.type: Function
164094332d3Sopenharmony_ci  */
165094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Video_0001, TestSize.Level3)
166094332d3Sopenharmony_ci{
167094332d3Sopenharmony_ci    std::cout << "==========[test log] Performance: Preview + video, commit together, 100 times." << std::endl;
168094332d3Sopenharmony_ci    // Turn on the camera
169094332d3Sopenharmony_ci    Test_->Open();
170094332d3Sopenharmony_ci    for (int i = 1; i < 101; i++) {
171094332d3Sopenharmony_ci        std::cout << "Running " << i << " time" << std::endl;
172094332d3Sopenharmony_ci        std::cout << "==========[test log] Performance: Preview + video, commit together, success." << std::endl;
173094332d3Sopenharmony_ci        // Configure two streams of information
174094332d3Sopenharmony_ci        Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
175094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
176094332d3Sopenharmony_ci        // Capture preview stream
177094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
178094332d3Sopenharmony_ci        // Capture video stream
179094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
180094332d3Sopenharmony_ci        // post-processing
181094332d3Sopenharmony_ci        Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
182094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_preview);
183094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_video);
184094332d3Sopenharmony_ci        Test_->StopStream(Test_->captureIds, Test_->streamIds);
185094332d3Sopenharmony_ci        Test_->StopConsumer(Test_->intents);
186094332d3Sopenharmony_ci    }
187094332d3Sopenharmony_ci    Test_->Close();
188094332d3Sopenharmony_ci}
189094332d3Sopenharmony_ci
190094332d3Sopenharmony_ci/**
191094332d3Sopenharmony_ci  * @tc.name: Video
192094332d3Sopenharmony_ci  * @tc.desc: Dynamic Video start&stop, for 100 times, success.
193094332d3Sopenharmony_ci  * @tc.size: MediumTest
194094332d3Sopenharmony_ci  * @tc.type: Function
195094332d3Sopenharmony_ci  */
196094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Video_0002, TestSize.Level3)
197094332d3Sopenharmony_ci{
198094332d3Sopenharmony_ci    std::cout << "==========[test log]Check video: Dynamic Video start&stop, for 100 times, success." << std::endl;
199094332d3Sopenharmony_ci    for (int i = 0; i < 100; i++) {
200094332d3Sopenharmony_ci        // Turn on the camera
201094332d3Sopenharmony_ci        Test_->Open();
202094332d3Sopenharmony_ci        std::cout << "Running " << i << " time" << std::endl;
203094332d3Sopenharmony_ci        // start preview stream
204094332d3Sopenharmony_ci        Test_->intents = {Camera::PREVIEW};
205094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
206094332d3Sopenharmony_ci        // Get preview
207094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
208094332d3Sopenharmony_ci        // start stream
209094332d3Sopenharmony_ci        Test_->intents = {Camera::VIDEO};
210094332d3Sopenharmony_ci        Test_->StartStream(Test_->intents);
211094332d3Sopenharmony_ci        Test_->StopConsumer(Test_->intents);
212094332d3Sopenharmony_ci        // Start capture
213094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
214094332d3Sopenharmony_ci        Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
215094332d3Sopenharmony_ci        // release stream
216094332d3Sopenharmony_ci        Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
217094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_preview);
218094332d3Sopenharmony_ci        Test_->streamIds.push_back(Test_->streamId_video);
219094332d3Sopenharmony_ci        Test_->intents = {Camera::PREVIEW};
220094332d3Sopenharmony_ci        Test_->StopStream(Test_->captureIds, Test_->streamIds);
221094332d3Sopenharmony_ci        Test_->StopConsumer(Test_->intents);
222094332d3Sopenharmony_ci        Test_->Close();
223094332d3Sopenharmony_ci    }
224094332d3Sopenharmony_ci}
225094332d3Sopenharmony_ci
226094332d3Sopenharmony_ci/**
227094332d3Sopenharmony_ci  * @tc.name: set 3A 100 times
228094332d3Sopenharmony_ci  * @tc.desc: set 3A 100 times, check result.
229094332d3Sopenharmony_ci  * @tc.size: MediumTest
230094332d3Sopenharmony_ci  * @tc.type: Function
231094332d3Sopenharmony_ci  */
232094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_3a_0001, TestSize.Level3)
233094332d3Sopenharmony_ci{
234094332d3Sopenharmony_ci    std::cout << "==========[test log] Check Performance: Set 3A 100 times, check result." << std::endl;
235094332d3Sopenharmony_ci    Test_->Open();
236094332d3Sopenharmony_ci    // Issue 3A parameters
237094332d3Sopenharmony_ci    std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
238094332d3Sopenharmony_ci    std::vector<uint8_t> awbMode = {
239094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_OFF,
240094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_AUTO,
241094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_INCANDESCENT,
242094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_FLUORESCENT,
243094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_WARM_FLUORESCENT,
244094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_DAYLIGHT,
245094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_CLOUDY_DAYLIGHT,
246094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_TWILIGHT,
247094332d3Sopenharmony_ci        OHOS_CAMERA_AWB_MODE_SHADE
248094332d3Sopenharmony_ci    };
249094332d3Sopenharmony_ci    for (int round = 0; round < 10; round++) {
250094332d3Sopenharmony_ci        for (int i = 0; i < awbMode.size(); i++) {
251094332d3Sopenharmony_ci            int times = (round * 10) + i + 1;
252094332d3Sopenharmony_ci            std::cout << "==========[test log] Check Performance: Set 3A Times: " << times << std::endl;
253094332d3Sopenharmony_ci            meta->addEntry(OHOS_CONTROL_AWB_MODE, &awbMode.at(i), 1);
254094332d3Sopenharmony_ci            std::cout << "==========[test log] UpdateSettings, awb mode :" << awbMode.at(i) << std::endl;
255094332d3Sopenharmony_ci            Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
256094332d3Sopenharmony_ci            if (Test_->rc == Camera::NO_ERROR) {
257094332d3Sopenharmony_ci                std::cout << "==========[test log] Check Performance: UpdateSettings success." << std::endl;
258094332d3Sopenharmony_ci            } else {
259094332d3Sopenharmony_ci                std::cout << "==========[test log] Check Performance: UpdateSettings fail, , at the " << (i+1);
260094332d3Sopenharmony_ci                std::cout <<"times, RetCode is " << Test_->rc << std::endl;
261094332d3Sopenharmony_ci            }
262094332d3Sopenharmony_ci            sleep(1);
263094332d3Sopenharmony_ci        }
264094332d3Sopenharmony_ci    }
265094332d3Sopenharmony_ci    Test_->Close();
266094332d3Sopenharmony_ci}
267094332d3Sopenharmony_ci
268094332d3Sopenharmony_ci/**
269094332d3Sopenharmony_ci  * @tc.name: flashlight
270094332d3Sopenharmony_ci  * @tc.desc: Turn on and off the flashlight, for 1000 times.
271094332d3Sopenharmony_ci  * @tc.size: MediumTest
272094332d3Sopenharmony_ci  * @tc.type: Function
273094332d3Sopenharmony_ci  */
274094332d3Sopenharmony_ciHWTEST_F(StabilityTest, Camera_Stability_Flashlight_0001, TestSize.Level3)
275094332d3Sopenharmony_ci{
276094332d3Sopenharmony_ci    std::cout << "==========[test log]Performance: Turn on and off the flashlight, 1000 times." << std::endl;
277094332d3Sopenharmony_ci    Test_->GetCameraAbility();
278094332d3Sopenharmony_ci    // Cycle to turn on and off the flashlight
279094332d3Sopenharmony_ci    for (int i = 0; i < 1000; i++) {
280094332d3Sopenharmony_ci        std::cout <<"times: " << i << std::endl;
281094332d3Sopenharmony_ci        bool status = true;
282094332d3Sopenharmony_ci        Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), status);
283094332d3Sopenharmony_ci        if (Test_->rc != Camera::NO_ERROR) {
284094332d3Sopenharmony_ci            std::cout << "==========[test log] Check Performance: Flashlight turn on fail, at the " << (i+1);
285094332d3Sopenharmony_ci            std::cout <<"times, RetCode is " << Test_->rc << std::endl;
286094332d3Sopenharmony_ci        }
287094332d3Sopenharmony_ci        status = false;
288094332d3Sopenharmony_ci        Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), status);
289094332d3Sopenharmony_ci        if (Test_->rc != Camera::NO_ERROR) {
290094332d3Sopenharmony_ci            std::cout << "==========[test log] Check Performance: Flashlight turn off fail, at the " <<(i+1);
291094332d3Sopenharmony_ci            std::cout<<"times, RetCode is " << Test_->rc << std::endl;
292094332d3Sopenharmony_ci        }
293094332d3Sopenharmony_ci        sleep(1);
294094332d3Sopenharmony_ci    }
295094332d3Sopenharmony_ci    Test_->Close();
296094332d3Sopenharmony_ci}
297