tests/run-tests.py: Automatically detect native arch and mpy-cross flag.

Now that some ports support multiple architectures (eg esp32 has both
Xtensa and RISC-V CPUs) it's no longer possible to set mpy-cross flags
based on the target, eg `./run-tests.py --target esp32`.  Instead this
commit makes it so the `-march=xxx` argument to mpy-cross is detected
automatically via evaluation of `sys.implementation._mpy`.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2024-08-17 00:10:40 +10:00
parent 838c490eb4
commit 6be1dbc784
3 changed files with 29 additions and 17 deletions

View File

@ -0,0 +1,22 @@
# Retrieve the native architecture of the target.
# See https://docs.micropython.org/en/latest/reference/mpyfiles.html#versioning-and-compatibility-of-mpy-files
# for more details.
import sys
sys_mpy = getattr(sys.implementation, "_mpy", 0)
arch = [
None,
"x86",
"x64",
"armv6",
"armv6m",
"armv7m",
"armv7em",
"armv7emsp",
"armv7emdp",
"xtensa",
"xtensawin",
"rv32imc",
][sys_mpy >> 10]
print(arch)

View File

View File

@ -1065,11 +1065,6 @@ the last matching regex is used:
pyb = None pyb = None
elif args.target in LOCAL_TARGETS: elif args.target in LOCAL_TARGETS:
pyb = None pyb = None
if not args.mpy_cross_flags:
if args.target == "unix":
args.mpy_cross_flags = "-march=host"
elif args.target == "qemu-arm":
args.mpy_cross_flags = "-march=armv7m"
if args.target == "webassembly": if args.target == "webassembly":
pyb = PyboardNodeRunner() pyb = PyboardNodeRunner()
elif args.target in EXTERNAL_TARGETS: elif args.target in EXTERNAL_TARGETS:
@ -1077,24 +1072,19 @@ the last matching regex is used:
sys.path.append(base_path("../tools")) sys.path.append(base_path("../tools"))
import pyboard import pyboard
if not args.mpy_cross_flags:
if args.target == "esp8266":
args.mpy_cross_flags = "-march=xtensa"
elif args.target == "esp32":
args.mpy_cross_flags = "-march=xtensawin"
elif args.target == "rp2":
args.mpy_cross_flags = "-march=armv6m"
elif args.target == "pyboard":
args.mpy_cross_flags = "-march=armv7emsp"
else:
args.mpy_cross_flags = "-march=armv7m"
pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password) pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password)
pyboard.Pyboard.run_script_on_remote_target = run_script_on_remote_target pyboard.Pyboard.run_script_on_remote_target = run_script_on_remote_target
pyb.enter_raw_repl() pyb.enter_raw_repl()
else: else:
raise ValueError("target must be one of %s" % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS)) raise ValueError("target must be one of %s" % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS))
# Automatically detect the native architecture for mpy-cross if not given.
if not (args.list_tests or args.write_exp) and not args.mpy_cross_flags:
output = run_feature_check(pyb, args, "target_info.py")
arch = str(output, "ascii").strip()
if arch != "None":
args.mpy_cross_flags = "-march=" + arch
if args.run_failures and (any(args.files) or args.test_dirs is not None): if args.run_failures and (any(args.files) or args.test_dirs is not None):
raise ValueError( raise ValueError(
"--run-failures cannot be used together with files or --test-dirs arguments" "--run-failures cannot be used together with files or --test-dirs arguments"