-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathautotest.py
executable file
·121 lines (96 loc) · 3.98 KB
/
autotest.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
#!/usr/bin/python3 -I
# main function for autotests
# try to catch keyboard interrupt in imports
import os, signal
# don't complain about os._exit
# pylint: disable=protected-access
if __name__ == "__main__":
signal.signal(signal.SIGINT, lambda signum, frame: os._exit(2))
# pylint: disable=wrong-import-position
import json, re, sys, traceback
from collections import OrderedDict
# add autotest directory to module path
if __name__ == "__main__":
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from util import AutotestException, TestSpecificationError
from command_line_arguments import process_arguments
from copy_files_to_temp_directory import copy_files_to_temp_directory
from run_tests import run_tests, run_tests_creating_log, generate_expected_output
from upload_results import upload_results_http
from helper import run_helper
from command_line_arguments import REPO_INFORMATION
from sandbox import run_tests_in_sandbox, continue_inside_sandbox
def main():
debug = os.environ.get("AUTOTEST_DEBUG", 0) # turn on debugging
my_name = re.sub(r"\.py$", "", os.path.basename(sys.argv[0]))
# there may be other threads running so use os._exit(1) to terminate entire program on interrupt
if not debug:
signal.signal(signal.SIGINT, lambda signum, frame: os._exit(2))
try:
sys.exit(run_autotest())
except TestSpecificationError as e:
print(f"{my_name}: {e}", file=sys.stderr)
if debug:
traceback.print_exc(file=sys.stderr)
print("\n" + REPO_INFORMATION)
sys.exit(2)
except AutotestException as e:
print(f"{my_name}: {e}", file=sys.stderr)
if debug:
traceback.print_exc(file=sys.stderr)
# print('\n' + REPO_INFORMATION)
sys.exit(2)
except Exception:
etype, evalue, _etraceback = sys.exc_info()
eformatted = "\n".join(traceback.format_exception_only(etype, evalue))
print(f"{my_name}: internal error: {eformatted}", file=sys.stderr)
if debug:
traceback.print_exc(file=sys.stderr)
print("\n" + REPO_INFORMATION)
sys.exit(2)
def run_autotest():
args, tests, parameters = process_arguments()
if args.print_test_names:
test_groups = OrderedDict()
for test in tests.values():
files = tuple(sorted(test.files))
test_groups.setdefault(files, []).append(test.label)
print(
json.dumps(
[
{"files": files, "labels": labels}
for (files, labels) in test_groups.items()
]
)
)
return 0
inside_sandbox = args.inside_sandbox
starting_sandbox = not inside_sandbox and parameters.get("sandbox", "")
if starting_sandbox:
# get absolute path for argv[0]
# before lost because of cd in copy_files_to_temp_directory
argv0_realpath = os.path.realpath(sys.argv[0])
if inside_sandbox:
# we have been re-invoked inside the sandbox
# files were copied to the temporary directory before re-invocation
# need to recover variables from original invocation
(tests, args, parameters) = continue_inside_sandbox()
else:
copy_files_to_temp_directory(args, parameters)
uploading_results = parameters.get("upload_url", "")
if starting_sandbox:
exit_status = run_tests_in_sandbox(argv0_realpath, tests, args, parameters)
else:
if args.generate_expected_output != "no":
return generate_expected_output(tests, args)
if uploading_results:
exit_status = run_tests_creating_log(tests, parameters, args)
else:
exit_status = run_tests(tests, parameters, args)
run_helper(tests, parameters, args)
if uploading_results and not inside_sandbox:
# upload of tests in sandbox may fail because network is sandbox
upload_results_http(tests, parameters, args)
return exit_status
if __name__ == "__main__":
main()