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