diff --git a/.gitignore b/.gitignore index 80b20087dd..9a8527d336 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ integration_tests/b1/* integration_tests/b2/* integration_tests/b3/* integration_tests/b4/* +integration_tests/_lpython-tmp-test-* inst/bin/* *.tlog *.filters diff --git a/ci/test.xsh b/ci/test.xsh index 7648396076..50a0649d19 100644 --- a/ci/test.xsh +++ b/ci/test.xsh @@ -18,4 +18,4 @@ src/bin/lpython --show-cpp tests/doconcurrentloop_01.py if $WIN != "1": python run_tests.py cd integration_tests - ./run_tests.sh -j16 + python run_tests_new.py -j16 -b llvm cpython c wasm diff --git a/integration_tests/run_tests_new.py b/integration_tests/run_tests_new.py new file mode 100644 index 0000000000..e038e7adf3 --- /dev/null +++ b/integration_tests/run_tests_new.py @@ -0,0 +1,64 @@ +#!/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'] +BASE_DIR = os.path.dirname(os.path.realpath(__file__)) +LPYTHON_PATH = f"{BASE_DIR}/../src/bin" + + +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} ..", cwd=cwd) + run_cmd(f"make -j{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)" % \ + ", ".join(SUPPORTED_BACKENDS)) + return parser.parse_args() + + +def main(): + args = get_args() + + # Setup + global DEFAULT_THREADS_TO_USE + 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 + for backend in args.backends: + test_backend(backend) + + +if __name__ == "__main__": + main()