Hash :
c03a4235
Author :
Date :
2021-02-20T16:14:37
Suppress UNINSTANTIATED_PARAMETERIZED_TEST failures on Nexus 5X GTest complains that we don't run some tests on GLES backend. Bug: chromium:1180570 Change-Id: I9427ac25c3b6f06f3c042caa3c0afc7000cf1599 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2710783 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
//
// 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.
//
// EGLProgramCacheControlTest:
// Unit tests for the EGL_ANGLE_program_cache_control extension.
#include "common/angleutils.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
using namespace angle;
constexpr EGLint kEnabledCacheSize = 0x10000;
constexpr char kEGLExtName[] = "EGL_ANGLE_program_cache_control";
void TestCacheProgram(PlatformMethods *platform,
const ProgramKeyType &key,
size_t programSize,
const uint8_t *programBytes);
class EGLProgramCacheControlTest : public ANGLETest
{
public:
void onCache(const ProgramKeyType &key, size_t programSize, const uint8_t *programBytes)
{
mCachedKey = key;
mCachedBinary.assign(&programBytes[0], &programBytes[programSize]);
}
protected:
EGLProgramCacheControlTest()
{
// Test flakiness was noticed when reusing displays.
forceNewDisplay();
setDeferContextInit(true);
setContextProgramCacheEnabled(true);
gDefaultPlatformMethods.cacheProgram = TestCacheProgram;
}
void testSetUp() override
{
if (extensionAvailable())
{
EGLDisplay display = getEGLWindow()->getDisplay();
eglProgramCacheResizeANGLE(display, kEnabledCacheSize, EGL_PROGRAM_CACHE_RESIZE_ANGLE);
ASSERT_EGL_SUCCESS();
}
ASSERT_TRUE(getEGLWindow()->initializeContext());
}
void testTearDown() override { gDefaultPlatformMethods.cacheProgram = DefaultCacheProgram; }
bool extensionAvailable()
{
EGLDisplay display = getEGLWindow()->getDisplay();
return IsEGLDisplayExtensionEnabled(display, kEGLExtName);
}
bool programBinaryAvailable()
{
return (getClientMajorVersion() >= 3 || IsGLExtensionEnabled("GL_OES_get_program_binary"));
}
ProgramKeyType mCachedKey;
std::vector<uint8_t> mCachedBinary;
};
void TestCacheProgram(PlatformMethods *platform,
const ProgramKeyType &key,
size_t programSize,
const uint8_t *programBytes)
{
auto *testPlatformContext = static_cast<TestPlatformContext *>(platform->context);
auto *testCase =
reinterpret_cast<EGLProgramCacheControlTest *>(testPlatformContext->currentTest);
testCase->onCache(key, programSize, programBytes);
}
// Tests error conditions of the APIs.
TEST_P(EGLProgramCacheControlTest, NegativeAPI)
{
ANGLE_SKIP_TEST_IF(!extensionAvailable());
constexpr char kDefaultKey[] = "defaultMakeItLongEnough";
constexpr char kDefaultBinary[] = "defaultMakeItLongEnough";
constexpr EGLint kDefaultKeySize = static_cast<EGLint>(ArraySize(kDefaultKey));
constexpr EGLint kDefaultBinarySize = static_cast<EGLint>(ArraySize(kDefaultBinary));
// Test that passing an invalid display to the entry point methods fails.
eglProgramCacheGetAttribANGLE(EGL_NO_DISPLAY, EGL_PROGRAM_CACHE_KEY_LENGTH_ANGLE);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
eglProgramCachePopulateANGLE(EGL_NO_DISPLAY, kDefaultKey, kDefaultKeySize, kDefaultBinary,
kDefaultBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
EGLint tempKeySize = 0;
EGLint tempBinarySize = 0;
eglProgramCacheQueryANGLE(EGL_NO_DISPLAY, 0, nullptr, &tempKeySize, nullptr, &tempBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
eglProgramCacheResizeANGLE(EGL_NO_DISPLAY, 0, EGL_PROGRAM_CACHE_TRIM_ANGLE);
EXPECT_EGL_ERROR(EGL_BAD_DISPLAY);
// Test querying properties with bad parameters.
EGLDisplay display = getEGLWindow()->getDisplay();
eglProgramCacheGetAttribANGLE(display, EGL_PROGRAM_CACHE_RESIZE_ANGLE);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
// Test populating with invalid parameters.
EGLint keySize = eglProgramCacheGetAttribANGLE(display, EGL_PROGRAM_CACHE_KEY_LENGTH_ANGLE);
EXPECT_GT(kDefaultKeySize, keySize);
eglProgramCachePopulateANGLE(display, kDefaultKey, keySize + 1, kDefaultBinary,
kDefaultBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCachePopulateANGLE(display, kDefaultKey, keySize, kDefaultBinary, -1);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCachePopulateANGLE(display, nullptr, keySize, kDefaultBinary, kDefaultBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCachePopulateANGLE(display, kDefaultKey, keySize, nullptr, kDefaultBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
// Test querying cache entries with invalid parameters.
eglProgramCachePopulateANGLE(display, kDefaultKey, keySize, kDefaultBinary, kDefaultBinarySize);
ASSERT_EGL_SUCCESS();
EGLint cacheSize = eglProgramCacheGetAttribANGLE(display, EGL_PROGRAM_CACHE_SIZE_ANGLE);
ASSERT_EQ(1, cacheSize);
eglProgramCacheQueryANGLE(display, -1, nullptr, &tempKeySize, nullptr, &tempBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCacheQueryANGLE(display, 1, nullptr, &tempKeySize, nullptr, &tempBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCacheQueryANGLE(display, 0, nullptr, nullptr, nullptr, &tempBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCacheQueryANGLE(display, 0, nullptr, &tempKeySize, nullptr, nullptr);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCacheQueryANGLE(display, 0, nullptr, &tempKeySize, nullptr, &tempBinarySize);
ASSERT_EGL_SUCCESS();
ASSERT_EQ(keySize, tempKeySize);
ASSERT_EQ(kDefaultBinarySize, tempBinarySize);
std::vector<uint8_t> tempKey(tempKeySize + 5);
std::vector<uint8_t> tempBinary(tempBinarySize + 5);
tempKeySize--;
eglProgramCacheQueryANGLE(display, 0, tempKey.data(), &tempKeySize, tempBinary.data(),
&tempBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
tempKeySize++;
tempBinarySize--;
eglProgramCacheQueryANGLE(display, 0, tempKey.data(), &tempKeySize, tempBinary.data(),
&tempBinarySize);
EXPECT_EGL_ERROR(EGL_BAD_ACCESS);
// Test resizing with invalid parameters.
eglProgramCacheResizeANGLE(display, -1, EGL_PROGRAM_CACHE_TRIM_ANGLE);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
eglProgramCacheResizeANGLE(display, 0, EGL_PROGRAM_CACHE_KEY_LENGTH_ANGLE);
EXPECT_EGL_ERROR(EGL_BAD_PARAMETER);
}
// Tests a basic use case.
TEST_P(EGLProgramCacheControlTest, SaveAndReload)
{
ANGLE_SKIP_TEST_IF(!extensionAvailable() || !programBinaryAvailable());
constexpr char kVS[] = "attribute vec4 position; void main() { gl_Position = position; }";
constexpr char kFS[] = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }";
// Link a program, which will miss the cache.
{
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ANGLE_GL_PROGRAM(program, kVS, kFS);
drawQuad(program, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
}
EGLDisplay display = getEGLWindow()->getDisplay();
EGLint cacheSize = eglProgramCacheGetAttribANGLE(display, EGL_PROGRAM_CACHE_SIZE_ANGLE);
EXPECT_EQ(1, cacheSize);
EGLint keySize = 0;
EGLint binarySize = 0;
eglProgramCacheQueryANGLE(display, 0, nullptr, &keySize, nullptr, &binarySize);
EXPECT_EQ(static_cast<EGLint>(mCachedKey.size()), keySize);
ASSERT_EGL_SUCCESS();
ProgramKeyType keyBuffer;
std::vector<uint8_t> binaryBuffer(binarySize);
eglProgramCacheQueryANGLE(display, 0, keyBuffer.data(), &keySize, binaryBuffer.data(),
&binarySize);
ASSERT_EGL_SUCCESS();
EXPECT_EQ(mCachedKey, keyBuffer);
EXPECT_EQ(mCachedBinary, binaryBuffer);
// Restart EGL and GL.
recreateTestFixture();
// Warm up the cache.
EGLint newCacheSize = eglProgramCacheGetAttribANGLE(display, EGL_PROGRAM_CACHE_SIZE_ANGLE);
EXPECT_EQ(0, newCacheSize);
eglProgramCachePopulateANGLE(display, keyBuffer.data(), keySize, binaryBuffer.data(),
binarySize);
mCachedBinary.clear();
// Link a program, which will hit the cache.
{
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ANGLE_GL_PROGRAM(program, kVS, kFS);
drawQuad(program, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
}
// Verify no new shader was compiled.
EXPECT_TRUE(mCachedBinary.empty());
}
// Tests that trying to link a program without correct shaders doesn't buggily call the cache.
TEST_P(EGLProgramCacheControlTest, LinkProgramWithBadShaders)
{
ANGLE_SKIP_TEST_IF(!extensionAvailable());
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
GLuint program = glCreateProgram();
glAttachShader(program, shader);
glLinkProgram(program);
GLint linkStatus = 0;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
EXPECT_GL_NO_ERROR();
glDeleteShader(shader);
glDeleteProgram(program);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLProgramCacheControlTest);
ANGLE_INSTANTIATE_TEST(EGLProgramCacheControlTest,
ES2_D3D9(),
ES2_D3D11(),
ES2_OPENGL(),
ES2_VULKAN());