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