blob: b07629649e1c6bb6dcfb0b798942a23d6529c85a [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
28#include "Camera2Device.h"
29#include "utils/StrongPointer.h"
30
31#include <gui/CpuConsumer.h>
32#include <gui/SurfaceTextureClient.h>
33
34#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()
96 << " because the format was not available: 0x"
97 << std::hex << GetParam().mFormat << std::endl;
98 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 Murashkine302ee32012-11-05 11:14:49 -0800145 /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR,
146 /*mHeapCount*/ 1
147 },
148 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800149 /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR,
150 /*mHeapCount*/ 2
151 },
152 {
Igor Murashkine302ee32012-11-05 11:14:49 -0800153 /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR,
154 /*mHeapCount*/ 3
155 },
156};
157
Igor Murashkineab33fc2012-11-06 17:02:54 -0800158INSTANTIATE_TEST_CASE_P(StreamParameterCombinations, CameraStreamTest,
Igor Murashkine302ee32012-11-05 11:14:49 -0800159 testing::ValuesIn(TestParameters));
160
161
162}
163}
164}
165