-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_scripts.py
More file actions
executable file
·74 lines (62 loc) · 2.14 KB
/
run_scripts.py
File metadata and controls
executable file
·74 lines (62 loc) · 2.14 KB
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
#!/usr/bin/env python3
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
#
# SPDX-License-Identifier: MIT OR Apache-2.0
import argparse
import os
import pathlib
import subprocess
import sys
def get_tests(args):
result = []
for path in args.tests:
if not os.path.exists(path):
raise ValueError(f"Path {path} does not exist!")
if os.path.isdir(path):
result += pathlib.Path(path).rglob("*.sm")
else:
result.append(path)
print(f"Found {len(result)} tests")
return result
def run(args):
"""Run tests and return the number of failures"""
failed = []
print(args.smoldr, args.arg)
tests = get_tests(args)
if args.quiet:
output = subprocess.DEVNULL
else:
# Pass through
output = None
for path in tests:
print(path)
try:
complete = subprocess.run([args.smoldr, *args.arg, path], timeout=args.timeout, stdout=output)
if complete.returncode != 0:
print("FAIL")
failed.append(path)
else:
print("PASS")
except subprocess.TimeoutExpired:
print("FAIL; timeout")
failed.append(path)
if len(failed) > 0:
print(f"There were {len(failed)} failures:")
for f in failed:
print(" " + str(f))
return len(failed)
def get_args():
parser = argparse.ArgumentParser(description="Run smoldr testing")
parser.add_argument('smoldr', type=pathlib.Path, help="The smoldr binary to run")
parser.add_argument('tests', nargs="+", default=[], help="Can be directories or test file names. For directories, all .sm files in the directory are used as test.")
parser.add_argument('--quiet', '-q', action='store_true')
parser.add_argument('-t', '--timeout', default="40", help="Change the timeout to the given value", type=int);
parser.add_argument('-a', '--arg', nargs='*', default=[], help="Pass an argument to smoldr")
return parser.parse_args()
def main():
args = get_args()
fails = run(args)
if fails > 0:
sys.exit(1)
if __name__ == '__main__':
main()