blob: 69ee274d5917fa8664ba301c6200d79f62920233 [file] [log] [blame]
Igor Murashkine302ee32012-11-05 11:14:49 -08001/*
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
Igor Murashkin02f3ac02012-12-14 16:33:46 -080017#include <iostream>
18#include <iomanip>
Igor Murashkine302ee32012-11-05 11:14:49 -080019#include <gtest/gtest.h>
20
Igor Murashkineab33fc2012-11-06 17:02:54 -080021#define LOG_TAG "CameraStreamTest"
Igor Murashkine302ee32012-11-05 11:14:49 -080022#define LOG_NDEBUG 0
23#include <utils/Log.h>
24
25#include "hardware/hardware.h"
26#include "hardware/camera2.h"
27
Eino-Ville Talvala48bb03f2013-07-25 17:09:14 -070028#include <utils/StrongPointer.h>
Igor Murashkine302ee32012-11-05 11:14:49 -080029#include <gui/CpuConsumer.h>
Mathias Agopianb4f1e622013-02-15 14:27:15 -080030#include <gui/Surface.h>
Igor Murashkine302ee32012-11-05 11:14:49 -080031
Eino-Ville Talvala48bb03f2013-07-25 17:09:14 -070032#include <device2/Camera2Device.h>
33
Igor Murashkine302ee32012-11-05 11:14:49 -080034#include "CameraStreamFixture.h"
Igor Murashkineab33fc2012-11-06 17:02:54 -080035#include "TestExtensions.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080036
37using namespace android;
38using namespace android::camera2;
39
40namespace android {
41namespace camera2 {
42namespace tests {
43
Igor Murashkineab33fc2012-11-06 17:02:54 -080044class CameraStreamTest
Igor Murashkine302ee32012-11-05 11:14:49 -080045 : public ::testing::TestWithParam<CameraStreamParams>,
46 public CameraStreamFixture {
47
48public:
Igor Murashkineab33fc2012-11-06 17:02:54 -080049 CameraStreamTest() : CameraStreamFixture(GetParam()) {
50 TEST_EXTENSION_FORKING_CONSTRUCTOR;
Igor Murashkine302ee32012-11-05 11:14:49 -080051 }
52
Igor Murashkineab33fc2012-11-06 17:02:54 -080053 ~CameraStreamTest() {
54 TEST_EXTENSION_FORKING_DESTRUCTOR;
Igor Murashkine302ee32012-11-05 11:14:49 -080055 }
56
57 virtual void SetUp() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080058 TEST_EXTENSION_FORKING_SET_UP;
Igor Murashkine302ee32012-11-05 11:14:49 -080059 }
60 virtual void TearDown() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080061 TEST_EXTENSION_FORKING_TEAR_DOWN;
Igor Murashkine302ee32012-11-05 11:14:49 -080062 }
63
64protected:
65
66};
67
Igor Murashkineab33fc2012-11-06 17:02:54 -080068TEST_P(CameraStreamTest, CreateStream) {
Igor Murashkine302ee32012-11-05 11:14:49 -080069
Igor Murashkineab33fc2012-11-06 17:02:54 -080070 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080071
Igor Murashkin02f3ac02012-12-14 16:33:46 -080072 /** Make sure the format requested is supported. PASS this test if it's not
73 * not supported.
74 *
75 * TODO: would be nice of not running this test in the first place
76 * somehow.
77 */
78 {
79 camera_metadata_ro_entry availableFormats =
80 GetStaticEntry(ANDROID_SCALER_AVAILABLE_FORMATS);
81
82 bool hasFormat = false;
83 for (size_t i = 0; i < availableFormats.count; ++i) {
84 if (availableFormats.data.i32[i] == GetParam().mFormat) {
85 hasFormat = true;
86 break;
87 }
88 }
89
90 if (!hasFormat) {
91 const ::testing::TestInfo* const test_info =
92 ::testing::UnitTest::GetInstance()->current_test_info();
93 std::cerr << "Skipping test "
94 << test_info->test_case_name() << "."
95 << test_info->name()
Eino-Ville Talvala4c543a12013-06-25 18:12:19 -070096 << " because the format was not available: "
97 << GetParam() << std::endl;
Igor Murashkin02f3ac02012-12-14 16:33:46 -080098 return;
99 }
100 }
101
Igor Murashkineab33fc2012-11-06 17:02:54 -0800102 ASSERT_NO_FATAL_FAILURE(CreateStream());
103 ASSERT_NO_FATAL_FAILURE(DeleteStream());
Igor Murashkine302ee32012-11-05 11:14:49 -0800104}
105
106//TODO: use a combinatoric generator
107static CameraStreamParams TestParameters[] = {
108 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800109 /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
110 /*mHeapCount*/ 1
111 },
112 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800113 /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
114 /*mHeapCount*/ 2
115 },
116 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800117 /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
118 /*mHeapCount*/ 3
119 },
120 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800121 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, // NV21
122 /*mHeapCount*/ 1
123 },
124 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800125 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP,
126 /*mHeapCount*/ 2
127 },
128 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800129 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP,
130 /*mHeapCount*/ 3
131 },
132 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800133 /*mFormat*/ HAL_PIXEL_FORMAT_YV12,
134 /*mHeapCount*/ 1
135 },
136 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800137 /*mFormat*/ HAL_PIXEL_FORMAT_YV12,
138 /*mHeapCount*/ 2
139 },
140 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800141 /*mFormat*/ HAL_PIXEL_FORMAT_YV12,
142 /*mHeapCount*/ 3
143 },
144 {
Igor Murashkin7a7f3572013-02-11 15:52:03 -0800145 /*mFormat*/ HAL_PIXEL_FORMAT_Y8,
146 /*mHeapCount*/ 1
147 },
148 {
149 /*mFormat*/ HAL_PIXEL_FORMAT_Y8,
150 /*mHeapCount*/ 2
151 },
152 {
153 /*mFormat*/ HAL_PIXEL_FORMAT_Y8,
154 /*mHeapCount*/ 3
155 },
156 {
157 /*mFormat*/ HAL_PIXEL_FORMAT_Y16,
158 /*mHeapCount*/ 1
159 },
160 {
161 /*mFormat*/ HAL_PIXEL_FORMAT_Y16,
162 /*mHeapCount*/ 2
163 },
164 {
165 /*mFormat*/ HAL_PIXEL_FORMAT_Y16,
166 /*mHeapCount*/ 3
167 },
168 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800169 /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR,
170 /*mHeapCount*/ 1
171 },
172 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800173 /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR,
174 /*mHeapCount*/ 2
175 },
176 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800177 /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR,
178 /*mHeapCount*/ 3
179 },
180};
181
Igor Murashkineab33fc2012-11-06 17:02:54 -0800182INSTANTIATE_TEST_CASE_P(StreamParameterCombinations, CameraStreamTest,
Igor Murashkine302ee32012-11-05 11:14:49 -0800183 testing::ValuesIn(TestParameters));
184
185
186}
187}
188}