-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_tests.py
executable file
·95 lines (82 loc) · 2.85 KB
/
run_tests.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
90
91
92
93
94
95
#!/usr/bin/env python
# Execute this script to run through all tests (wrap, build, run).
# Check that the correct Fortran compiler is set in Tests.mk. If
# necessary, add "-c gfortran" to OPTS below (gfortran name mangling
# is currently the default)
from __future__ import print_function
import sys
import os
import glob
import subprocess
OPTS = '-g --clean -d wrap' # FortWrap options
# Add the executable to the command. This way the tests are run with
# the chosen python instead of the default
cmd = sys.executable + ' ' + os.path.normpath('../../fortwrap.py')
custom_opts = { 'c_arrays' : OPTS + ' --no-vector',
'interface_file' : OPTS + ' -i interface.i',
'multidim_arrays' : OPTS + ' --no-vector --no-fmat',
'strings2' : OPTS + ' --no-std-string' }
# Tests for demonstration purposes only:
excludes = [ 'comments' ]
tests_dir = os.path.abspath('tests')
os.chdir('tests')
tests = glob.glob('*')
num_err = 0
FNULL = open(os.devnull, 'w')
# Use a command arg to prevent making clean
make_clean = True
if len(sys.argv) > 1:
print("Not making clean")
make_clean = False
failed_tests = []
for test in tests:
os.chdir(tests_dir)
if test in excludes or (not os.path.isdir(test)):
continue
if not os.path.exists(os.path.join(test, 'Makefile')):
# This can happen if there are leftover directories for tests
# that only exist on a different branch
continue
print("Running test:", test, end=' ')
os.chdir(test)
# Create "wrap" directory if doesn't exist:
if not os.path.exists('wrap'):
os.makedirs('wrap')
# Run wrapper generator
if test in custom_opts:
opts = custom_opts[test]
else:
opts = OPTS
if make_clean:
subprocess.call('make clean', stdout=FNULL, shell=True)
p = subprocess.Popen(cmd + ' ' + opts, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = p.communicate()
if p.returncode != 0 or 'Error:' in stderr.decode():
num_err += 1
failed_tests.append((test,'wrapper'))
print("[FAIL: wrapper]")
continue
# Build test program
stat = subprocess.call('make', stdout=FNULL)
if stat!=0:
num_err += 1
failed_tests.append((test,'build'))
print("[FAIL: build]")
continue
# Run test program
#
# This command can be tricky on Windows if the path contains
# spaces. With os.system, they need to be protected with outer
# quotes (so Windows sees the quotes); that isn't necessary with
# subprocess.call
stat = subprocess.call(os.path.abspath('prog'))
if stat!=0:
num_err += 1
failed_tests.append((test,'run'))
print("[FAIL: run]")
continue
print("[PASS]")
if num_err == 0:
print("Tests successful")
else:
print(num_err, "error(s):", failed_tests)