diff --git a/tests/feature_check/target_info.py b/tests/feature_check/target_info.py new file mode 100644 index 000000000..df8949670 --- /dev/null +++ b/tests/feature_check/target_info.py @@ -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) diff --git a/tests/feature_check/target_info.py.exp b/tests/feature_check/target_info.py.exp new file mode 100644 index 000000000..e69de29bb diff --git a/tests/run-tests.py b/tests/run-tests.py index 60bfc2599..999812bd5 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1065,11 +1065,6 @@ the last matching regex is used: pyb = None elif args.target in LOCAL_TARGETS: 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": pyb = PyboardNodeRunner() elif args.target in EXTERNAL_TARGETS: @@ -1077,24 +1072,19 @@ the last matching regex is used: sys.path.append(base_path("../tools")) 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) pyboard.Pyboard.run_script_on_remote_target = run_script_on_remote_target pyb.enter_raw_repl() else: 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): raise ValueError( "--run-failures cannot be used together with files or --test-dirs arguments"