3 # Copyright © 2018 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 """Script to generate and run glsl optimization tests."""
25 from __future__
import print_function
32 import lower_jump_cases
36 parser
= argparse
.ArgumentParser()
40 help='The glsl_test binary.')
41 return parser
.parse_args()
44 def compare(actual
, expected
):
45 """Compare the s-expresions and return a diff if they are different."""
46 actual
= sexps
.sort_decls(sexps
.parse_sexp(actual
))
47 expected
= sexps
.sort_decls(sexps
.parse_sexp(expected
))
49 if actual
== expected
:
52 actual
= sexps
.sexp_to_string(actual
)
53 expected
= sexps
.sexp_to_string(expected
)
55 return difflib
.unified_diff(expected
.splitlines(), actual
.splitlines())
59 """Generate each test and report pass or fail."""
65 for gen
in lower_jump_cases
.CASES
:
66 for name
, opt
, source
, expected
in gen():
68 print('{}: '.format(name
), end
='')
69 proc
= subprocess
.Popen(
70 [args
.test_runner
, 'optpass', '--quiet', '--input-ir', opt
],
71 stdout
=subprocess
.PIPE
,
72 stderr
=subprocess
.PIPE
,
73 stdin
=subprocess
.PIPE
)
74 out
, err
= proc
.communicate(source
.encode('utf-8'))
75 out
= out
.decode('utf-8')
76 err
= err
.decode('utf-8')
79 print('Unexpected output on stderr: {}'.format(err
),
83 result
= compare(out
, expected
)
84 if result
is not None:
87 print(l
, file=sys
.stderr
)
92 print('{}/{} tests returned correct results'.format(passes
, total
))
93 exit(0 if passes
== total
else 1)
96 if __name__
== '__main__':