1 //
2 // Copyright 2015 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
7 // BindGeneratesResourceTest.cpp : Tests of the GL_CHROMIUM_bind_generates_resource extension.
8
9 #include "test_utils/ANGLETest.h"
10
11 namespace angle
12 {
13 class ContextLostTest : public ANGLETest
14 {
15 protected:
ContextLostTest()16 ContextLostTest() { setContextResetStrategy(EGL_LOSE_CONTEXT_ON_RESET_EXT); }
17 };
18
19 // GL_CHROMIUM_lose_context is implemented in the frontend
TEST_P(ContextLostTest,ExtensionStringExposed)20 TEST_P(ContextLostTest, ExtensionStringExposed)
21 {
22 EXPECT_TRUE(EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
23 }
24
25 // Use GL_CHROMIUM_lose_context to lose a context and verify
TEST_P(ContextLostTest,BasicUsage)26 TEST_P(ContextLostTest, BasicUsage)
27 {
28 ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
29 ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_robustness"));
30
31 glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
32 EXPECT_GL_NO_ERROR();
33 EXPECT_GLENUM_EQ(glGetGraphicsResetStatusEXT(), GL_GUILTY_CONTEXT_RESET);
34
35 glBindTexture(GL_TEXTURE_2D, 0);
36 EXPECT_GL_ERROR(GL_OUT_OF_MEMORY);
37 }
38
39 // When context is lost, polling queries such as glGetSynciv with GL_SYNC_STATUS should always
40 // return GL_SIGNALED
TEST_P(ContextLostTest,PollingQuery)41 TEST_P(ContextLostTest, PollingQuery)
42 {
43 ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
44 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
45
46 GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
47 EXPECT_GL_NO_ERROR();
48
49 glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
50 EXPECT_GL_NO_ERROR();
51
52 GLint syncStatus = 0;
53 glGetSynciv(sync, GL_SYNC_STATUS, 1, nullptr, &syncStatus);
54 EXPECT_GL_ERROR(GL_CONTEXT_LOST);
55 EXPECT_GLENUM_EQ(syncStatus, GL_SIGNALED);
56
57 // Check that the query fails and the result is unmodified for other queries
58 GLint syncCondition = 0xBADF00D;
59 glGetSynciv(sync, GL_SYNC_CONDITION, 1, nullptr, &syncCondition);
60 EXPECT_GL_ERROR(GL_CONTEXT_LOST);
61 EXPECT_GLENUM_EQ(syncCondition, 0xBADF00D);
62 }
63
64 // When context is lost, polling queries such as glGetSynciv with GL_SYNC_STATUS should always
65 // return GL_SIGNALED
TEST_P(ContextLostTest,ParallelCompileReadyQuery)66 TEST_P(ContextLostTest, ParallelCompileReadyQuery)
67 {
68 ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
69 ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_KHR_parallel_shader_compile"));
70
71 GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Simple());
72 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl1_shaders::fs::UniformColor());
73
74 GLuint program = glCreateProgram();
75 glAttachShader(program, vs);
76 glAttachShader(program, fs);
77 glLinkProgram(program);
78
79 EXPECT_GL_NO_ERROR();
80
81 glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
82 EXPECT_GL_NO_ERROR();
83
84 GLint shaderCompletionStatus = 0;
85 glGetShaderiv(vs, GL_COMPLETION_STATUS_KHR, &shaderCompletionStatus);
86 EXPECT_GL_ERROR(GL_CONTEXT_LOST);
87 EXPECT_GLENUM_EQ(shaderCompletionStatus, GL_TRUE);
88
89 GLint programCompletionStatus = 0;
90 glGetProgramiv(program, GL_COMPLETION_STATUS_KHR, &programCompletionStatus);
91 EXPECT_GL_ERROR(GL_CONTEXT_LOST);
92 EXPECT_GLENUM_EQ(programCompletionStatus, GL_TRUE);
93
94 // Check that the query fails and the result is unmodified for other queries
95 GLint shaderType = 0xBADF00D;
96 glGetShaderiv(vs, GL_SHADER_TYPE, &shaderType);
97 EXPECT_GL_ERROR(GL_CONTEXT_LOST);
98 EXPECT_GLENUM_EQ(shaderType, 0xBADF00D);
99
100 GLint linkStatus = 0xBADF00D;
101 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
102 EXPECT_GL_ERROR(GL_CONTEXT_LOST);
103 EXPECT_GLENUM_EQ(linkStatus, 0xBADF00D);
104 }
105
106 class ContextLostSkipValidationTest : public ANGLETest
107 {
108 protected:
ContextLostSkipValidationTest()109 ContextLostSkipValidationTest()
110 {
111 setContextResetStrategy(EGL_LOSE_CONTEXT_ON_RESET_EXT);
112 setNoErrorEnabled(true);
113 }
114 };
115
116 // Use GL_CHROMIUM_lose_context to lose a context and verify
TEST_P(ContextLostSkipValidationTest,LostNoErrorGetProgram)117 TEST_P(ContextLostSkipValidationTest, LostNoErrorGetProgram)
118 {
119 ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
120
121 GLuint program = glCreateProgram();
122
123 glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
124
125 GLint val = 0;
126 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &val); // Should not crash.
127 }
128
129 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
130 // tests should be run against.
131 ANGLE_INSTANTIATE_TEST(ContextLostTest,
132 WithRobustness(ES2_NULL()),
133 WithRobustness(ES2_D3D9()),
134 WithRobustness(ES2_D3D11()),
135 WithRobustness(ES3_D3D11()),
136 WithRobustness(ES2_VULKAN()),
137 WithRobustness(ES3_VULKAN()));
138
139 ANGLE_INSTANTIATE_TEST(ContextLostSkipValidationTest,
140 WithRobustness(ES2_NULL()),
141 WithRobustness(ES2_D3D9()),
142 WithRobustness(ES2_D3D11()),
143 WithRobustness(ES3_D3D11()),
144 WithRobustness(ES2_VULKAN()),
145 WithRobustness(ES3_VULKAN()));
146
147 } // namespace angle
148