run_tests.py
1 #!/usr/bin/env python3 2 3 import pytest 4 import argparse 5 import os 6 from pathlib import Path 7 8 topdir = Path(__file__).parent.parent 9 10 11 def cd_to_topdir(): 12 os.chdir(topdir) 13 14 15 def main(): 16 parser = argparse.ArgumentParser() 17 parser.add_argument("-l", "--list", action="store_true", help="List all tests") 18 parser.add_argument("-t", "--trace", action="store_true", help="Dump waveforms") 19 parser.add_argument("-p", "--profile", action="store_true", help="Write execution profiles") 20 parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") 21 parser.add_argument("-s", "--no-capture", action="store_true", help="Don't capture output") 22 parser.add_argument("-a", "--all", action="store_true", default=False, help="Run all tests") 23 parser.add_argument( 24 "-b", "--backend", default="cocotb", choices=["cocotb", "pysim"], help="Simulation backend for regression tests" 25 ) 26 parser.add_argument("-c", "--count", type=int, help="Start `c` first tests which match regexp") 27 parser.add_argument( 28 "-j", "--jobs", type=int, default=len(os.sched_getaffinity(0)), help="Start `j` jobs in parallel. Default: all" 29 ) 30 parser.add_argument("--log-level", default="WARNING", action="store", help="Level of messages to display.") 31 parser.add_argument("--log-filter", default=".*", action="store", help="Regexp used to filter out logs.") 32 parser.add_argument("test_name", nargs="?") 33 34 args = parser.parse_args() 35 36 pytest_arguments = ["--max-worker-restart=1"] 37 38 if args.trace: 39 pytest_arguments.append("--coreblocks-traces") 40 if args.profile: 41 pytest_arguments.append("--coreblocks-profile") 42 if args.test_name: 43 pytest_arguments += [f"--coreblocks-test-name={args.test_name}"] 44 if args.count: 45 pytest_arguments += ["--coreblocks-test-count", str(args.count)] 46 if args.list: 47 pytest_arguments.append("--coreblocks-list") 48 if args.no_capture: 49 pytest_arguments.append("-s") 50 if args.jobs and not args.list and not args.no_capture: 51 # To list tests we can not use xdist, because it doesn't support forwarding of stdout from workers. 52 pytest_arguments += ["-n", str(args.jobs)] 53 if args.all: 54 pytest_arguments.append("--coreblocks-regression") 55 if args.verbose: 56 pytest_arguments.append("--verbose") 57 if args.backend: 58 pytest_arguments += [f"--coreblocks-backend={args.backend}"] 59 if args.log_level: 60 pytest_arguments += [f"--log-level={args.log_level}"] 61 if args.log_filter: 62 pytest_arguments += [f"--coreblocks-log-filter={args.log_filter}"] 63 64 ret = pytest.main(pytest_arguments, []) 65 66 exit(ret) 67 68 69 if __name__ == "__main__": 70 cd_to_topdir() 71 main()