1b8e80941Smrg# encoding=utf-8
2b8e80941Smrg# Copyright © 2017 Intel Corporation
3b8e80941Smrg
4b8e80941Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy
5b8e80941Smrg# of this software and associated documentation files (the "Software"), to deal
6b8e80941Smrg# in the Software without restriction, including without limitation the rights
7b8e80941Smrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8b8e80941Smrg# copies of the Software, and to permit persons to whom the Software is
9b8e80941Smrg# furnished to do so, subject to the following conditions:
10b8e80941Smrg
11b8e80941Smrg# The above copyright notice and this permission notice shall be included in
12b8e80941Smrg# all copies or substantial portions of the Software.
13b8e80941Smrg
14b8e80941Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b8e80941Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b8e80941Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17b8e80941Smrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18b8e80941Smrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19b8e80941Smrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20b8e80941Smrg# SOFTWARE.
21b8e80941Smrg
22b8e80941Smrgfrom __future__ import print_function
23b8e80941Smrgimport argparse
24b8e80941Smrgimport os
25b8e80941Smrgimport subprocess
26b8e80941Smrg
27b8e80941Smrg
28b8e80941Smrgdef arg_parser():
29b8e80941Smrg    parser = argparse.ArgumentParser()
30b8e80941Smrg    parser.add_argument(
31b8e80941Smrg        '--glsl-compiler',
32b8e80941Smrg        required=True,
33b8e80941Smrg        help='Path to the standalone glsl compiler')
34b8e80941Smrg    parser.add_argument(
35b8e80941Smrg        '--test-directory',
36b8e80941Smrg        required=True,
37b8e80941Smrg        help='Directory containing tests to run.')
38b8e80941Smrg    return parser.parse_args()
39b8e80941Smrg
40b8e80941Smrg
41b8e80941Smrgdef main():
42b8e80941Smrg    args = arg_parser()
43b8e80941Smrg    files = [f for f in os.listdir(args.test_directory) if f.endswith('.vert')]
44b8e80941Smrg    passed = 0
45b8e80941Smrg
46b8e80941Smrg    if not files:
47b8e80941Smrg        print('Could not find any tests')
48b8e80941Smrg        exit(1)
49b8e80941Smrg
50b8e80941Smrg    print('====== Testing compilation output ======')
51b8e80941Smrg    for file in files:
52b8e80941Smrg        print('Testing {} ...'.format(file), end='')
53b8e80941Smrg        file = os.path.join(args.test_directory, file)
54b8e80941Smrg
55b8e80941Smrg        with open('{}.expected'.format(file), 'rb') as f:
56b8e80941Smrg            expected = f.read().strip()
57b8e80941Smrg
58b8e80941Smrg        actual = subprocess.check_output(
59b8e80941Smrg            [args.glsl_compiler, '--just-log', '--version', '150', file]
60b8e80941Smrg        ).strip()
61b8e80941Smrg
62b8e80941Smrg        if actual == expected:
63b8e80941Smrg            print('PASS')
64b8e80941Smrg            passed += 1
65b8e80941Smrg        else:
66b8e80941Smrg            print('FAIL')
67b8e80941Smrg
68b8e80941Smrg    print('{}/{} tests returned correct results'.format(passed, len(files)))
69b8e80941Smrg    exit(0 if passed == len(files) else 1)
70b8e80941Smrg
71b8e80941Smrg
72b8e80941Smrgif __name__ == '__main__':
73b8e80941Smrg    main()
74