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 | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 17 | #ifndef __ANDROID_HAL_CAMERA2_TESTS_MODULE_FIXTURE__ |
| 18 | #define __ANDROID_HAL_CAMERA2_TESTS_MODULE_FIXTURE__ |
| 19 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 20 | #include <gtest/gtest.h> |
| 21 | |
| 22 | #include "hardware/hardware.h" |
| 23 | #include "hardware/camera2.h" |
| 24 | |
| 25 | #include "Camera2Device.h" |
| 26 | #include "camera2_utils.h" |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 27 | #include "TestExtensions.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace camera2 { |
| 31 | namespace tests { |
| 32 | |
| 33 | template <bool InfoQuirk = false> |
| 34 | struct CameraModuleFixture { |
| 35 | |
| 36 | CameraModuleFixture(int CameraID = -1) { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 37 | TEST_EXTENSION_FORKING_CONSTRUCTOR; |
| 38 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 39 | mCameraID = CameraID; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | ~CameraModuleFixture() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 43 | TEST_EXTENSION_FORKING_DESTRUCTOR; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Igor Murashkin | 02f3ac0 | 2012-12-14 16:33:46 -0800 | [diff] [blame] | 46 | camera_metadata_ro_entry GetStaticEntry(uint32_t tag) const { |
| 47 | const CameraMetadata& staticInfo = mDevice->info(); |
| 48 | camera_metadata_ro_entry entry = staticInfo.find(tag); |
| 49 | return entry; |
| 50 | } |
| 51 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 52 | void SetUp() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 53 | TEST_EXTENSION_FORKING_SET_UP; |
| 54 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 55 | ASSERT_LE(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID, |
| 56 | (const hw_module_t **)&mModule)) << "Could not load camera module"; |
| 57 | ASSERT_NE((void*)0, mModule); |
| 58 | |
| 59 | mNumberOfCameras = mModule->get_number_of_cameras(); |
| 60 | ASSERT_LE(0, mNumberOfCameras); |
| 61 | |
| 62 | ASSERT_EQ( |
| 63 | CAMERA_MODULE_API_VERSION_2_0, mModule->common.module_api_version) |
| 64 | << "Wrong module API version"; |
| 65 | |
| 66 | /* For using this fixture in other tests only */ |
| 67 | SetUpMixin(); |
| 68 | } |
| 69 | |
| 70 | void TearDown() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 71 | TEST_EXTENSION_FORKING_TEAR_DOWN; |
| 72 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 73 | TearDownMixin(); |
| 74 | |
| 75 | /* important: device must be destructed before closing module, |
| 76 | since it calls back into HAL */ |
| 77 | mDevice.clear(); |
| 78 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 79 | if (!TEST_EXTENSION_FORKING_ENABLED) { |
| 80 | ASSERT_EQ(0, HWModuleHelpers::closeModule(&mModule->common)) |
| 81 | << "Failed to close camera HAL module"; |
| 82 | } |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Igor Murashkin | 7acb21a | 2012-12-18 13:38:40 -0800 | [diff] [blame] | 85 | private: |
| 86 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 87 | void SetUpMixin() { |
| 88 | /* For using this fixture in other tests only */ |
| 89 | if (mCameraID != -1) { |
| 90 | EXPECT_LE(0, mCameraID); |
| 91 | EXPECT_LT(mCameraID, mNumberOfCameras); |
| 92 | |
| 93 | /* HALBUG (Exynos5); crashes if trying to initialize |
| 94 | before calling get_camera_info */ |
| 95 | if (InfoQuirk) { |
| 96 | struct camera_info info; |
| 97 | ASSERT_EQ(OK, mModule->get_camera_info(mCameraID, &info)); |
| 98 | } |
| 99 | |
| 100 | mDevice = new Camera2Device(mCameraID); |
| 101 | ASSERT_EQ(OK, mDevice->initialize(mModule)) |
| 102 | << "Failed to initialize device " << mCameraID; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void TearDownMixin() { |
| 107 | |
| 108 | } |
| 109 | |
| 110 | protected: |
| 111 | int mNumberOfCameras; |
| 112 | camera_module_t *mModule; |
| 113 | sp<Camera2Device> mDevice; |
| 114 | |
| 115 | private: |
| 116 | int mCameraID; |
| 117 | }; |
| 118 | |
| 119 | |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 124 | #endif |