From 7d3204783a3550ab8a5a848901e0e512d54a4163 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 23 May 2022 11:10:37 +1000 Subject: [PATCH] tests/run-tests.py: Handle case where mpy-cross fails to compile script. Signed-off-by: Damien George --- tests/run-perfbench.py | 5 ++++- tests/run-tests.py | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/run-perfbench.py b/tests/run-perfbench.py index 22ad6308fb..a2e9e8079a 100755 --- a/tests/run-perfbench.py +++ b/tests/run-perfbench.py @@ -120,7 +120,10 @@ def run_benchmarks(args, target, param_n, param_m, n_average, test_list): # Process script through mpy-cross if needed if isinstance(target, pyboard.Pyboard) or args.via_mpy: - test_script_target = prepare_script_for_target(args, script_text=test_script) + crash, test_script_target = prepare_script_for_target(args, script_text=test_script) + if crash: + print("CRASH:", test_script_target) + continue else: test_script_target = test_script diff --git a/tests/run-tests.py b/tests/run-tests.py index 35e28aac9b..1fc8576014 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -122,11 +122,15 @@ def prepare_script_for_target(args, *, script_filename=None, script_text=None, f else: cleanup_script_filename = False - subprocess.check_output( - [MPYCROSS] - + args.mpy_cross_flags.split() - + ["-o", mpy_filename, "-X", "emit=" + args.emit, script_filename] - ) + try: + subprocess.check_output( + [MPYCROSS] + + args.mpy_cross_flags.split() + + ["-o", mpy_filename, "-X", "emit=" + args.emit, script_filename], + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError as er: + return True, b"mpy-cross crash\n" + er.output with open(mpy_filename, "rb") as f: script_text = b"__buf=" + bytes(repr(f.read()), "ascii") + b"\n" @@ -140,11 +144,16 @@ def prepare_script_for_target(args, *, script_filename=None, script_text=None, f print("error: using emit={} must go via .mpy".format(args.emit)) sys.exit(1) - return script_text + return False, script_text def run_script_on_remote_target(pyb, args, test_file, is_special): - script = prepare_script_for_target(args, script_filename=test_file, force_plain=is_special) + had_crash, script = prepare_script_for_target( + args, script_filename=test_file, force_plain=is_special + ) + if had_crash: + return True, script + try: had_crash = False pyb.enter_raw_repl()