2 # Copyright © 2018 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Script to generate and run glsl optimization tests."""
24 from __future__
import print_function
33 import lower_jump_cases
37 parser
= argparse
.ArgumentParser()
41 help='The glsl_test binary.')
42 return parser
.parse_args()
45 def compare(actual
, expected
):
46 """Compare the s-expresions and return a diff if they are different."""
47 actual
= sexps
.sort_decls(sexps
.parse_sexp(actual
))
48 expected
= sexps
.sort_decls(sexps
.parse_sexp(expected
))
50 if actual
== expected
:
53 actual
= sexps
.sexp_to_string(actual
)
54 expected
= sexps
.sexp_to_string(expected
)
56 return difflib
.unified_diff(expected
.splitlines(), actual
.splitlines())
59 def get_test_runner(runner
):
60 """Wrap the test runner in the exe wrapper if necessary."""
61 wrapper
= os
.environ
.get('MESON_EXE_WRAPPER', None)
64 return [wrapper
, runner
]
68 """Generate each test and report pass or fail."""
74 runner
= get_test_runner(args
.test_runner
)
76 for gen
in lower_jump_cases
.CASES
:
77 for name
, opt
, source
, expected
in gen():
79 print('{}: '.format(name
), end
='')
80 proc
= subprocess
.Popen(
81 runner
+ ['optpass', '--quiet', '--input-ir', opt
],
82 stdout
=subprocess
.PIPE
,
83 stderr
=subprocess
.PIPE
,
84 stdin
=subprocess
.PIPE
)
85 out
, err
= proc
.communicate(source
.encode('utf-8'))
86 out
= out
.decode('utf-8')
87 err
= err
.decode('utf-8')
90 print('Unexpected output on stderr: {}'.format(err
),
94 result
= compare(out
, expected
)
95 if result
is not None:
98 print(l
, file=sys
.stderr
)
103 print('{}/{} tests returned correct results'.format(passes
, total
))
104 exit(0 if passes
== total
else 1)
107 if __name__
== '__main__':
111 if e
.errno
== errno
.ENOEXEC
:
112 print('Skipping due to lack of exe_wrapper.', file=sys
.stderr
)