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