Hash :
f455f756
Author :
Date :
2019-03-20T20:49:44
Reuse angle_end2end_test windows and displays. This both speeds up test execution and cuts down on the number of new windows and displays created for a test config. This feature is only currently enabled for Windows NVIDIA and Intel. On every other config there were blocking issues that would need investigation. Several tests were manually flagged as needed new displays on each iteration to prevent test flakiness. This feature might fix the issues with Intel test flakiness that have been prominent on the ANGLE CQ. WGL configurations have also been removed from ANGLE tests. So this removes more of the code from ANGLETest.cpp. Bug: angleproject:3261 Change-Id: Ic2864d4806ad38e0eeaa3c0afcd54ae1c548090f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1520995 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
//
// Copyright 2018 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.
//
// EGLBlobCacheTest:
// Unit tests for the EGL_ANDROID_blob_cache extension.
#include <map>
#include <vector>
#include "common/angleutils.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
using namespace angle;
constexpr char kEGLExtName[] = "EGL_ANDROID_blob_cache";
enum class CacheOpResult
{
SET_SUCCESS,
GET_NOT_FOUND,
GET_MEMORY_TOO_SMALL,
GET_SUCCESS,
VALUE_NOT_SET,
};
namespace
{
std::map<std::vector<uint8_t>, std::vector<uint8_t>> gApplicationCache;
CacheOpResult gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET;
void SetBlob(const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize)
{
std::vector<uint8_t> keyVec(keySize);
memcpy(keyVec.data(), key, keySize);
std::vector<uint8_t> valueVec(valueSize);
memcpy(valueVec.data(), value, valueSize);
gApplicationCache[keyVec] = valueVec;
gLastCacheOpResult = CacheOpResult::SET_SUCCESS;
}
EGLsizeiANDROID GetBlob(const void *key,
EGLsizeiANDROID keySize,
void *value,
EGLsizeiANDROID valueSize)
{
std::vector<uint8_t> keyVec(keySize);
memcpy(keyVec.data(), key, keySize);
auto entry = gApplicationCache.find(keyVec);
if (entry == gApplicationCache.end())
{
gLastCacheOpResult = CacheOpResult::GET_NOT_FOUND;
return 0;
}
if (entry->second.size() <= static_cast<size_t>(valueSize))
{
memcpy(value, entry->second.data(), entry->second.size());
gLastCacheOpResult = CacheOpResult::GET_SUCCESS;
}
else
{
gLastCacheOpResult = CacheOpResult::GET_MEMORY_TOO_SMALL;
}
return entry->second.size();
}
} // anonymous namespace
class EGLBlobCacheTest : public ANGLETest
{
protected:
EGLBlobCacheTest() : mHasBlobCache(false)
{
// Force disply caching off. Blob cache functions require it.
forceNewDisplay();
}
void SetUp() override
{
ANGLETest::SetUp();
EGLDisplay display = getEGLWindow()->getDisplay();
mHasBlobCache = eglDisplayExtensionEnabled(display, kEGLExtName);
}
bool programBinaryAvailable()
{
return (getClientMajorVersion() >= 3 || extensionEnabled("GL_OES_get_program_binary"));
}
bool mHasBlobCache;
};
// Makes sure the extension exists and works
TEST_P(EGLBlobCacheTest, Functional)
{
EGLDisplay display = getEGLWindow()->getDisplay();
EXPECT_TRUE(mHasBlobCache);
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
constexpr char kVertexShaderSrc[] = R"(attribute vec4 aTest;
attribute vec2 aPosition;
varying vec4 vTest;
void main()
{
vTest = aTest;
gl_Position = vec4(aPosition, 0.0, 1.0);
gl_PointSize = 1.0;
})";
constexpr char kFragmentShaderSrc[] = R"(precision mediump float;
varying vec4 vTest;
void main()
{
gl_FragColor = vTest;
})";
constexpr char kVertexShaderSrc2[] = R"(attribute vec4 aTest;
attribute vec2 aPosition;
varying vec4 vTest;
void main()
{
vTest = aTest;
gl_Position = vec4(aPosition, 1.0, 1.0);
gl_PointSize = 1.0;
})";
constexpr char kFragmentShaderSrc2[] = R"(precision mediump float;
varying vec4 vTest;
void main()
{
gl_FragColor = vTest - vec4(0.0, 1.0, 0.0, 0.0);
})";
// Compile a shader so it puts something in the cache
if (programBinaryAvailable())
{
GLuint program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::SET_SUCCESS, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET;
// Compile the same shader again, so it would try to retrieve it from the cache
program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::GET_SUCCESS, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET;
// Compile another shader, which should create a new entry
program = CompileProgram(kVertexShaderSrc2, kFragmentShaderSrc2);
ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::SET_SUCCESS, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET;
// Compile the first shader again, which should still reside in the cache
program = CompileProgram(kVertexShaderSrc, kFragmentShaderSrc);
ASSERT_NE(0u, program);
EXPECT_EQ(CacheOpResult::GET_SUCCESS, gLastCacheOpResult);
gLastCacheOpResult = CacheOpResult::VALUE_NOT_SET;
}
}
// Tests error conditions of the APIs.
TEST_P(EGLBlobCacheTest, NegativeAPI)
{
EXPECT_TRUE(mHasBlobCache);
// Test bad display
eglSetBlobCacheFuncsANDROID(EGL_NO_DISPLAY, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
eglSetBlobCacheFuncsANDROID(EGL_NO_DISPLAY, SetBlob, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
EGLDisplay display = getEGLWindow()->getDisplay();
// Test bad arguments
eglSetBlobCacheFuncsANDROID(display, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, SetBlob, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, nullptr, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
// Set the arguments once and test setting them again (which should fail)
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
ASSERT_EGL_SUCCESS();
eglSetBlobCacheFuncsANDROID(display, SetBlob, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
// Try again with bad parameters
eglSetBlobCacheFuncsANDROID(EGL_NO_DISPLAY, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
eglSetBlobCacheFuncsANDROID(display, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, SetBlob, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglSetBlobCacheFuncsANDROID(display, nullptr, GetBlob);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
}
ANGLE_INSTANTIATE_TEST(EGLBlobCacheTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_VULKAN());