34wordWithUnderscores = pp.Word(pp.alphanums +
'_')
36pipeList = pp.delimited_list(pp.SkipTo(pp.Literal(
"|") | pp.Literal(
"]")), delim=
"|")
37bracketedPipeList = pp.Group(pp.Literal(
"[").suppress() +
39 pp.Literal(
"]").suppress())
40unbracketedValue = pp.Group(pp.SkipTo(
";"))
42valueList = (pp.Word(pp.alphanums) +
43 pp.Word(pp.alphanums) +
44 pp.Literal(
"=").suppress() +
45 (bracketedPipeList | unbracketedValue) +
46 pp.Literal(
";").suppress())
47value = pp.Group((pp.Keyword(
"input") | pp.Keyword(
"output") | pp.Keyword(
"uniform")) +
49values = (pp.Keyword(
"values") +
50 pp.Literal(
"{").suppress() +
51 pp.ZeroOrMore(value) +
52 pp.Literal(
"}").suppress())
54expectation = (pp.Keyword(
"expect").suppress() + (pp.Keyword(
"compile_fail") |
57code = ((pp.Keyword(
"both") + pp.QuotedString(
'""', multiline=
True)) |
58 (pp.Keyword(
"vertex") + pp.QuotedString(
'""', multiline=
True) +
59 pp.Keyword(
"fragment") + pp.QuotedString(
'""', multiline=
True)))
61reqGlsl100 = pp.Keyword(
"require").suppress() + pp.Keyword(
"full_glsl_es_100_support")
63desc = pp.Keyword(
"desc") + pp.QuotedString(
'"')
64version100es = pp.Keyword(
"version") + pp.Keyword(
"100") + pp.Keyword(
"es")
65ignoredCaseItem = (desc | version100es).suppress()
67caseItem = pp.Group(values | expectation | code | reqGlsl100) | ignoredCaseItem
69caseBody = pp.ZeroOrMore(caseItem)
71blockEnd = pp.Keyword(
"end").suppress();
73caseHeader = pp.Keyword(
"case") + wordWithUnderscores
74case = pp.Group(caseHeader + caseBody + blockEnd)
78groupHeader = (pp.Keyword(
"group") + wordWithUnderscores + pp.QuotedString(
'"')).suppress()
81group <<= pp.OneOrMore(case | (groupHeader + group + blockEnd))
85group.ignore(
'#' + pp.restOfLine)
87testCases = grammar.parse_string(sys.stdin.read(), parse_all=
True)
90testDirectory = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
91passDirectory = testDirectory +
"/pass"
92failDirectory = testDirectory +
"/fail"
93os.makedirs(passDirectory, exist_ok=
True)
94os.makedirs(failDirectory, exist_ok=
True)
103 assert isinstance(testName, str)
109 allowMismatch =
False
118 if caseItem ==
'compile_fail':
121 elif caseItem ==
'pass':
124 elif caseItem ==
'vertex' or caseItem ==
'fragment':
125 skipTest =
'Uses vertex'
127 elif caseItem ==
'both':
129 assert isinstance(testCode, str)
131 elif caseItem ==
'values':
136 if valueType ==
'uniform':
137 skipTest =
'Uses uniform'
138 elif valueType ==
'input':
139 inputs.append(v.asList())
140 elif valueType ==
'output':
141 outputs.append(v.asList())
143 elif caseItem ==
'full_glsl_es_100_support':
144 skipTest =
'Uses while loop'
150 if "void main" not in testCode:
151 skipTest =
'Missing main'
154 print(
"skipped %s (%s)" % (testName, skipTest))
159 if re.fullmatch(
'argument_eval_order_[12]', testName):
161 print(
"allowing mismatch in %s" % testName)
167 compare =
lambda type, a, b :
'((' + a +
') == (' + b +
'))'
168 if (testName ==
'math_float' or
169 testName ==
'struct' or
170 testName ==
'nested_struct' or
171 testName ==
'nested_builtin_funcs'):
172 compare =
lambda type, a, b : (
173 '(floor(20 * abs((' + a +
') - (' + b +
'))) == ' + type +
'(0))'
178 if (re.fullmatch(
'(vec|bvec|ivec)[234]_to_(float|int|bool)', testName)
or
179 re.fullmatch(
'(vec|bvec|ivec)[34]_to_(vec|bvec|ivec)2', testName)
or
180 re.fullmatch(
'(vec|bvec|ivec)[4]_to_(vec|bvec|ivec)3', testName)
or
182 re.fullmatch(
'(out|inout)_lowp_(int|float)', testName)
or
184 testName ==
'missing_returns' or
186 testName ==
'default_vs_explicit_precision' or
188 testName ==
'variable_in_if_hides_global_variable'):
191 print(
"moved %s to fail" % testName)
195 testCode = testCode.replace(
"precision highp ",
"// precision highp ");
196 testCode = testCode.replace(
"precision mediump ",
"// precision mediump ");
197 testCode = testCode.replace(
"precision lowp ",
"// precision lowp ");
200 testCode = testCode.replace(
"#version",
"// #version");
203 testCode = testCode.replace(
"void main",
"bool execute_test");
206 if "${POSITION_FRAG_COLOR}" in testCode:
207 testCode = testCode.replace(
"${POSITION_FRAG_COLOR}",
"PositionFragColor");
208 if "${DECLARATIONS}" in testCode:
209 testCode = testCode.replace(
"${DECLARATIONS}",
210 "vec4 PositionFragColor;\n${DECLARATIONS}");
212 testCode =
"vec4 PositionFragColor;\n" + testCode
216 testCode +=
"half4 main(float2 coords) {\n"
217 testCode +=
" return execute_test() ? half4(0,1,0,1) : half4(1,0,0,1);\n"
220 testDirectory = passDirectory
222 testDirectory = failDirectory
226 for v
in inputs + outputs:
227 numVariables =
max(numVariables,
len(v[2]))
230 assert "${DECLARATIONS}" in testCode
231 assert "${OUTPUT}" in testCode
232 for varIndex
in range(0, numVariables):
233 testSpecialization = testCode
238 if len(v[2]) > varIndex:
239 declarations +=
"%s %s = %s;\n" % (v[0], v[1], v[2][varIndex]);
243 declarations +=
"%s %s;\n" % (v[0], v[1]);
246 outputChecks =
"return true"
247 if not allowMismatch:
249 if len(v[2]) > varIndex:
250 outputChecks +=
" && " +
compare(v[0], v[1], v[2][varIndex])
252 outputChecks +=
";\n"
255 testSpecialization = testSpecialization.replace(
"${DECLARATIONS}", declarations)
256 testSpecialization = testSpecialization.replace(
"${SETUP}",
'')
257 testSpecialization = testSpecialization.replace(
"${OUTPUT}", outputChecks)
260 path =
"%s/%s_%d.rts" % (testDirectory, testName, varIndex)
261 assert path
not in written
264 f.write(testSpecialization)
267 testCode = testCode.replace(
"${DECLARATIONS}",
'')
268 testCode = testCode.replace(
"${SETUP}",
'')
269 testCode = testCode.replace(
"${OUTPUT}",
'return true;')
272 path =
"%s/%s.rts" % (testDirectory, testName)
273 assert path
not in written
static float max(float r, float g, float b)
def print(*args, **kwargs)