-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathrun_tests.py
executable file
·70 lines (54 loc) · 2.45 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
#!/usr/bin/env python
import argparse
import subprocess
import os
# Initialization
DEFAULT_THREADS_TO_USE = 8 # default no of threads is 8
SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64', 'c_py', 'c_sym', 'cpython_sym', 'llvm_sym', 'llvm_py', 'llvm_jit']
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
LPYTHON_PATH = f"{BASE_DIR}/../src/bin"
fast_tests = "no"
python_libs_req = "no"
def run_cmd(cmd, cwd=None):
print(f"+ {cmd}")
process = subprocess.run(cmd, shell=True, cwd=cwd)
if process.returncode != 0:
print(f"Command failed: {cmd}")
exit(1)
def run_test(backend):
run_cmd(f"mkdir {BASE_DIR}/_lpython-tmp-test-{backend}", cwd=BASE_DIR)
cwd = f"{BASE_DIR}/_lpython-tmp-test-{backend}"
run_cmd(f"cmake -DKIND={backend} -DFAST={fast_tests} -DPYTHON_LIBS_REQ={python_libs_req} ..", cwd=cwd)
run_cmd(f"cmake --build . --parallel {DEFAULT_THREADS_TO_USE}", cwd=cwd)
run_cmd(f"ctest -j{DEFAULT_THREADS_TO_USE} --output-on-failure",
cwd=cwd)
def test_backend(backend):
if backend not in SUPPORTED_BACKENDS:
print(f"Unsupported Backend: {backend}\n")
return
run_test(backend)
def get_args():
parser = argparse.ArgumentParser(description="LPython Integration Test Suite")
parser.add_argument("-j", "-n", "--no_of_threads", type=int,
help="Parallel testing on given number of threads")
parser.add_argument("-b", "--backends", nargs="*", default=["llvm", "cpython"],
type=str, help="Test the requested backends (%s), default: llvm, cpython" % \
", ".join(SUPPORTED_BACKENDS))
parser.add_argument("-f", "--fast", action='store_true',
help="Run supported tests with --fast")
return parser.parse_args()
def main():
args = get_args()
# Setup
global DEFAULT_THREADS_TO_USE, fast_tests, python_libs_req
os.environ["PATH"] = LPYTHON_PATH + os.pathsep + os.environ["PATH"]
# delete previously created directories (if any)
for backend in SUPPORTED_BACKENDS:
run_cmd(f"rm -rf {BASE_DIR}/_lpython-tmp-test-{backend}")
DEFAULT_THREADS_TO_USE = args.no_of_threads or DEFAULT_THREADS_TO_USE
fast_tests = "yes" if args.fast else "no"
for backend in args.backends:
python_libs_req = "yes" if backend in ["cpython", "c_py", "c_sym", "llvm_sym", 'llvm_py', 'llvm_jit'] else "no"
test_backend(backend)
if __name__ == "__main__":
main()