From 6e7b92b25a015618fa4831f0342efc204c228c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 6 Sep 2022 17:31:45 +0200 Subject: [PATCH] GL: unify tests for Shader/ShaderProgram compile/link failures. In particular, test also output of the non-async variant. --- .../GL/Test/AbstractShaderProgramGLTest.cpp | 27 ++++++++-- src/Magnum/GL/Test/ShaderGLTest.cpp | 51 ++++++++++++------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp b/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp index e378aca0e..20753b820 100644 --- a/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp +++ b/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp @@ -485,6 +485,7 @@ void AbstractShaderProgramGLTest::linkFailure() { , Shader::Type::Fragment); shader.addSource("[fu] bleh error #:! stuff\n"); + /* The compilation should fail */ { Error redirectError{nullptr}; CORRADE_VERIFY(!shader.compile()); @@ -492,10 +493,19 @@ void AbstractShaderProgramGLTest::linkFailure() { MyPublicShader program; program.attachShaders({shader}); - CORRADE_VERIFY(!program.link()); + + /* And thus linking as well, saying something like "error: linking with + uncompiled/unspecialized shader" */ + std::ostringstream out; + { + Error redirectError{&out}; + CORRADE_VERIFY(!program.link()); + } Utility::System::sleep(200); CORRADE_VERIFY(program.isLinkFinished()); + CORRADE_COMPARE_AS(out.str(), "GL::AbstractShaderProgram::link(): linking failed with the following message:", + TestSuite::Compare::StringHasPrefix); } void AbstractShaderProgramGLTest::linkFailureAsync() { @@ -512,6 +522,7 @@ void AbstractShaderProgramGLTest::linkFailureAsync() { , Shader::Type::Fragment); shader.addSource("[fu] bleh error #:! stuff\n"); + /* The compilation should fail */ { Error redirectError{nullptr}; CORRADE_VERIFY(!shader.compile()); @@ -520,16 +531,24 @@ void AbstractShaderProgramGLTest::linkFailureAsync() { MyPublicShader program; program.attachShaders({shader}); + /* The link submission should not print anything ... */ std::ostringstream out; - Error redirectError{&out}; - program.submitLink(); + { + Error redirectError{&out}; + program.submitLink(); + } while(!program.isLinkFinished()) Utility::System::sleep(100); CORRADE_VERIFY(out.str().empty()); - CORRADE_VERIFY(!program.checkLink()); + /* ... only the final check should. In this case it's "error: linking with + uncompiled/unspecialized shader" as well. */ + { + Error redirectError{&out}; + CORRADE_VERIFY(!program.checkLink()); + } CORRADE_VERIFY(program.isLinkFinished()); CORRADE_COMPARE_AS(out.str(), "GL::AbstractShaderProgram::link(): linking failed with the following message:", TestSuite::Compare::StringHasPrefix); diff --git a/src/Magnum/GL/Test/ShaderGLTest.cpp b/src/Magnum/GL/Test/ShaderGLTest.cpp index 49ef6cc66..bd74c93e9 100644 --- a/src/Magnum/GL/Test/ShaderGLTest.cpp +++ b/src/Magnum/GL/Test/ShaderGLTest.cpp @@ -58,9 +58,9 @@ struct ShaderGLTest: OpenGLTester { void addSourceNoVersion(); void addFile(); void compile(); - void compileFailure(); void compileAsync(); - void compileAsyncFailure(); + void compileFailure(); + void compileFailureAsync(); void compileUtf8(); void compileNoVersion(); }; @@ -78,9 +78,9 @@ ShaderGLTest::ShaderGLTest() { &ShaderGLTest::addSourceNoVersion, &ShaderGLTest::addFile, &ShaderGLTest::compile, - &ShaderGLTest::compileFailure, &ShaderGLTest::compileAsync, - &ShaderGLTest::compileAsyncFailure, + &ShaderGLTest::compileFailure, + &ShaderGLTest::compileFailureAsync, &ShaderGLTest::compileUtf8, &ShaderGLTest::compileNoVersion}); } @@ -290,7 +290,7 @@ void ShaderGLTest::compile() { CORRADE_VERIFY(shader.isCompileFinished()); } -void ShaderGLTest::compileFailure() { +void ShaderGLTest::compileAsync() { #ifndef MAGNUM_TARGET_GLES constexpr Version v = #ifndef CORRADE_TARGET_APPLE @@ -304,13 +304,17 @@ void ShaderGLTest::compileFailure() { #endif Shader shader(v, Shader::Type::Fragment); - shader.addSource("[fu] bleh error #:! stuff\n"); + shader.addSource("void main() {}\n"); + shader.submitCompile(); + + while(!shader.isCompileFinished()) + Utility::System::sleep(100); - CORRADE_VERIFY(!shader.compile()); + CORRADE_VERIFY(shader.checkCompile()); CORRADE_VERIFY(shader.isCompileFinished()); } -void ShaderGLTest::compileAsync() { +void ShaderGLTest::compileFailure() { #ifndef MAGNUM_TARGET_GLES constexpr Version v = #ifndef CORRADE_TARGET_APPLE @@ -323,18 +327,20 @@ void ShaderGLTest::compileAsync() { constexpr Version v = Version::GLES200; #endif - Shader shader(v, Shader::Type::Fragment); - shader.addSource("void main() {}\n"); - shader.submitCompile(); - - while(!shader.isCompileFinished()) - Utility::System::sleep(100); + Shader shader(v, Shader::Type::Vertex); + shader.addSource("[fu] bleh error #:! stuff\n"); - CORRADE_VERIFY(shader.checkCompile()); + std::ostringstream out; + { + Error redirectError{&out}; + CORRADE_VERIFY(!shader.compile()); + } CORRADE_VERIFY(shader.isCompileFinished()); + CORRADE_COMPARE_AS(out.str(), "GL::Shader::compile(): compilation of vertex shader failed with the following message:", + TestSuite::Compare::StringHasPrefix); } -void ShaderGLTest::compileAsyncFailure() { +void ShaderGLTest::compileFailureAsync() { #ifndef MAGNUM_TARGET_GLES constexpr Version v = #ifndef CORRADE_TARGET_APPLE @@ -350,16 +356,23 @@ void ShaderGLTest::compileAsyncFailure() { Shader shader(v, Shader::Type::Fragment); shader.addSource("[fu] bleh error #:! stuff\n"); + /* The compile submission should not print anything ... */ std::ostringstream out; - Error redirectError{&out}; - shader.submitCompile(); + { + Error redirectError{&out}; + shader.submitCompile(); + } while(!shader.isCompileFinished()) Utility::System::sleep(100); CORRADE_VERIFY(out.str().empty()); - CORRADE_VERIFY(!shader.checkCompile()); + /* ... only the final check should */ + { + Error redirectError{&out}; + CORRADE_VERIFY(!shader.checkCompile()); + } CORRADE_VERIFY(shader.isCompileFinished()); CORRADE_COMPARE_AS(out.str(), "GL::Shader::compile(): compilation of fragment shader failed with the following message:", TestSuite::Compare::StringHasPrefix);