blob: 7f203ce943ba028d81428263598be934469f6951 [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>
23#include "BufferStateLayer.h"
24
25namespace android {
26
27class SlotGenerationTest : public testing::Test {
28protected:
Vishnu Nair397a0e32022-07-26 00:01:48 +000029 sp<HwcSlotGenerator> mHwcSlotGenerator = sp<HwcSlotGenerator>::make();
Valerie Hau64499682019-04-10 11:04:29 -070030 sp<GraphicBuffer> mBuffer1{new GraphicBuffer(1, 1, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
31 sp<GraphicBuffer> mBuffer2{new GraphicBuffer(1, 1, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
32 sp<GraphicBuffer> mBuffer3{new GraphicBuffer(10, 10, HAL_PIXEL_FORMAT_RGBA_8888, 1, 0)};
33};
34
35TEST_F(SlotGenerationTest, getHwcCacheSlot_Invalid) {
36 sp<IBinder> binder = new BBinder();
37 // test getting invalid client_cache_id
38 client_cache_t id;
rnleeed20fa42021-08-10 18:00:03 -070039 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070040 EXPECT_EQ(BufferQueue::INVALID_BUFFER_SLOT, slot);
41}
42
43TEST_F(SlotGenerationTest, getHwcCacheSlot_Basic) {
44 sp<IBinder> binder = new BBinder();
45 client_cache_t id;
46 id.token = binder;
47 id.id = 0;
rnleeed20fa42021-08-10 18:00:03 -070048 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070049 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
50
51 client_cache_t idB;
52 idB.token = binder;
53 idB.id = 1;
Ady Abrahama0a16272021-03-03 15:23:35 -080054 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070055 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
56
Ady Abrahama0a16272021-03-03 15:23:35 -080057 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070058 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
59
Ady Abrahama0a16272021-03-03 15:23:35 -080060 slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070061 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
62}
63
64TEST_F(SlotGenerationTest, getHwcCacheSlot_Reuse) {
65 sp<IBinder> binder = new BBinder();
66 std::vector<client_cache_t> ids;
67 uint32_t cacheId = 0;
68 // fill up cache
rnleeed20fa42021-08-10 18:00:03 -070069 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Valerie Hau64499682019-04-10 11:04:29 -070070 client_cache_t id;
71 id.token = binder;
72 id.id = cacheId;
73 ids.push_back(id);
74
rnleeed20fa42021-08-10 18:00:03 -070075 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070076 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
77 cacheId++;
78 }
rnleeed20fa42021-08-10 18:00:03 -070079 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
80 int slot = mHwcSlotGenerator->getHwcCacheSlot(ids[static_cast<uint32_t>(i)]);
Valerie Hau64499682019-04-10 11:04:29 -070081 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
82 }
83
rnleeed20fa42021-08-10 18:00:03 -070084 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Valerie Hau64499682019-04-10 11:04:29 -070085 client_cache_t id;
86 id.token = binder;
87 id.id = cacheId;
rnleeed20fa42021-08-10 18:00:03 -070088 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070089 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
90 cacheId++;
91 }
92}
93} // namespace android