xref: /aosp_15_r20/hardware/libhardware/modules/camera/3_4/static_properties_test.cpp (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "static_properties.h"
18 
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 #include <hardware/camera3.h>
22 #include <system/camera.h>
23 
24 #include "metadata/metadata_reader_mock.h"
25 
26 using testing::AtMost;
27 using testing::DoAll;
28 using testing::Expectation;
29 using testing::Return;
30 using testing::SetArgPointee;
31 using testing::Test;
32 using testing::_;
33 
34 namespace default_camera_hal {
35 
36 class StaticPropertiesTest : public Test {
37  protected:
SetUp()38   virtual void SetUp() {
39     // Ensure tests will probably fail if PrepareDUT isn't called.
40     dut_.reset();
41     mock_reader_ = std::make_unique<MetadataReaderMock>();
42   }
43 
PrepareDUT()44   void PrepareDUT() {
45     dut_.reset(StaticProperties::NewStaticProperties(std::move(mock_reader_)));
46   }
47 
PrepareDefaultDUT()48   void PrepareDefaultDUT() {
49     SetDefaultExpectations();
50     PrepareDUT();
51     ASSERT_NE(dut_, nullptr);
52   }
53 
SetDefaultExpectations()54   void SetDefaultExpectations() {
55     EXPECT_CALL(*mock_reader_, Facing(_))
56         .Times(AtMost(1))
57         .WillOnce(DoAll(SetArgPointee<0>(test_facing_), Return(0)));
58     EXPECT_CALL(*mock_reader_, Orientation(_))
59         .Times(AtMost(1))
60         .WillOnce(DoAll(SetArgPointee<0>(test_orientation_), Return(0)));
61     EXPECT_CALL(*mock_reader_, MaxInputStreams(_))
62         .Times(AtMost(1))
63         .WillOnce(DoAll(SetArgPointee<0>(test_max_inputs_), Return(0)));
64     EXPECT_CALL(*mock_reader_, MaxOutputStreams(_, _, _))
65         .Times(AtMost(1))
66         .WillOnce(DoAll(SetArgPointee<0>(test_max_raw_outputs_),
67                         SetArgPointee<1>(test_max_non_stalling_outputs_),
68                         SetArgPointee<2>(test_max_stalling_outputs_),
69                         Return(0)));
70     EXPECT_CALL(*mock_reader_, RequestCapabilities(_))
71         .Times(AtMost(1))
72         .WillOnce(
73             DoAll(SetArgPointee<0>(test_request_capabilities_), Return(0)));
74     EXPECT_CALL(*mock_reader_, StreamConfigurations(_))
75         .Times(AtMost(1))
76         .WillOnce(DoAll(SetArgPointee<0>(test_configs_), Return(0)));
77     EXPECT_CALL(*mock_reader_, StreamStallDurations(_))
78         .Times(AtMost(1))
79         .WillOnce(DoAll(SetArgPointee<0>(test_stalls_), Return(0)));
80     EXPECT_CALL(*mock_reader_, ReprocessFormats(_))
81         .Times(AtMost(1))
82         .WillOnce(DoAll(SetArgPointee<0>(test_reprocess_map_), Return(0)));
83   }
84 
MakeStream(int32_t format,bool output=true,bool input=false,int32_t width=kWidth,int32_t height=kHeight)85   camera3_stream_t MakeStream(int32_t format,
86                               bool output = true,
87                               bool input = false,
88                               int32_t width = kWidth,
89                               int32_t height = kHeight) {
90     int type = -1;
91     if (output && input) {
92       type = CAMERA3_STREAM_BIDIRECTIONAL;
93     } else if (output) {
94       type = CAMERA3_STREAM_OUTPUT;
95     } else if (input) {
96       type = CAMERA3_STREAM_INPUT;
97     }
98     camera3_stream_t stream;
99     stream.stream_type = type;
100     stream.width = width;
101     stream.height = height;
102     stream.format = format;
103     return stream;
104   }
105 
ExpectConfigurationSupported(std::vector<camera3_stream_t> & streams,bool expected)106   void ExpectConfigurationSupported(std::vector<camera3_stream_t>& streams,
107                                     bool expected) {
108     std::vector<camera3_stream_t*> stream_addresses;
109     for (size_t i = 0; i < streams.size(); ++i) {
110       stream_addresses.push_back(&streams[i]);
111     }
112     camera3_stream_configuration_t config = {
113         static_cast<uint32_t>(stream_addresses.size()),
114         stream_addresses.data(),
115         CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE,
116         nullptr};
117     PrepareDefaultDUT();
118     EXPECT_EQ(dut_->StreamConfigurationSupported(&config), expected);
119   }
120 
121   std::unique_ptr<StaticProperties> dut_;
122   std::unique_ptr<MetadataReaderMock> mock_reader_;
123 
124   // Some helper values used for stream testing.
125   static constexpr int32_t kWidth = 320;
126   static constexpr int32_t kHeight = 240;
127   static constexpr int32_t kAlternateWidth = 640;
128   static constexpr int32_t kAlternateHeight = 480;
129 
130   const int test_facing_ = CAMERA_FACING_FRONT;
131   const int test_orientation_ = 90;
132   const int32_t test_max_inputs_ = 3;
133   const int32_t test_max_raw_outputs_ = 1;
134   const int32_t test_max_non_stalling_outputs_ = 2;
135   const int32_t test_max_stalling_outputs_ = 3;
136   const std::set<uint8_t> test_request_capabilities_ = {
137       ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE,
138       ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR,
139       ANDROID_REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING};
140 
141   // Some formats for various purposes (in various combinations,
142   // these types should be capable of testing all failure conditions).
143   const int32_t output_multisize_non_stalling_ = 1;
144   const int32_t bidirectional_self_supporting_stalling_ = 2;
145   const int32_t bidirectional_raw_ = HAL_PIXEL_FORMAT_RAW10;
146   const int32_t input_ = 3;
147   const int32_t other = input_;
148 
149   const std::vector<StreamConfiguration> test_configs_ = {
150       {{{output_multisize_non_stalling_,
151          kWidth,
152          kHeight,
153          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}},
154       {{{output_multisize_non_stalling_,
155          kAlternateWidth,
156          kAlternateHeight,
157          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}},
158       {{{bidirectional_self_supporting_stalling_,
159          kWidth,
160          kHeight,
161          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT}}},
162       {{{bidirectional_self_supporting_stalling_,
163          kWidth,
164          kHeight,
165          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}},
166       {{{bidirectional_raw_,
167          kWidth,
168          kHeight,
169          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT}}},
170       {{{bidirectional_raw_,
171          kWidth,
172          kHeight,
173          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}},
174       {{{input_,
175          kWidth,
176          kHeight,
177          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT}}}};
178   // Raw having a stall duration shouldn't matter,
179   // it should still be counted as the raw type.
180   const std::vector<StreamStallDuration> test_stalls_ = {
181       {{{output_multisize_non_stalling_, kWidth, kHeight, 0}}},
182       {{{output_multisize_non_stalling_,
183          kAlternateWidth,
184          kAlternateHeight,
185          0}}},
186       {{{bidirectional_self_supporting_stalling_, kWidth, kHeight, 10}}},
187       {{{bidirectional_raw_, kWidth, kHeight, 15}}}};
188   // Format 2 can go to itself or 1. 3 and RAW can only go to 1.
189   const ReprocessFormatMap test_reprocess_map_ = {
190       {bidirectional_self_supporting_stalling_,
191        {output_multisize_non_stalling_,
192         bidirectional_self_supporting_stalling_}},
193       {bidirectional_raw_, {output_multisize_non_stalling_}},
194       {input_, {output_multisize_non_stalling_}}};
195   // Codify the above information about format capabilities in some helpful
196   // vectors.
197   int32_t multi_size_format_ = 1;
198   const std::vector<int32_t> input_formats_ = {2, 3, HAL_PIXEL_FORMAT_RAW10};
199   const std::vector<int32_t> output_formats_ = {1, 2, HAL_PIXEL_FORMAT_RAW10};
200 };
201 
TEST_F(StaticPropertiesTest,FactorySuccess)202 TEST_F(StaticPropertiesTest, FactorySuccess) {
203   PrepareDefaultDUT();
204   EXPECT_EQ(dut_->facing(), test_facing_);
205   EXPECT_EQ(dut_->orientation(), test_orientation_);
206 
207   // Stream configurations tested seperately.
208 }
209 
TEST_F(StaticPropertiesTest,FactoryFailedFacing)210 TEST_F(StaticPropertiesTest, FactoryFailedFacing) {
211   SetDefaultExpectations();
212   // Override with a failure expectation.
213   EXPECT_CALL(*mock_reader_, Facing(_)).WillOnce(Return(99));
214   PrepareDUT();
215   EXPECT_EQ(dut_, nullptr);
216 }
217 
TEST_F(StaticPropertiesTest,FactoryFailedOrientation)218 TEST_F(StaticPropertiesTest, FactoryFailedOrientation) {
219   SetDefaultExpectations();
220   // Override with a failure expectation.
221   EXPECT_CALL(*mock_reader_, Orientation(_)).WillOnce(Return(99));
222   PrepareDUT();
223   EXPECT_EQ(dut_, nullptr);
224 }
225 
TEST_F(StaticPropertiesTest,FactoryFailedMaxInputs)226 TEST_F(StaticPropertiesTest, FactoryFailedMaxInputs) {
227   SetDefaultExpectations();
228   // Override with a failure expectation.
229   EXPECT_CALL(*mock_reader_, MaxInputStreams(_)).WillOnce(Return(99));
230   PrepareDUT();
231   EXPECT_EQ(dut_, nullptr);
232 }
233 
TEST_F(StaticPropertiesTest,FactoryFailedMaxOutputs)234 TEST_F(StaticPropertiesTest, FactoryFailedMaxOutputs) {
235   SetDefaultExpectations();
236   // Override with a failure expectation.
237   EXPECT_CALL(*mock_reader_, MaxOutputStreams(_, _, _)).WillOnce(Return(99));
238   PrepareDUT();
239   EXPECT_EQ(dut_, nullptr);
240 }
241 
TEST_F(StaticPropertiesTest,FactoryFailedRequestCapabilities)242 TEST_F(StaticPropertiesTest, FactoryFailedRequestCapabilities) {
243   SetDefaultExpectations();
244   // Override with a failure expectation.
245   EXPECT_CALL(*mock_reader_, RequestCapabilities(_)).WillOnce(Return(99));
246   PrepareDUT();
247   EXPECT_EQ(dut_, nullptr);
248 }
249 
TEST_F(StaticPropertiesTest,FactoryFailedStreamConfigs)250 TEST_F(StaticPropertiesTest, FactoryFailedStreamConfigs) {
251   SetDefaultExpectations();
252   // Override with a failure expectation.
253   EXPECT_CALL(*mock_reader_, StreamConfigurations(_)).WillOnce(Return(99));
254   PrepareDUT();
255   EXPECT_EQ(dut_, nullptr);
256 }
257 
TEST_F(StaticPropertiesTest,FactoryFailedStallDurations)258 TEST_F(StaticPropertiesTest, FactoryFailedStallDurations) {
259   SetDefaultExpectations();
260   // Override with a failure expectation.
261   EXPECT_CALL(*mock_reader_, StreamStallDurations(_)).WillOnce(Return(99));
262   PrepareDUT();
263   EXPECT_EQ(dut_, nullptr);
264 }
265 
TEST_F(StaticPropertiesTest,FactoryFailedReprocessFormats)266 TEST_F(StaticPropertiesTest, FactoryFailedReprocessFormats) {
267   SetDefaultExpectations();
268   // Override with a failure expectation.
269   EXPECT_CALL(*mock_reader_, ReprocessFormats(_)).WillOnce(Return(99));
270   PrepareDUT();
271   EXPECT_EQ(dut_, nullptr);
272 }
273 
TEST_F(StaticPropertiesTest,FactoryNoReprocessFormats)274 TEST_F(StaticPropertiesTest, FactoryNoReprocessFormats) {
275   // If there are no inputs allowed, the reprocess formats shouldn't matter.
276   SetDefaultExpectations();
277   // Override max inputs.
278   EXPECT_CALL(*mock_reader_, MaxInputStreams(_))
279       .WillOnce(DoAll(SetArgPointee<0>(0), Return(0)));
280   // Override reprocess formats with a failure expectation.
281   EXPECT_CALL(*mock_reader_, ReprocessFormats(_))
282       .Times(AtMost(1))
283       .WillOnce(Return(99));
284   PrepareDUT();
285   // Should be ok.
286   EXPECT_NE(dut_, nullptr);
287 }
288 
TEST_F(StaticPropertiesTest,FactoryInvalidCapabilities)289 TEST_F(StaticPropertiesTest, FactoryInvalidCapabilities) {
290   SetDefaultExpectations();
291   // Override configs with an extra output format.
292   std::vector<StreamConfiguration> configs = test_configs_;
293   configs.push_back(
294       {{{5,
295          kWidth,
296          kHeight,
297          ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}});
298   EXPECT_CALL(*mock_reader_, StreamConfigurations(_))
299       .WillOnce(DoAll(SetArgPointee<0>(configs), Return(0)));
300   PrepareDUT();
301   // Should fail because not every output has a stall.
302   EXPECT_EQ(dut_, nullptr);
303 }
304 
TEST_F(StaticPropertiesTest,InvalidReprocessNoInputs)305 TEST_F(StaticPropertiesTest, InvalidReprocessNoInputs) {
306   SetDefaultExpectations();
307   // Override configs by removing all inputs.
308   std::vector<StreamConfiguration> configs = test_configs_;
309   for (auto it = configs.begin(); it != configs.end();) {
310     if ((*it).direction ==
311         ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT) {
312       it = configs.erase(it);
313     } else {
314       ++it;
315     }
316   }
317   EXPECT_CALL(*mock_reader_, StreamConfigurations(_))
318       .WillOnce(DoAll(SetArgPointee<0>(configs), Return(0)));
319   PrepareDUT();
320   // Should fail because inputs are supported but there are no input formats.
321   EXPECT_EQ(dut_, nullptr);
322 }
323 
TEST_F(StaticPropertiesTest,InvalidReprocessExtraInput)324 TEST_F(StaticPropertiesTest, InvalidReprocessExtraInput) {
325   SetDefaultExpectations();
326   // Override configs with an extra input format.
327   std::vector<StreamConfiguration> configs = test_configs_;
328   configs.push_back({{{5,
329                        kWidth,
330                        kHeight,
331                        ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT}}});
332   EXPECT_CALL(*mock_reader_, StreamConfigurations(_))
333       .WillOnce(DoAll(SetArgPointee<0>(configs), Return(0)));
334   PrepareDUT();
335   // Should fail because no reprocess outputs are listed for the extra input.
336   EXPECT_EQ(dut_, nullptr);
337 }
338 
TEST_F(StaticPropertiesTest,InvalidReprocessExtraMapEntry)339 TEST_F(StaticPropertiesTest, InvalidReprocessExtraMapEntry) {
340   SetDefaultExpectations();
341   // Override the reprocess map with an extra entry.
342   ReprocessFormatMap reprocess_map = test_reprocess_map_;
343   reprocess_map[5] = {1};
344   EXPECT_CALL(*mock_reader_, ReprocessFormats(_))
345       .WillOnce(DoAll(SetArgPointee<0>(reprocess_map), Return(0)));
346   PrepareDUT();
347   // Should fail because the extra map entry doesn't correspond to an input.
348   EXPECT_EQ(dut_, nullptr);
349 }
350 
TEST_F(StaticPropertiesTest,InvalidReprocessWrongMapEntries)351 TEST_F(StaticPropertiesTest, InvalidReprocessWrongMapEntries) {
352   SetDefaultExpectations();
353   // Override the reprocess map replacing the entry for the
354   // input-only format with the output-only format.
355   ReprocessFormatMap reprocess_map = test_reprocess_map_;
356   reprocess_map.erase(input_);
357   reprocess_map[output_multisize_non_stalling_] = {1};
358   EXPECT_CALL(*mock_reader_, ReprocessFormats(_))
359       .WillOnce(DoAll(SetArgPointee<0>(reprocess_map), Return(0)));
360   PrepareDUT();
361   // Should fail because not all input formats are present/
362   // one of the map "input" formats is output only.
363   EXPECT_EQ(dut_, nullptr);
364 }
365 
TEST_F(StaticPropertiesTest,InvalidReprocessNotAnOutput)366 TEST_F(StaticPropertiesTest, InvalidReprocessNotAnOutput) {
367   SetDefaultExpectations();
368   // Override the reprocess map with a non-output output entry.
369   ReprocessFormatMap reprocess_map = test_reprocess_map_;
370   reprocess_map[input_].insert(input_);
371   EXPECT_CALL(*mock_reader_, ReprocessFormats(_))
372       .WillOnce(DoAll(SetArgPointee<0>(reprocess_map), Return(0)));
373   PrepareDUT();
374   // Should fail because a specified output format doesn't support output.
375   EXPECT_EQ(dut_, nullptr);
376 }
377 
TEST_F(StaticPropertiesTest,TemplatesValid)378 TEST_F(StaticPropertiesTest, TemplatesValid) {
379   PrepareDefaultDUT();
380   for (int i = 1; i < CAMERA3_TEMPLATE_COUNT; ++i) {
381     EXPECT_TRUE(dut_->TemplateSupported(i));
382   }
383 }
384 
TEST_F(StaticPropertiesTest,ConfigureSingleOutput)385 TEST_F(StaticPropertiesTest, ConfigureSingleOutput) {
386   std::vector<camera3_stream_t> streams;
387   streams.push_back(MakeStream(output_multisize_non_stalling_));
388   ExpectConfigurationSupported(streams, true);
389 }
390 
TEST_F(StaticPropertiesTest,ConfigureMultipleOutputs)391 TEST_F(StaticPropertiesTest, ConfigureMultipleOutputs) {
392   std::vector<camera3_stream_t> streams;
393   // 2 outputs, of different sizes.
394   streams.push_back(MakeStream(bidirectional_raw_));
395   // Use the alternate size.
396   streams.push_back(MakeStream(output_multisize_non_stalling_,
397                                true,
398                                false,
399                                kAlternateWidth,
400                                kAlternateHeight));
401   ExpectConfigurationSupported(streams, true);
402 }
403 
TEST_F(StaticPropertiesTest,ConfigureInput)404 TEST_F(StaticPropertiesTest, ConfigureInput) {
405   std::vector<camera3_stream_t> streams;
406   // Single input -> different output.
407   streams.push_back(MakeStream(input_, false, true));
408   // Use the alternate size, it should be ok.
409   streams.push_back(MakeStream(output_multisize_non_stalling_,
410                                true,
411                                false,
412                                kAlternateWidth,
413                                kAlternateHeight));
414   ExpectConfigurationSupported(streams, true);
415 }
416 
TEST_F(StaticPropertiesTest,ConfigureBidirectional)417 TEST_F(StaticPropertiesTest, ConfigureBidirectional) {
418   std::vector<camera3_stream_t> streams;
419   // Single input -> same output.
420   streams.push_back(
421       MakeStream(bidirectional_self_supporting_stalling_, true, true));
422   ExpectConfigurationSupported(streams, true);
423 }
424 
TEST_F(StaticPropertiesTest,ConfigureMultipleReprocess)425 TEST_F(StaticPropertiesTest, ConfigureMultipleReprocess) {
426   std::vector<camera3_stream_t> streams;
427   // Single input -> multiple outputs.
428   streams.push_back(
429       MakeStream(bidirectional_self_supporting_stalling_, true, true));
430   streams.push_back(MakeStream(output_multisize_non_stalling_));
431   ExpectConfigurationSupported(streams, true);
432 }
433 
TEST_F(StaticPropertiesTest,ConfigureNull)434 TEST_F(StaticPropertiesTest, ConfigureNull) {
435   PrepareDefaultDUT();
436   EXPECT_FALSE(dut_->StreamConfigurationSupported(nullptr));
437 }
438 
TEST_F(StaticPropertiesTest,ConfigureEmptyStreams)439 TEST_F(StaticPropertiesTest, ConfigureEmptyStreams) {
440   std::vector<camera3_stream_t*> streams(1);
441   camera3_stream_configuration_t config = {
442       0, streams.data(), CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, nullptr};
443   PrepareDefaultDUT();
444   EXPECT_FALSE(dut_->StreamConfigurationSupported(&config));
445 }
446 
TEST_F(StaticPropertiesTest,ConfigureNullStreams)447 TEST_F(StaticPropertiesTest, ConfigureNullStreams) {
448   std::vector<camera3_stream_t*> streams(2, nullptr);
449   camera3_stream_configuration_t config = {
450       static_cast<uint32_t>(streams.size()),
451       streams.data(),
452       CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE,
453       nullptr};
454   PrepareDefaultDUT();
455   EXPECT_FALSE(dut_->StreamConfigurationSupported(&config));
456 }
457 
TEST_F(StaticPropertiesTest,ConfigureNullStreamVector)458 TEST_F(StaticPropertiesTest, ConfigureNullStreamVector) {
459   // Even if the camera claims to have multiple streams, check for null.
460   camera3_stream_configuration_t config = {
461       3, nullptr, CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, nullptr};
462   PrepareDefaultDUT();
463   EXPECT_FALSE(dut_->StreamConfigurationSupported(&config));
464 }
465 
TEST_F(StaticPropertiesTest,ConfigureNoOutput)466 TEST_F(StaticPropertiesTest, ConfigureNoOutput) {
467   std::vector<camera3_stream_t> streams;
468   // Only an input stream, no output.
469   streams.push_back(MakeStream(input_, false, true));
470   ExpectConfigurationSupported(streams, false);
471 }
472 
TEST_F(StaticPropertiesTest,ConfigureInvalidType)473 TEST_F(StaticPropertiesTest, ConfigureInvalidType) {
474   std::vector<camera3_stream_t> streams;
475   // Not input, output, or bidirectional.
476   streams.push_back(MakeStream(output_multisize_non_stalling_, false, false));
477   ExpectConfigurationSupported(streams, false);
478 }
479 
TEST_F(StaticPropertiesTest,ConfigureSpecFormatDoesNotExist)480 TEST_F(StaticPropertiesTest, ConfigureSpecFormatDoesNotExist) {
481   std::vector<camera3_stream_t> streams;
482   // Format 99 is not supported in any form.
483   streams.push_back(MakeStream(99));
484   ExpectConfigurationSupported(streams, false);
485 }
486 
TEST_F(StaticPropertiesTest,ConfigureSpecSizeDoesNotExist)487 TEST_F(StaticPropertiesTest, ConfigureSpecSizeDoesNotExist) {
488   std::vector<camera3_stream_t> streams;
489   // Size 99 x 99 not supported for the output format.
490   streams.push_back(
491       MakeStream(output_multisize_non_stalling_, true, false, 99, 99));
492   ExpectConfigurationSupported(streams, false);
493 }
494 
TEST_F(StaticPropertiesTest,ConfigureNotAnInput)495 TEST_F(StaticPropertiesTest, ConfigureNotAnInput) {
496   std::vector<camera3_stream_t> streams;
497   streams.push_back(MakeStream(output_multisize_non_stalling_));
498   // Can't use output-only format as an input.
499   streams.push_back(MakeStream(output_multisize_non_stalling_, false, true));
500   ExpectConfigurationSupported(streams, false);
501 }
502 
TEST_F(StaticPropertiesTest,ConfigureNotAnOutput)503 TEST_F(StaticPropertiesTest, ConfigureNotAnOutput) {
504   std::vector<camera3_stream_t> streams;
505   // Can't use input-only format as an output.
506   streams.push_back(MakeStream(input_));
507   ExpectConfigurationSupported(streams, false);
508 }
509 
TEST_F(StaticPropertiesTest,ConfigureTooManyInputs)510 TEST_F(StaticPropertiesTest, ConfigureTooManyInputs) {
511   std::vector<camera3_stream_t> streams;
512   // At the threshold is ok.
513   for (int32_t i = 0; i < test_max_inputs_; ++i) {
514     streams.push_back(MakeStream(input_, false, true));
515   }
516   // Have a valid output still.
517   streams.push_back(MakeStream(output_multisize_non_stalling_));
518   ExpectConfigurationSupported(streams, false);
519 
520   // Reset.
521   mock_reader_ = std::make_unique<MetadataReaderMock>();
522   streams.clear();
523 
524   // Try again with too many.
525   for (int32_t i = 0; i <= test_max_inputs_; ++i) {
526     streams.push_back(MakeStream(input_, false, true));
527   }
528   // Have a valid output still.
529   streams.push_back(MakeStream(output_multisize_non_stalling_));
530   ExpectConfigurationSupported(streams, false);
531 }
532 
TEST_F(StaticPropertiesTest,ConfigureTooManyRaw)533 TEST_F(StaticPropertiesTest, ConfigureTooManyRaw) {
534   std::vector<camera3_stream_t> streams;
535   // At the threshold is ok.
536   for (int32_t i = 0; i < test_max_raw_outputs_; ++i) {
537     streams.push_back(MakeStream(bidirectional_raw_));
538   }
539   ExpectConfigurationSupported(streams, true);
540 
541   // Reset.
542   mock_reader_ = std::make_unique<MetadataReaderMock>();
543   streams.clear();
544 
545   // Try again with too many.
546   for (int32_t i = 0; i <= test_max_raw_outputs_; ++i) {
547     streams.push_back(MakeStream(bidirectional_raw_));
548   }
549   ExpectConfigurationSupported(streams, false);
550 }
551 
TEST_F(StaticPropertiesTest,ConfigureTooManyStalling)552 TEST_F(StaticPropertiesTest, ConfigureTooManyStalling) {
553   std::vector<camera3_stream_t> streams;
554   // At the threshold is ok.
555   for (int32_t i = 0; i < test_max_stalling_outputs_; ++i) {
556     streams.push_back(MakeStream(bidirectional_self_supporting_stalling_));
557   }
558   ExpectConfigurationSupported(streams, true);
559 
560   // Reset.
561   mock_reader_ = std::make_unique<MetadataReaderMock>();
562   streams.clear();
563 
564   // Try again with too many.
565   for (int32_t i = 0; i <= test_max_stalling_outputs_; ++i) {
566     streams.push_back(MakeStream(bidirectional_self_supporting_stalling_));
567   }
568   ExpectConfigurationSupported(streams, false);
569 }
570 
TEST_F(StaticPropertiesTest,ConfigureTooManyNonStalling)571 TEST_F(StaticPropertiesTest, ConfigureTooManyNonStalling) {
572   std::vector<camera3_stream_t> streams;
573   // At the threshold is ok.
574   for (int32_t i = 0; i < test_max_non_stalling_outputs_; ++i) {
575     streams.push_back(MakeStream(output_multisize_non_stalling_));
576   }
577   ExpectConfigurationSupported(streams, true);
578 
579   // Reset.
580   mock_reader_ = std::make_unique<MetadataReaderMock>();
581   streams.clear();
582 
583   // Try again with too many.
584   for (int32_t i = 0; i <= test_max_non_stalling_outputs_; ++i) {
585     streams.push_back(MakeStream(output_multisize_non_stalling_));
586   }
587   ExpectConfigurationSupported(streams, false);
588 }
589 
TEST_F(StaticPropertiesTest,ConfigureUnuspportedInput)590 TEST_F(StaticPropertiesTest, ConfigureUnuspportedInput) {
591   std::vector<camera3_stream_t> streams;
592   streams.push_back(MakeStream(input_, false, true));
593   streams.push_back(MakeStream(bidirectional_raw_));
594   // No matching output format for input.
595   ExpectConfigurationSupported(streams, false);
596 }
597 
TEST_F(StaticPropertiesTest,ConfigureUnsupportedOutput)598 TEST_F(StaticPropertiesTest, ConfigureUnsupportedOutput) {
599   std::vector<camera3_stream_t> streams;
600   streams.push_back(MakeStream(input_, false, true));
601   // The universal output does match input.
602   streams.push_back(MakeStream(output_multisize_non_stalling_));
603   // Raw does not match input.
604   streams.push_back(MakeStream(bidirectional_raw_));
605   // Input is matched; it's ok that raw doesn't match (only the actual
606   // requests care).
607   ExpectConfigurationSupported(streams, true);
608 }
609 
TEST_F(StaticPropertiesTest,ConfigureUnsupportedBidirectional)610 TEST_F(StaticPropertiesTest, ConfigureUnsupportedBidirectional) {
611   std::vector<camera3_stream_t> streams;
612   // The test raw format, while supporting both input and output,
613   // does not actually support itself.
614   streams.push_back(MakeStream(bidirectional_raw_, true, true));
615   ExpectConfigurationSupported(streams, false);
616 }
617 
TEST_F(StaticPropertiesTest,ConfigureBadOperationMode)618 TEST_F(StaticPropertiesTest, ConfigureBadOperationMode) {
619   // A valid stream set.
620   camera3_stream_t stream = MakeStream(output_multisize_non_stalling_);
621   camera3_stream_t* stream_address = &stream;
622   // But not a valid config.
623   camera3_stream_configuration_t config = {
624       1,
625       &stream_address,
626       99, // Not a valid operation mode.
627       nullptr
628   };
629   PrepareDefaultDUT();
630   EXPECT_FALSE(dut_->StreamConfigurationSupported(&config));
631 }
632 
TEST_F(StaticPropertiesTest,ReprocessingSingleOutput)633 TEST_F(StaticPropertiesTest, ReprocessingSingleOutput) {
634   camera3_stream_t input_stream = MakeStream(input_);
635   camera3_stream_t output_stream = MakeStream(output_multisize_non_stalling_);
636   PrepareDefaultDUT();
637   EXPECT_TRUE(dut_->ReprocessingSupported(&input_stream, {&output_stream}));
638 }
639 
TEST_F(StaticPropertiesTest,ReprocessingMultipleOutputs)640 TEST_F(StaticPropertiesTest, ReprocessingMultipleOutputs) {
641   camera3_stream_t input_stream =
642       MakeStream(bidirectional_self_supporting_stalling_, false, true);
643   // Bi-directional self-supporting supports the universal output and itself.
644   camera3_stream_t output_stream1 = MakeStream(output_multisize_non_stalling_);
645   camera3_stream_t output_stream2 =
646       MakeStream(bidirectional_self_supporting_stalling_);
647   PrepareDefaultDUT();
648   EXPECT_TRUE(dut_->ReprocessingSupported(&input_stream,
649                                           {&output_stream1, &output_stream2}));
650 }
651 
TEST_F(StaticPropertiesTest,ReprocessingNoInput)652 TEST_F(StaticPropertiesTest, ReprocessingNoInput) {
653   camera3_stream_t output_stream = MakeStream(output_multisize_non_stalling_);
654   PrepareDefaultDUT();
655   EXPECT_FALSE(dut_->ReprocessingSupported(nullptr, {&output_stream}));
656 }
657 
TEST_F(StaticPropertiesTest,ReprocessingNoOutput)658 TEST_F(StaticPropertiesTest, ReprocessingNoOutput) {
659   camera3_stream_t input_stream = MakeStream(input_);
660   PrepareDefaultDUT();
661   EXPECT_FALSE(dut_->ReprocessingSupported(&input_stream, {}));
662 }
663 
TEST_F(StaticPropertiesTest,ReprocessingInvalidOutput)664 TEST_F(StaticPropertiesTest, ReprocessingInvalidOutput) {
665   camera3_stream_t input_stream = MakeStream(input_, false, true);
666   // The universal output does match input.
667   camera3_stream_t output_stream1 = MakeStream(output_multisize_non_stalling_);
668   // Raw does not match input.
669   camera3_stream_t output_stream2 = MakeStream(bidirectional_raw_);
670   PrepareDefaultDUT();
671   EXPECT_FALSE(dut_->ReprocessingSupported(&input_stream,
672                                            {&output_stream1, &output_stream2}));
673 }
674 
675 }  // namespace default_camera_hal
676