blob: c1cbbfb4ef77468eaf9f60c0c94c6e184c74fc04 [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
17#undef LOG_TAG
18#define LOG_TAG "CachingTest"
19
20#include <gmock/gmock.h>
21#include <gtest/gtest.h>
22#include <gui/BufferQueue.h>
Patrick Williams83f36b22022-09-14 17:57:35 +000023
24#include "HwcSlotGenerator.h"
Valerie Hau64499682019-04-10 11:04:29 -070025
26namespace android {
27
28class SlotGenerationTest : public testing::Test {
29protected:
Vishnu Nair397a0e32022-07-26 00:01:48 +000030 sp<HwcSlotGenerator> mHwcSlotGenerator = sp<HwcSlotGenerator>::make();
Ady Abrahamd11bade2022-08-01 16:18:03 -070031 sp<GraphicBuffer> mBuffer1 =
32 sp<GraphicBuffer>::make(1u, 1u, HAL_PIXEL_FORMAT_RGBA_8888, 1u, 0u);
33 sp<GraphicBuffer> mBuffer2 =
34 sp<GraphicBuffer>::make(1u, 1u, HAL_PIXEL_FORMAT_RGBA_8888, 1u, 0u);
35 sp<GraphicBuffer> mBuffer3 =
36 sp<GraphicBuffer>::make(10u, 10u, HAL_PIXEL_FORMAT_RGBA_8888, 1u, 0u);
Valerie Hau64499682019-04-10 11:04:29 -070037};
38
39TEST_F(SlotGenerationTest, getHwcCacheSlot_Invalid) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070040 sp<IBinder> binder = sp<BBinder>::make();
Valerie Hau64499682019-04-10 11:04:29 -070041 // test getting invalid client_cache_id
42 client_cache_t id;
rnleeed20fa42021-08-10 18:00:03 -070043 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070044 EXPECT_EQ(BufferQueue::INVALID_BUFFER_SLOT, slot);
45}
46
47TEST_F(SlotGenerationTest, getHwcCacheSlot_Basic) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070048 sp<IBinder> binder = sp<BBinder>::make();
Valerie Hau64499682019-04-10 11:04:29 -070049 client_cache_t id;
50 id.token = binder;
51 id.id = 0;
rnleeed20fa42021-08-10 18:00:03 -070052 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070053 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
54
55 client_cache_t idB;
56 idB.token = binder;
57 idB.id = 1;
Ady Abrahama0a16272021-03-03 15:23:35 -080058 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070059 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
60
Ady Abrahama0a16272021-03-03 15:23:35 -080061 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070062 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
63
Ady Abrahama0a16272021-03-03 15:23:35 -080064 slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070065 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
66}
67
68TEST_F(SlotGenerationTest, getHwcCacheSlot_Reuse) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070069 sp<IBinder> binder = sp<BBinder>::make();
Valerie Hau64499682019-04-10 11:04:29 -070070 std::vector<client_cache_t> ids;
71 uint32_t cacheId = 0;
72 // fill up cache
rnleeed20fa42021-08-10 18:00:03 -070073 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Valerie Hau64499682019-04-10 11:04:29 -070074 client_cache_t id;
75 id.token = binder;
76 id.id = cacheId;
77 ids.push_back(id);
78
rnleeed20fa42021-08-10 18:00:03 -070079 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070080 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
81 cacheId++;
82 }
rnleeed20fa42021-08-10 18:00:03 -070083 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
84 int slot = mHwcSlotGenerator->getHwcCacheSlot(ids[static_cast<uint32_t>(i)]);
Valerie Hau64499682019-04-10 11:04:29 -070085 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
86 }
87
rnleeed20fa42021-08-10 18:00:03 -070088 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Valerie Hau64499682019-04-10 11:04:29 -070089 client_cache_t id;
90 id.token = binder;
91 id.id = cacheId;
rnleeed20fa42021-08-10 18:00:03 -070092 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070093 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
94 cacheId++;
95 }
96}
97} // namespace android