glsl/tests: Handle no-exec errors
[mesa.git] / src / compiler / glsl / tests / warnings_test.py
1 # encoding=utf-8
2 # Copyright © 2017 Intel Corporation
3
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:
10
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
13
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
20 # SOFTWARE.
21
22 from __future__ import print_function
23 import argparse
24 import errno
25 import os
26 import subprocess
27 import sys
28
29
30 def arg_parser():
31 parser = argparse.ArgumentParser()
32 parser.add_argument(
33 '--glsl-compiler',
34 required=True,
35 help='Path to the standalone glsl compiler')
36 parser.add_argument(
37 '--test-directory',
38 required=True,
39 help='Directory containing tests to run.')
40 return parser.parse_args()
41
42
43 def get_test_runner(runner):
44 """Wrap the test runner in the exe wrapper if necessary."""
45 wrapper = os.environ.get('MESON_EXE_WRAPPER', None)
46 if wrapper is None:
47 return [runner]
48 return [wrapper, runner]
49
50
51 def main():
52 args = arg_parser()
53 files = [f for f in os.listdir(args.test_directory) if f.endswith('.vert')]
54 passed = 0
55
56 if not files:
57 print('Could not find any tests')
58 exit(1)
59
60 runner = get_test_runner(args.glsl_compiler)
61
62 print('====== Testing compilation output ======')
63 for file in files:
64 print('Testing {} ...'.format(file), end='')
65 file = os.path.join(args.test_directory, file)
66
67 with open('{}.expected'.format(file), 'rb') as f:
68 expected = f.read().strip()
69
70 actual = subprocess.check_output(
71 runner + ['--just-log', '--version', '150', file]
72 ).strip()
73
74 if actual == expected:
75 print('PASS')
76 passed += 1
77 else:
78 print('FAIL')
79
80 print('{}/{} tests returned correct results'.format(passed, len(files)))
81 exit(0 if passed == len(files) else 1)
82
83
84 if __name__ == '__main__':
85 try:
86 main()
87 except OSError as e:
88 if e.errno == errno.ENOEXEC:
89 print('Skipping due to lack of exe_wrapper.', file=sys.stderr)
90 sys.exit(77)
91 else:
92 raise