Hash :
9137adea
        
        Author :
  
        
        Date :
2018-08-27T14:22:37
        
      
Add support for EGL_ANDROID_blob_cache The functionality of MemoryProgramCache is divided up in two. BlobCache is now a generic binary cache, which interfaces with the callbacks from EGL_ANDROID_blob_cache. MemoryProgramCache handles program [de]serialization and interacts with BlobCache. Bug: angleproject:2516 Change-Id: Ie4328a2e56a26338e033d84f4e53a1103411937d Reviewed-on: https://chromium-review.googlesource.com/1194285 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SizedMRUCache_unittest.h: Unit tests for the sized MRU cached.
#include <gtest/gtest.h>
#include "libANGLE/SizedMRUCache.h"
namespace angle
{
using Blob = std::vector<uint8_t>;
Blob MakeBlob(size_t size)
{
    Blob blob;
    for (uint8_t value = 0; value < size; ++value)
    {
        blob.push_back(value);
    }
    return blob;
}
// Test a cache with a value that takes up maximum size.
TEST(SizedMRUCacheTest, MaxSizedValue)
{
    constexpr size_t kSize = 32;
    SizedMRUCache<std::string, Blob> sizedCache(kSize);
    EXPECT_TRUE(sizedCache.put("test", MakeBlob(kSize), kSize));
    EXPECT_EQ(32u, sizedCache.size());
    EXPECT_FALSE(sizedCache.empty());
    EXPECT_TRUE(sizedCache.put("test2", MakeBlob(kSize), kSize));
    EXPECT_EQ(32u, sizedCache.size());
    EXPECT_FALSE(sizedCache.empty());
    const Blob *blob = nullptr;
    EXPECT_FALSE(sizedCache.get("test", &blob));
    sizedCache.clear();
    EXPECT_TRUE(sizedCache.empty());
}
// Test a cache with many small values, that it can handle unlimited inserts.
TEST(SizedMRUCacheTest, ManySmallValues)
{
    constexpr size_t kSize = 32;
    SizedMRUCache<size_t, size_t> sizedCache(kSize);
    for (size_t value = 0; value < kSize; ++value)
    {
        EXPECT_TRUE(sizedCache.put(value, std::move(value), 1));
        const size_t *qvalue = nullptr;
        EXPECT_TRUE(sizedCache.get(value, &qvalue));
        if (qvalue)
        {
            EXPECT_EQ(value, *qvalue);
        }
    }
    EXPECT_EQ(32u, sizedCache.size());
    EXPECT_FALSE(sizedCache.empty());
    // Putting one element evicts the first element.
    EXPECT_TRUE(sizedCache.put(kSize, std::move(static_cast<int>(kSize)), 1));
    const size_t *qvalue = nullptr;
    EXPECT_FALSE(sizedCache.get(0, &qvalue));
    // Putting one large element cleans out the whole stack.
    EXPECT_TRUE(sizedCache.put(kSize + 1, kSize + 1, kSize));
    EXPECT_EQ(32u, sizedCache.size());
    EXPECT_FALSE(sizedCache.empty());
    for (size_t value = 0; value <= kSize; ++value)
    {
        EXPECT_FALSE(sizedCache.get(value, &qvalue));
    }
    EXPECT_TRUE(sizedCache.get(kSize + 1, &qvalue));
    if (qvalue)
    {
        EXPECT_EQ(kSize + 1, *qvalue);
    }
    // Put a bunch of items in the cache sequentially.
    for (size_t value = 0; value < kSize * 10; ++value)
    {
        EXPECT_TRUE(sizedCache.put(value, std::move(value), 1));
    }
    EXPECT_EQ(32u, sizedCache.size());
}
// Tests putting an oversize element.
TEST(SizedMRUCacheTest, OversizeValue)
{
    constexpr size_t kSize = 32;
    SizedMRUCache<size_t, size_t> sizedCache(kSize);
    EXPECT_FALSE(sizedCache.put(5, 5, 100));
}
}  // namespace angle