1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file expected 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 "dfx_test.h"
16 #include <fstream>
17 #ifdef CAMERA_BUILT_ON_OHOS_LITE
18 #include "parameter.h"
19 #else
20 #include "parameters.h"
21 #endif
22 
23 namespace {
24     static const int TIME_TRANSFORMATION_US = 1000000; // 1000000:1000000 microseconds
25     static const int CYCLE_TIMES = 1000; // 1000:Cycle 1000 times
26     std::ofstream g_writeIntoFile;
27 }
28 
29 using namespace OHOS;
30 using namespace std;
31 using namespace testing::ext;
32 using namespace OHOS::Camera;
calTime(struct timeval start,struct timeval end)33 float DfxTest::calTime(struct timeval start, struct timeval end)
34 {
35     float time_use = 0;
36     time_use = (end.tv_sec - start.tv_sec) * TIME_TRANSFORMATION_US + (end.tv_usec - start.tv_usec);
37     return time_use;
38 }
SetUpTestCase(void)39 void DfxTest::SetUpTestCase(void) {}
TearDownTestCase(void)40 void DfxTest::TearDownTestCase(void) {}
SetUp(void)41 void DfxTest::SetUp(void)
42 {
43     Test_ = std::make_shared<OHOS::Camera::Test>();
44     Test_->Init();
45 }
TearDown(void)46 void DfxTest::TearDown(void)
47 {
48     Test_->Close();
49 }
50 
51 #ifdef CAMERA_BUILT_ON_OHOS_LITE
52 /**
53   * @tc.name: Frame interrupt detection.
54   * @tc.desc: Frame interrupt detection.
55   * @tc.size: MediumTest
56   * @tc.type: DFX
57   */
58 HWTEST_F(DfxTest, Camera_Dfx_0001, TestSize.Level3)
59 {
60     std::cout << "==========[test log] Dfx: Frame interrupt detection, mock 20s timeout" << std::endl;
61     int result = 0;
62     char property[] = "frame_timeout";
63     char value[] = "on";
64     result = SetParameter(property, value);
65     if (!result) {
66         Test_->Open();
67         // Start stream
68         Test_->intents = {Camera::PREVIEW};
69         Test_->StartStream(Test_->intents);
70         // Get preview
71         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
72         // release stream
73         Test_->captureIds = {Test_->captureId_preview};
74         Test_->streamIds = {Test_->streamId_preview};
75         Test_->StopStream(Test_->captureIds, Test_->streamIds);
76     }
77 }
78 
79 /**
80   * @tc.name: GetStreamOperator timeout.
81   * @tc.desc: mock Hdi_GetStreamOperator_Timeout.
82   * @tc.size: MediumTest
83   * @tc.type: DFX
84   */
85 HWTEST_F(DfxTest, Camera_Dfx_0010, TestSize.Level3)
86 {
87     std::cout << "==========[test log] Dfx: mock Hdi_GetStreamOperator_Timeout." << std::endl;
88     int result = 0;
89     char property[] = "hdi_getstreamoperator_timeout";
90     char value[] = "on";
91     result = SetParameter(property, value);
92     if (!result) {
93         char defValue[] = "on";
94         char value1[32] = {0};
95         int parameter = GetParameter(property, defValue, value1, 32);
96         std::cout << "==========[test log] DFX: GetProperty Hdi_GetStreamOperator_Timeout = " << parameter << std::endl;
97         Test_->Open();
98         Test_->streamOperatorCallback = std::make_shared<StreamOperatorCallback>();
99         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
100         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
101     }
102 }
103 
104 /**
105   * @tc.name: UpdateSettings timeout.
106   * @tc.desc: mock Hdi_UpdateSettings_Timeout.
107   * @tc.size: MediumTest
108   * @tc.type: DFX
109   */
110 HWTEST_F(DfxTest, Camera_Dfx_0011, TestSize.Level3)
111 {
112     std::cout << "==========[test log] Dfx: mock Hdi_UpdateSettings_Timeout." << std::endl;
113     int result = 0;
114     char property[] = "hdi_updatesettings_timeout";
115     char value[] = "on";
116     result = SetParameter(property, value);
117     if (!result) {
118         char defValue[] = "on";
119         char value1[32] = {0};
120         int parameter = GetParameter(property, defValue, value1, 32);
121         std::cout << "==========[test log] DFX: GetProperty Hdi_UpdateSettings_Timeout = " << parameter << std::endl;
122         Test_->Open();
123         // Issue 3A parameters
124         std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
125         int32_t expo = 0xa0;
126         meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
127         Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
128         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
129         std::cout << "cameraDevice->UpdateSettings's rc " << Test_->rc << std::endl;
130     }
131 }
132 
133 /**
134   * @tc.name: Hdi_GetEnabledResults_Timeout.
135   * @tc.desc: mock Hdi_GetEnabledResults_Timeout.
136   * @tc.size: MediumTest
137   * @tc.type: DFX
138   */
139 HWTEST_F(DfxTest, Camera_Dfx_0012, TestSize.Level3)
140 {
141     std::cout << "==========[test log] Dfx: mock Hdi_GetEnabledResults_Timeout." << std::endl;
142     int result = 0;
143     char property[] = "hdi_getenabledresults_timeout";
144     char value[] = "on";
145     result = SetParameter(property, value);
146     if (!result) {
147         char defValue[] = "on";
148         char value1[32] = {0};
149         int parameter = GetParameter(property, defValue, value1, 32);
150         std::cout << "==========[test log] DFX: GetProperty Hdi_GetEnabledResults_Timeout = " << parameter << std::endl;
151         Test_->Open();
152         EXPECT_EQ(true, Test_->cameraDevice != nullptr);
153         std::vector<Camera::MetaType> enableTypes;
154         Test_->rc = Test_->cameraDevice->GetEnabledResults(enableTypes);
155         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
156         for (const auto &type : enableTypes) {
157             std::cout << "==========[test log]Check hdi_device: type = " << type << std::endl;
158         }
159         Test_->rc = Test_->cameraDevice->SetResultMode(Camera::PER_FRAME);
160         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
161     }
162 }
163 
164 /**
165   * @tc.name: Hdi_GetEnabledResults_Timeout.
166   * @tc.desc: mock Hdi_GetEnabledResults_Timeout.
167   * @tc.size: MediumTest
168   * @tc.type: DFX
169   */
170 HWTEST_F(DfxTest, Camera_Dfx_0013, TestSize.Level3)
171 {
172     std::cout << "==========[test log] Dfx: mock Hdi_GetEnabledResults_Timeout." << std::endl;
173     int result = 0;
174     char property[] = "hdi_getenabledresults_timeout";
175     char value[] = "on";
176     result = SetParameter(property, value);
177     if (!result) {
178         char defValue[] = "on";
179         char value1[32] = {0};
180         int parameter = GetParameter(property, defValue, value1, 32);
181         std::cout << "==========[test log] DFX: GetProperty Hdi_GetEnabledResults_Timeout = " << parameter << std::endl;
182         Test_->Open();
183         EXPECT_EQ(true, Test_->cameraDevice != nullptr);
184         std::vector<Camera::MetaType> enableTypes;
185         Test_->rc = Test_->cameraDevice->GetEnabledResults(enableTypes);
186         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
187         for (const auto &type : enableTypes) {
188             std::cout << "==========[test log]Check hdi_device: type = " << type << std::endl;
189         }
190         Test_->rc = Test_->cameraDevice->SetResultMode(Camera::PER_FRAME);
191         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
192     }
193 }
194 
195 /**
196   * @tc.name: Hdi_DisableResult_Timeout.
197   * @tc.desc: mock Hdi_DisableResult_Timeout.
198   * @tc.size: MediumTest
199   * @tc.type: DFX
200   */
201 HWTEST_F(DfxTest, Camera_Dfx_0014, TestSize.Level3)
202 {
203     std::cout << "==========[test log] Dfx: mock Hdi_DisableResult_Timeout." << std::endl;
204     int result = 0;
205     char property[] = "hdi_disableresult_timeout";
206     char value[] = "on";
207     result = SetParameter(property, value);
208     if (!result) {
209         char defValue[] = "on";
210         char value1[32] = {0};
211         int parameter = GetParameter(property, defValue, value1, 32);
212         std::cout << "==========[test log] DFX: GetProperty Hdi_DisableResult_Timeout = " << parameter << std::endl;
213         Test_->Open();
214         // Get the parameter tag currently supported by the device
215         std::vector<Camera::MetaType> results_first;
216         results_first.push_back(OHOS_SENSOR_EXPOSURE_TIME);
217         results_first.push_back(OHOS_SENSOR_COLOR_CORRECTION_GAINS);
218         Test_->rc = Test_->cameraDevice->EnableResult(results_first);
219         std::vector<Camera::MetaType> results_original;
220         Test_->rc = Test_->cameraDevice->GetEnabledResults(results_original);
221         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
222         std::cout << "==========[test log]GetEnabledResults, size = " << results_original.size() << std::endl;
223 
224         // disable a tag
225         std::vector<Camera::MetaType> disable_tag;
226         disable_tag.push_back(results_original[1]);
227         Test_->rc = Test_->cameraDevice->DisableResult(disable_tag);
228         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
229         std::cout << "==========[test log]Check hdi_device: DisableResult the tag:" << results_original[0] << std::endl;
230 
231         // Get the parameter tag currently supported by the device again
232         std::vector<Camera::MetaType> results;
233         Test_->rc = Test_->cameraDevice->GetEnabledResults(results);
234         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
235     }
236 }
237 
238 /**
239   * @tc.name: Hdi_Close_Timeout.
240   * @tc.desc: mock Hdi_Close_Timeout.
241   * @tc.size: MediumTest
242   * @tc.type: DFX
243   */
244 HWTEST_F(DfxTest, Camera_Dfx_0015, TestSize.Level3)
245 {
246     std::cout << "==========[test log] Dfx: mock Hdi_Close_Timeout." << std::endl;
247     int result = 0;
248     char property[] = "hdi_close_timeout";
249     char value[] = "on";
250     result = SetParameter(property, value);
251     if (!result) {
252         char defValue[] = "on";
253         char value1[32] = {0};
254         int parameter = GetParameter(property, defValue, value1, 32);
255         std::cout << "==========[test log] DFX: GetProperty Hdi_Close_Timeout = " << parameter << std::endl;
256         Test_->Open();
257         Test_->Close();
258     }
259 }
260 
261 /**
262   * @tc.name: Hdi_IsStreamsSupported_Timeout.
263   * @tc.desc: mock Hdi_IsStreamsSupported_Timeout.
264   * @tc.size: MediumTest
265   * @tc.type: DFX
266   */
267 HWTEST_F(DfxTest, Camera_Dfx_0020, TestSize.Level3) {
268     std::cout << "==========[test log] Dfx: mock Hdi_IsStreamsSupported_Timeout." << std::endl;
269     int result = 0;
270     char property[] = "Hdi_IsStreamsSupported_Timeout";
271     char value[] = "on";
272     result = SetParameter(property, value);
273     if (!result) {
274         char defValue[] = "on";
275         char value1[32] = {0};
276         int parameter = GetParameter(property, defValue, value1, 32);
277         std::cout << "==========[test log] DFX:GetProperty Hdi_IsStreamsSupported_Timeout = " << parameter << std::endl;
278         // Turn on the camera
279         Test_->Open();
280         EXPECT_EQ(false, Test_->cameraDevice == nullptr);
281         // Get streamOperator
282         Test_->streamOperatorCallback = std::make_shared<StreamOperatorCallback>();
283         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
284         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
285         // Configure mode and modeSetting
286         Camera::OperationMode mode = Camera::NORMAL;
287         std::shared_ptr<CameraMetadata> modeSetting =
288             std::make_shared<CameraMetadata>(2, 128);
289         int64_t expoTime = 0;
290         modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
291         int64_t colorGains[4] = {0};
292         modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
293         // Configure stream information
294         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
295         Test_->streamInfo->streamId_ = 1001; // 1001:streamId
296         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
297         Test_->streamInfo->height_ = 480; // 480:height of stream
298         Test_->streamInfo->width_ = 640; // 640:width of stream
299         Test_->streamInfo->dataspace_ = 8;
300         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
301         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0202(OHOS::SurfaceBuffer* buffer) 302         Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
303             Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize());
304         });
305         Test_->streamInfo->bufferQueue_->SetQueueSize(8);
306         Test_->consumerMap_[Test_->streamInfo->intent_] = consumer;
307         Test_->streamInfo->intent_ = Camera::PREVIEW;
308         Test_->streamInfo->tunneledMode_ = 5;
309         Camera::StreamSupportType pType;
310         std::vector<std::shared_ptr<Camera::StreamInfo>> stre;
311         stre.push_back(Test_->streamInfo);
312         Test_->rc = Test_->streamOperator->IsStreamsSupported(NORMAL, modeSetting, stre, pType);
313         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
314         EXPECT_NE(pType, NOT_SUPPORTED);
315         if (Test_->rc == Camera::NO_ERROR) {
316             std::cout << "==========[test log]Check hdi: IsStreamsSupported success, pType = " << pType << std::endl;
317         } else {
318             std::cout << "==========[test log]Check hdi: IsStreamsSupported fail, rc = " << Test_->rc << std::endl;
319         }
320     }
321     result = SetParameter(property, "off");
322 }
323 
324 /**
325   * @tc.name: Hdi_CreateStreams_Timeout.
326   * @tc.desc: mock Hdi_CreateStreams_Timeout.
327   * @tc.size: MediumTest
328   * @tc.type: DFX
329   */
330 HWTEST_F(DfxTest, Camera_Dfx_0021, TestSize.Level3)
331 {
332     std::cout << "==========[test log] Dfx: mock Hdi_CreateStreams_Timeout." << std::endl;
333     int result = 0;
334     char property[] = "hdi_createstreams_timeout";
335     char value[] = "on";
336     result = SetParameter(property, value);
337     if (!result) {
338         char defValue[] = "on";
339         char value1[32] = {0};
340         int parameter = GetParameter(property, defValue, value1, 32);
341         std::cout << "==========[test log] DFX: GetProperty Hdi_CreateStreams_Timeout = " << parameter << std::endl;
342         Test_->Open();
343         // Create and get streamOperator information
344         Test_->streamOperatorCallback = std::make_shared<StreamOperatorCallback>();
345         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
346         EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR || Test_->streamOperator == nullptr);
347         // Create data stream
348         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
349         Test_->streamInfo->streamId_ = 1001;
350         Test_->streamInfo->width_ = 640;
351         Test_->streamInfo->height_ = 480;
352         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
353         Test_->streamInfo->dataspace_ = 8;
354         Test_->streamInfo->intent_ = Camera::PREVIEW;
355         Test_->streamInfo->tunneledMode_ = 5;
356         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
357         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0302(OHOS::SurfaceBuffer* buffer) 358         Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
359             Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize());
360         });
361         Test_->consumerMap_[Test_->streamInfo->intent_] = consumer;
362         Test_->streamInfos.push_back(Test_->streamInfo);
363         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
364         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
365         // release stream
366         std::vector<int> streamIds;
367         streamIds.push_back(Test_->streamInfo->streamId_);
368         Test_->rc = Test_->streamOperator->ReleaseStreams(streamIds);
369         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
370     }
371     result = SetParameter(property, "off");
372 }
373 
374 /**
375   * @tc.name: Hdi_ReleaseStreams_Timeout.
376   * @tc.desc: mock Hdi_ReleaseStreams_Timeout.
377   * @tc.size: MediumTest
378   * @tc.type: DFX
379   */
380 HWTEST_F(DfxTest, Camera_Dfx_0022, TestSize.Level3)
381 {
382     std::cout << "==========[test log] Dfx: mock Hdi_ReleaseStreams_Timeout." << std::endl;
383     int result = 0;
384     char property[] = "hdi_releasestreams_timeout";
385     char value[] = "on";
386     result = SetParameter(property, value);
387     if (!result) {
388         char defValue[] = "on";
389         char value1[32] = {0};
390         int parameter = GetParameter(property, defValue, value1, 32);
391         std::cout << "==========[test log] DFX: GetProperty Hdi_ReleaseStreams_Timeout = " << parameter << std::endl;
392         Test_->Open();
393         // Create and get streamOperator information
394         Test_->streamOperatorCallback = std::make_shared<StreamOperatorCallback>();
395         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
396         EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR || Test_->streamOperator == nullptr);
397         // Create data stream
398         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
399         Test_->streamInfo->streamId_ = 1001;
400         Test_->streamInfo->width_ = 640;
401         Test_->streamInfo->height_ = 480;
402         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
403         Test_->streamInfo->dataspace_ = 8;
404         Test_->streamInfo->intent_ = Camera::PREVIEW;
405         Test_->streamInfo->tunneledMode_ = 5;
406         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
407         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0402(OHOS::SurfaceBuffer* buffer) 408         Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
409             Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize());
410         });
411         Test_->consumerMap_[Test_->streamInfo->intent_] = consumer;
412         Test_->streamInfos.push_back(Test_->streamInfo);
413         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
414         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
415         // release stream
416         std::vector<int> streamIds;
417         streamIds.push_back(Test_->streamInfo->streamId_);
418         Test_->rc = Test_->streamOperator->ReleaseStreams(streamIds);
419         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
420     }
421     result = SetParameter(property, "off");
422 }
423 
424 /**
425   * @tc.name: Hdi_CommitStreams_Timeout.
426   * @tc.desc: mock Hdi_CommitStreams_Timeout.
427   * @tc.size: MediumTest
428   * @tc.type: DFX
429   */
430 HWTEST_F(DfxTest, Camera_Dfx_0023, TestSize.Level3)
431 {
432     std::cout << "==========[test log] Dfx: mock Hdi_CommitStreams_Timeout." << std::endl;
433     int result = 0;
434     char property[] = "hdi_commitstreams_timeout";
435     char value[] = "on";
436     result = SetParameter(property, value);
437     if (!result) {
438         char defValue[] = "on";
439         char value1[32] = {0};
440         int parameter = GetParameter(property, defValue, value1, 32);
441         std::cout << "==========[test log] DFX: GetProperty Hdi_CommitStreams_Timeout = " << parameter << std::endl;
442         Test_->Open();
443         // Start stream
444         Test_->intents = {Camera::PREVIEW};
445         Test_->StartStream(Test_->intents);
446         // release stream
447         Test_->captureIds = {};
448         Test_->streamIds = {Test_->streamId_preview};
449         Test_->StopStream(Test_->captureIds, Test_->streamIds);
450     }
451 }
452 
453 /**
454   * @tc.name: Hdi_AttachBufferQueue_Timeout.
455   * @tc.desc: mock Hdi_AttachBufferQueue_Timeout.
456   * @tc.size: MediumTest
457   * @tc.type: DFX
458   */
459 HWTEST_F(DfxTest, Camera_Dfx_0024, TestSize.Level3)
460 {
461     std::cout << "==========[test log] Dfx: mock Hdi_AttachBufferQueue_Timeout." << std::endl;
462     int result = 0;
463     char property[] = "hdi_attachbufferqueue_timeout";
464     char value[] = "on";
465     result = SetParameter(property, value);
466     if (!result) {
467         char defValue[] = "on";
468         char value1[32] = {0};
469         int parameter = GetParameter(property, defValue, value1, 32);
470         std::cout << "==========[test log] DFX: GetProperty Hdi_AttachBufferQueue_Timeout = " << parameter << std::endl;
471         Test_->Open();
472         Test_->streamOperatorCallback = std::make_shared<StreamOperatorCallback>();
473         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
474         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
475         // Create data stream
476         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
477         Test_->streamInfo->streamId_ = 1001;
478         Test_->streamInfo->height_ = 480;
479         Test_->streamInfo->width_ = 640;
480         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
481         Test_->streamInfo->dataspace_ = 8;
482         Test_->streamInfo->intent_ = Camera::PREVIEW;
483         Test_->streamInfo->tunneledMode_ = 5;
484         std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos);
485         Test_->streamInfos.push_back(Test_->streamInfo);
486         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
487         std::cout << "==========[test log]Check hdi: streamOperator->CreateStreams's rc " << Test_->rc << std::endl;
488         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
489         // Distribution stream
490         Test_->rc = Test_->service->GetCameraAbility(Test_->cameraIds.front(), Test_->ability);
491         Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability);
492         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
493         std::cout << "==========[test log]Check hdi: streamOperator->CommitStreams's rc " << Test_->rc << std::endl;
494         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
495         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0502(OHOS::SurfaceBuffer* buffer) 496         std::shared_ptr<OHOS::Surface> producer = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
497             Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize());
498         });
499         Test_->rc = Test_->streamOperator->AttachBufferQueue(Test_->streamInfo->streamId_, producer);
500         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
501         if (Test_->rc == Camera::NO_ERROR) {
502             std::cout << "==========[test log]Check hdi: AttachBufferQueue success. " << std::endl;
503         } else {
504             std::cout << "==========[test log]Check hdi: AttachBufferQueue fail, rc = " << Test_->rc << std::endl;
505         }
506         // release stream
507         Test_->captureIds = {};
508         Test_->streamIds = {1001};
509         Test_->StopStream(Test_->captureIds, Test_->streamIds);
510     }
511     result = SetParameter(property, "off");
512 }
513 
514 /**
515   * @tc.name: Hdi_DetachBufferQueue_Timeout.
516   * @tc.desc: mock Hdi_DetachBufferQueue_Timeout.
517   * @tc.size: MediumTest
518   * @tc.type: DFX
519   */
520 HWTEST_F(DfxTest, Camera_Dfx_0025, TestSize.Level3)
521 {
522     std::cout << "==========[test log] Dfx: mock Hdi_DetachBufferQueue_Timeout." << std::endl;
523     int result = 0;
524     char property[] = "hdi_detachbufferqueue_timeout";
525     char value[] = "on";
526     result = SetParameter(property, value);
527     if (!result) {
528         char defValue[] = "on";
529         char value1[32] = {0};
530         int parameter = GetParameter(property, defValue, value1, 32);
531         std::cout << "==========[test log] DFX: GetProperty Hdi_DetachBufferQueue_Timeout = " << parameter << std::endl;
532         Test_->Open();
533         Test_->streamOperatorCallback = std::make_shared<StreamOperatorCallback>();
534         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
535         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
536         // Create data stream
537         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
538         Test_->streamInfo->streamId_ = 1001;
539         Test_->streamInfo->width_ = 640;
540         Test_->streamInfo->height_ = 480;
541         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
542         Test_->streamInfo->intent_ = Camera::PREVIEW;
543         Test_->streamInfo->dataspace_ = 8;
544         Test_->streamInfo->tunneledMode_ = 5;
545         std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos);
546         Test_->streamInfos.push_back(Test_->streamInfo);
547         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
548         std::cout << "==========[test log]Check hdi: streamOperator->CreateStreams's rc " << Test_->rc << std::endl;
549         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
550         // Distribution stream
551         Test_->rc = Test_->service->GetCameraAbility(Test_->cameraIds.front(), Test_->ability);
552         Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability);
553         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
554         std::cout << "==========[test log]Check hdi: streamOperator->CommitStreams's rc " << Test_->rc << std::endl;
555         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
556         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0602(OHOS::SurfaceBuffer* buffer) 557         std::shared_ptr<OHOS::Surface> producer = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
558             Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize());
559         });
560         Test_->rc = Test_->streamOperator->AttachBufferQueue(Test_->streamInfo->streamId_, producer);
561         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
562         if (Test_->rc == Camera::NO_ERROR) {
563             std::cout << "==========[test log]Check hdi: AttachBufferQueue success. " << std::endl;
564         } else {
565             std::cout << "==========[test log]Check hdi: AttachBufferQueue fail, rc = " << Test_->rc << std::endl;
566         }
567         sleep(3); // sleep for 3 seconds
568         Test_->rc = Test_->streamOperator->DetachBufferQueue(Test_->streamInfo->streamId_);
569         std::cout << "==========[test log]Check hdi: streamOperator->DetachBufferQueue's rc " << Test_->rc << std::endl;
570         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
571         // release stream
572         Test_->captureIds = {};
573         Test_->streamIds = {1001};
574         Test_->StopStream(Test_->captureIds, Test_->streamIds);
575     }
576     result = SetParameter(property, "off");
577 }
578 
579 /**
580   * @tc.name: Hdi_Capture_Timeout.
581   * @tc.desc: mock Hdi_Capture_Timeout.
582   * @tc.size: MediumTest
583   * @tc.type: DFX
584   */
585 HWTEST_F(DfxTest, Camera_Dfx_0026, TestSize.Level3)
586 {
587     std::cout << "==========[test log] Dfx: mock Hdi_Capture_Timeout." << std::endl;
588     int result = 0;
589     char property[] = "hdi_capture_timeout";
590     char value[] = "on";
591     result = SetParameter(property, value);
592     if (!result) {
593         char defValue[] = "on";
594         char value1[32] = {0};
595         int parameter = GetParameter(property, defValue, value1, 32);
596         std::cout << "==========[test log] DFX: GetProperty Hdi_Capture_Timeout = " << parameter << std::endl;
597         Test_->Open();
598         // Configure preview stream information
599         Test_->intents = {Camera::PREVIEW};
600         Test_->StartStream(Test_->intents);
601         // Capture preview stream
602         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, true, true);
603         // post-processing
604         Test_->captureIds = {Test_->captureId_preview};
605         Test_->streamIds = {Test_->streamId_preview};
606         Test_->StopStream(Test_->captureIds, Test_->streamIds);
607     }
608 }
609 
610 /**
611   * @tc.name: Hdi_ChangeToOfflineStream_Timeout.
612   * @tc.desc: mock Hdi_ChangeToOfflineStream_Timeout.
613   * @tc.size: MediumTest
614   * @tc.type: DFX
615   */
616 HWTEST_F(DfxTest, Camera_Dfx_0027, TestSize.Level3)
617 {
618     std::cout << "==========[test log] Dfx: mock Hdi_ChangeToOfflineStream_Timeout." << std::endl;
619     int result = 0;
620     char property[] = "hdi_change_to_offlinestream_timeout";
621     char value[] = "on";
622     result = SetParameter(property, value);
623     if (!result) {
624         char defValue[] = "on";
625         char value1[32] = {0};
626         int parameter = GetParameter(property, defValue, value1, 32);
627         std::cout << "======[test log] DFX:GetProperty Hdi_ChangeToOfflineStream_Timeout = " << parameter << std::endl;
628         Test_->Open();
629         // 1. Configure two streams of information
630         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
631         Test_->StartStream(Test_->intents);
632         // 2. Capture the preview stream
633         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
634         // 3. Capture the camera stream, continuous shooting
635         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
636         sleep(3); // sleep for 3 seconds
637         // 4. Convert to offline stream
638         Test_->offlineStreamOperatorCallback = std::make_shared<OHOS::Camera::StreamOperatorCallback>();
639         std::vector<int> offlineIds;
640         offlineIds.push_back(Test_->streamId_capture);
641         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
642             offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
643         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
644         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
645         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
646         if (Test_->rc == Camera::NO_ERROR) {
647             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
648         } else {
649             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
650         }
651         // 5. Post-processing of the original stream
652         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
653         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
654         Test_->StopStream(Test_->captureIds, Test_->streamIds);
655         // 6. Post-processing of offline streams
656         Test_->cameraDevice->Close();
657         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
658         sleep(3); // sleep for 3 seconds
659         Test_->StopOfflineStream(Test_->captureId_capture);
660     }
661 }
662 
663 /**
664   * @tc.name: Hdi_Offline_CancelCapture_Timeout.
665   * @tc.desc: mock Hdi_Offline_ReleaseStreams_Timeout.
666   * @tc.size: MediumTest
667   * @tc.type: DFX
668   */
669 HWTEST_F(DfxTest, Camera_Dfx_0030, TestSize.Level3)
670 {
671     std::cout << "==========[test log] Dfx: mock Hdi_Offline_CancelCapture_Timeout." << std::endl;
672     int result = 0;
673     char property[] = "hdi_offline_cancelcapture_timeout";
674     char value[] = "on";
675     result = SetParameter(property, value);
676     if (!result) {
677         char defValue[] = "on";
678         char value1[32] = {0};
679         int parameter = GetParameter(property, defValue, value1, 32);
680         std::cout << "======[test log] DFX:GetProperty Hdi_Offline_CancelCapture_Timeout = " << parameter << std::endl;
681         Test_->Open();
682         // 1. Configure two streams of information
683         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
684         Test_->StartStream(Test_->intents);
685         // 2. Capture the preview stream
686         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
687         // 3. Capture the camera stream, continuous shooting
688         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
689         sleep(3); // sleep for 3 seconds
690         // 4. Convert to offline stream
691         Test_->offlineStreamOperatorCallback = std::make_shared<OHOS::Camera::StreamOperatorCallback>();
692         std::vector<int> offlineIds;
693         offlineIds.push_back(Test_->streamId_capture);
694         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
695             offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
696         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
697         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
698         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
699         if (Test_->rc == Camera::NO_ERROR) {
700             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
701         } else {
702             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
703         }
704         // 5. Post-processing of the original stream
705         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
706         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
707         Test_->StopStream(Test_->captureIds, Test_->streamIds);
708         // 6. Post-processing of offline streams
709         Test_->cameraDevice->Close();
710         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
711         sleep(3); // sleep for 3 seconds
712         Test_->StopOfflineStream(Test_->captureId_capture);
713     }
714 }
715 
716 /**
717   * @tc.name: Hdi_Offline_ReleaseStreams_Timeout.
718   * @tc.desc: mock Hdi_Offline_ReleaseStreams_Timeout.
719   * @tc.size: MediumTest
720   * @tc.type: DFX
721   */
722 HWTEST_F(DfxTest, Camera_Dfx_0031, TestSize.Level3)
723 {
724     std::cout << "==========[test log] Dfx: mock Hdi_Offline_ReleaseStreams_Timeout." << std::endl;
725     int result = 0;
726     char property[] = "hdi_offline_releasestreams_timeout";
727     char value[] = "on";
728     result = SetParameter(property, value);
729     if (!result) {
730         char defValue[] = "on";
731         char value1[32] = {0};
732         int parameter = GetParameter(property, defValue, value1, 32);
733         std::cout << "=====[test log] DFX:GetProperty Hdi_Offline_ReleaseStreams_Timeout = " << parameter << std::endl;
734         Test_->Open();
735         // 1. Configure two streams of information
736         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
737         Test_->StartStream(Test_->intents);
738         // 2. Capture the preview stream
739         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
740         // 3. Capture the camera stream, continuous shooting
741         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
742         sleep(3); // sleep for 3 seconds
743         // 4. Convert to offline stream
744         Test_->offlineStreamOperatorCallback = std::make_shared<OHOS::Camera::StreamOperatorCallback>();
745         std::vector<int> offlineIds;
746         offlineIds.push_back(Test_->streamId_capture);
747         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
748             offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
749         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
750         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
751         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
752         if (Test_->rc == Camera::NO_ERROR) {
753             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
754         } else {
755             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
756         }
757         // 5. Post-processing of the original stream
758         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
759         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
760         Test_->StopStream(Test_->captureIds, Test_->streamIds);
761         // 6. Post-processing of offline streams
762         Test_->cameraDevice->Close();
763         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
764         sleep(3); // sleep for 3 seconds
765         Test_->StopOfflineStream(Test_->captureId_capture);
766     }
767 }
768 
769 /**
770   * @tc.name: Hdi_Offline_Release_Timeout.
771   * @tc.desc: mock Hdi_Offline_Release_Timeout.
772   * @tc.size: MediumTest
773   * @tc.type: DFX
774   */
775 HWTEST_F(DfxTest, Camera_Dfx_0032, TestSize.Level3)
776 {
777     std::cout << "==========[test log] Dfx: mock Hdi_Offline_Release_Timeout." << std::endl;
778     int result = 0;
779     char property[] = "hdi_offline_release_timeout";
780     char value[] = "on";
781     result = SetParameter(property, value);
782     if (!result) {
783         char defValue[] = "on";
784         char value1[32] = {0};
785         int parameter = GetParameter(property, defValue, value1, 32);
786         std::cout << "==========[test log] DFX: GetProperty Hdi_Offline_Release_Timeout = " << parameter << std::endl;
787         Test_->Open();
788         // 1. Configure two streams of information
789         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
790         Test_->StartStream(Test_->intents);
791         // 2. Capture the preview stream
792         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
793         // 3. Capture the camera stream, continuous shooting
794         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
795         sleep(3); // sleep for 3 seconds
796         // 4. Convert to offline stream
797         Test_->offlineStreamOperatorCallback = std::make_shared<OHOS::Camera::StreamOperatorCallback>();
798         std::vector<int> offlineIds;
799         offlineIds.push_back(Test_->streamId_capture);
800         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
801             offlineIds, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
802         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
803         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
804         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
805         if (Test_->rc == Camera::NO_ERROR) {
806             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
807         } else {
808             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
809         }
810         // 5. Post-processing of the original stream
811         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
812         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
813         Test_->StopStream(Test_->captureIds, Test_->streamIds);
814         // 6. Post-processing of offline streams
815         Test_->cameraDevice->Close();
816         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
817         sleep(3); // sleep for 3 seconds
818         Test_->StopOfflineStream(Test_->captureId_capture);
819     }
820 }
821 #else
822 /**
823   * @tc.name: Frame interrupt detection.
824   * @tc.desc: Frame interrupt detection.
825   * @tc.size: MediumTest
826   * @tc.type: DFX
827   */
828 HWTEST_F(DfxTest, Camera_Dfx_0001, TestSize.Level3)
829 {
830     std::cout << "==========[test log] Dfx: Frame interrupt detection, mock 20s timeout" << std::endl;
831     bool result = false;
832     std::string property = "Frame_Timeout";
833     std::string value = "on";
834     result = OHOS::system::SetParameter(property, value);
835     if (result) {
836         Test_->Open();
837         // Start stream
838         Test_->intents = {Camera::PREVIEW};
839         Test_->StartStream(Test_->intents);
840         // Get preview
841         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
842         // release stream
843         Test_->captureIds = {Test_->captureId_preview};
844         Test_->streamIds = {Test_->streamId_preview};
845         Test_->StopStream(Test_->captureIds, Test_->streamIds);
846         Test_->StopConsumer(Test_->intents);
847     }
848 }
849 
850 /**
851   * @tc.name: GetStreamOperator timeout.
852   * @tc.desc: mock Hdi_GetStreamOperator_Timeout.
853   * @tc.size: MediumTest
854   * @tc.type: DFX
855   */
856 HWTEST_F(DfxTest, Camera_Dfx_0010, TestSize.Level3)
857 {
858     std::cout << "==========[test log] Dfx: mock Hdi_GetStreamOperator_Timeout." << std::endl;
859     bool result = false;
860     std::string property = "Hdi_GetStreamOperator_Timeout";
861     std::string value = "on";
862     result = OHOS::system::SetParameter(property, value);
863     if (result) {
864         std::string parameter = OHOS::system::GetParameter(property, value);
865         std::cout << "==========[test log] DFX: GetProperty Hdi_GetStreamOperator_Timeout = " << parameter << std::endl;
866         Test_->Open();
867         Test_->streamOperatorCallback = new StreamOperatorCallback();
868         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
869         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
870     }
871 }
872 
873 /**
874   * @tc.name: UpdateSettings timeout.
875   * @tc.desc: mock Hdi_UpdateSettings_Timeout.
876   * @tc.size: MediumTest
877   * @tc.type: DFX
878   */
879 HWTEST_F(DfxTest, Camera_Dfx_0011, TestSize.Level3)
880 {
881     std::cout << "==========[test log] Dfx: mock Hdi_UpdateSettings_Timeout." << std::endl;
882     bool result = false;
883     std::string property = "Hdi_UpdateSettings_Timeout";
884     std::string value = "on";
885     result = OHOS::system::SetParameter(property, value);
886     if (result) {
887         std::string parameter = OHOS::system::GetParameter(property, value);
888         std::cout << "==========[test log] DFX: GetProperty Hdi_UpdateSettings_Timeout = " << parameter << std::endl;
889         Test_->Open();
890         // Issue 3A parameters
891         std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
892         int32_t expo = 0xa0;
893         meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
894         Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
895         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
896         std::cout << "cameraDevice->UpdateSettings's rc " << Test_->rc << std::endl;
897     }
898 }
899 
900 /**
901   * @tc.name: Hdi_GetEnabledResults_Timeout.
902   * @tc.desc: mock Hdi_GetEnabledResults_Timeout.
903   * @tc.size: MediumTest
904   * @tc.type: DFX
905   */
906 HWTEST_F(DfxTest, Camera_Dfx_0012, TestSize.Level3)
907 {
908     std::cout << "==========[test log] Dfx: mock Hdi_GetEnabledResults_Timeout." << std::endl;
909     bool result = false;
910     std::string property = "Hdi_GetEnabledResults_Timeout";
911     std::string value = "on";
912     result = OHOS::system::SetParameter(property, value);
913     if (result) {
914         std::string parameter = OHOS::system::GetParameter(property, value);
915         std::cout << "==========[test log] DFX: GetProperty Hdi_GetEnabledResults_Timeout = " << parameter << std::endl;
916         Test_->Open();
917         EXPECT_EQ(true, Test_->cameraDevice != nullptr);
918         std::vector<Camera::MetaType> enableTypes;
919         Test_->rc = Test_->cameraDevice->GetEnabledResults(enableTypes);
920         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
921         for (const auto &type : enableTypes) {
922             std::cout << "==========[test log]Check hdi_device: type = " << type << std::endl;
923         }
924         Test_->rc = Test_->cameraDevice->SetResultMode(Camera::PER_FRAME);
925         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
926     }
927 }
928 
929 /**
930   * @tc.name: Hdi_GetEnabledResults_Timeout.
931   * @tc.desc: mock Hdi_GetEnabledResults_Timeout.
932   * @tc.size: MediumTest
933   * @tc.type: DFX
934   */
935 HWTEST_F(DfxTest, Camera_Dfx_0013, TestSize.Level3)
936 {
937     std::cout << "==========[test log] Dfx: mock Hdi_GetEnabledResults_Timeout." << std::endl;
938     bool result = false;
939     std::string property = "Hdi_GetEnabledResults_Timeout";
940     std::string value = "on";
941     result = OHOS::system::SetParameter(property, value);
942     if (result) {
943         std::string parameter = OHOS::system::GetParameter(property, value);
944         std::cout << "==========[test log] DFX: GetProperty Hdi_GetEnabledResults_Timeout = " << parameter << std::endl;
945         Test_->Open();
946         EXPECT_EQ(true, Test_->cameraDevice != nullptr);
947         std::vector<Camera::MetaType> enableTypes;
948         Test_->rc = Test_->cameraDevice->GetEnabledResults(enableTypes);
949         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
950         for (const auto &type : enableTypes) {
951             std::cout << "==========[test log]Check hdi_device: type = " << type << std::endl;
952         }
953         Test_->rc = Test_->cameraDevice->SetResultMode(Camera::PER_FRAME);
954         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
955     }
956 }
957 
958 /**
959   * @tc.name: Hdi_DisableResult_Timeout.
960   * @tc.desc: mock Hdi_DisableResult_Timeout.
961   * @tc.size: MediumTest
962   * @tc.type: DFX
963   */
964 HWTEST_F(DfxTest, Camera_Dfx_0014, TestSize.Level3)
965 {
966     std::cout << "==========[test log] Dfx: mock Hdi_DisableResult_Timeout." << std::endl;
967     bool result = false;
968     std::string property = "Hdi_DisableResult_Timeout";
969     std::string value = "on";
970     result = OHOS::system::SetParameter(property, value);
971     if (result) {
972         std::string parameter = OHOS::system::GetParameter(property, value);
973         std::cout << "==========[test log] DFX: GetProperty Hdi_DisableResult_Timeout = " << parameter << std::endl;
974         Test_->Open();
975         std::vector<Camera::MetaType> results;
976         results.push_back(OHOS_SENSOR_EXPOSURE_TIME);
977         results.push_back(OHOS_SENSOR_COLOR_CORRECTION_GAINS);
978         Test_->rc = Test_->cameraDevice->EnableResult(results);
979         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
980         std::vector<Camera::MetaType> results_original;
981         Test_->rc = Test_->cameraDevice->GetEnabledResults(results_original);
982         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
983         std::cout << "==========[test log]GetEnabledResults, size = " << results_original.size() << std::endl;
984 
985         // disable a tag
986         std::vector<Camera::MetaType> disable_tag;
987         disable_tag.push_back(results_original[1]);
988         Test_->rc = Test_->cameraDevice->DisableResult(disable_tag);
989         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
990         std::cout << "==========[test log]Check hdi_device: DisableResult the tag:" << results_original[0] << std::endl;
991 
992         // Get the parameter tag currently supported by the device again
993         Test_->rc = Test_->cameraDevice->GetEnabledResults(results);
994         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
995     }
996 }
997 
998 /**
999   * @tc.name: Hdi_Close_Timeout.
1000   * @tc.desc: mock Hdi_Close_Timeout.
1001   * @tc.size: MediumTest
1002   * @tc.type: DFX
1003   */
1004 HWTEST_F(DfxTest, Camera_Dfx_0015, TestSize.Level3)
1005 {
1006     std::cout << "==========[test log] Dfx: mock Hdi_Close_Timeout." << std::endl;
1007     bool result = false;
1008     std::string property = "Hdi_Close_Timeout";
1009     std::string value = "on";
1010     result = OHOS::system::SetParameter(property, value);
1011     if (result) {
1012         std::string parameter = OHOS::system::GetParameter(property, value);
1013         std::cout << "==========[test log] DFX: GetProperty Hdi_Close_Timeout = " << parameter << std::endl;
1014         Test_->Open();
1015         Test_->Close();
1016     }
1017 }
1018 
1019 /**
1020   * @tc.name: Hdi_IsStreamsSupported_Timeout.
1021   * @tc.desc: mock Hdi_IsStreamsSupported_Timeout.
1022   * @tc.size: MediumTest
1023   * @tc.type: DFX
1024   */
1025 HWTEST_F(DfxTest, Camera_Dfx_0020, TestSize.Level3) {
1026     std::cout << "==========[test log] Dfx: mock Hdi_IsStreamsSupported_Timeout." << std::endl;
1027     bool result = false;
1028     std::string property = "Hdi_IsStreamsSupported_Timeout";
1029     std::string value = "on";
1030     result = OHOS::system::SetParameter(property, value);
1031     if (result) {
1032         std::string parameter = OHOS::system::GetParameter(property, value);
1033         std::cout << "======[test log] DFX: GetProperty Hdi_IsStreamsSupported_Timeout = " << parameter << std::endl;
1034         // Turn on the camera
1035         Test_->Open();
1036         EXPECT_EQ(false, Test_->cameraDevice == nullptr);
1037         // Get streamOperator
1038         Test_->streamOperatorCallback = new StreamOperatorCallback();
1039         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
1040         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1041         // Configure mode and modeSetting
1042         Camera::OperationMode mode = Camera::NORMAL;
1043         std::shared_ptr<CameraMetadata> modeSetting =
1044             std::make_shared<CameraMetadata>(2, 128);
1045         int64_t expoTime = 0;
1046         modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
1047         int64_t colorGains[4] = {0};
1048         modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
1049         // Configure stream information
1050         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
1051         Test_->streamInfo->streamId_ = 1001; // 1001:streamId
1052         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
1053         Test_->streamInfo->height_ = 480; // 480:height of stream
1054         Test_->streamInfo->width_ = 640; // 640:width of stream
1055         Test_->streamInfo->dataspace_ = 8;
1056         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
1057         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0702(void* addr, uint32_t size) 1058         Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](void* addr, uint32_t size) {
1059             Test_->SaveYUV("preview", addr, size);
1060         });
1061         Test_->streamInfo->bufferQueue_->SetQueueSize(8);
1062         Test_->consumerMap_[Test_->streamInfo->intent_] = consumer;
1063         Test_->streamInfo->intent_ = Camera::PREVIEW;
1064         Test_->streamInfo->tunneledMode_ = 5;
1065         Camera::StreamSupportType pType;
1066         Test_->rc = Test_->streamOperator->IsStreamsSupported(NORMAL, modeSetting, {Test_->streamInfo}, pType);
1067         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1068         EXPECT_NE(pType, NOT_SUPPORTED);
1069         if (Test_->rc == Camera::NO_ERROR) {
1070             std::cout << "==========[test log]Check hdi: IsStreamsSupported success, pType = " << pType << std::endl;
1071         } else {
1072             std::cout << "==========[test log]Check hdi: IsStreamsSupported fail, rc = " << Test_->rc << std::endl;
1073         }
1074     }
1075     result = OHOS::system::SetParameter(property, "off");
1076 }
1077 
1078 /**
1079   * @tc.name: Hdi_CreateStreams_Timeout.
1080   * @tc.desc: mock Hdi_CreateStreams_Timeout.
1081   * @tc.size: MediumTest
1082   * @tc.type: DFX
1083   */
1084 HWTEST_F(DfxTest, Camera_Dfx_0021, TestSize.Level3)
1085 {
1086     std::cout << "==========[test log] Dfx: mock Hdi_CreateStreams_Timeout." << std::endl;
1087     bool result = false;
1088     std::string property = "Hdi_CreateStreams_Timeout";
1089     std::string value = "on";
1090     result = OHOS::system::SetParameter(property, value);
1091     if (result) {
1092         std::string parameter = OHOS::system::GetParameter(property, value);
1093         std::cout << "==========[test log] DFX: GetProperty Hdi_CreateStreams_Timeout = " << parameter << std::endl;
1094         Test_->Open();
1095         // Create and get streamOperator information
1096         Test_->streamOperatorCallback = new StreamOperatorCallback();
1097         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
1098         EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR || Test_->streamOperator == nullptr);
1099         // Create data stream
1100         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
1101         Test_->streamInfo->streamId_ = 1001;
1102         Test_->streamInfo->width_ = 640;
1103         Test_->streamInfo->height_ = 480;
1104         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
1105         Test_->streamInfo->dataspace_ = 8;
1106         Test_->streamInfo->intent_ = Camera::PREVIEW;
1107         Test_->streamInfo->tunneledMode_ = 5;
1108         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
1109         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0802(void* addr, uint32_t size) 1110         Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](void* addr, uint32_t size) {
1111             Test_->SaveYUV("preview", addr, size);
1112         });
1113         Test_->consumerMap_[Test_->streamInfo->intent_] = consumer;
1114         Test_->streamInfos.push_back(Test_->streamInfo);
1115         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
1116         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1117         // release stream
1118         std::vector<int> streamIds;
1119         streamIds.push_back(Test_->streamInfo->streamId_);
1120         Test_->rc = Test_->streamOperator->ReleaseStreams(streamIds);
1121         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1122     }
1123     result = OHOS::system::SetParameter(property, "off");
1124 }
1125 
1126 /**
1127   * @tc.name: Hdi_ReleaseStreams_Timeout.
1128   * @tc.desc: mock Hdi_ReleaseStreams_Timeout.
1129   * @tc.size: MediumTest
1130   * @tc.type: DFX
1131   */
1132 HWTEST_F(DfxTest, Camera_Dfx_0022, TestSize.Level3)
1133 {
1134     std::cout << "==========[test log] Dfx: mock Hdi_ReleaseStreams_Timeout." << std::endl;
1135     bool result = false;
1136     std::string property = "Hdi_ReleaseStreams_Timeout";
1137     std::string value = "on";
1138     result = OHOS::system::SetParameter(property, value);
1139     if (result) {
1140         std::string parameter = OHOS::system::GetParameter(property, value);
1141         std::cout << "==========[test log] DFX: GetProperty Hdi_ReleaseStreams_Timeout = " << parameter << std::endl;
1142         Test_->Open();
1143         // Create and get streamOperator information
1144         Test_->streamOperatorCallback = new StreamOperatorCallback();
1145         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
1146         EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR || Test_->streamOperator == nullptr);
1147         // Create data stream
1148         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
1149         Test_->streamInfo->streamId_ = 1001;
1150         Test_->streamInfo->width_ = 640;
1151         Test_->streamInfo->height_ = 480;
1152         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
1153         Test_->streamInfo->dataspace_ = 8;
1154         Test_->streamInfo->intent_ = Camera::PREVIEW;
1155         Test_->streamInfo->tunneledMode_ = 5;
1156         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
1157         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0902(void* addr, uint32_t size) 1158         Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](void* addr, uint32_t size) {
1159             Test_->SaveYUV("preview", addr, size);
1160         });
1161         Test_->consumerMap_[Test_->streamInfo->intent_] = consumer;
1162         Test_->streamInfos.push_back(Test_->streamInfo);
1163         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
1164         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1165         // release stream
1166         std::vector<int> streamIds;
1167         streamIds.push_back(Test_->streamInfo->streamId_);
1168         Test_->rc = Test_->streamOperator->ReleaseStreams(streamIds);
1169         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1170     }
1171     result = OHOS::system::SetParameter(property, "off");
1172 }
1173 
1174 /**
1175   * @tc.name: Hdi_CommitStreams_Timeout.
1176   * @tc.desc: mock Hdi_CommitStreams_Timeout.
1177   * @tc.size: MediumTest
1178   * @tc.type: DFX
1179   */
1180 HWTEST_F(DfxTest, Camera_Dfx_0023, TestSize.Level3)
1181 {
1182     std::cout << "==========[test log] Dfx: mock Hdi_CommitStreams_Timeout." << std::endl;
1183     bool result = false;
1184     std::string property = "Hdi_CommitStreams_Timeout";
1185     std::string value = "on";
1186     result = OHOS::system::SetParameter(property, value);
1187     if (result) {
1188         std::string parameter = OHOS::system::GetParameter(property, value);
1189         std::cout << "==========[test log] DFX: GetProperty Hdi_CommitStreams_Timeout = " << parameter << std::endl;
1190         Test_->Open();
1191         // Start stream
1192         Test_->intents = {Camera::PREVIEW};
1193         Test_->StartStream(Test_->intents);
1194         // release stream
1195         Test_->captureIds = {};
1196         Test_->streamIds = {Test_->streamId_preview};
1197         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1198         Test_->StopConsumer(Test_->intents);
1199     }
1200 }
1201 
1202 /**
1203   * @tc.name: Hdi_AttachBufferQueue_Timeout.
1204   * @tc.desc: mock Hdi_AttachBufferQueue_Timeout.
1205   * @tc.size: MediumTest
1206   * @tc.type: DFX
1207   */
1208 HWTEST_F(DfxTest, Camera_Dfx_0024, TestSize.Level3)
1209 {
1210     std::cout << "==========[test log] Dfx: mock Hdi_AttachBufferQueue_Timeout." << std::endl;
1211     bool result = false;
1212     std::string property = "Hdi_AttachBufferQueue_Timeout";
1213     std::string value = "on";
1214     result = OHOS::system::SetParameter(property, value);
1215     if (result) {
1216         std::string parameter = OHOS::system::GetParameter(property, value);
1217         std::cout << "==========[test log] DFX: GetProperty Hdi_AttachBufferQueue_Timeout = " << parameter << std::endl;
1218         Test_->Open();
1219         Test_->streamOperatorCallback = new StreamOperatorCallback();
1220         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
1221         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1222         // Create data stream
1223         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
1224         Test_->streamInfo->streamId_ = 1001;
1225         Test_->streamInfo->height_ = 480;
1226         Test_->streamInfo->width_ = 640;
1227         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
1228         Test_->streamInfo->dataspace_ = 8;
1229         Test_->streamInfo->intent_ = Camera::PREVIEW;
1230         Test_->streamInfo->tunneledMode_ = 5;
1231         std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos);
1232         Test_->streamInfos.push_back(Test_->streamInfo);
1233         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
1234         std::cout << "==========[test log]Check hdi: streamOperator->CreateStreams's rc " << Test_->rc << std::endl;
1235         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1236         // Distribution stream
1237         Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability);
1238         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1239         std::cout << "==========[test log]Check hdi: streamOperator->CommitStreams's rc " << Test_->rc << std::endl;
1240         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
1241         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0a02(void* addr, uint32_t size) 1242         OHOS::sptr<OHOS::IBufferProducer> producer = consumer->CreateProducer([this](void* addr, uint32_t size) {
1243             Test_->SaveYUV("preview", addr, size);
1244         });
1245         Test_->rc = Test_->streamOperator->AttachBufferQueue(Test_->streamInfo->streamId_, producer);
1246         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1247         if (Test_->rc == Camera::NO_ERROR) {
1248             std::cout << "==========[test log]Check hdi: AttachBufferQueue success. " << std::endl;
1249         } else {
1250             std::cout << "==========[test log]Check hdi: AttachBufferQueue fail, rc = " << Test_->rc << std::endl;
1251         }
1252         // release stream
1253         Test_->captureIds = {};
1254         Test_->streamIds = {1001};
1255         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1256         Test_->StopConsumer(Test_->intents);
1257     }
1258     result = OHOS::system::SetParameter(property, "off");
1259 }
1260 
1261 /**
1262   * @tc.name: Hdi_DetachBufferQueue_Timeout.
1263   * @tc.desc: mock Hdi_DetachBufferQueue_Timeout.
1264   * @tc.size: MediumTest
1265   * @tc.type: DFX
1266   */
1267 HWTEST_F(DfxTest, Camera_Dfx_0025, TestSize.Level3)
1268 {
1269     std::cout << "==========[test log] Dfx: mock Hdi_DetachBufferQueue_Timeout." << std::endl;
1270     bool result = false;
1271     std::string property = "Hdi_DetachBufferQueue_Timeout";
1272     std::string value = "on";
1273     result = OHOS::system::SetParameter(property, value);
1274     if (result) {
1275         std::string parameter = OHOS::system::GetParameter(property, value);
1276         std::cout << "==========[test log] DFX: GetProperty Hdi_DetachBufferQueue_Timeout = " << parameter << std::endl;
1277         Test_->Open();
1278         Test_->streamOperatorCallback = new StreamOperatorCallback();
1279         Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
1280         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1281         // Create data stream
1282         Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
1283         Test_->streamInfo->streamId_ = 1001;
1284         Test_->streamInfo->width_ = 640;
1285         Test_->streamInfo->height_ = 480;
1286         Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
1287         Test_->streamInfo->intent_ = Camera::PREVIEW;
1288         Test_->streamInfo->dataspace_ = 8;
1289         Test_->streamInfo->tunneledMode_ = 5;
1290         std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos);
1291         Test_->streamInfos.push_back(Test_->streamInfo);
1292         Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
1293         std::cout << "==========[test log]Check hdi: streamOperator->CreateStreams's rc " << Test_->rc << std::endl;
1294         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1295         // Distribution stream
1296         Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability);
1297         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1298         std::cout << "==========[test log]Check hdi: streamOperator->CommitStreams's rc " << Test_->rc << std::endl;
1299         std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
1300         std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon42dcb3cf0b02(void* addr, uint32_t size) 1301         OHOS::sptr<OHOS::IBufferProducer> producer = consumer->CreateProducer([this](void* addr, uint32_t size) {
1302             Test_->SaveYUV("preview", addr, size);
1303         });
1304         Test_->rc = Test_->streamOperator->AttachBufferQueue(Test_->streamInfo->streamId_, producer);
1305         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1306         if (Test_->rc == Camera::NO_ERROR) {
1307             std::cout << "==========[test log]Check hdi: AttachBufferQueue success. " << std::endl;
1308         } else {
1309             std::cout << "==========[test log]Check hdi: AttachBufferQueue fail, rc = " << Test_->rc << std::endl;
1310         }
1311         sleep(3); // sleep for 3 seconds
1312         Test_->rc = Test_->streamOperator->DetachBufferQueue(Test_->streamInfo->streamId_);
1313         std::cout << "==========[test log]Check hdi: streamOperator->DetachBufferQueue's rc " << Test_->rc << std::endl;
1314         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
1315         // release stream
1316         Test_->captureIds = {};
1317         Test_->streamIds = {1001};
1318         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1319         Test_->StopConsumer(Test_->intents);
1320     }
1321     result = OHOS::system::SetParameter(property, "off");
1322 }
1323 
1324 /**
1325   * @tc.name: Hdi_Capture_Timeout.
1326   * @tc.desc: mock Hdi_Capture_Timeout.
1327   * @tc.size: MediumTest
1328   * @tc.type: DFX
1329   */
1330 HWTEST_F(DfxTest, Camera_Dfx_0026, TestSize.Level3)
1331 {
1332     std::cout << "==========[test log] Dfx: mock Hdi_Capture_Timeout." << std::endl;
1333     bool result = false;
1334     std::string property = "Hdi_Capture_Timeout";
1335     std::string value = "on";
1336     result = OHOS::system::SetParameter(property, value);
1337     if (result) {
1338         std::string parameter = OHOS::system::GetParameter(property, value);
1339         std::cout << "==========[test log] DFX: GetProperty Hdi_Capture_Timeout = " << parameter << std::endl;
1340         Test_->Open();
1341         // Configure preview stream information
1342         Test_->intents = {Camera::PREVIEW};
1343         Test_->StartStream(Test_->intents);
1344         // Capture preview stream
1345         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, true, true);
1346         // post-processing
1347         Test_->captureIds = {Test_->captureId_preview};
1348         Test_->streamIds = {Test_->streamId_preview};
1349         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1350         Test_->StopConsumer(Test_->intents);
1351     }
1352 }
1353 
1354 /**
1355   * @tc.name: Hdi_ChangeToOfflineStream_Timeout.
1356   * @tc.desc: mock Hdi_ChangeToOfflineStream_Timeout.
1357   * @tc.size: MediumTest
1358   * @tc.type: DFX
1359   */
1360 HWTEST_F(DfxTest, Camera_Dfx_0027, TestSize.Level3)
1361 {
1362     std::cout << "==========[test log] Dfx: mock Hdi_ChangeToOfflineStream_Timeout." << std::endl;
1363     bool result = false;
1364     std::string property = "Hdi_ChangeToOfflineStream_Timeout";
1365     std::string value = "on";
1366     result = OHOS::system::SetParameter(property, value);
1367     if (result) {
1368         std::string parameter = OHOS::system::GetParameter(property, value);
1369         std::cout << "======[test log] DFX: GetProperty Hdi_ChangeToOfflineStream_Timeout = " << parameter << std::endl;
1370         Test_->Open();
1371         // 1. Configure two streams of information
1372         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
1373         Test_->StartStream(Test_->intents);
1374         // 2. Capture the preview stream
1375         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
1376         // 3. Capture the camera stream, continuous shooting
1377         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
1378         sleep(3); // sleep for 3 seconds
1379         // 4. Convert to offline stream
1380         Test_->offlineStreamOperatorCallback = Test_->streamOperatorCallback;
1381         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
1382             {Test_->streamId_capture}, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
1383         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
1384         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
1385         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
1386         if (Test_->rc == Camera::NO_ERROR) {
1387             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
1388         } else {
1389             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
1390         }
1391         // 5. Post-processing of the original stream
1392         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
1393         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
1394         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1395         // 6. Post-processing of offline streams
1396         Test_->cameraDevice->Close();
1397         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
1398         sleep(3); // sleep for 3 seconds
1399         Test_->StopOfflineStream(Test_->captureId_capture);
1400         Test_->StopConsumer(Test_->intents);
1401     }
1402 }
1403 
1404 /**
1405   * @tc.name: Hdi_Offline_CancelCapture_Timeout.
1406   * @tc.desc: mock Hdi_Offline_ReleaseStreams_Timeout.
1407   * @tc.size: MediumTest
1408   * @tc.type: DFX
1409   */
1410 HWTEST_F(DfxTest, Camera_Dfx_0030, TestSize.Level3)
1411 {
1412     std::cout << "=======[test log] Dfx: mock Hdi_Offline_CancelCapture_Timeout." << std::endl;
1413     bool result = false;
1414     std::string property = "Hdi_Offline_CancelCapture_Timeout";
1415     std::string value = "on";
1416     result = OHOS::system::SetParameter(property, value);
1417     if (result) {
1418         std::string parameter = OHOS::system::GetParameter(property, value);
1419         std::cout << "====[test log] DFX: GetProperty Hdi_Offline_CancelCapture_Timeout = " << parameter << std::endl;
1420         Test_->Open();
1421         // 1. Configure two streams of information
1422         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
1423         Test_->StartStream(Test_->intents);
1424         // 2. Capture the preview stream
1425         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
1426         // 3. Capture the camera stream, continuous shooting
1427         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
1428         sleep(3); // sleep for 3 seconds
1429         // 4. Convert to offline stream
1430         Test_->offlineStreamOperatorCallback = Test_->streamOperatorCallback;
1431         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
1432             {Test_->streamId_capture}, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
1433         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
1434         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
1435         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
1436         if (Test_->rc == Camera::NO_ERROR) {
1437             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
1438         } else {
1439             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
1440         }
1441         // 5. Post-processing of the original stream
1442         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
1443         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
1444         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1445         // 6. Post-processing of offline streams
1446         Test_->cameraDevice->Close();
1447         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
1448         sleep(3); // sleep for 3 seconds
1449         Test_->StopOfflineStream(Test_->captureId_capture);
1450         Test_->StopConsumer(Test_->intents);
1451     }
1452 }
1453 
1454 /**
1455   * @tc.name: Hdi_Offline_ReleaseStreams_Timeout.
1456   * @tc.desc: mock Hdi_Offline_ReleaseStreams_Timeout.
1457   * @tc.size: MediumTest
1458   * @tc.type: DFX
1459   */
1460 HWTEST_F(DfxTest, Camera_Dfx_0031, TestSize.Level3)
1461 {
1462     std::cout << "==========[test log] Dfx: mock Hdi_Offline_ReleaseStreams_Timeout." << std::endl;
1463     bool result = false;
1464     std::string property = "Hdi_Offline_ReleaseStreams_Timeout";
1465     std::string value = "on";
1466     result = OHOS::system::SetParameter(property, value);
1467     if (result) {
1468         std::string parameter = OHOS::system::GetParameter(property, value);
1469         std::cout << "======[test log] DFX: GetProperty Hdi_Offline_ReleaseStreams_Timeout = ";
1470         std::cout << parameter << std::endl;
1471         Test_->Open();
1472         // 1. Configure two streams of information
1473         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
1474         Test_->StartStream(Test_->intents);
1475         // 2. Capture the preview stream
1476         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
1477         // 3. Capture the camera stream, continuous shooting
1478         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
1479         sleep(3); // sleep for 3 seconds
1480         // 4. Convert to offline stream
1481         Test_->offlineStreamOperatorCallback = Test_->streamOperatorCallback;
1482         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
1483             {Test_->streamId_capture}, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
1484         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
1485         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
1486         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
1487         if (Test_->rc == Camera::NO_ERROR) {
1488             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
1489         } else {
1490             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
1491         }
1492         // 5. Post-processing of the original stream
1493         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
1494         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
1495         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1496         // 6. Post-processing of offline streams
1497         Test_->cameraDevice->Close();
1498         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
1499         sleep(3); // sleep for 3 seconds
1500         Test_->StopOfflineStream(Test_->captureId_capture);
1501         Test_->StopConsumer(Test_->intents);
1502     }
1503 }
1504 
1505 /**
1506   * @tc.name: Hdi_Offline_Release_Timeout.
1507   * @tc.desc: mock Hdi_Offline_Release_Timeout.
1508   * @tc.size: MediumTest
1509   * @tc.type: DFX
1510   */
1511 HWTEST_F(DfxTest, Camera_Dfx_0032, TestSize.Level3)
1512 {
1513     std::cout << "==========[test log] Dfx: mock Hdi_Offline_Release_Timeout." << std::endl;
1514     bool result = false;
1515     std::string property = "Hdi_Offline_Release_Timeout";
1516     std::string value = "on";
1517     result = OHOS::system::SetParameter(property, value);
1518     if (result) {
1519         std::string parameter = OHOS::system::GetParameter(property, value);
1520         std::cout << "==========[test log] DFX: GetProperty Hdi_Offline_Release_Timeout = " << parameter << std::endl;
1521         Test_->Open();
1522         // 1. Configure two streams of information
1523         Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
1524         Test_->StartStream(Test_->intents);
1525         // 2. Capture the preview stream
1526         Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
1527         // 3. Capture the camera stream, continuous shooting
1528         Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
1529         sleep(3); // sleep for 3 seconds
1530         // 4. Convert to offline stream
1531         Test_->offlineStreamOperatorCallback = Test_->streamOperatorCallback;
1532         Test_->rc = Test_->streamOperator->ChangeToOfflineStream(
1533             {Test_->streamId_capture}, Test_->offlineStreamOperatorCallback, Test_->offlineStreamOperator);
1534         ASSERT_EQ(Test_->rc, Camera::NO_ERROR);
1535         std::cout << "==========[test log] ChangeToOfflineStream rc = " << Test_->rc << std::endl;
1536         EXPECT_EQ(true, Test_->offlineStreamOperator != nullptr);
1537         if (Test_->rc == Camera::NO_ERROR) {
1538             std::cout << "==========[test log] offline StreamOperator != nullptr" << std::endl;
1539         } else {
1540             std::cout << "==========[test log] offline StreamOperator == nullptr" << std::endl;
1541         }
1542         // 5. Post-processing of the original stream
1543         Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
1544         Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
1545         Test_->StopStream(Test_->captureIds, Test_->streamIds);
1546         // 6. Post-processing of offline streams
1547         Test_->cameraDevice->Close();
1548         std::cout << "==========[test log] Pretend to wait 5s for callback..." << std::endl;
1549         sleep(3); // sleep for 3 seconds
1550         Test_->StopOfflineStream(Test_->captureId_capture);
1551         Test_->StopConsumer(Test_->intents);
1552     }
1553 }
1554 #endif
1555