Path: blob/main_old/src/tests/test_utils/compiler_test.h
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// compiler_test.h:6// utilities for compiler unit tests.78#ifndef TESTS_TEST_UTILS_COMPILER_TEST_H_9#define TESTS_TEST_UTILS_COMPILER_TEST_H_1011#include <map>12#include <regex>13#include <vector>1415#include "gtest/gtest.h"1617#include "GLSLANG/ShaderLang.h"18#include "angle_gl.h"19#include "compiler/translator/TranslatorESSL.h"20#include "compiler/translator/tree_util/FindSymbolNode.h"2122namespace sh23{2425bool compileTestShader(GLenum type,26ShShaderSpec spec,27ShShaderOutput output,28const std::string &shaderString,29ShBuiltInResources *resources,30ShCompileOptions compileOptions,31std::string *translatedCode,32std::string *infoLog);3334bool compileTestShader(GLenum type,35ShShaderSpec spec,36ShShaderOutput output,37const std::string &shaderString,38ShCompileOptions compileOptions,39std::string *translatedCode,40std::string *infoLog);4142class MatchOutputCodeTest : public testing::Test43{44protected:45MatchOutputCodeTest(GLenum shaderType,46ShCompileOptions defaultCompileOptions,47ShShaderOutput outputType);4849void addOutputType(const ShShaderOutput outputType);5051ShBuiltInResources *getResources();5253// Compile functions clear any results from earlier calls to them.54void compile(const std::string &shaderString);55void compile(const std::string &shaderString, const ShCompileOptions compileOptions);5657bool foundInESSLCode(const char *stringToFind) const58{59return foundInCode(SH_ESSL_OUTPUT, stringToFind);60}6162bool foundInGLSLCode(const char *stringToFind) const63{64return foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, stringToFind);65}6667bool foundInCode(ShShaderOutput output, const char *stringToFind) const;68bool foundInCodeRegex(ShShaderOutput output,69const std::regex ®exToFind,70std::smatch *match = nullptr) const;7172// Test that the strings are found in the specified output in the specified order.73bool foundInCodeInOrder(ShShaderOutput output, std::vector<const char *> stringsToFind);7475// Test that the string occurs for exactly expectedOccurrences times76bool foundInCode(ShShaderOutput output,77const char *stringToFind,78const int expectedOccurrences) const;7980// Test that the string is found in all outputs81bool foundInCode(const char *stringToFind) const;82bool foundInCodeRegex(const std::regex ®exToFind, std::smatch *match = nullptr) const;8384// Test that the string occurs for exactly expectedOccurrences times in all outputs85bool foundInCode(const char *stringToFind, const int expectedOccurrences) const;8687// Test that the strings are found in all outputs in the specified order.88bool foundInCodeInOrder(std::vector<const char *> stringsToFind);8990// Test that the string is found in none of the outputs91bool notFoundInCode(const char *stringToFind) const;9293private:94bool compileWithSettings(ShShaderOutput output,95const std::string &shaderString,96ShCompileOptions compileOptions,97std::string *translatedCode,98std::string *infoLog);99100GLenum mShaderType;101ShCompileOptions mDefaultCompileOptions;102ShBuiltInResources mResources;103104std::map<ShShaderOutput, std::string> mOutputCode;105};106107// Returns a pointer to a function call node with a mangled name functionName.108const TIntermAggregate *FindFunctionCallNode(TIntermNode *root, const TString &functionName);109} // namespace sh110111#endif // TESTS_TEST_UTILS_COMPILER_TEST_H_112113114