Skip to content

tests: automatically skip tests that are too large for the target (not enough memory) #17361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/misc/print_exception.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Test sys.print_exception (MicroPython) / traceback.print_exception (CPython).

try:
import io
import sys
Expand Down
73 changes: 50 additions & 23 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,11 @@ def open(self, path, mode):
# These are tests that are difficult to detect that they should not be run on the given target.
platform_tests_to_skip = {
"esp8266": (
"micropython/viper_args.py", # too large
"micropython/viper_binop_arith.py", # too large
"misc/rge_sm.py", # too large
"misc/rge_sm.py", # incorrect values due to object representation C
),
"minimal": (
"basics/class_inplace_op.py", # all special methods not supported
"basics/subclass_native_init.py", # native subclassing corner cases not support
"misc/rge_sm.py", # too large
"micropython/opt_level.py", # don't assume line numbers are stored
),
"nrf": (
Expand Down Expand Up @@ -272,22 +269,17 @@ def detect_test_platform(pyb, args):
print()


def prepare_script_for_target(args, *, script_filename=None, script_text=None, force_plain=False):
def prepare_script_for_target(args, *, script_text=None, force_plain=False):
if force_plain or (not args.via_mpy and args.emit == "bytecode"):
if script_filename is not None:
with open(script_filename, "rb") as f:
script_text = f.read()
# A plain test to run as-is, no processing needed.
pass
elif args.via_mpy:
tempname = tempfile.mktemp(dir="")
mpy_filename = tempname + ".mpy"

if script_filename is None:
script_filename = tempname + ".py"
cleanup_script_filename = True
with open(script_filename, "wb") as f:
f.write(script_text)
else:
cleanup_script_filename = False
script_filename = tempname + ".py"
with open(script_filename, "wb") as f:
f.write(script_text)

try:
subprocess.check_output(
Expand All @@ -303,8 +295,7 @@ def prepare_script_for_target(args, *, script_filename=None, script_text=None, f
script_text = b"__buf=" + bytes(repr(f.read()), "ascii") + b"\n"

rm_f(mpy_filename)
if cleanup_script_filename:
rm_f(script_filename)
rm_f(script_filename)

script_text += bytes(injected_import_hook_code, "ascii")
else:
Expand All @@ -315,9 +306,21 @@ def prepare_script_for_target(args, *, script_filename=None, script_text=None, f


def run_script_on_remote_target(pyb, args, test_file, is_special):
had_crash, script = prepare_script_for_target(
args, script_filename=test_file, force_plain=is_special
)
with open(test_file, "rb") as f:
script = f.read()

# If the test is not a special test, prepend it with a print to indicate that it started.
# If the print does not execute this means that the test did not even start, eg it was
# too large for the target.
prepend_start_test = not is_special
if prepend_start_test:
if script.startswith(b"#"):
script = b"print('START TEST')" + script
else:
script = b"print('START TEST')\n" + script

had_crash, script = prepare_script_for_target(args, script_text=script, force_plain=is_special)

if had_crash:
return True, script

Expand All @@ -328,9 +331,19 @@ def run_script_on_remote_target(pyb, args, test_file, is_special):
except pyboard.PyboardError as e:
had_crash = True
if not is_special and e.args[0] == "exception":
output_mupy = e.args[1] + e.args[2] + b"CRASH"
if prepend_start_test and e.args[1] == b"" and b"MemoryError" in e.args[2]:
output_mupy = b"SKIP-TOO-LARGE\n"
else:
output_mupy = e.args[1] + e.args[2] + b"CRASH"
else:
output_mupy = bytes(e.args[0], "ascii") + b"\nCRASH"

if prepend_start_test:
if output_mupy.startswith(b"START TEST\r\n"):
output_mupy = output_mupy.removeprefix(b"START TEST\r\n")
else:
had_crash = True

return had_crash, output_mupy


Expand Down Expand Up @@ -474,7 +487,7 @@ def send_get(what):
output_mupy = output_mupy.replace(b"\r\n", b"\n")

# don't try to convert the output if we should skip this test
if had_crash or output_mupy in (b"SKIP\n", b"CRASH"):
if had_crash or output_mupy in (b"SKIP\n", b"SKIP-TOO-LARGE\n", b"CRASH"):
return output_mupy

# skipped special tests will output "SKIP" surrounded by other interpreter debug output
Expand Down Expand Up @@ -911,6 +924,10 @@ def run_one_test(test_file):
print("skip ", test_file)
test_results.append((test_name, test_file, "skip", ""))
return
elif output_mupy == b"SKIP-TOO-LARGE\n":
print("lrge ", test_file)
test_results.append((test_name, test_file, "skip", "too large"))
return

# Look at the output of the test to see if unittest was used.
uses_unittest = False
Expand Down Expand Up @@ -1035,7 +1052,10 @@ def run_one_test(test_file):

test_results = test_results.value
passed_tests = list(r for r in test_results if r[2] == "pass")
skipped_tests = list(r for r in test_results if r[2] == "skip")
skipped_tests = list(r for r in test_results if r[2] == "skip" and r[3] != "too large")
skipped_tests_too_large = list(
r for r in test_results if r[2] == "skip" and r[3] == "too large"
)
failed_tests = list(r for r in test_results if r[2] == "fail")

print(
Expand All @@ -1052,6 +1072,13 @@ def run_one_test(test_file):
)
)

if len(skipped_tests_too_large) > 0:
print(
"{} tests skipped because they are too large: {}".format(
len(skipped_tests_too_large), " ".join(test[0] for test in skipped_tests_too_large)
)
)

if len(failed_tests) > 0:
print(
"{} tests failed: {}".format(
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy