Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 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 | |
Igor Murashkin | 02f3ac0 | 2012-12-14 16:33:46 -0800 | [diff] [blame] | 17 | #include <iostream> |
| 18 | #include <iomanip> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 21 | #define LOG_TAG "CameraStreamTest" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 22 | #define LOG_NDEBUG 0 |
| 23 | #include <utils/Log.h> |
| 24 | |
| 25 | #include "hardware/hardware.h" |
| 26 | #include "hardware/camera2.h" |
| 27 | |
Eino-Ville Talvala | 48bb03f | 2013-07-25 17:09:14 -0700 | [diff] [blame^] | 28 | #include <utils/StrongPointer.h> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 29 | #include <gui/CpuConsumer.h> |
Mathias Agopian | b4f1e62 | 2013-02-15 14:27:15 -0800 | [diff] [blame] | 30 | #include <gui/Surface.h> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 31 | |
Eino-Ville Talvala | 48bb03f | 2013-07-25 17:09:14 -0700 | [diff] [blame^] | 32 | #include <device2/Camera2Device.h> |
| 33 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 34 | #include "CameraStreamFixture.h" |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 35 | #include "TestExtensions.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 36 | |
| 37 | using namespace android; |
| 38 | using namespace android::camera2; |
| 39 | |
| 40 | namespace android { |
| 41 | namespace camera2 { |
| 42 | namespace tests { |
| 43 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 44 | class CameraStreamTest |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 45 | : public ::testing::TestWithParam<CameraStreamParams>, |
| 46 | public CameraStreamFixture { |
| 47 | |
| 48 | public: |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 49 | CameraStreamTest() : CameraStreamFixture(GetParam()) { |
| 50 | TEST_EXTENSION_FORKING_CONSTRUCTOR; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 53 | ~CameraStreamTest() { |
| 54 | TEST_EXTENSION_FORKING_DESTRUCTOR; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | virtual void SetUp() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 58 | TEST_EXTENSION_FORKING_SET_UP; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 59 | } |
| 60 | virtual void TearDown() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 61 | TEST_EXTENSION_FORKING_TEAR_DOWN; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | protected: |
| 65 | |
| 66 | }; |
| 67 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 68 | TEST_P(CameraStreamTest, CreateStream) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 69 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 70 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 71 | |
Igor Murashkin | 02f3ac0 | 2012-12-14 16:33:46 -0800 | [diff] [blame] | 72 | /** 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 Talvala | 4c543a1 | 2013-06-25 18:12:19 -0700 | [diff] [blame] | 96 | << " because the format was not available: " |
| 97 | << GetParam() << std::endl; |
Igor Murashkin | 02f3ac0 | 2012-12-14 16:33:46 -0800 | [diff] [blame] | 98 | return; |
| 99 | } |
| 100 | } |
| 101 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 102 | ASSERT_NO_FATAL_FAILURE(CreateStream()); |
| 103 | ASSERT_NO_FATAL_FAILURE(DeleteStream()); |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | //TODO: use a combinatoric generator |
| 107 | static CameraStreamParams TestParameters[] = { |
| 108 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 109 | /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, |
| 110 | /*mHeapCount*/ 1 |
| 111 | }, |
| 112 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 113 | /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, |
| 114 | /*mHeapCount*/ 2 |
| 115 | }, |
| 116 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 117 | /*mFormat*/ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, |
| 118 | /*mHeapCount*/ 3 |
| 119 | }, |
| 120 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 121 | /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, // NV21 |
| 122 | /*mHeapCount*/ 1 |
| 123 | }, |
| 124 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 125 | /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, |
| 126 | /*mHeapCount*/ 2 |
| 127 | }, |
| 128 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 129 | /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, |
| 130 | /*mHeapCount*/ 3 |
| 131 | }, |
| 132 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 133 | /*mFormat*/ HAL_PIXEL_FORMAT_YV12, |
| 134 | /*mHeapCount*/ 1 |
| 135 | }, |
| 136 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 137 | /*mFormat*/ HAL_PIXEL_FORMAT_YV12, |
| 138 | /*mHeapCount*/ 2 |
| 139 | }, |
| 140 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 141 | /*mFormat*/ HAL_PIXEL_FORMAT_YV12, |
| 142 | /*mHeapCount*/ 3 |
| 143 | }, |
| 144 | { |
Igor Murashkin | 7a7f357 | 2013-02-11 15:52:03 -0800 | [diff] [blame] | 145 | /*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 Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 169 | /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR, |
| 170 | /*mHeapCount*/ 1 |
| 171 | }, |
| 172 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 173 | /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR, |
| 174 | /*mHeapCount*/ 2 |
| 175 | }, |
| 176 | { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 177 | /*mFormat*/ HAL_PIXEL_FORMAT_RAW_SENSOR, |
| 178 | /*mHeapCount*/ 3 |
| 179 | }, |
| 180 | }; |
| 181 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 182 | INSTANTIATE_TEST_CASE_P(StreamParameterCombinations, CameraStreamTest, |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 183 | testing::ValuesIn(TestParameters)); |
| 184 | |
| 185 | |
| 186 | } |
| 187 | } |
| 188 | } |