forked from phoenix-rtos/phoenix-rtos-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.py
executable file
·140 lines (105 loc) · 4.41 KB
/
runner.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
import argparse
import logging
import pathlib
import sys
import trunner.config as config
from trunner.test_runner import TestsRunner
from trunner.tools.color import Color
def set_logger(level=logging.INFO):
root = logging.getLogger()
root.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(level)
stream_handler.terminator = ''
formatter = logging.Formatter('%(message)s')
stream_handler.setFormatter(formatter)
root.addHandler(stream_handler)
def args_file(arg):
path = pathlib.Path(arg)
if not path.exists():
print(f"Path {path} does not exist")
sys.exit(1)
path = path.resolve()
return path
def parse_args():
logging_level = {
'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR
}
parser = argparse.ArgumentParser()
parser.add_argument("-T", "--target",
action='append', choices=config.ALL_TARGETS,
help="Filter targets on which test will be built and run. "
"By default runs tests on all available targets. "
"Flag can be used multiple times.")
parser.add_argument("-t", "--test",
default=[], action='append', type=args_file,
help="Specify directory in which test will be searched. "
"If flag is not used then runner searches for tests in "
"phoenix-rtos-tests directory. Flag can be used multiple times.")
parser.add_argument("--build",
default=False, action='store_true',
help="Runner will build all tests.")
parser.add_argument("-l", "--log-level",
default='info',
choices=logging_level,
help="Specify verbosity level. By default uses level info.")
parser.add_argument("-s", "--serial",
default=config.DEVICE_SERIAL_PORT,
help="Specify serial to communicate with device board. "
"By default uses %(default)s.")
parser.add_argument("-b", "--baudrate",
default=config.DEVICE_SERIAL_BAUDRATE,
help="Specify the connection speed of serial. "
"By default uses 115200")
parser.add_argument("--no-flash",
default=False, action='store_true',
help="Board will not be flashed by runner.")
# Add alternative option "--long-test" "" for long-test argument, which is False
# Needed for proper disabling long tests in gh actions
# because of problem with passing empty argument through gh workflows
parser.add_argument("--long-test",
type=bool,
nargs='?', default=False, const=True,
help="Long tests will be run")
args = parser.parse_args()
args.log_level = logging_level[args.log_level]
if not args.test:
args.test = [config.PHRTOS_TEST_DIR]
if not args.target:
# Run on all available targets
args.target = config.ALL_TARGETS
if not args.serial:
args.serial = config.DEVICE_SERIAL_PORT
if not args.baudrate:
args.serial = config.DEVICE_SERIAL_BAUDRATE
return args
def main():
args = parse_args()
set_logger(args.log_level)
runner = TestsRunner(targets=args.target,
test_paths=args.test,
build=args.build,
flash=not args.no_flash,
serial=(args.serial, args.baudrate),
log=(args.log_level == logging.DEBUG),
long_test=args.long_test
)
passed, failed, skipped = runner.run()
total = passed + failed + skipped
summary = f'TESTS: {total}'
summary += f' {Color.colorify("PASSED", Color.OK)}: {passed}'
summary += f' {Color.colorify("FAILED", Color.FAIL)}: {failed}'
summary += f' {Color.colorify("SKIPPED", Color.SKIP)}: {skipped}\n'
logging.info(summary)
if failed == 0:
print("Succeeded!")
sys.exit(0)
else:
print("Failed!")
sys.exit(1)
if __name__ == "__main__":
main()