blob: 2e85d81a275c4b93c4af6f45f63ce5defeb3235a [file] [log] [blame]
Igor Murashkine302ee32012-11-05 11:14:49 -08001/*
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 Murashkineab33fc2012-11-06 17:02:54 -080019#define LOG_TAG "CameraModuleTest"
Igor Murashkine302ee32012-11-05 11:14:49 -080020#define LOG_NDEBUG 0
21#include <utils/Log.h>
Eino-Ville Talvala48bb03f2013-07-25 17:09:14 -070022#include <utils/StrongPointer.h>
23#include <common/CameraDeviceBase.h>
Igor Murashkine302ee32012-11-05 11:14:49 -080024
25#include "hardware/hardware.h"
26#include "hardware/camera2.h"
27
Igor Murashkine302ee32012-11-05 11:14:49 -080028#include "CameraModuleFixture.h"
29
30namespace android {
31namespace camera2 {
32namespace tests {
33
Igor Murashkineab33fc2012-11-06 17:02:54 -080034class CameraModuleTest : public ::testing::Test,
Igor Murashkine302ee32012-11-05 11:14:49 -080035 public CameraModuleFixture<> {
Igor Murashkin7acb21a2012-12-18 13:38:40 -080036
37public:
38 CameraModuleTest() {
39 CameraModuleFixture::SetUp();
40 }
41
42 ~CameraModuleTest() {
43 CameraModuleFixture::TearDown();
44 }
Igor Murashkin0a7a4302012-12-18 14:08:27 -080045
46 status_t initializeDevice(int cameraId) {
47
48 // ignore HAL1s. count as test pass
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080049 status_t stat;
50 if (isDeviceVersionHal2(cameraId, &stat) && stat == OK) {
51 stat = mDevice->initialize(mModule);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080052 }
53
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080054 return stat;
Igor Murashkin0a7a4302012-12-18 14:08:27 -080055 }
56
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080057 bool isDeviceVersionHal2(int cameraId, status_t* status) {
58 return getDeviceVersion(cameraId, status)
59 >= CAMERA_DEVICE_API_VERSION_2_0;
Igor Murashkin0a7a4302012-12-18 14:08:27 -080060 }
Igor Murashkine302ee32012-11-05 11:14:49 -080061};
62
Igor Murashkineab33fc2012-11-06 17:02:54 -080063TEST_F(CameraModuleTest, LoadModule) {
Igor Murashkine302ee32012-11-05 11:14:49 -080064
Igor Murashkineab33fc2012-11-06 17:02:54 -080065 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080066
Zhijun Heb44ff652013-10-28 15:52:56 -070067 status_t stat;
Igor Murashkine302ee32012-11-05 11:14:49 -080068 for (int i = 0; i < mNumberOfCameras; ++i) {
Zhijun Heb44ff652013-10-28 15:52:56 -070069 if (isDeviceVersionHal2(i, &stat) && stat == OK) {
70 CreateCamera(i, &mDevice);
71 ASSERT_EQ(OK, initializeDevice(i))
72 << "Failed to initialize device " << i;
73 mDevice.clear();
74 } else {
75 const ::testing::TestInfo* const test_info =
76 ::testing::UnitTest::GetInstance()->current_test_info();
77 std::cerr << "Skipping test "
78 << test_info->test_case_name() << "."
79 << test_info->name()
80 << " because HAL device version is V1"
81 << std::endl;
82 }
Igor Murashkine302ee32012-11-05 11:14:49 -080083 }
84
85}
86
Igor Murashkineab33fc2012-11-06 17:02:54 -080087TEST_F(CameraModuleTest, LoadModuleBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080088
Igor Murashkineab33fc2012-11-06 17:02:54 -080089 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080090
91 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
Zhijun He60cbb522013-09-18 09:44:19 -070092 hw_device_t *device = NULL;
Igor Murashkine302ee32012-11-05 11:14:49 -080093
94 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
Zhijun He60cbb522013-09-18 09:44:19 -070095 String8 deviceName = String8::format("%d", idx[i]);
Yin-Chia Yeh7eb3d912015-02-02 16:20:46 -080096 status_t res = mModule->open(deviceName, &device);
Zhijun He60cbb522013-09-18 09:44:19 -070097 EXPECT_NE(OK, res);
98 EXPECT_EQ(-ENODEV, res)
99 << "Incorrect error code when trying to open camera with invalid id "
100 << deviceName;
Igor Murashkine302ee32012-11-05 11:14:49 -0800101 }
102}
103
Igor Murashkineab33fc2012-11-06 17:02:54 -0800104TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800105
Igor Murashkineab33fc2012-11-06 17:02:54 -0800106 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800107
108 for (int i = 0; i < mNumberOfCameras; ++i) {
109 struct camera_info info;
Yin-Chia Yeh7eb3d912015-02-02 16:20:46 -0800110 ASSERT_EQ(OK, mModule->getCameraInfo(i, &info));
Igor Murashkine302ee32012-11-05 11:14:49 -0800111 }
112
113}
114
Igor Murashkineab33fc2012-11-06 17:02:54 -0800115TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800116
Igor Murashkineab33fc2012-11-06 17:02:54 -0800117 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800118
119 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
120 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
121 struct camera_info info;
Yin-Chia Yeh7eb3d912015-02-02 16:20:46 -0800122 EXPECT_NE(OK, mModule->getCameraInfo(idx[i], &info));
123 EXPECT_EQ(-ENODEV, mModule->getCameraInfo(idx[i], &info))
Igor Murashkine302ee32012-11-05 11:14:49 -0800124 << "Incorrect error code for get_camera_info idx= "
125 << idx[i];
126 }
127}
128
129/**
130 * TODO: Additional test to add: open two cameras at once.
131 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -0800132 * - open same device multiple times
133 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -0800134 */
135
136
137
138
139}
140}
141}