Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/test_utils/compiler_test.h
1693 views
1
//
2
// Copyright 2015 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
// compiler_test.h:
7
// utilities for compiler unit tests.
8
9
#ifndef TESTS_TEST_UTILS_COMPILER_TEST_H_
10
#define TESTS_TEST_UTILS_COMPILER_TEST_H_
11
12
#include <map>
13
#include <regex>
14
#include <vector>
15
16
#include "gtest/gtest.h"
17
18
#include "GLSLANG/ShaderLang.h"
19
#include "angle_gl.h"
20
#include "compiler/translator/TranslatorESSL.h"
21
#include "compiler/translator/tree_util/FindSymbolNode.h"
22
23
namespace sh
24
{
25
26
bool compileTestShader(GLenum type,
27
ShShaderSpec spec,
28
ShShaderOutput output,
29
const std::string &shaderString,
30
ShBuiltInResources *resources,
31
ShCompileOptions compileOptions,
32
std::string *translatedCode,
33
std::string *infoLog);
34
35
bool compileTestShader(GLenum type,
36
ShShaderSpec spec,
37
ShShaderOutput output,
38
const std::string &shaderString,
39
ShCompileOptions compileOptions,
40
std::string *translatedCode,
41
std::string *infoLog);
42
43
class MatchOutputCodeTest : public testing::Test
44
{
45
protected:
46
MatchOutputCodeTest(GLenum shaderType,
47
ShCompileOptions defaultCompileOptions,
48
ShShaderOutput outputType);
49
50
void addOutputType(const ShShaderOutput outputType);
51
52
ShBuiltInResources *getResources();
53
54
// Compile functions clear any results from earlier calls to them.
55
void compile(const std::string &shaderString);
56
void compile(const std::string &shaderString, const ShCompileOptions compileOptions);
57
58
bool foundInESSLCode(const char *stringToFind) const
59
{
60
return foundInCode(SH_ESSL_OUTPUT, stringToFind);
61
}
62
63
bool foundInGLSLCode(const char *stringToFind) const
64
{
65
return foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, stringToFind);
66
}
67
68
bool foundInCode(ShShaderOutput output, const char *stringToFind) const;
69
bool foundInCodeRegex(ShShaderOutput output,
70
const std::regex &regexToFind,
71
std::smatch *match = nullptr) const;
72
73
// Test that the strings are found in the specified output in the specified order.
74
bool foundInCodeInOrder(ShShaderOutput output, std::vector<const char *> stringsToFind);
75
76
// Test that the string occurs for exactly expectedOccurrences times
77
bool foundInCode(ShShaderOutput output,
78
const char *stringToFind,
79
const int expectedOccurrences) const;
80
81
// Test that the string is found in all outputs
82
bool foundInCode(const char *stringToFind) const;
83
bool foundInCodeRegex(const std::regex &regexToFind, std::smatch *match = nullptr) const;
84
85
// Test that the string occurs for exactly expectedOccurrences times in all outputs
86
bool foundInCode(const char *stringToFind, const int expectedOccurrences) const;
87
88
// Test that the strings are found in all outputs in the specified order.
89
bool foundInCodeInOrder(std::vector<const char *> stringsToFind);
90
91
// Test that the string is found in none of the outputs
92
bool notFoundInCode(const char *stringToFind) const;
93
94
private:
95
bool compileWithSettings(ShShaderOutput output,
96
const std::string &shaderString,
97
ShCompileOptions compileOptions,
98
std::string *translatedCode,
99
std::string *infoLog);
100
101
GLenum mShaderType;
102
ShCompileOptions mDefaultCompileOptions;
103
ShBuiltInResources mResources;
104
105
std::map<ShShaderOutput, std::string> mOutputCode;
106
};
107
108
// Returns a pointer to a function call node with a mangled name functionName.
109
const TIntermAggregate *FindFunctionCallNode(TIntermNode *root, const TString &functionName);
110
} // namespace sh
111
112
#endif // TESTS_TEST_UTILS_COMPILER_TEST_H_
113
114