diff options
author | Eino-Ville Talvala <etalvala@google.com> | 2012-03-22 13:11:05 -0700 |
---|---|---|
committer | Eino-Ville Talvala <etalvala@google.com> | 2012-04-11 11:23:31 -0700 |
commit | fed0c0244b569e0bae4280af145a94ef3b1a1468 (patch) | |
tree | ecfe0c5b13cdfccbede81d79fbab4060a8b00731 /tests | |
parent | c65a2fe3925f46b4d4301cef97b308dbc3e22da9 (diff) | |
download | hardware_libhardware-fed0c0244b569e0bae4280af145a94ef3b1a1468.zip hardware_libhardware-fed0c0244b569e0bae4280af145a94ef3b1a1468.tar.gz hardware_libhardware-fed0c0244b569e0bae4280af145a94ef3b1a1468.tar.bz2 |
Revise camera HAL 2, and add unit test skeleton.
- Add missing method in stream_ops (set_buffers_geometry)
- Remove extra method in stream_ops (set_swap_interval)
- Document metadata queue protocol
- Change metadata queue methods to be set/get through function calls
only, instead of a struct member in the HAL device ops.
- Change vendor extension tag query methods to be retrieved by a get
call, instead of a struct member in the HAL device ops.
- Add basic gtest unit test skeleton, which currently just returns
static info from all camera devices.
Change-Id: I94117097b0243023ad60638070cc7f0cefec18e6
Diffstat (limited to 'tests')
-rw-r--r-- | tests/camera2/Android.mk | 27 | ||||
-rw-r--r-- | tests/camera2/camera2.cpp | 123 |
2 files changed, 150 insertions, 0 deletions
diff --git a/tests/camera2/Android.mk b/tests/camera2/Android.mk new file mode 100644 index 0000000..340ec30 --- /dev/null +++ b/tests/camera2/Android.mk @@ -0,0 +1,27 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + camera2.cpp + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libstlport \ + libhardware \ + libcamera_metadata + +LOCAL_STATIC_LIBRARIES := \ + libgtest \ + libgtest_main + +LOCAL_C_INCLUDES += \ + bionic \ + bionic/libstdc++/include \ + external/gtest/include \ + external/stlport/stlport \ + system/media/camera/include \ + +LOCAL_MODULE:= camera2_hal_tests +LOCAL_MODULE_TAGS := tests + +include $(BUILD_EXECUTABLE) diff --git a/tests/camera2/camera2.cpp b/tests/camera2/camera2.cpp new file mode 100644 index 0000000..d13d7cd --- /dev/null +++ b/tests/camera2/camera2.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <system/camera_metadata.h> +#include <hardware/camera2.h> +#include <gtest/gtest.h> +#include <iostream> + +class Camera2Test: public testing::Test { + public: + static void SetUpTestCase() { + int res; + + hw_module_t *module = NULL; + res = hw_get_module(CAMERA_HARDWARE_MODULE_ID, + (const hw_module_t **)&module); + + ASSERT_EQ(0, res) + << "Failure opening camera hardware module: " << res; + ASSERT_TRUE(NULL != module) + << "No camera module was set by hw_get_module"; + + std::cout << " Camera module name: " << module->name << std::endl; + std::cout << " Camera module author: " << module->author << std::endl; + std::cout << " Camera module API version: 0x" << std::hex + << module->module_api_version << std::endl; + std::cout << " Camera module HAL API version: 0x" << std::hex + << module->hal_api_version << std::endl; + + int16_t version2_0 = CAMERA_MODULE_API_VERSION_2_0; + ASSERT_EQ(version2_0, module->module_api_version) + << "Camera module version is 0x" + << std::hex << module->module_api_version + << ", not 2.0. (0x" + << std::hex << CAMERA_MODULE_API_VERSION_2_0 << ")"; + + sCameraModule = reinterpret_cast<camera_module_t*>(module); + + sNumCameras = sCameraModule->get_number_of_cameras(); + ASSERT_LT(0, sNumCameras) << "No camera devices available!"; + + std::cout << " Camera device count: " << sNumCameras << std::endl; + sCameraSupportsHal2 = new bool[sNumCameras]; + + for (int i = 0; i < sNumCameras; i++) { + camera_info info; + res = sCameraModule->get_camera_info(i, &info); + ASSERT_EQ(0, res) + << "Failure getting camera info for camera " << i; + std::cout << " Camera device: " << std::dec + << i << std::endl;; + std::cout << " Facing: " << std::dec + << info.facing << std::endl; + std::cout << " Orientation: " << std::dec + << info.orientation << std::endl; + std::cout << " Version: 0x" << std::hex << + info.device_version << std::endl; + if (info.device_version >= CAMERA_DEVICE_API_VERSION_2_0) { + sCameraSupportsHal2[i] = true; + ASSERT_TRUE(NULL != info.static_camera_characteristics); + std::cout << " Static camera metadata:" << std::endl; + dump_camera_metadata(info.static_camera_characteristics, 0, 1); + } else { + sCameraSupportsHal2[i] = false; + } + } + } + + static const camera_module_t *getCameraModule() { + return sCameraModule; + } + + static const camera2_device_t *openCameraDevice(int id) { + if (NULL == sCameraSupportsHal2) return NULL; + if (id >= sNumCameras) return NULL; + if (!sCameraSupportsHal2[id]) return NULL; + + hw_device_t *device = NULL; + const camera_module_t *cam_module = getCameraModule(); + char camId[10]; + int res; + + snprintf(camId, 10, "%d", id); + res = cam_module->common.methods->open( + (const hw_module_t*)cam_module, + camId, + &device); + if (res < 0 || cam_module == NULL) { + return NULL; + } + camera2_device_t *cam_device = + reinterpret_cast<camera2_device_t*>(device); + return cam_device; + } + + private: + + static camera_module_t *sCameraModule; + static int sNumCameras; + static bool *sCameraSupportsHal2; +}; + +camera_module_t *Camera2Test::sCameraModule = NULL; +int Camera2Test::sNumCameras = 0; +bool *Camera2Test::sCameraSupportsHal2 = NULL; + + +TEST_F(Camera2Test, Basic) { + ASSERT_TRUE(NULL != getCameraModule()); +} |