Path: blob/main_old/src/tests/gl_tests/ContextLostTest.cpp
1693 views
//1// Copyright 2015 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// BindGeneratesResourceTest.cpp : Tests of the GL_CHROMIUM_bind_generates_resource extension.78#include "test_utils/ANGLETest.h"910namespace angle11{12class ContextLostTest : public ANGLETest13{14protected:15ContextLostTest()16{17if (IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"))18{19setContextResetStrategy(EGL_LOSE_CONTEXT_ON_RESET_EXT);20}21else22{23setContextResetStrategy(EGL_NO_RESET_NOTIFICATION_EXT);24}25}26};2728// GL_CHROMIUM_lose_context is implemented in the frontend29TEST_P(ContextLostTest, ExtensionStringExposed)30{31EXPECT_TRUE(EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));32}3334// Use GL_CHROMIUM_lose_context to lose a context and verify35TEST_P(ContextLostTest, BasicUsage)36{37ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));38ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_robustness") ||39!IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"));4041glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);42EXPECT_GL_NO_ERROR();43EXPECT_GLENUM_EQ(glGetGraphicsResetStatusEXT(), GL_GUILTY_CONTEXT_RESET);4445// Errors should be continually generated46for (size_t i = 0; i < 10; i++)47{48glBindTexture(GL_TEXTURE_2D, 0);49EXPECT_GL_ERROR(GL_CONTEXT_LOST);50}51}5253// When context is lost, polling queries such as glGetSynciv with GL_SYNC_STATUS should always54// return GL_SIGNALED55TEST_P(ContextLostTest, PollingQuery)56{57ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));58ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);5960GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);61EXPECT_GL_NO_ERROR();6263glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);64EXPECT_GL_NO_ERROR();6566GLint syncStatus = 0;67glGetSynciv(sync, GL_SYNC_STATUS, 1, nullptr, &syncStatus);68EXPECT_GL_ERROR(GL_CONTEXT_LOST);69EXPECT_GLENUM_EQ(syncStatus, GL_SIGNALED);7071// Check that the query fails and the result is unmodified for other queries72GLint syncCondition = 0xBADF00D;73glGetSynciv(sync, GL_SYNC_CONDITION, 1, nullptr, &syncCondition);74EXPECT_GL_ERROR(GL_CONTEXT_LOST);75EXPECT_GLENUM_EQ(syncCondition, 0xBADF00D);76}7778// When context is lost, polling queries such as glGetSynciv with GL_SYNC_STATUS should always79// return GL_SIGNALED80TEST_P(ContextLostTest, ParallelCompileReadyQuery)81{82ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));83ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_KHR_parallel_shader_compile"));8485GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Simple());86GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl1_shaders::fs::UniformColor());8788GLuint program = glCreateProgram();89glAttachShader(program, vs);90glAttachShader(program, fs);91glLinkProgram(program);9293EXPECT_GL_NO_ERROR();9495glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);96EXPECT_GL_NO_ERROR();9798GLint shaderCompletionStatus = 0;99glGetShaderiv(vs, GL_COMPLETION_STATUS_KHR, &shaderCompletionStatus);100EXPECT_GL_ERROR(GL_CONTEXT_LOST);101EXPECT_GLENUM_EQ(shaderCompletionStatus, GL_TRUE);102103GLint programCompletionStatus = 0;104glGetProgramiv(program, GL_COMPLETION_STATUS_KHR, &programCompletionStatus);105EXPECT_GL_ERROR(GL_CONTEXT_LOST);106EXPECT_GLENUM_EQ(programCompletionStatus, GL_TRUE);107108// Check that the query fails and the result is unmodified for other queries109GLint shaderType = 0xBADF00D;110glGetShaderiv(vs, GL_SHADER_TYPE, &shaderType);111EXPECT_GL_ERROR(GL_CONTEXT_LOST);112EXPECT_GLENUM_EQ(shaderType, 0xBADF00D);113114GLint linkStatus = 0xBADF00D;115glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);116EXPECT_GL_ERROR(GL_CONTEXT_LOST);117EXPECT_GLENUM_EQ(linkStatus, 0xBADF00D);118}119120class ContextLostSkipValidationTest : public ANGLETest121{122protected:123ContextLostSkipValidationTest()124{125if (IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"))126{127setContextResetStrategy(EGL_LOSE_CONTEXT_ON_RESET_EXT);128setNoErrorEnabled(true);129}130else131{132setContextResetStrategy(EGL_NO_RESET_NOTIFICATION_EXT);133}134}135};136137// Use GL_CHROMIUM_lose_context to lose a context and verify138TEST_P(ContextLostSkipValidationTest, LostNoErrorGetProgram)139{140ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));141142GLuint program = glCreateProgram();143144glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);145146GLint val = 0;147glGetProgramiv(program, GL_INFO_LOG_LENGTH, &val); // Should not crash.148}149150// Use this to select which configurations (e.g. which renderer, which GLES major version) these151// tests should be run against.152ANGLE_INSTANTIATE_TEST(ContextLostTest,153WithRobustness(ES2_NULL()),154WithRobustness(ES2_D3D9()),155WithRobustness(ES2_D3D11()),156WithRobustness(ES3_D3D11()),157WithRobustness(ES2_VULKAN()),158WithRobustness(ES3_VULKAN()));159160ANGLE_INSTANTIATE_TEST(ContextLostSkipValidationTest,161WithRobustness(ES2_NULL()),162WithRobustness(ES2_D3D9()),163WithRobustness(ES2_D3D11()),164WithRobustness(ES3_D3D11()),165WithRobustness(ES2_VULKAN()),166WithRobustness(ES3_VULKAN()));167168} // namespace angle169170171