From 849c67bcdc9f848a674554f3e03ef850a8f70692 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Thu, 25 Sep 2025 00:12:00 +0200 Subject: [PATCH] tests/run-tests.py: Pass auto-detected architecture flags to mpy-cross. This commit lets "run-tests.py" use the encoded architecture flags provided by the interpreter when invoking "mpy-cross". If architecture flags are detected, they're mapped into the necessary strings needed by "mpy-cross"'s "-march-flags" argument, so that tests will always use all available extensions reported by the target. Currently this is limited to the RV32 platform, as it is the only one that is making use of this facility as of now. This also lets the QEMU port remove forced arguments to "mpy-cross" when running the test suite. Signed-off-by: Alessandro Gatti --- ports/qemu/Makefile | 2 +- tests/run-tests.py | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ports/qemu/Makefile b/ports/qemu/Makefile index 03f004c753..ba9c53841a 100644 --- a/ports/qemu/Makefile +++ b/ports/qemu/Makefile @@ -196,7 +196,7 @@ CFLAGS += $(SPECS_FRAGMENT) LDFLAGS += $(SPECS_FRAGMENT) endif -RUN_TESTS_FULL_ARGS = -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../ports/qemu/$<" --mpy-cross-flags='$(MPY_CROSS_FLAGS)' $(RUN_TESTS_ARGS) +RUN_TESTS_FULL_ARGS = -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../ports/qemu/$<" $(RUN_TESTS_ARGS) ################################################################################ # Source files and libraries diff --git a/tests/run-tests.py b/tests/run-tests.py index f184203a84..d8d2c42ad2 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -22,6 +22,8 @@ TEST_TIMEOUT = float(os.environ.get("MICROPY_TEST_TIMEOUT", 30)) # are guaranteed to always work, this one should though. BASEPATH = os.path.dirname(os.path.abspath(inspect.getsourcefile(lambda: None))) +RV32_ARCH_FLAGS = {"zba": 1 << 0} + def base_path(*p): return os.path.abspath(os.path.join(BASEPATH, *p)).replace("\\", "/") @@ -382,6 +384,17 @@ def detect_inline_asm_arch(pyb, args): return None +def map_rv32_arch_flags(flags): + mapped_flags = [] + for extension, bit in RV32_ARCH_FLAGS.items(): + if flags & bit: + mapped_flags.append(extension) + flags &= ~bit + if flags: + raise Exception("Unexpected flag bits set in value {}".format(flags)) + return mapped_flags + + def detect_test_platform(pyb, args): # Run a script to detect various bits of information about the target test instance. output = run_feature_check(pyb, args, "target_info.py") @@ -397,12 +410,18 @@ def detect_test_platform(pyb, args): thread = None float_prec = int(float_prec) unicode = unicode == "True" + if arch == "rv32imc": + arch_flags = map_rv32_arch_flags(int(arch_flags)) + else: + arch_flags = None args.platform = platform args.arch = arch + args.arch_flags = arch_flags if arch and not args.mpy_cross_flags: args.mpy_cross_flags = "-march=" + arch - args.arch_flags = arch_flags + if arch_flags: + args.mpy_cross_flags += " -march-flags=" + ",".join(arch_flags) args.inlineasm_arch = inlineasm_arch args.build = build args.thread = thread @@ -413,7 +432,8 @@ def detect_test_platform(pyb, args): print("platform={}".format(platform), end="") if arch: print(" arch={}".format(arch), end="") - print(" arch_flags={}".format(arch_flags), end="") + if arch_flags: + print(" arch_flags={}".format(",".join(arch_flags)), end="") if inlineasm_arch: print(" inlineasm={}".format(inlineasm_arch), end="") if thread: