101e04c3fSmrg# encoding=utf-8 201e04c3fSmrg# Copyright © 2017 Intel Corporation 301e04c3fSmrg 401e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 501e04c3fSmrg# of this software and associated documentation files (the "Software"), to deal 601e04c3fSmrg# in the Software without restriction, including without limitation the rights 701e04c3fSmrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 801e04c3fSmrg# copies of the Software, and to permit persons to whom the Software is 901e04c3fSmrg# furnished to do so, subject to the following conditions: 1001e04c3fSmrg 1101e04c3fSmrg# The above copyright notice and this permission notice shall be included in 1201e04c3fSmrg# all copies or substantial portions of the Software. 1301e04c3fSmrg 1401e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1501e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1601e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1701e04c3fSmrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1801e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1901e04c3fSmrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2001e04c3fSmrg# SOFTWARE. 2101e04c3fSmrg 2201e04c3fSmrgimport argparse 237ec681f3Smrgimport errno 2401e04c3fSmrgimport os 2501e04c3fSmrgimport subprocess 267ec681f3Smrgimport sys 277ec681f3Smrg 287ec681f3Smrg# The meson version handles windows paths better, but if it's not available 297ec681f3Smrg# fall back to shlex 307ec681f3Smrgtry: 317ec681f3Smrg from meson.mesonlib import split_args 327ec681f3Smrgexcept ImportError: 337ec681f3Smrg from shlex import split as split_args 3401e04c3fSmrg 3501e04c3fSmrg 3601e04c3fSmrgdef arg_parser(): 3701e04c3fSmrg parser = argparse.ArgumentParser() 3801e04c3fSmrg parser.add_argument( 3901e04c3fSmrg '--glsl-compiler', 4001e04c3fSmrg required=True, 4101e04c3fSmrg help='Path to the standalone glsl compiler') 4201e04c3fSmrg parser.add_argument( 4301e04c3fSmrg '--test-directory', 4401e04c3fSmrg required=True, 4501e04c3fSmrg help='Directory containing tests to run.') 4601e04c3fSmrg return parser.parse_args() 4701e04c3fSmrg 4801e04c3fSmrg 497ec681f3Smrgdef get_test_runner(runner): 507ec681f3Smrg """Wrap the test runner in the exe wrapper if necessary.""" 517ec681f3Smrg wrapper = os.environ.get('MESON_EXE_WRAPPER', None) 527ec681f3Smrg if wrapper is None: 537ec681f3Smrg return [runner] 547ec681f3Smrg return split_args(wrapper) + [runner] 557ec681f3Smrg 567ec681f3Smrg 5701e04c3fSmrgdef main(): 5801e04c3fSmrg args = arg_parser() 5901e04c3fSmrg files = [f for f in os.listdir(args.test_directory) if f.endswith('.vert')] 6001e04c3fSmrg passed = 0 6101e04c3fSmrg 6201e04c3fSmrg if not files: 6301e04c3fSmrg print('Could not find any tests') 6401e04c3fSmrg exit(1) 6501e04c3fSmrg 667ec681f3Smrg runner = get_test_runner(args.glsl_compiler) 677ec681f3Smrg 6801e04c3fSmrg print('====== Testing compilation output ======') 6901e04c3fSmrg for file in files: 7001e04c3fSmrg print('Testing {} ...'.format(file), end='') 7101e04c3fSmrg file = os.path.join(args.test_directory, file) 7201e04c3fSmrg 7301e04c3fSmrg with open('{}.expected'.format(file), 'rb') as f: 747ec681f3Smrg expected = f.read().splitlines() 757ec681f3Smrg 767ec681f3Smrg proc= subprocess.run( 777ec681f3Smrg runner + ['--just-log', '--version', '150', file], 787ec681f3Smrg stdout=subprocess.PIPE 797ec681f3Smrg ) 807ec681f3Smrg if proc.returncode == 255: 817ec681f3Smrg print("Test returned general error, possibly missing linker") 827ec681f3Smrg sys.exit(77) 837ec681f3Smrg elif proc.returncode != 0: 847ec681f3Smrg print("Test returned error: {}, output:\n{}\n".format(proc.returncode, proc.stdout)) 8501e04c3fSmrg 867ec681f3Smrg actual = proc.stdout.splitlines() 8701e04c3fSmrg 8801e04c3fSmrg if actual == expected: 8901e04c3fSmrg print('PASS') 9001e04c3fSmrg passed += 1 9101e04c3fSmrg else: 9201e04c3fSmrg print('FAIL') 9301e04c3fSmrg 9401e04c3fSmrg print('{}/{} tests returned correct results'.format(passed, len(files))) 9501e04c3fSmrg exit(0 if passed == len(files) else 1) 9601e04c3fSmrg 9701e04c3fSmrg 9801e04c3fSmrgif __name__ == '__main__': 997ec681f3Smrg try: 1007ec681f3Smrg main() 1017ec681f3Smrg except OSError as e: 1027ec681f3Smrg if e.errno == errno.ENOEXEC: 1037ec681f3Smrg print('Skipping due to inability to run host binaries', file=sys.stderr) 1047ec681f3Smrg sys.exit(77) 1057ec681f3Smrg raise 106