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 os
25import subprocess
26
27
28def arg_parser():
29    parser = argparse.ArgumentParser()
30    parser.add_argument(
31        '--glsl-compiler',
32        required=True,
33        help='Path to the standalone glsl compiler')
34    parser.add_argument(
35        '--test-directory',
36        required=True,
37        help='Directory containing tests to run.')
38    return parser.parse_args()
39
40
41def main():
42    args = arg_parser()
43    files = [f for f in os.listdir(args.test_directory) if f.endswith('.vert')]
44    passed = 0
45
46    if not files:
47        print('Could not find any tests')
48        exit(1)
49
50    print('====== Testing compilation output ======')
51    for file in files:
52        print('Testing {} ...'.format(file), end='')
53        file = os.path.join(args.test_directory, file)
54
55        with open('{}.expected'.format(file), 'rb') as f:
56            expected = f.read().strip()
57
58        actual = subprocess.check_output(
59            [args.glsl_compiler, '--just-log', '--version', '150', file]
60        ).strip()
61
62        if actual == expected:
63            print('PASS')
64            passed += 1
65        else:
66            print('FAIL')
67
68    print('{}/{} tests returned correct results'.format(passed, len(files)))
69    exit(0 if passed == len(files) else 1)
70
71
72if __name__ == '__main__':
73    main()
74