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
35 # The meson version handles windows paths better, but if it's not available
38 from meson
.mesonlib
import split_args
40 from shlex
import split
as split_args
44 parser
= argparse
.ArgumentParser()
48 help='The glsl_test binary.')
49 return parser
.parse_args()
52 def compare(actual
, expected
):
53 """Compare the s-expresions and return a diff if they are different."""
54 actual
= sexps
.sort_decls(sexps
.parse_sexp(actual
))
55 expected
= sexps
.sort_decls(sexps
.parse_sexp(expected
))
57 if actual
== expected
:
60 actual
= sexps
.sexp_to_string(actual
)
61 expected
= sexps
.sexp_to_string(expected
)
63 return difflib
.unified_diff(expected
.splitlines(), actual
.splitlines())
66 def get_test_runner(runner
):
67 """Wrap the test runner in the exe wrapper if necessary."""
68 wrapper
= os
.environ
.get('MESON_EXE_WRAPPER', None)
71 return split_args(wrapper
) + [runner
]
75 """Generate each test and report pass or fail."""
81 runner
= get_test_runner(args
.test_runner
)
83 for gen
in lower_jump_cases
.CASES
:
84 for name
, opt
, source
, expected
in gen():
86 print('{}: '.format(name
), end
='')
87 proc
= subprocess
.Popen(
88 runner
+ ['optpass', '--quiet', '--input-ir', opt
],
89 stdout
=subprocess
.PIPE
,
90 stderr
=subprocess
.PIPE
,
91 stdin
=subprocess
.PIPE
)
92 out
, err
= proc
.communicate(source
.encode('utf-8'))
93 out
= out
.decode('utf-8')
94 err
= err
.decode('utf-8')
97 print('Unexpected output on stderr: {}'.format(err
),
101 result
= compare(out
, expected
)
102 if result
is not None:
105 print(l
, file=sys
.stderr
)
110 print('{}/{} tests returned correct results'.format(passes
, total
))
111 exit(0 if passes
== total
else 1)
114 if __name__
== '__main__':
118 if e
.errno
== errno
.ENOEXEC
:
119 print('Skipping due to inability to run host binaries', file=sys
.stderr
)