Home | History | Annotate | Download | only in camera2
      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 <device2/Camera2Device.h>
     33 
     34 #include "CameraStreamFixture.h"
     35 #include "TestExtensions.h"
     36 
     37 using namespace android;
     38 using namespace android::camera2;
     39 
     40 namespace android {
     41 namespace camera2 {
     42 namespace tests {
     43 
     44 class CameraStreamTest
     45     : public ::testing::TestWithParam<CameraStreamParams>,
     46       public CameraStreamFixture {
     47 
     48 public:
     49     CameraStreamTest() : CameraStreamFixture(GetParam()) {
     50         TEST_EXTENSION_FORKING_CONSTRUCTOR;
     51     }
     52 
     53     ~CameraStreamTest() {
     54         TEST_EXTENSION_FORKING_DESTRUCTOR;
     55     }
     56 
     57     virtual void SetUp() {
     58         TEST_EXTENSION_FORKING_SET_UP;
     59     }
     60     virtual void TearDown() {
     61         TEST_EXTENSION_FORKING_TEAR_DOWN;
     62     }
     63 
     64 protected:
     65 
     66 };
     67 
     68 TEST_P(CameraStreamTest, CreateStream) {
     69 
     70     TEST_EXTENSION_FORKING_INIT;
     71 
     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()
     96                       << " because the format was not available: "
     97                       << GetParam() << std::endl;
     98             return;
     99         }
    100     }
    101 
    102     ASSERT_NO_FATAL_FAILURE(CreateStream());
    103     ASSERT_NO_FATAL_FAILURE(DeleteStream());
    104 }
    105 
    106 //TODO: use a combinatoric generator
    107 static CameraStreamParams TestParameters[] = {
    108     {
    109         /*mFormat*/    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
    110         /*mHeapCount*/ 1
    111     },
    112     {
    113         /*mFormat*/    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
    114         /*mHeapCount*/ 2
    115     },
    116     {
    117         /*mFormat*/    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
    118         /*mHeapCount*/ 3
    119     },
    120     {
    121         /*mFormat*/    HAL_PIXEL_FORMAT_YCrCb_420_SP, // NV21
    122         /*mHeapCount*/ 1
    123     },
    124     {
    125         /*mFormat*/    HAL_PIXEL_FORMAT_YCrCb_420_SP,
    126         /*mHeapCount*/ 2
    127     },
    128     {
    129         /*mFormat*/    HAL_PIXEL_FORMAT_YCrCb_420_SP,
    130         /*mHeapCount*/ 3
    131     },
    132     {
    133         /*mFormat*/    HAL_PIXEL_FORMAT_YV12,
    134         /*mHeapCount*/ 1
    135     },
    136     {
    137         /*mFormat*/    HAL_PIXEL_FORMAT_YV12,
    138         /*mHeapCount*/ 2
    139     },
    140     {
    141         /*mFormat*/    HAL_PIXEL_FORMAT_YV12,
    142         /*mHeapCount*/ 3
    143     },
    144     {
    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     {
    169         /*mFormat*/    HAL_PIXEL_FORMAT_RAW_SENSOR,
    170         /*mHeapCount*/ 1
    171     },
    172     {
    173         /*mFormat*/    HAL_PIXEL_FORMAT_RAW_SENSOR,
    174         /*mHeapCount*/ 2
    175     },
    176     {
    177         /*mFormat*/    HAL_PIXEL_FORMAT_RAW_SENSOR,
    178         /*mHeapCount*/ 3
    179     },
    180 };
    181 
    182 INSTANTIATE_TEST_CASE_P(StreamParameterCombinations, CameraStreamTest,
    183     testing::ValuesIn(TestParameters));
    184 
    185 
    186 }
    187 }
    188 }
    189