| Valerie Hau | 6449968 | 2019-04-10 11:04:29 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 18 | #pragma clang diagnostic push | 
|  | 19 | #pragma clang diagnostic ignored "-Wconversion" | 
|  | 20 |  | 
| Valerie Hau | 6449968 | 2019-04-10 11:04:29 -0700 | [diff] [blame] | 21 | #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 |  | 
|  | 29 | namespace android { | 
|  | 30 |  | 
|  | 31 | class SlotGenerationTest : public testing::Test { | 
|  | 32 | protected: | 
|  | 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 |  | 
|  | 39 | TEST_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 |  | 
|  | 47 | TEST_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 |  | 
|  | 68 | TEST_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 Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 98 |  | 
|  | 99 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 100 | #pragma clang diagnostic pop // ignored "-Wconversion" |