Skip to content

Commit 3f9a948

Browse files
committed
tests/run-tests.py: Allow target_wiring on fs to override.
Signed-off-by: Damien George <damien@micropython.org>
1 parent fb8cb0a commit 3f9a948

File tree

1 file changed

+43
-32
lines changed

1 file changed

+43
-32
lines changed

tests/run-tests.py

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,6 @@ def detect_inline_asm_arch(pyb, args):
298298
return None
299299

300300

301-
def detect_target_wiring_script(args):
302-
port = platform_to_port(args.platform)
303-
build = args.build
304-
tw_board_exact = None
305-
tw_board_partial = None
306-
tw_port = None
307-
for file in os.listdir("target_wiring"):
308-
file_base = file.removesuffix(".py")
309-
if file_base == build:
310-
# A file matching the target's board/build name.
311-
tw_board_exact = file
312-
elif file_base.endswith("x") and build.startswith(file_base.removesuffix("x")):
313-
# A file with a partial match to the target's board/build name.
314-
tw_board_partial = file
315-
elif file_base == port:
316-
# A file matching the target's port.
317-
tw_port = file
318-
return tw_board_exact or tw_board_partial or tw_port
319-
320-
321301
def detect_test_platform(pyb, args):
322302
# Run a script to detect various bits of information about the target test instance.
323303
output = run_feature_check(pyb, args, "target_info.py")
@@ -342,16 +322,6 @@ def detect_test_platform(pyb, args):
342322
args.float_prec = float_prec
343323
args.unicode = unicode
344324

345-
# Get the target_wiring script, if one exists for this target.
346-
tw = None
347-
if pyb:
348-
tw = detect_target_wiring_script(args)
349-
data = b""
350-
if tw:
351-
with open("target_wiring/" + tw, "rb") as f:
352-
data = f.read()
353-
pyb.target_wiring_script = data
354-
355325
# Print the detected information about the target.
356326
print("platform={}".format(platform), end="")
357327
if arch:
@@ -364,11 +334,48 @@ def detect_test_platform(pyb, args):
364334
print(" float={}-bit".format(float_prec), end="")
365335
if unicode:
366336
print(" unicode", end="")
367-
if tw:
368-
print(" target_wiring={}".format(tw), end="")
369337
print()
370338

371339

340+
def detect_target_wiring_script(pyb, args):
341+
tw_data = b""
342+
tw_source = None
343+
has_target_wiring = (
344+
pyb.exec_("try:\n import target_wiring\n print(True)\nexcept:\n print(False)").strip()
345+
== b"True"
346+
)
347+
if has_target_wiring:
348+
# The board already has a target_wiring module available, so use that.
349+
tw_source = "target's filesystem"
350+
else:
351+
port = platform_to_port(args.platform)
352+
build = args.build
353+
tw_board_exact = None
354+
tw_board_partial = None
355+
tw_port = None
356+
for file in os.listdir("target_wiring"):
357+
file_base = file.removesuffix(".py")
358+
if file_base == build:
359+
# A file matching the target's board/build name.
360+
tw_board_exact = file
361+
elif file_base.endswith("x") and build.startswith(file_base.removesuffix("x")):
362+
# A file with a partial match to the target's board/build name.
363+
tw_board_partial = file
364+
elif file_base == port:
365+
# A file matching the target's port.
366+
tw_port = file
367+
tw = tw_board_exact or tw_board_partial or tw_port
368+
if tw:
369+
with open("target_wiring/" + tw, "rb") as f:
370+
tw_data = f.read()
371+
tw_source = f"host file {tw}"
372+
if tw_source:
373+
print(f"using target_wiring module from {tw_source}")
374+
else:
375+
print(f"WARNING: target_wiring module not found for this target")
376+
pyb.target_wiring_script = tw_data
377+
378+
372379
def prepare_script_for_target(args, *, script_text=None, force_plain=False):
373380
if force_plain or (not args.via_mpy and args.emit == "bytecode"):
374381
# A plain test to run as-is, no processing needed.
@@ -1430,6 +1437,10 @@ def main():
14301437
# tests explicitly given
14311438
tests = args.files
14321439

1440+
# If any tests need it, prepare the target_wiring script for the target.
1441+
if pyb and any(test.endswith(tests_requiring_target_wiring) for test in tests):
1442+
detect_target_wiring_script(pyb, args)
1443+
14331444
if not args.keep_path:
14341445
# Clear search path to make sure tests use only builtin modules, those in
14351446
# extmod, and a path to unittest in case it's needed.

0 commit comments

Comments
 (0)