• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 <iostream>
18 #include <iomanip>
19 #include <gtest/gtest.h>
20 
21 #define LOG_TAG "CameraStreamTest"
22 #define LOG_NDEBUG 0
23 #include <utils/Log.h>
24 
25 #include "hardware/hardware.h"
26 #include "hardware/camera2.h"
27 
28 #include <utils/StrongPointer.h>
29 #include <gui/CpuConsumer.h>
30 #include <gui/Surface.h>
31 
32 #include "CameraStreamFixture.h"
33 #include "TestExtensions.h"
34 
35 using namespace android;
36 using namespace android::camera2;
37 
38 namespace android {
39 namespace camera2 {
40 namespace tests {
41 
42 class CameraStreamTest
43     : public ::testing::TestWithParam<CameraStreamParams>,
44       public CameraStreamFixture {
45 
46 public:
CameraStreamTest()47     CameraStreamTest() : CameraStreamFixture(GetParam()) {
48         TEST_EXTENSION_FORKING_CONSTRUCTOR;
49     }
50 
~CameraStreamTest()51     ~CameraStreamTest() {
52         TEST_EXTENSION_FORKING_DESTRUCTOR;
53     }
54 
SetUp()55     virtual void SetUp() {
56         TEST_EXTENSION_FORKING_SET_UP;
57     }
TearDown()58     virtual void TearDown() {
59         TEST_EXTENSION_FORKING_TEAR_DOWN;
60     }
61 
62 protected:
63 
64 };
65 
TEST_P(CameraStreamTest,CreateStream)66 TEST_P(CameraStreamTest, CreateStream) {
67 
68     TEST_EXTENSION_FORKING_INIT;
69 
70     /** Make sure the format requested is supported. PASS this test if it's not
71       * not supported.
72       *
73       * TODO: would be nice of not running this test in the first place
74       *       somehow.
75       */
76     {
77         camera_metadata_ro_entry availableFormats =
78             GetStaticEntry(ANDROID_SCALER_AVAILABLE_FORMATS);
79 
80         bool hasFormat = false;
81         for (size_t i = 0; i < availableFormats.count; ++i) {
82             if (availableFormats.data.i32[i] == GetParam().mFormat) {
83                 hasFormat = true;
84                 break;
85             }
86         }
87 
88         if (!hasFormat) {
89             const ::testing::TestInfo* const test_info =
90                 ::testing::UnitTest::GetInstance()->current_test_info();
91             std::cerr << "Skipping test "
92                       << test_info->test_case_name() << "."
93                       << test_info->name()
94                       << " because the format was not available: "
95                       << GetParam() << std::endl;
96             return;
97         }
98     }
99 
100     ASSERT_NO_FATAL_FAILURE(CreateStream());
101     ASSERT_NO_FATAL_FAILURE(DeleteStream());
102 }
103 
104 //TODO: use a combinatoric generator
105 static CameraStreamParams TestParameters[] = {
106     {
107         /*mFormat*/    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
108         /*mHeapCount*/ 1
109     },
110     {
111         /*mFormat*/    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
112         /*mHeapCount*/ 2
113     },
114     {
115         /*mFormat*/    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
116         /*mHeapCount*/ 3
117     },
118     {
119         /*mFormat*/    HAL_PIXEL_FORMAT_YCrCb_420_SP, // NV21
120         /*mHeapCount*/ 1
121     },
122     {
123         /*mFormat*/    HAL_PIXEL_FORMAT_YCrCb_420_SP,
124         /*mHeapCount*/ 2
125     },
126     {
127         /*mFormat*/    HAL_PIXEL_FORMAT_YCrCb_420_SP,
128         /*mHeapCount*/ 3
129     },
130     {
131         /*mFormat*/    HAL_PIXEL_FORMAT_YV12,
132         /*mHeapCount*/ 1
133     },
134     {
135         /*mFormat*/    HAL_PIXEL_FORMAT_YV12,
136         /*mHeapCount*/ 2
137     },
138     {
139         /*mFormat*/    HAL_PIXEL_FORMAT_YV12,
140         /*mHeapCount*/ 3
141     },
142     {
143         /*mFormat*/    HAL_PIXEL_FORMAT_Y8,
144         /*mHeapCount*/ 1
145     },
146     {
147         /*mFormat*/    HAL_PIXEL_FORMAT_Y8,
148         /*mHeapCount*/ 2
149     },
150     {
151         /*mFormat*/    HAL_PIXEL_FORMAT_Y8,
152         /*mHeapCount*/ 3
153     },
154     {
155         /*mFormat*/    HAL_PIXEL_FORMAT_Y16,
156         /*mHeapCount*/ 1
157     },
158     {
159         /*mFormat*/    HAL_PIXEL_FORMAT_Y16,
160         /*mHeapCount*/ 2
161     },
162     {
163         /*mFormat*/    HAL_PIXEL_FORMAT_Y16,
164         /*mHeapCount*/ 3
165     },
166     {
167         /*mFormat*/    HAL_PIXEL_FORMAT_RAW16,
168         /*mHeapCount*/ 1
169     },
170     {
171         /*mFormat*/    HAL_PIXEL_FORMAT_RAW16,
172         /*mHeapCount*/ 2
173     },
174     {
175         /*mFormat*/    HAL_PIXEL_FORMAT_RAW16,
176         /*mHeapCount*/ 3
177     },
178 };
179 
180 INSTANTIATE_TEST_CASE_P(StreamParameterCombinations, CameraStreamTest,
181     testing::ValuesIn(TestParameters));
182 
183 
184 }
185 }
186 }
187