forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
executable file
·150 lines (122 loc) · 5.48 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
import argparse
import hashlib
import os
import subprocess
import toml
from compiler_tester.tester import (RunException, run, run_test, color,
style, print_check, fg)
def main():
parser = argparse.ArgumentParser(description="LFortran Test Suite")
parser.add_argument("-u", "--update", action="store_true",
help="update all reference results")
parser.add_argument("-l", "--list", action="store_true",
help="list all tests")
parser.add_argument("-t", metavar="TEST",
help="Run a specific test")
parser.add_argument("-v", "--verbose", action="store_true",
help="increase test verbosity")
parser.add_argument("--no-llvm", action="store_true",
help="Skip LLVM tests")
args = parser.parse_args()
update_reference = args.update
list_tests = args.list
specific_test = args.t
verbose = args.verbose
no_llvm = args.no_llvm
# So that the tests find the `lfortran` executable
os.environ["PATH"] = os.path.join(os.getcwd(), "src", "bin") \
+ os.pathsep + os.environ["PATH"]
d = toml.load(open("tests/tests.toml"))
for test in d["test"]:
filename = test["filename"]
if specific_test and filename != specific_test:
continue
tokens = test.get("tokens", False)
ast = test.get("ast", False)
ast_indent = test.get("ast_indent", False)
ast_f90 = test.get("ast_f90", False)
ast_cpp = test.get("ast_cpp", False)
ast_cpp_hip = test.get("ast_cpp_hip", False)
ast_openmp = test.get("ast_openmp", False)
asr = test.get("asr", False)
asr_preprocess = test.get("asr_preprocess", False)
asr_indent = test.get("asr_indent", False)
mod_to_asr = test.get("mod_to_asr", False)
llvm = test.get("llvm", False)
cpp = test.get("cpp", False)
obj = test.get("obj", False)
x86 = test.get("x86", False)
bin_ = test.get("bin", False)
pass_ = test.get("pass", None)
if pass_ and pass_ not in ["do_loops", "global_stmts"]:
raise Exception("Unknown pass: %s" % pass_)
print(color(style.bold)+"TEST:"+color(style.reset), filename)
extra_args = "--no-error-banner"
if tokens:
run_test("tokens", "lfortran --no-color --show-tokens {infile} -o {outfile}",
filename, update_reference, extra_args)
if ast:
run_test("ast", "lpython --show-ast --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if ast_f90:
if filename.endswith(".f"):
# Use fixed form
run_test("ast_f90", "lfortran --fixed-form --show-ast-f90 --no-color {infile}",
filename, update_reference, extra_args)
else:
# Use free form
run_test("ast_f90", "lfortran --show-ast-f90 --no-color {infile}",
filename, update_reference, extra_args)
if ast_openmp:
run_test("ast_openmp", "cpptranslate --show-ast-openmp {infile}",
filename, update_reference)
if asr:
run_test("asr", "lfortran --show-asr --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if asr_preprocess:
run_test("asr_preprocess", "lfortran --cpp --show-asr --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if asr_indent:
run_test("asr_indent", "lfortran --show-asr --indent --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if mod_to_asr:
run_test("mod_to_asr", "lfortran mod --show-asr --no-color {infile}",
filename, update_reference)
if pass_ == "do_loops":
run_test("pass_do_loops", "lfortran --pass=do_loops --show-asr --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if pass_ == "global_stmts":
run_test("pass_global_stmts", "lfortran --pass=global_stmts --show-asr --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if llvm:
if no_llvm:
print(" * llvm SKIPPED as requested")
else:
run_test("llvm", "lfortran --no-color --show-llvm {infile} -o {outfile}",
filename, update_reference, extra_args)
if cpp:
run_test("cpp", "lfortran --no-color --show-cpp {infile}",
filename, update_reference, extra_args)
if obj:
if no_llvm:
print(" * obj SKIPPED as requested")
else:
run_test("obj", "lfortran --no-color -c {infile} -o output.o",
filename, update_reference, extra_args)
if x86:
run_test("x86", "lfortran --no-color --backend=x86 {infile} -o output",
filename, update_reference, extra_args)
if bin_:
run_test("bin", "lfortran --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
print()
if list_tests:
return
if update_reference:
print("Reference tests updated.")
else:
print("%sTESTS PASSED%s" % (color(fg.green)+color(style.bold),
color(fg.reset)+color(style.reset)))
if __name__ == "__main__":
main()