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 "HwlBufferAllocatorTests"
18 #include <log/log.h>
19
20 #include <gtest/gtest.h>
21 #include <hwl_buffer_allocator.h>
22 #include "mock_buffer_allocator_hwl.h"
23
24 namespace android {
25 namespace google_camera_hal {
26
27 static const uint32_t kBufferWidth = 4032;
28 static const uint32_t kBufferHeight = 3024;
29 static const uint32_t kMaxBufferDepth = 10;
30
31 // Test HwlBufferAllocator Create.
TEST(HwlBufferAllocatorTests,Create)32 TEST(HwlBufferAllocatorTests, Create) {
33 auto mock_allocator_hwl = MockBufferAllocatorHwl::Create();
34 ASSERT_NE(mock_allocator_hwl, nullptr);
35
36 auto allocator = HwlBufferAllocator::Create(mock_allocator_hwl.get());
37 ASSERT_NE(allocator, nullptr) << "Create HwlBufferAllocator failed.";
38 }
39
40 // Test HwlBufferAllocator AllocateFreeBuffers.
TEST(HwlBufferAllocatorTests,AllocateFreeBuffers)41 TEST(HwlBufferAllocatorTests, AllocateFreeBuffers) {
42 auto mock_allocator_hwl = MockBufferAllocatorHwl::Create();
43 ASSERT_NE(mock_allocator_hwl, nullptr);
44
45 auto allocator = HwlBufferAllocator::Create(mock_allocator_hwl.get());
46 ASSERT_NE(allocator, nullptr) << "Create HwlBufferAllocator failed.";
47
48 HalBufferDescriptor buffer_descriptor = {};
49 buffer_descriptor.width = kBufferWidth;
50 buffer_descriptor.height = kBufferHeight;
51 buffer_descriptor.format = HAL_PIXEL_FORMAT_RAW10;
52 buffer_descriptor.producer_flags = GRALLOC1_PRODUCER_USAGE_CAMERA;
53 buffer_descriptor.consumer_flags = GRALLOC1_CONSUMER_USAGE_CAMERA;
54 buffer_descriptor.immediate_num_buffers = kMaxBufferDepth;
55 buffer_descriptor.max_num_buffers = kMaxBufferDepth;
56
57 std::vector<buffer_handle_t> buffers_;
58 status_t res = allocator->AllocateBuffers(buffer_descriptor, &buffers_);
59 ASSERT_EQ(res, OK) << "AllocateBuffers failed: " << strerror(res);
60 ASSERT_EQ(buffers_.size(), (uint32_t)kMaxBufferDepth)
61 << "AllocateBuffers failed with wrong buffer number " << buffers_.size();
62
63 allocator->FreeBuffers(&buffers_);
64 ASSERT_EQ(buffers_.size(), (uint32_t)0)
65 << "AllocateBuffers failed with wrong buffer number " << buffers_.size();
66 }
67 } // namespace google_camera_hal
68 } // namespace android
69