blob: 1b8c76d1b9c29d47c22525372dc2b8fce1406aaf [file] [log] [blame]
Valerie Hau64499682019-04-10 11:04:29 -07001/*
2 * Copyright 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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Valerie Hau64499682019-04-10 11:04:29 -070021#undef LOG_TAG
22#define LOG_TAG "CachingTest"
23
24#include <gmock/gmock.h>
25#include <gtest/gtest.h>
26#include <gui/BufferQueue.h>
27#include "BufferStateLayer.h"
28
29namespace android {
30
31class SlotGenerationTest : public testing::Test {
32protected:
33 BufferStateLayer::HwcSlotGenerator mHwcSlotGenerator;
34 sp<GraphicBuffer> mBuffer1{new GraphicBuffer(1, 1, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
35 sp<GraphicBuffer> mBuffer2{new GraphicBuffer(1, 1, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
36 sp<GraphicBuffer> mBuffer3{new GraphicBuffer(10, 10, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
37};
38
39TEST_F(SlotGenerationTest, getHwcCacheSlot_Invalid) {
40 sp<IBinder> binder = new BBinder();
41 // test getting invalid client_cache_id
42 client_cache_t id;
43 uint32_t slot = mHwcSlotGenerator.getHwcCacheSlot(id);
44 EXPECT_EQ(BufferQueue::INVALID_BUFFER_SLOT, slot);
45}
46
47TEST_F(SlotGenerationTest, getHwcCacheSlot_Basic) {
48 sp<IBinder> binder = new BBinder();
49 client_cache_t id;
50 id.token = binder;
51 id.id = 0;
52 uint32_t slot = mHwcSlotGenerator.getHwcCacheSlot(id);
53 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
54
55 client_cache_t idB;
56 idB.token = binder;
57 idB.id = 1;
58 slot = mHwcSlotGenerator.getHwcCacheSlot(idB);
59 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
60
61 slot = mHwcSlotGenerator.getHwcCacheSlot(idB);
62 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
63
64 slot = mHwcSlotGenerator.getHwcCacheSlot(id);
65 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
66}
67
68TEST_F(SlotGenerationTest, getHwcCacheSlot_Reuse) {
69 sp<IBinder> binder = new BBinder();
70 std::vector<client_cache_t> ids;
71 uint32_t cacheId = 0;
72 // fill up cache
73 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
74 client_cache_t id;
75 id.token = binder;
76 id.id = cacheId;
77 ids.push_back(id);
78
79 uint32_t slot = mHwcSlotGenerator.getHwcCacheSlot(id);
80 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
81 cacheId++;
82 }
83 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
84 uint32_t slot = mHwcSlotGenerator.getHwcCacheSlot(ids[i]);
85 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
86 }
87
88 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
89 client_cache_t id;
90 id.token = binder;
91 id.id = cacheId;
92 uint32_t slot = mHwcSlotGenerator.getHwcCacheSlot(id);
93 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
94 cacheId++;
95 }
96}
97} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080098
99// TODO(b/129481165): remove the #pragma below and fix conversion issues
100#pragma clang diagnostic pop // ignored "-Wconversion"