/
run.py
executable file
·89 lines (73 loc) · 2.55 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /usr/bin/env python
import argparse
import os
import os.path
import subprocess
import sys
parser = argparse.ArgumentParser(description='Run the DWARF/Ada testsuite')
parser.add_argument(
'testcase', nargs='*',
help='Optional list of paths for testcases to run. If not provided, all'
' testcases in the "tests" directory are run.'
)
parser.add_argument(
'--gnat1',
help="If provided, don't use `gcc` to build Ada material, but rather use"
" the provided gnat1 program"
)
# Move to the testsuite's root directory and setup paths
os.chdir(os.path.dirname(os.path.abspath(__file__)))
lib_path = os.path.abspath('utils')
sys.path.append(lib_path)
def indent(text):
return '\n'.join(' {}'.format(line) for line in text.rstrip().split('\n'))
def run_test(test_file):
test_name = os.path.dirname(test_file)
with open(os.devnull, 'r') as devnull:
env = dict(os.environ)
if 'PYTHONPATH' in env:
env['PYTHONPATH'] = '{}:{}'.format(lib_path, env['PYTHONPATH'])
else:
env['PYTHONPATH'] = '{}'.format(lib_path)
p = subprocess.Popen(
[sys.executable, os.path.abspath(test_file)],
cwd=os.path.dirname(test_file),
env=env,
stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, stderr = p.communicate()
if p.returncode != 0:
print('\x1b[31mERROR\x1b[0m: {}'.format(test_name))
if stdout:
print(indent(stdout))
if stderr:
print(indent(stderr))
else:
print('\x1b[32mOK\x1b[0m: {}'.format(test_name))
def which(program):
return subprocess.check_output(['which', program]).strip()
def main(args):
# If provided, register --gnat1 in the environment so that testcases can
# use it.
if args.gnat1:
os.environ['GNAT1'] = os.path.expanduser(args.gnat1)
print('Using compiler: {}'.format(which(
os.environ['GNAT1']
if 'GNAT1' in os.environ else
'gcc'
)))
test_list = args.testcase or (os.path.join('tests', d)
for d in os.listdir('tests'))
one_test_run = False
for child in sorted(test_list):
test_file = os.path.join(child, 'test.py')
if os.path.isfile(test_file):
one_test_run = True
run_test(test_file)
if not one_test_run:
print('Warning: no test run')
if __name__ == '__main__':
try:
main(parser.parse_args())
except KeyboardInterrupt:
sys.exit(1)