Skip to content

Commit badd512

Browse files
committed
run-vmtest: exit gracefully from print_test_summary.py
When selftests fail because of a watchdog timeout or segfault or anything similar, a JSON summary might be empty or absent. Currently this leads to print_test_summary.py to verbosly fail with an exception, which is confusing when looking at the job log. Handle common errors gracefully in the script. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 151eda0 commit badd512

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

run-vmtest/print_test_summary.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
import argparse
1111
import json
12-
12+
import os
13+
import sys
1314

1415
def parse_args():
1516
parser = argparse.ArgumentParser()
@@ -75,14 +76,28 @@ def test_error_console_log(test_error: str, test_message: str) -> str:
7576
else:
7677
return error_msg
7778

79+
def error_die(msg: str):
80+
print("print_test_summary.py: {}".format(msg), file=sys.stderr)
81+
exit(0)
7882

7983
if __name__ == "__main__":
8084
args = parse_args()
8185
step_open_mode = "a" if args.append else "w"
86+
str_summary = None
8287
json_summary = None
8388

89+
if not os.path.exists(args.json_summary):
90+
error_die("Could not find {}".format(args.json_summary))
91+
elif os.stat(args.json_summary).st_size == 0:
92+
error_die("{} is empty".format(args.json_summary))
93+
8494
with open(args.json_summary, "r") as f:
85-
json_summary = json.load(f)
95+
str_summary = f.read()
96+
97+
try:
98+
json_summary = json.loads(str_summary)
99+
except json.JSONDecodeError:
100+
error_die("{} is not a valid JSON\n{}".format(args.json_summary, str_summary))
86101

87102
with open(args.step_summary, step_open_mode) as f:
88103
log_gh_summary(f, "# Tests summary")

0 commit comments

Comments
 (0)