1 /*
2 * Copyright (C) 2019 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 #define LOG_TAG "RequestProcessorTest"
18 #include <log/log.h>
19
20 #include <gtest/gtest.h>
21 #include <memory>
22
23 #include "basic_request_processor.h"
24 #include "mock_device_session_hwl.h"
25 #include "mock_process_block.h"
26 #include "result_processor.h"
27 #include "test_utils.h"
28
29 using ::testing::_;
30
31 namespace android {
32 namespace google_camera_hal {
33
34 using RequestProcessorCreateFunc =
35 std::function<std::unique_ptr<RequestProcessor>()>;
36
37 class RequestProcessorTest : public ::testing::Test {
38 protected:
SetUp()39 void SetUp() override {
40 // Create a mock session HWL.
41 session_hwl_ = std::make_unique<MockDeviceSessionHwl>();
42 ASSERT_NE(session_hwl_, nullptr);
43
44 session_hwl_->DelegateCallsToFakeSession();
45 }
46
CreateBasicRequestrocessor()47 std::unique_ptr<RequestProcessor> CreateBasicRequestrocessor() {
48 return BasicRequestProcessor::Create(session_hwl_.get());
49 }
50
51 // All result processor implementation classes should be added to this
52 // vector.
53 std::vector<RequestProcessorCreateFunc> request_processor_create_funcs_ = {
__anonb2e6840c0102() 54 [&]() { return CreateBasicRequestrocessor(); },
55 };
56
57 std::unique_ptr<MockDeviceSessionHwl> session_hwl_;
58 };
59
TEST_F(RequestProcessorTest,Create)60 TEST_F(RequestProcessorTest, Create) {
61 for (auto& create_func : request_processor_create_funcs_) {
62 auto request_processor = create_func();
63 ASSERT_NE(request_processor, nullptr)
64 << "Creating a request processor failed";
65 }
66 }
67
TEST_F(RequestProcessorTest,StreamConfiguration)68 TEST_F(RequestProcessorTest, StreamConfiguration) {
69 auto stream_manager = InternalStreamManager::Create();
70 StreamConfiguration preview_config;
71 test_utils::GetPreviewOnlyStreamConfiguration(&preview_config);
72
73 for (auto& create_func : request_processor_create_funcs_) {
74 auto request_processor = create_func();
75 ASSERT_NE(request_processor, nullptr)
76 << "Creating a request processor failed";
77
78 EXPECT_EQ(request_processor->ConfigureStreams(
79 stream_manager.get(), preview_config,
80 /*process_block_stream_config=*/nullptr),
81 BAD_VALUE)
82 << "Configuring streams with nullptr process_block_stream_config "
83 "should fail.";
84
85 StreamConfiguration process_block_stream_config;
86 EXPECT_EQ(
87 request_processor->ConfigureStreams(
88 stream_manager.get(), preview_config, &process_block_stream_config),
89 OK);
90
91 // Verify that all streams in process_block_stream_config are physical
92 // streams.
93 if (test_utils::IsLogicalCamera(session_hwl_.get())) {
94 for (auto& stream : process_block_stream_config.streams) {
95 EXPECT_TRUE(stream.is_physical_camera_stream);
96 }
97 }
98 }
99 }
100
TEST_F(RequestProcessorTest,SetProcessBlock)101 TEST_F(RequestProcessorTest, SetProcessBlock) {
102 for (auto& create_func : request_processor_create_funcs_) {
103 auto request_processor = create_func();
104 ASSERT_NE(request_processor, nullptr)
105 << "Creating a request processor failed";
106
107 EXPECT_EQ(request_processor->SetProcessBlock(nullptr), BAD_VALUE)
108 << "Setting nullptr process block should fail.";
109
110 EXPECT_EQ(
111 request_processor->SetProcessBlock(std::make_unique<MockProcessBlock>()),
112 OK);
113
114 EXPECT_EQ(
115 request_processor->SetProcessBlock(std::make_unique<MockProcessBlock>()),
116 ALREADY_EXISTS)
117 << "Setting process block again should fail.";
118 }
119 }
120
TEST_F(RequestProcessorTest,Flush)121 TEST_F(RequestProcessorTest, Flush) {
122 for (auto& create_func : request_processor_create_funcs_) {
123 auto request_processor = create_func();
124 ASSERT_NE(request_processor, nullptr)
125 << "Creating a request processor failed";
126
127 auto process_block = std::make_unique<MockProcessBlock>();
128 ASSERT_NE(process_block, nullptr);
129
130 // Expect request process to flush the process block.
131 EXPECT_CALL(*process_block, Flush()).Times(1);
132
133 EXPECT_EQ(request_processor->SetProcessBlock(std::move(process_block)), OK);
134 EXPECT_EQ(request_processor->Flush(), OK);
135 }
136 }
137
TEST_F(RequestProcessorTest,BasicRequestProcessorRequest)138 TEST_F(RequestProcessorTest, BasicRequestProcessorRequest) {
139 auto request_processor = CreateBasicRequestrocessor();
140 ASSERT_NE(request_processor, nullptr);
141
142 auto process_block = std::make_unique<MockProcessBlock>();
143 ASSERT_NE(process_block, nullptr);
144
145 // Expect request process to send a request to the process block.
146 EXPECT_CALL(*process_block, ProcessRequests(_, _)).Times(1);
147
148 EXPECT_EQ(request_processor->SetProcessBlock(std::move(process_block)), OK);
149
150 // Testing BasicRequestProcessorRequest with a dummy request.
151 CaptureRequest request = {};
152 ASSERT_EQ(request_processor->ProcessRequest(request), OK);
153 }
154
155 } // namespace google_camera_hal
156 } // namespace android
157