Commit cd8167fb by Jamie Madill Committed by Commit Bot

Vulkan: Fix EGLBlobCacheTest.

Several runs of the same test in a row would cause a failure if the cache would get hit. Fix the flakiness by resetting the cache between runs. Also cleans up some of the variable naming and adds a stream output for pretty test errors. Fixed while working on the standalone test harness. Bug: angleproject:3162 Change-Id: I64da8a37eedf562860e3e5409cbf6fb08e81dfa4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2047417Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 3c066404
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
// EGLBlobCacheTest: // EGLBlobCacheTest:
// Unit tests for the EGL_ANDROID_blob_cache extension. // Unit tests for the EGL_ANDROID_blob_cache extension.
// Must be included first to prevent errors with "None".
#include "test_utils/ANGLETest.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include "common/PackedEnums.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h" #include "test_utils/gl_raii.h"
#include "util/EGLWindow.h" #include "util/EGLWindow.h"
...@@ -20,18 +23,31 @@ constexpr char kEGLExtName[] = "EGL_ANDROID_blob_cache"; ...@@ -20,18 +23,31 @@ constexpr char kEGLExtName[] = "EGL_ANDROID_blob_cache";
enum class CacheOpResult enum class CacheOpResult
{ {
SET_SUCCESS, SetSuccess,
GET_NOT_FOUND, GetNotFound,
GET_MEMORY_TOO_SMALL, GetMemoryTooSmall,
GET_SUCCESS, GetSuccess,
ValueNotSet,
EnumCount = ValueNotSet,
};
VALUE_NOT_SET, angle::PackedEnumMap<CacheOpResult, std::string> kCacheOpToString = {
{CacheOpResult::SetSuccess, "SetSuccess"},
{CacheOpResult::GetNotFound, "GetNotFound"},
{CacheOpResult::GetMemoryTooSmall, "GetMemoryTooSmall"},
{CacheOpResult::GetSuccess, "GetSuccess"},
{CacheOpResult::ValueNotSet, "ValueNotSet"},
}; };
std::ostream &operator<<(std::ostream &os, CacheOpResult result)
{
return os << kCacheOpToString[result];
}
namespace namespace
{ {
std::map<std::vector<uint8_t>, std::vector<uint8_t>> gApplicationCache; std::map<std::vector<uint8_t>, std::vector<uint8_t>> gApplicationCache;
CacheOpResult gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET; CacheOpResult gLastCacheOpResult = CacheOpResult::ValueNotSet;
void SetBlob(const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize) void SetBlob(const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize)
{ {
...@@ -43,7 +59,7 @@ void SetBlob(const void *key, EGLsizeiANDROID keySize, const void *value, EGLsiz ...@@ -43,7 +59,7 @@ void SetBlob(const void *key, EGLsizeiANDROID keySize, const void *value, EGLsiz
gApplicationCache[keyVec] = valueVec; gApplicationCache[keyVec] = valueVec;
gLastCacheOpResult = CacheOpResult::SET_SUCCESS; gLastCacheOpResult = CacheOpResult::SetSuccess;
} }
EGLsizeiANDROID GetBlob(const void *key, EGLsizeiANDROID GetBlob(const void *key,
...@@ -57,18 +73,18 @@ EGLsizeiANDROID GetBlob(const void *key, ...@@ -57,18 +73,18 @@ EGLsizeiANDROID GetBlob(const void *key,
auto entry = gApplicationCache.find(keyVec); auto entry = gApplicationCache.find(keyVec);
if (entry == gApplicationCache.end()) if (entry == gApplicationCache.end())
{ {
gLastCacheOpResult = CacheOpResult::GET_NOT_FOUND; gLastCacheOpResult = CacheOpResult::GetNotFound;
return 0; return 0;
} }
if (entry->second.size() <= static_cast<size_t>(valueSize)) if (entry->second.size() <= static_cast<size_t>(valueSize))
{ {
memcpy(value, entry->second.data(), entry->second.size()); memcpy(value, entry->second.data(), entry->second.size());
gLastCacheOpResult = CacheOpResult::GET_SUCCESS; gLastCacheOpResult = CacheOpResult::GetSuccess;
} }
else else
{ {
gLastCacheOpResult = CacheOpResult::GET_MEMORY_TOO_SMALL; gLastCacheOpResult = CacheOpResult::GetMemoryTooSmall;
} }
return entry->second.size(); return entry->second.size();
...@@ -90,6 +106,8 @@ class EGLBlobCacheTest : public ANGLETest ...@@ -90,6 +106,8 @@ class EGLBlobCacheTest : public ANGLETest
mHasBlobCache = IsEGLDisplayExtensionEnabled(display, kEGLExtName); mHasBlobCache = IsEGLDisplayExtensionEnabled(display, kEGLExtName);
} }
void testTearDown() override { gApplicationCache.clear(); }
bool programBinaryAvailable() bool programBinaryAvailable()
{ {
return (getClientMajorVersion() >= 3 || IsGLExtensionEnabled("GL_OES_get_program_binary")); return (getClientMajorVersion() >= 3 || IsGLExtensionEnabled("GL_OES_get_program_binary"));
...@@ -146,26 +164,26 @@ void main() ...@@ -146,26 +164,26 @@ void main()
{ {
GLuint program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc); GLuint program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_NE(0u, program); ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::SET_SUCCESS, gLastCacheOpResult); EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET; gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Compile the same shader again, so it would try to retrieve it from the cache // Compile the same shader again, so it would try to retrieve it from the cache
program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc); program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_NE(0u, program); ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::GET_SUCCESS, gLastCacheOpResult); EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET; gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Compile another shader, which should create a new entry // Compile another shader, which should create a new entry
program = CompileProgram(kVertexShaderSrc2, kFragmentShaderSrc2); program = CompileProgram(kVertexShaderSrc2, kFragmentShaderSrc2);
ASSERT_NE(0u, program); ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::SET_SUCCESS, gLastCacheOpResult); EXPECT_EQ(CacheOpResult::SetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET; gLastCacheOpResult = CacheOpResult::ValueNotSet;
// Compile the first shader again, which should still reside in the cache // Compile the first shader again, which should still reside in the cache
program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc); program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_NE(0u, program); ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::GET_SUCCESS, gLastCacheOpResult); EXPECT_EQ(CacheOpResult::GetSuccess, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET; gLastCacheOpResult = CacheOpResult::ValueNotSet;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment