forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
executable file
·96 lines (80 loc) · 3.24 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
#!/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 ast:
run_test("ast", "lpython --show-ast --no-color {infile} -o {outfile}",
filename, update_reference, extra_args)
if asr:
run_test("asr", "lpython --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", "lpython --no-color --show-llvm {infile} -o {outfile}",
filename, update_reference, extra_args)
if cpp:
run_test("cpp", "lpython --no-color --show-cpp {infile}",
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()