blob: 828c56a18a5820370fd97692c8f91ffe2132c9b6 [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]);
96 status_t res =
97 mModule->common.methods->open(
98 &mModule->common,
99 deviceName,
100 &device);
101 EXPECT_NE(OK, res);
102 EXPECT_EQ(-ENODEV, res)
103 << "Incorrect error code when trying to open camera with invalid id "
104 << deviceName;
Igor Murashkine302ee32012-11-05 11:14:49 -0800105 }
106}
107
Igor Murashkineab33fc2012-11-06 17:02:54 -0800108TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800109
Igor Murashkineab33fc2012-11-06 17:02:54 -0800110 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800111
112 for (int i = 0; i < mNumberOfCameras; ++i) {
113 struct camera_info info;
114 ASSERT_EQ(OK, mModule->get_camera_info(i, &info));
115 }
116
117}
118
Igor Murashkineab33fc2012-11-06 17:02:54 -0800119TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800120
Igor Murashkineab33fc2012-11-06 17:02:54 -0800121 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800122
123 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
124 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
125 struct camera_info info;
126 EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info));
127 EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info))
128 << "Incorrect error code for get_camera_info idx= "
129 << idx[i];
130 }
131}
132
133/**
134 * TODO: Additional test to add: open two cameras at once.
135 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -0800136 * - open same device multiple times
137 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -0800138 */
139
140
141
142
143}
144}
145}