Path: blob/main_old/src/tests/compiler_tests/PruneUnusedFunctions_test.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//5// PruneUnusedFunctions_test.cpp:6// Test for the pruning of unused functions7//89#include "GLSLANG/ShaderLang.h"10#include "angle_gl.h"11#include "gtest/gtest.h"12#include "tests/test_utils/compiler_test.h"1314using namespace sh;1516namespace17{1819class PruneUnusedFunctionsTest : public MatchOutputCodeTest20{21public:22PruneUnusedFunctionsTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_ESSL_OUTPUT) {}2324protected:25void compile(const std::string &shaderString)26{27int compilationFlags = SH_VARIABLES;28MatchOutputCodeTest::compile(shaderString, compilationFlags);29}30};3132// Check that unused function and prototypes are removed iff the options is set33TEST_F(PruneUnusedFunctionsTest, UnusedFunctionAndProto)34{35const std::string &shaderString =36"precision mediump float;\n"37"float unused(float a);\n"38"void main() {\n"39" gl_FragColor = vec4(1.0);\n"40"}\n"41"float unused(float a) {\n"42" return a;\n"43"}\n";44compile(shaderString);45EXPECT_TRUE(notFoundInCode("unused("));46EXPECT_TRUE(foundInCode("main(", 1));47}4849// Check that unimplemented prototypes are removed iff the options is set50TEST_F(PruneUnusedFunctionsTest, UnimplementedPrototype)51{52const std::string &shaderString =53"precision mediump float;\n"54"float unused(float a);\n"55"void main() {\n"56" gl_FragColor = vec4(1.0);\n"57"}\n";58compile(shaderString);59EXPECT_TRUE(notFoundInCode("unused("));60EXPECT_TRUE(foundInCode("main(", 1));61}6263// Check that used functions are not pruned (duh)64TEST_F(PruneUnusedFunctionsTest, UsedFunction)65{66const std::string &shaderString =67"precision mediump float;\n"68"float used(float a);\n"69"void main() {\n"70" gl_FragColor = vec4(used(1.0));\n"71"}\n"72"float used(float a) {\n"73" return a;\n"74"}\n";75compile(shaderString);76EXPECT_TRUE(foundInCode("used(", 3));77EXPECT_TRUE(foundInCode("main(", 1));78}7980} // namespace818283