1 // 2 // Copyright 2017 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 // RewriteDoWhile_test.cpp: 7 // Tests that the RewriteDoWhile AST transform works correctly. 8 // 9 10 #include "GLSLANG/ShaderLang.h" 11 #include "angle_gl.h" 12 #include "gtest/gtest.h" 13 #include "tests/test_utils/ShaderCompileTreeTest.h" 14 15 using namespace sh; 16 17 class RewriteDoWhileCrashTest : public ShaderCompileTreeTest 18 { 19 public: RewriteDoWhileCrashTest()20 RewriteDoWhileCrashTest() {} 21 22 protected: getShaderType() const23 ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; } getShaderSpec() const24 ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; } 25 SetUp()26 void SetUp() override 27 { 28 mExtraCompileOptions |= SH_REWRITE_DO_WHILE_LOOPS; 29 ShaderCompileTreeTest::SetUp(); 30 } 31 }; 32 33 // Make sure that the RewriteDoWhile step doesn't crash. Regression test. TEST_F(RewriteDoWhileCrashTest,RunsSuccessfully)34TEST_F(RewriteDoWhileCrashTest, RunsSuccessfully) 35 { 36 const std::string &shaderString = 37 "#version 300 es\n" 38 "precision mediump float;\n" 39 "uniform int u;\n" 40 "out vec4 my_FragColor;\n" 41 "void main()\n" 42 "{\n" 43 " int foo = 1;" 44 " do\n" 45 " {\n" 46 " foo *= u;\n" 47 " } while (foo < 8);\n" 48 " my_FragColor = vec4(foo) * 0.1;" 49 "}\n"; 50 if (!compile(shaderString)) 51 { 52 FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog; 53 } 54 } 55