blob: de9ae8afcd6ef35bdaeba1cff2f3fe8f0fc43281 [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
32#include "CameraStreamFixture.h"
Igor Murashkineab33fc2012-11-06 17:02:54 -080033#include "TestExtensions.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080034
35using namespace android;
36using namespace android::camera2;
37
38namespace android {
39namespace camera2 {
40namespace tests {
41
Igor Murashkineab33fc2012-11-06 17:02:54 -080042class CameraStreamTest
Igor Murashkine302ee32012-11-05 11:14:49 -080043 : public ::testing::TestWithParam<CameraStreamParams>,
44 public CameraStreamFixture {
45
46public:
Igor Murashkineab33fc2012-11-06 17:02:54 -080047 CameraStreamTest() : CameraStreamFixture(GetParam()) {
48 TEST_EXTENSION_FORKING_CONSTRUCTOR;
Igor Murashkine302ee32012-11-05 11:14:49 -080049 }
50
Igor Murashkineab33fc2012-11-06 17:02:54 -080051 ~CameraStreamTest() {
52 TEST_EXTENSION_FORKING_DESTRUCTOR;
Igor Murashkine302ee32012-11-05 11:14:49 -080053 }
54
55 virtual void SetUp() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080056 TEST_EXTENSION_FORKING_SET_UP;
Igor Murashkine302ee32012-11-05 11:14:49 -080057 }
58 virtual void TearDown() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080059 TEST_EXTENSION_FORKING_TEAR_DOWN;
Igor Murashkine302ee32012-11-05 11:14:49 -080060 }
61
62protected:
63
64};
65
Igor Murashkineab33fc2012-11-06 17:02:54 -080066TEST_P(CameraStreamTest, CreateStream) {
Igor Murashkine302ee32012-11-05 11:14:49 -080067
Igor Murashkineab33fc2012-11-06 17:02:54 -080068 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080069
Igor Murashkin02f3ac02012-12-14 16:33:46 -080070 /** 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()
Eino-Ville Talvala4c543a12013-06-25 18:12:19 -070094 << " because the format was not available: "
95 << GetParam() << std::endl;
Igor Murashkin02f3ac02012-12-14 16:33:46 -080096 return;
97 }
98 }
99
Igor Murashkineab33fc2012-11-06 17:02:54 -0800100 ASSERT_NO_FATAL_FAILURE(CreateStream());
101 ASSERT_NO_FATAL_FAILURE(DeleteStream());
Igor Murashkine302ee32012-11-05 11:14:49 -0800102}
103
104//TODO: use a combinatoric generator
105static CameraStreamParams TestParameters[] = {
106 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800107 /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
108 /*mHeapCount*/ 1
109 },
110 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800111 /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
112 /*mHeapCount*/ 2
113 },
114 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800115 /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
116 /*mHeapCount*/ 3
117 },
118 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800119 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, // NV21
120 /*mHeapCount*/ 1
121 },
122 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800123 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP,
124 /*mHeapCount*/ 2
125 },
126 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800127 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP,
128 /*mHeapCount*/ 3
129 },
130 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800131 /*mFormat*/ HAL_PIXEL_FORMAT_YV12,
132 /*mHeapCount*/ 1
133 },
134 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800135 /*mFormat*/ HAL_PIXEL_FORMAT_YV12,
136 /*mHeapCount*/ 2
137 },
138 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800139 /*mFormat*/ HAL_PIXEL_FORMAT_YV12,
140 /*mHeapCount*/ 3
141 },
142 {
Igor Murashkin7a7f3572013-02-11 15:52:03 -0800143 /*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 {
Eino-Ville Talvalae69efbb2015-03-06 13:19:36 -0800167 /*mFormat*/ HAL_PIXEL_FORMAT_RAW16,
Igor Murashkine302ee32012-11-05 11:14:49 -0800168 /*mHeapCount*/ 1
169 },
170 {
Eino-Ville Talvalae69efbb2015-03-06 13:19:36 -0800171 /*mFormat*/ HAL_PIXEL_FORMAT_RAW16,
Igor Murashkine302ee32012-11-05 11:14:49 -0800172 /*mHeapCount*/ 2
173 },
174 {
Eino-Ville Talvalae69efbb2015-03-06 13:19:36 -0800175 /*mFormat*/ HAL_PIXEL_FORMAT_RAW16,
Igor Murashkine302ee32012-11-05 11:14:49 -0800176 /*mHeapCount*/ 3
177 },
178};
179
Igor Murashkineab33fc2012-11-06 17:02:54 -0800180INSTANTIATE_TEST_CASE_P(StreamParameterCombinations, CameraStreamTest,
Igor Murashkine302ee32012-11-05 11:14:49 -0800181 testing::ValuesIn(TestParameters));
182
183
184}
185}
186}