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 <a.gatti@frob.it>
This commit is contained in:
Alessandro Gatti
2025-09-25 00:12:00 +02:00
parent 331a5c46aa
commit 849c67bcdc
2 changed files with 23 additions and 3 deletions

View File

@@ -196,7 +196,7 @@ CFLAGS += $(SPECS_FRAGMENT)
LDFLAGS += $(SPECS_FRAGMENT) LDFLAGS += $(SPECS_FRAGMENT)
endif 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 # Source files and libraries

View File

@@ -22,6 +22,8 @@ TEST_TIMEOUT = float(os.environ.get("MICROPY_TEST_TIMEOUT", 30))
# are guaranteed to always work, this one should though. # are guaranteed to always work, this one should though.
BASEPATH = os.path.dirname(os.path.abspath(inspect.getsourcefile(lambda: None))) BASEPATH = os.path.dirname(os.path.abspath(inspect.getsourcefile(lambda: None)))
RV32_ARCH_FLAGS = {"zba": 1 << 0}
def base_path(*p): def base_path(*p):
return os.path.abspath(os.path.join(BASEPATH, *p)).replace("\\", "/") return os.path.abspath(os.path.join(BASEPATH, *p)).replace("\\", "/")
@@ -382,6 +384,17 @@ def detect_inline_asm_arch(pyb, args):
return None 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): def detect_test_platform(pyb, args):
# Run a script to detect various bits of information about the target test instance. # Run a script to detect various bits of information about the target test instance.
output = run_feature_check(pyb, args, "target_info.py") output = run_feature_check(pyb, args, "target_info.py")
@@ -397,12 +410,18 @@ def detect_test_platform(pyb, args):
thread = None thread = None
float_prec = int(float_prec) float_prec = int(float_prec)
unicode = unicode == "True" unicode = unicode == "True"
if arch == "rv32imc":
arch_flags = map_rv32_arch_flags(int(arch_flags))
else:
arch_flags = None
args.platform = platform args.platform = platform
args.arch = arch args.arch = arch
args.arch_flags = arch_flags
if arch and not args.mpy_cross_flags: if arch and not args.mpy_cross_flags:
args.mpy_cross_flags = "-march=" + arch 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.inlineasm_arch = inlineasm_arch
args.build = build args.build = build
args.thread = thread args.thread = thread
@@ -413,7 +432,8 @@ def detect_test_platform(pyb, args):
print("platform={}".format(platform), end="") print("platform={}".format(platform), end="")
if arch: if arch:
print(" arch={}".format(arch), end="") 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: if inlineasm_arch:
print(" inlineasm={}".format(inlineasm_arch), end="") print(" inlineasm={}".format(inlineasm_arch), end="")
if thread: if thread: