Path: blob/main_old/src/tests/compiler_tests/AppendixALimitations_test.cpp
1693 views
//1// Copyright 2017 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//5// AppendixALimitations_test.cpp:6// Tests for validating ESSL 1.00 Appendix A limitations.7//89#include "gtest/gtest.h"1011#include "GLSLANG/ShaderLang.h"12#include "angle_gl.h"13#include "gtest/gtest.h"14#include "tests/test_utils/ShaderCompileTreeTest.h"1516using namespace sh;1718class AppendixALimitationsTest : public ShaderCompileTreeTest19{20public:21AppendixALimitationsTest() {}2223protected:24::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }25ShShaderSpec getShaderSpec() const override { return SH_WEBGL_SPEC; }26};2728// Test an invalid shader where a for loop index is used as an out parameter.29TEST_F(AppendixALimitationsTest, IndexAsFunctionOutParameter)30{31const std::string &shaderString =32"precision mediump float;\n"33"void fun(out int a)\n"34"{\n"35" a = 2;\n"36"}\n"37"void main()\n"38"{\n"39" for (int i = 0; i < 2; ++i)\n"40" {\n"41" fun(i);\n"42" }\n"43" gl_FragColor = vec4(0.0);\n"44"}\n";45if (compile(shaderString))46{47FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;48}49}5051// Test an invalid shader where a for loop index is used as an inout parameter.52TEST_F(AppendixALimitationsTest, IndexAsFunctionInOutParameter)53{54const std::string &shaderString =55"precision mediump float;\n"56"void fun(int b, inout int a)\n"57"{\n"58" a += b;\n"59"}\n"60"void main()\n"61"{\n"62" for (int i = 0; i < 2; ++i)\n"63" {\n"64" fun(2, i);\n"65" }\n"66" gl_FragColor = vec4(0.0);\n"67"}\n";68if (compile(shaderString))69{70FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;71}72}7374// Test a valid shader where a for loop index is used as an in parameter in a function that also has75// an out parameter.76TEST_F(AppendixALimitationsTest, IndexAsFunctionInParameter)77{78const std::string &shaderString =79"precision mediump float;\n"80"void fun(int b, inout int a)\n"81"{\n"82" a += b;\n"83"}\n"84"void main()\n"85"{\n"86" for (int i = 0; i < 2; ++i)\n"87" {\n"88" int a = 1;"89" fun(i, a);\n"90" }\n"91" gl_FragColor = vec4(0.0);\n"92"}\n";93if (!compile(shaderString))94{95FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;96}97}9899// Test an invalid shader where a for loop index is used as a target of assignment.100TEST_F(AppendixALimitationsTest, IndexAsTargetOfAssignment)101{102const std::string &shaderString =103"precision mediump float;\n"104"void main()\n"105"{\n"106" for (int i = 0; i < 2; ++i)\n"107" {\n"108" i = 2;\n"109" }\n"110" gl_FragColor = vec4(0.0);\n"111"}\n";112if (compile(shaderString))113{114FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;115}116}117118// Test an invalid shader where a for loop index is incremented inside the loop.119TEST_F(AppendixALimitationsTest, IndexIncrementedInLoopBody)120{121const std::string &shaderString =122"precision mediump float;\n"123"void main()\n"124"{\n"125" for (int i = 0; i < 2; ++i)\n"126" {\n"127" ++i;\n"128" }\n"129" gl_FragColor = vec4(0.0);\n"130"}\n";131if (compile(shaderString))132{133FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;134}135}136137138