blob: 6a7ec9b5536034e0f3d925dc3624440d38a9475c [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:
Ady Abrahama0a16272021-03-03 15:23:35 -080034 sp<BufferStateLayer::HwcSlotGenerator> mHwcSlotGenerator =
35 sp<BufferStateLayer::HwcSlotGenerator>::make();
Valerie Hau64499682019-04-10 11:04:29 -070036 sp<GraphicBuffer> mBuffer1{new GraphicBuffer(1, 1, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
37 sp<GraphicBuffer> mBuffer2{new GraphicBuffer(1, 1, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
38 sp<GraphicBuffer> mBuffer3{new GraphicBuffer(10, 10, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
39};
40
41TEST_F(SlotGenerationTest, getHwcCacheSlot_Invalid) {
42 sp<IBinder> binder = new BBinder();
43 // test getting invalid client_cache_id
44 client_cache_t id;
Ady Abrahama0a16272021-03-03 15:23:35 -080045 uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070046 EXPECT_EQ(BufferQueue::INVALID_BUFFER_SLOT, slot);
47}
48
49TEST_F(SlotGenerationTest, getHwcCacheSlot_Basic) {
50 sp<IBinder> binder = new BBinder();
51 client_cache_t id;
52 id.token = binder;
53 id.id = 0;
Ady Abrahama0a16272021-03-03 15:23:35 -080054 uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070055 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
56
57 client_cache_t idB;
58 idB.token = binder;
59 idB.id = 1;
Ady Abrahama0a16272021-03-03 15:23:35 -080060 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070061 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
62
Ady Abrahama0a16272021-03-03 15:23:35 -080063 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070064 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
65
Ady Abrahama0a16272021-03-03 15:23:35 -080066 slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070067 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
68}
69
70TEST_F(SlotGenerationTest, getHwcCacheSlot_Reuse) {
71 sp<IBinder> binder = new BBinder();
72 std::vector<client_cache_t> ids;
73 uint32_t cacheId = 0;
74 // fill up cache
75 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
76 client_cache_t id;
77 id.token = binder;
78 id.id = cacheId;
79 ids.push_back(id);
80
Ady Abrahama0a16272021-03-03 15:23:35 -080081 uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070082 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
83 cacheId++;
84 }
85 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Ady Abrahama0a16272021-03-03 15:23:35 -080086 uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(ids[i]);
Valerie Hau64499682019-04-10 11:04:29 -070087 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
88 }
89
90 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
91 client_cache_t id;
92 id.token = binder;
93 id.id = cacheId;
Ady Abrahama0a16272021-03-03 15:23:35 -080094 uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070095 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
96 cacheId++;
97 }
98}
99} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800100
101// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100102#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"