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 22from __future__ import print_function 23import argparse 24import errno 25import os 26import subprocess 27import sys 28 29# The meson version handles windows paths better, but if it's not available 30# fall back to shlex 31try: 32 from meson.mesonlib import split_args 33except ImportError: 34 from shlex import split as split_args 35 36 37def arg_parser(): 38 parser = argparse.ArgumentParser() 39 parser.add_argument( 40 '--glsl-compiler', 41 required=True, 42 help='Path to the standalone glsl compiler') 43 parser.add_argument( 44 '--test-directory', 45 required=True, 46 help='Directory containing tests to run.') 47 return parser.parse_args() 48 49 50def get_test_runner(runner): 51 """Wrap the test runner in the exe wrapper if necessary.""" 52 wrapper = os.environ.get('MESON_EXE_WRAPPER', None) 53 if wrapper is None: 54 return [runner] 55 return split_args(wrapper) + [runner] 56 57 58def main(): 59 args = arg_parser() 60 files = [f for f in os.listdir(args.test_directory) if f.endswith('.vert')] 61 passed = 0 62 63 if not files: 64 print('Could not find any tests') 65 exit(1) 66 67 runner = get_test_runner(args.glsl_compiler) 68 69 print('====== Testing compilation output ======') 70 for file in files: 71 print('Testing {} ...'.format(file), end='') 72 file = os.path.join(args.test_directory, file) 73 74 with open('{}.expected'.format(file), 'rb') as f: 75 expected = f.read().splitlines() 76 77 proc= subprocess.run( 78 runner + ['--just-log', '--version', '150', file], 79 stdout=subprocess.PIPE 80 ) 81 if proc.returncode == 255: 82 print("Test returned general error, possibly missing linker") 83 sys.exit(77) 84 elif proc.returncode != 0: 85 print("Test returned error: {}, output:\n{}\n".format(proc.returncode, proc.stdout)) 86 87 actual = proc.stdout.splitlines() 88 89 if actual == expected: 90 print('PASS') 91 passed += 1 92 else: 93 print('FAIL') 94 95 print('{}/{} tests returned correct results'.format(passed, len(files))) 96 exit(0 if passed == len(files) else 1) 97 98 99if __name__ == '__main__': 100 try: 101 main() 102 except OSError as e: 103 if e.errno == errno.ENOEXEC: 104 print('Skipping due to inability to run host binaries', file=sys.stderr) 105 sys.exit(77) 106 raise 107