• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2012 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ANGLETest:
7 //   Implementation of common ANGLE testing fixture.
8 //
9 
10 #ifndef ANGLE_TESTS_ANGLE_TEST_H_
11 #define ANGLE_TESTS_ANGLE_TEST_H_
12 
13 #include <gtest/gtest.h>
14 #include <algorithm>
15 #include <array>
16 
17 #include "angle_test_configs.h"
18 #include "common/angleutils.h"
19 #include "common/vector_utils.h"
20 #include "platform/Platform.h"
21 #include "util/EGLWindow.h"
22 #include "util/shader_utils.h"
23 #include "util/system_utils.h"
24 #include "util/util_gl.h"
25 
26 namespace angle
27 {
28 struct SystemInfo;
29 }  // namespace angle
30 
31 #define ASSERT_GL_TRUE(a) ASSERT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
32 #define ASSERT_GL_FALSE(a) ASSERT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
33 #define EXPECT_GL_TRUE(a) EXPECT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
34 #define EXPECT_GL_FALSE(a) EXPECT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
35 
36 #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
37 #define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
38 
39 #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
40 #define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
41 
42 #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
43 #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
44 
45 // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u.
46 #define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
47 #define ASSERT_EGL_FALSE(a) \
48     ASSERT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
49 #define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
50 #define EXPECT_EGL_FALSE(a) \
51     EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
52 
53 #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
54 #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
55 
56 #define ASSERT_GLENUM_EQ(expected, actual) \
57     ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
58 #define EXPECT_GLENUM_EQ(expected, actual) \
59     EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
60 #define ASSERT_GLENUM_NE(expected, actual) \
61     ASSERT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
62 #define EXPECT_GLENUM_NE(expected, actual) \
63     EXPECT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
64 
65 #define ASSERT_EGLENUM_EQ(expected, actual) \
66     ASSERT_EQ(static_cast<EGLenum>(expected), static_cast<EGLenum>(actual))
67 #define EXPECT_EGLENUM_EQ(expected, actual) \
68     EXPECT_EQ(static_cast<EGLenum>(expected), static_cast<EGLenum>(actual))
69 
70 #define ASSERT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
71     ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
72 #define EXPECT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
73     EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
74 
75 namespace angle
76 {
77 struct GLColorRGB
78 {
GLColorRGBGLColorRGB79     constexpr GLColorRGB() : R(0), G(0), B(0) {}
GLColorRGBGLColorRGB80     constexpr GLColorRGB(GLubyte r, GLubyte g, GLubyte b) : R(r), G(g), B(b) {}
81     GLColorRGB(const angle::Vector3 &floatColor);
82 
dataGLColorRGB83     const GLubyte *data() const { return &R; }
dataGLColorRGB84     GLubyte *data() { return &R; }
85 
86     GLubyte R, G, B;
87 
88     static const GLColorRGB black;
89     static const GLColorRGB blue;
90     static const GLColorRGB green;
91     static const GLColorRGB red;
92     static const GLColorRGB yellow;
93 };
94 
95 struct GLColor
96 {
GLColorGLColor97     constexpr GLColor() : R(0), G(0), B(0), A(0) {}
GLColorGLColor98     constexpr GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a) {}
99     GLColor(const angle::Vector4 &floatColor);
100     GLColor(GLuint colorValue);
101 
102     angle::Vector4 toNormalizedVector() const;
103 
104     GLubyte &operator[](size_t index) { return (&R)[index]; }
105 
106     const GLubyte &operator[](size_t index) const { return (&R)[index]; }
107 
dataGLColor108     const GLubyte *data() const { return &R; }
dataGLColor109     GLubyte *data() { return &R; }
110 
111     testing::AssertionResult ExpectNear(const GLColor &expected, const GLColor &err) const;
112 
113     GLubyte R, G, B, A;
114 
115     static const GLColor black;
116     static const GLColor blue;
117     static const GLColor cyan;
118     static const GLColor green;
119     static const GLColor red;
120     static const GLColor transparentBlack;
121     static const GLColor white;
122     static const GLColor yellow;
123     static const GLColor magenta;
124 };
125 
126 struct GLColor32F
127 {
GLColor32FGLColor32F128     constexpr GLColor32F() : GLColor32F(0.0f, 0.0f, 0.0f, 0.0f) {}
GLColor32FGLColor32F129     constexpr GLColor32F(GLfloat r, GLfloat g, GLfloat b, GLfloat a) : R(r), G(g), B(b), A(a) {}
130 
131     GLfloat R, G, B, A;
132 };
133 
134 static constexpr GLColor32F kFloatRed   = {1.0f, 0.0f, 0.0f, 1.0f};
135 static constexpr GLColor32F kFloatGreen = {0.0f, 1.0f, 0.0f, 1.0f};
136 static constexpr GLColor32F kFloatBlue  = {0.0f, 0.0f, 1.0f, 1.0f};
137 
138 // The input here for pixelPoints are the expected integer window coordinates, we add .5 to every
139 // one of them and re-scale the numbers to be between [-1,1]. Using this technique, we can make
140 // sure the rasterization stage will end up drawing pixels at the expected locations.
141 void CreatePixelCenterWindowCoords(const std::vector<Vector2> &pixelPoints,
142                                    int windowWidth,
143                                    int windowHeight,
144                                    std::vector<Vector3> *outVertices);
145 
146 // Useful to cast any type to GLubyte.
147 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor(TR r,TG g,TB b,TA a)148 GLColor MakeGLColor(TR r, TG g, TB b, TA a)
149 {
150     return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
151                    static_cast<GLubyte>(a));
152 }
153 
154 bool operator==(const GLColor &a, const GLColor &b);
155 bool operator!=(const GLColor &a, const GLColor &b);
156 std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
157 GLColor ReadColor(GLint x, GLint y);
158 
159 // Useful to cast any type to GLfloat.
160 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor32F(TR r,TG g,TB b,TA a)161 GLColor32F MakeGLColor32F(TR r, TG g, TB b, TA a)
162 {
163     return GLColor32F(static_cast<GLfloat>(r), static_cast<GLfloat>(g), static_cast<GLfloat>(b),
164                       static_cast<GLfloat>(a));
165 }
166 
167 bool operator==(const GLColor32F &a, const GLColor32F &b);
168 std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color);
169 GLColor32F ReadColor32F(GLint x, GLint y);
170 
171 }  // namespace angle
172 
173 #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
174     EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
175 
176 #define EXPECT_PIXEL_NE(x, y, r, g, b, a) \
177     EXPECT_NE(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
178 
179 #define EXPECT_PIXEL_32F_EQ(x, y, r, g, b, a) \
180     EXPECT_EQ(angle::MakeGLColor32F(r, g, b, a), angle::ReadColor32F(x, y))
181 
182 #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
183 
184 #define EXPECT_PIXEL_ALPHA32F_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor32F(x, y).A)
185 
186 #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
187 #define EXPECT_PIXEL_COLOR_EQ_VEC2(vec2, angleColor) \
188     EXPECT_EQ(angleColor,                            \
189               angle::ReadColor(static_cast<GLint>(vec2.x()), static_cast<GLint>(vec2.y())))
190 
191 #define EXPECT_PIXEL_COLOR32F_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor32F(x, y))
192 
193 #define EXPECT_PIXEL_RECT_EQ(x, y, width, height, color)                                           \
194     do                                                                                             \
195     {                                                                                              \
196         std::vector<GLColor> actualColors(width *height);                                          \
197         glReadPixels((x), (y), (width), (height), GL_RGBA, GL_UNSIGNED_BYTE, actualColors.data()); \
198         std::vector<GLColor> expectedColors(width *height, color);                                 \
199         EXPECT_EQ(expectedColors, actualColors);                                                   \
200     } while (0)
201 
202 #define EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, ctype, format, type) \
203     do                                                                             \
204     {                                                                              \
205         ctype pixel[4];                                                            \
206         glReadPixels((x), (y), 1, 1, format, type, pixel);                         \
207         EXPECT_GL_NO_ERROR();                                                      \
208         EXPECT_NEAR((r), pixel[0], abs_error);                                     \
209         EXPECT_NEAR((g), pixel[1], abs_error);                                     \
210         EXPECT_NEAR((b), pixel[2], abs_error);                                     \
211         EXPECT_NEAR((a), pixel[3], abs_error);                                     \
212     } while (0)
213 
214 #define EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, ctype, format, type) \
215     do                                                                \
216     {                                                                 \
217         ctype pixel[4];                                               \
218         glReadPixels((x), (y), 1, 1, format, type, pixel);            \
219         EXPECT_GL_NO_ERROR();                                         \
220         EXPECT_EQ((r), pixel[0]);                                     \
221         EXPECT_EQ((g), pixel[1]);                                     \
222         EXPECT_EQ((b), pixel[2]);                                     \
223         EXPECT_EQ((a), pixel[3]);                                     \
224     } while (0)
225 
226 #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
227     EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLubyte, GL_RGBA, GL_UNSIGNED_BYTE)
228 
229 #define EXPECT_PIXEL_32F_NEAR(x, y, r, g, b, a, abs_error) \
230     EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLfloat, GL_RGBA, GL_FLOAT)
231 
232 #define EXPECT_PIXEL_8I(x, y, r, g, b, a) \
233     EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLbyte, GL_RGBA_INTEGER, GL_BYTE)
234 
235 #define EXPECT_PIXEL_8UI(x, y, r, g, b, a) \
236     EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLubyte, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE)
237 
238 // TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
239 #define EXPECT_PIXEL_COLOR_NEAR(x, y, angleColor, abs_error) \
240     EXPECT_PIXEL_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
241 
242 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
243     EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
244 
245 #define EXPECT_COLOR_NEAR(expected, actual, abs_error) \
246     do                                                 \
247     {                                                  \
248         EXPECT_NEAR(expected.R, actual.R, abs_error);  \
249         EXPECT_NEAR(expected.G, actual.G, abs_error);  \
250         EXPECT_NEAR(expected.B, actual.B, abs_error);  \
251         EXPECT_NEAR(expected.A, actual.A, abs_error);  \
252     } while (0)
253 #define EXPECT_PIXEL32F_NEAR(x, y, r, g, b, a, abs_error)       \
254     do                                                          \
255     {                                                           \
256         GLfloat pixel[4];                                       \
257         glReadPixels((x), (y), 1, 1, GL_RGBA, GL_FLOAT, pixel); \
258         EXPECT_GL_NO_ERROR();                                   \
259         EXPECT_NEAR((r), pixel[0], abs_error);                  \
260         EXPECT_NEAR((g), pixel[1], abs_error);                  \
261         EXPECT_NEAR((b), pixel[2], abs_error);                  \
262         EXPECT_NEAR((a), pixel[3], abs_error);                  \
263     } while (0)
264 
265 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
266     EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
267 
268 class ANGLETestBase;
269 class EGLWindow;
270 class GLWindowBase;
271 class OSWindow;
272 class WGLWindow;
273 
274 struct TestPlatformContext final : private angle::NonCopyable
275 {
276     bool ignoreMessages        = false;
277     bool warningsAsErrors      = false;
278     ANGLETestBase *currentTest = nullptr;
279 };
280 
281 class ANGLETestBase
282 {
283   protected:
284     ANGLETestBase(const angle::PlatformParameters &params);
285     virtual ~ANGLETestBase();
286 
287   public:
288     void setWindowVisible(bool isVisible);
289 
overrideWorkaroundsD3D(angle::FeaturesD3D * featuresD3D)290     virtual void overrideWorkaroundsD3D(angle::FeaturesD3D *featuresD3D) {}
overrideFeaturesVk(angle::FeaturesVk * featuresVulkan)291     virtual void overrideFeaturesVk(angle::FeaturesVk *featuresVulkan) {}
292 
293   protected:
294     void ANGLETestSetUp();
295     void ANGLETestTearDown();
296 
297     virtual void swapBuffers();
298 
299     void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
300     void setupIndexedQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
301     void setupIndexedQuadIndexBuffer();
302 
303     void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
304     void drawQuad(GLuint program,
305                   const std::string &positionAttribName,
306                   GLfloat positionAttribZ,
307                   GLfloat positionAttribXYScale);
308     void drawQuad(GLuint program,
309                   const std::string &positionAttribName,
310                   GLfloat positionAttribZ,
311                   GLfloat positionAttribXYScale,
312                   bool useVertexBuffer);
313     void drawQuadInstanced(GLuint program,
314                            const std::string &positionAttribName,
315                            GLfloat positionAttribZ,
316                            GLfloat positionAttribXYScale,
317                            bool useVertexBuffer,
318                            GLuint numInstances);
319 
320     static std::array<angle::Vector3, 6> GetQuadVertices();
321     static std::array<GLushort, 6> GetQuadIndices();
322     static std::array<angle::Vector3, 4> GetIndexedQuadVertices();
323 
324     void drawIndexedQuad(GLuint program,
325                          const std::string &positionAttribName,
326                          GLfloat positionAttribZ);
327     void drawIndexedQuad(GLuint program,
328                          const std::string &positionAttribName,
329                          GLfloat positionAttribZ,
330                          GLfloat positionAttribXYScale);
331     void drawIndexedQuad(GLuint program,
332                          const std::string &positionAttribName,
333                          GLfloat positionAttribZ,
334                          GLfloat positionAttribXYScale,
335                          bool useBufferObject);
336 
337     void drawIndexedQuad(GLuint program,
338                          const std::string &positionAttribName,
339                          GLfloat positionAttribZ,
340                          GLfloat positionAttribXYScale,
341                          bool useBufferObject,
342                          bool restrictedRange);
343 
344     void draw2DTexturedQuad(GLfloat positionAttribZ,
345                             GLfloat positionAttribXYScale,
346                             bool useVertexBuffer);
347 
348     // The layer parameter chooses the 3D texture layer to sample from.
349     void draw3DTexturedQuad(GLfloat positionAttribZ,
350                             GLfloat positionAttribXYScale,
351                             bool useVertexBuffer,
352                             float layer);
353 
354     void setWindowWidth(int width);
355     void setWindowHeight(int height);
356     void setConfigRedBits(int bits);
357     void setConfigGreenBits(int bits);
358     void setConfigBlueBits(int bits);
359     void setConfigAlphaBits(int bits);
360     void setConfigDepthBits(int bits);
361     void setConfigStencilBits(int bits);
362     void setConfigComponentType(EGLenum componentType);
363     void setMultisampleEnabled(bool enabled);
364     void setSamples(EGLint samples);
365     void setDebugEnabled(bool enabled);
366     void setNoErrorEnabled(bool enabled);
367     void setWebGLCompatibilityEnabled(bool webglCompatibility);
368     void setExtensionsEnabled(bool extensionsEnabled);
369     void setRobustAccess(bool enabled);
370     void setBindGeneratesResource(bool bindGeneratesResource);
371     void setClientArraysEnabled(bool enabled);
372     void setRobustResourceInit(bool enabled);
373     void setContextProgramCacheEnabled(bool enabled);
374     void setContextResetStrategy(EGLenum resetStrategy);
375     void forceNewDisplay();
376 
377     // Some EGL extension tests would like to defer the Context init until the test body.
378     void setDeferContextInit(bool enabled);
379 
380     int getClientMajorVersion() const;
381     int getClientMinorVersion() const;
382 
383     GLWindowBase *getGLWindow() const;
384     EGLWindow *getEGLWindow() const;
385     int getWindowWidth() const;
386     int getWindowHeight() const;
387     bool isMultisampleEnabled() const;
388 
389     EGLint getPlatformRenderer() const;
390 
391     void ignoreD3D11SDKLayersWarnings();
392 
393     // Allows a test to be more restrictive about platform warnings.
394     void treatPlatformWarningsAsErrors();
395 
getOSWindow()396     OSWindow *getOSWindow() { return mFixture->osWindow; }
397 
398     GLuint get2DTexturedQuadProgram();
399 
400     // Has a float uniform "u_layer" to choose the 3D texture layer.
401     GLuint get3DTexturedQuadProgram();
402 
403     class ScopedIgnorePlatformMessages : angle::NonCopyable
404     {
405       public:
406         ScopedIgnorePlatformMessages();
407         ~ScopedIgnorePlatformMessages();
408     };
409 
410     // Can be used before we get a GL context.
isGLRenderer()411     bool isGLRenderer() const
412     {
413         return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
414     }
415 
isGLESRenderer()416     bool isGLESRenderer() const
417     {
418         return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
419     }
420 
isD3D11Renderer()421     bool isD3D11Renderer() const
422     {
423         return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
424     }
425 
isVulkanRenderer()426     bool isVulkanRenderer() const
427     {
428         return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
429     }
430 
431   private:
432     void checkD3D11SDKLayersMessages();
433 
434     void drawQuad(GLuint program,
435                   const std::string &positionAttribName,
436                   GLfloat positionAttribZ,
437                   GLfloat positionAttribXYScale,
438                   bool useVertexBuffer,
439                   bool useInstancedDrawCalls,
440                   GLuint numInstances);
441 
442     void initOSWindow();
443 
444     struct TestFixture
445     {
446         TestFixture();
447         ~TestFixture();
448 
449         EGLWindow *eglWindow = nullptr;
450         WGLWindow *wglWindow = nullptr;
451         OSWindow *osWindow   = nullptr;
452         ConfigParameters configParams;
453         uint32_t reuseCounter = 0;
454     };
455 
456     int mWidth;
457     int mHeight;
458 
459     bool mIgnoreD3D11SDKLayersWarnings;
460 
461     // Used for indexed quad rendering
462     GLuint mQuadVertexBuffer;
463     GLuint mQuadIndexBuffer;
464 
465     // Used for texture rendering.
466     GLuint m2DTexturedQuadProgram;
467     GLuint m3DTexturedQuadProgram;
468 
469     bool mDeferContextInit;
470     bool mAlwaysForceNewDisplay;
471     bool mForceNewDisplay;
472 
473     bool mSetUpCalled;
474     bool mTearDownCalled;
475 
476     // On most systems we force a new display on every test instance. For these configs we can
477     // share a single OSWindow instance. With display reuse we need a separate OSWindow for each
478     // different config. This OSWindow sharing seemed to lead to driver bugs on some platforms.
479     static OSWindow *mOSWindowSingleton;
480 
481     static std::map<angle::PlatformParameters, TestFixture> gFixtures;
482     const angle::PlatformParameters *mCurrentParams;
483     TestFixture *mFixture;
484 
485     // Workaround for NVIDIA not being able to share a window with OpenGL and Vulkan.
486     static Optional<EGLint> mLastRendererType;
487 };
488 
489 template <typename Params = angle::PlatformParameters>
490 class ANGLETestWithParam : public ANGLETestBase, public ::testing::TestWithParam<Params>
491 {
492   protected:
493     ANGLETestWithParam();
494 
testSetUp()495     virtual void testSetUp() {}
testTearDown()496     virtual void testTearDown() {}
497 
recreateTestFixture()498     void recreateTestFixture()
499     {
500         TearDown();
501         SetUp();
502     }
503 
504   private:
SetUp()505     void SetUp() final
506     {
507         ANGLETestBase::ANGLETestSetUp();
508         testSetUp();
509     }
510 
TearDown()511     void TearDown() final
512     {
513         testTearDown();
514         ANGLETestBase::ANGLETestTearDown();
515     }
516 };
517 
518 template <typename Params>
ANGLETestWithParam()519 ANGLETestWithParam<Params>::ANGLETestWithParam()
520     : ANGLETestBase(std::get<angle::PlatformParameters>(this->GetParam()))
521 {}
522 
523 template <>
ANGLETestWithParam()524 inline ANGLETestWithParam<angle::PlatformParameters>::ANGLETestWithParam()
525     : ANGLETestBase(this->GetParam())
526 {}
527 
528 // Note: this hack is not necessary in C++17.  Once we switch to C++17, we can just rename
529 // ANGLETestWithParam to ANGLETest.
530 using ANGLETest = ANGLETestWithParam<>;
531 
532 class ANGLETestEnvironment : public testing::Environment
533 {
534   public:
535     void SetUp() override;
536     void TearDown() override;
537 
538     static angle::Library *GetEGLLibrary();
539     static angle::Library *GetWGLLibrary();
540 
541   private:
542     // For loading entry points.
543     static std::unique_ptr<angle::Library> gEGLLibrary;
544     static std::unique_ptr<angle::Library> gWGLLibrary;
545 };
546 
547 // Driver vendors
548 bool IsAdreno();
549 
550 // Renderer back-ends
551 // Note: FL9_3 is explicitly *not* considered D3D11.
552 bool IsD3D11();
553 bool IsD3D11_FL93();
554 // Is a D3D9-class renderer.
555 bool IsD3D9();
556 // Is D3D9 or SM9_3 renderer.
557 bool IsD3DSM3();
558 bool IsDesktopOpenGL();
559 bool IsOpenGLES();
560 bool IsOpenGL();
561 bool IsNULL();
562 bool IsVulkan();
563 
564 // Debug/Release
565 bool IsDebug();
566 bool IsRelease();
567 
568 bool EnsureGLExtensionEnabled(const std::string &extName);
569 bool IsEGLClientExtensionEnabled(const std::string &extName);
570 bool IsEGLDeviceExtensionEnabled(EGLDeviceEXT device, const std::string &extName);
571 bool IsEGLDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
572 bool IsGLExtensionEnabled(const std::string &extName);
573 bool IsGLExtensionRequestable(const std::string &extName);
574 
575 extern angle::PlatformMethods gDefaultPlatformMethods;
576 
577 #define ANGLE_SKIP_TEST_IF(COND)                                  \
578     do                                                            \
579     {                                                             \
580         if (COND)                                                 \
581         {                                                         \
582             std::cout << "Test skipped: " #COND "." << std::endl; \
583             return;                                               \
584         }                                                         \
585     } while (0)
586 
587 #endif  // ANGLE_TESTS_ANGLE_TEST_H_
588