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 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 19 | #define LOG_TAG "CameraModuleTest" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 20 | #define LOG_NDEBUG 0 |
| 21 | #include <utils/Log.h> |
Eino-Ville Talvala | 48bb03f | 2013-07-25 17:09:14 -0700 | [diff] [blame] | 22 | #include <utils/StrongPointer.h> |
| 23 | #include <common/CameraDeviceBase.h> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 24 | |
| 25 | #include "hardware/hardware.h" |
| 26 | #include "hardware/camera2.h" |
| 27 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 28 | #include "CameraModuleFixture.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace camera2 { |
| 32 | namespace tests { |
| 33 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 34 | class CameraModuleTest : public ::testing::Test, |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 35 | public CameraModuleFixture<> { |
Igor Murashkin | 7acb21a | 2012-12-18 13:38:40 -0800 | [diff] [blame] | 36 | |
| 37 | public: |
| 38 | CameraModuleTest() { |
| 39 | CameraModuleFixture::SetUp(); |
| 40 | } |
| 41 | |
| 42 | ~CameraModuleTest() { |
| 43 | CameraModuleFixture::TearDown(); |
| 44 | } |
Igor Murashkin | 0a7a430 | 2012-12-18 14:08:27 -0800 | [diff] [blame] | 45 | |
| 46 | status_t initializeDevice(int cameraId) { |
| 47 | |
| 48 | // ignore HAL1s. count as test pass |
Igor Murashkin | e9b0eaa | 2012-12-20 17:11:56 -0800 | [diff] [blame] | 49 | status_t stat; |
| 50 | if (isDeviceVersionHal2(cameraId, &stat) && stat == OK) { |
| 51 | stat = mDevice->initialize(mModule); |
Igor Murashkin | 0a7a430 | 2012-12-18 14:08:27 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Igor Murashkin | e9b0eaa | 2012-12-20 17:11:56 -0800 | [diff] [blame] | 54 | return stat; |
Igor Murashkin | 0a7a430 | 2012-12-18 14:08:27 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Igor Murashkin | e9b0eaa | 2012-12-20 17:11:56 -0800 | [diff] [blame] | 57 | bool isDeviceVersionHal2(int cameraId, status_t* status) { |
| 58 | return getDeviceVersion(cameraId, status) |
| 59 | >= CAMERA_DEVICE_API_VERSION_2_0; |
Igor Murashkin | 0a7a430 | 2012-12-18 14:08:27 -0800 | [diff] [blame] | 60 | } |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 63 | TEST_F(CameraModuleTest, LoadModule) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 64 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 65 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 66 | |
| 67 | for (int i = 0; i < mNumberOfCameras; ++i) { |
Eino-Ville Talvala | 4c543a1 | 2013-06-25 18:12:19 -0700 | [diff] [blame] | 68 | CreateCamera(i, &mDevice); |
Igor Murashkin | 0a7a430 | 2012-12-18 14:08:27 -0800 | [diff] [blame] | 69 | ASSERT_EQ(OK, initializeDevice(i)) |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 70 | << "Failed to initialize device " << i; |
| 71 | mDevice.clear(); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 76 | TEST_F(CameraModuleTest, LoadModuleBadIndices) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 77 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 78 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 79 | |
| 80 | int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 }; |
Zhijun He | 60cbb52 | 2013-09-18 09:44:19 -0700 | [diff] [blame^] | 81 | hw_device_t *device = NULL; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 82 | |
| 83 | for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) { |
Zhijun He | 60cbb52 | 2013-09-18 09:44:19 -0700 | [diff] [blame^] | 84 | String8 deviceName = String8::format("%d", idx[i]); |
| 85 | status_t res = |
| 86 | mModule->common.methods->open( |
| 87 | &mModule->common, |
| 88 | deviceName, |
| 89 | &device); |
| 90 | EXPECT_NE(OK, res); |
| 91 | EXPECT_EQ(-ENODEV, res) |
| 92 | << "Incorrect error code when trying to open camera with invalid id " |
| 93 | << deviceName; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 97 | TEST_F(CameraModuleTest, GetCameraInfo) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 98 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 99 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 100 | |
| 101 | for (int i = 0; i < mNumberOfCameras; ++i) { |
| 102 | struct camera_info info; |
| 103 | ASSERT_EQ(OK, mModule->get_camera_info(i, &info)); |
| 104 | } |
| 105 | |
| 106 | } |
| 107 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 108 | TEST_F(CameraModuleTest, GetCameraInfoBadIndices) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 109 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 110 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 111 | |
| 112 | int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 }; |
| 113 | for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) { |
| 114 | struct camera_info info; |
| 115 | EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info)); |
| 116 | EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info)) |
| 117 | << "Incorrect error code for get_camera_info idx= " |
| 118 | << idx[i]; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * TODO: Additional test to add: open two cameras at once. |
| 124 | * (is allowed to fail, at least for now, but should not blow up) |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 125 | * - open same device multiple times |
| 126 | * - close same device multiple times |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 127 | */ |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | } |
| 133 | } |
| 134 | } |