Skip to content

Commit 849c67b

Browse files
committed
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 <[email protected]>
1 parent 331a5c4 commit 849c67b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

ports/qemu/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ CFLAGS += $(SPECS_FRAGMENT)
196196
LDFLAGS += $(SPECS_FRAGMENT)
197197
endif
198198

199-
RUN_TESTS_FULL_ARGS = -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../ports/qemu/$<" --mpy-cross-flags='$(MPY_CROSS_FLAGS)' $(RUN_TESTS_ARGS)
199+
RUN_TESTS_FULL_ARGS = -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../ports/qemu/$<" $(RUN_TESTS_ARGS)
200200

201201
################################################################################
202202
# Source files and libraries

tests/run-tests.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# are guaranteed to always work, this one should though.
2323
BASEPATH = os.path.dirname(os.path.abspath(inspect.getsourcefile(lambda: None)))
2424

25+
RV32_ARCH_FLAGS = {"zba": 1 << 0}
26+
2527

2628
def base_path(*p):
2729
return os.path.abspath(os.path.join(BASEPATH, *p)).replace("\\", "/")
@@ -382,6 +384,17 @@ def detect_inline_asm_arch(pyb, args):
382384
return None
383385

384386

387+
def map_rv32_arch_flags(flags):
388+
mapped_flags = []
389+
for extension, bit in RV32_ARCH_FLAGS.items():
390+
if flags & bit:
391+
mapped_flags.append(extension)
392+
flags &= ~bit
393+
if flags:
394+
raise Exception("Unexpected flag bits set in value {}".format(flags))
395+
return mapped_flags
396+
397+
385398
def detect_test_platform(pyb, args):
386399
# Run a script to detect various bits of information about the target test instance.
387400
output = run_feature_check(pyb, args, "target_info.py")
@@ -397,12 +410,18 @@ def detect_test_platform(pyb, args):
397410
thread = None
398411
float_prec = int(float_prec)
399412
unicode = unicode == "True"
413+
if arch == "rv32imc":
414+
arch_flags = map_rv32_arch_flags(int(arch_flags))
415+
else:
416+
arch_flags = None
400417

401418
args.platform = platform
402419
args.arch = arch
420+
args.arch_flags = arch_flags
403421
if arch and not args.mpy_cross_flags:
404422
args.mpy_cross_flags = "-march=" + arch
405-
args.arch_flags = arch_flags
423+
if arch_flags:
424+
args.mpy_cross_flags += " -march-flags=" + ",".join(arch_flags)
406425
args.inlineasm_arch = inlineasm_arch
407426
args.build = build
408427
args.thread = thread
@@ -413,7 +432,8 @@ def detect_test_platform(pyb, args):
413432
print("platform={}".format(platform), end="")
414433
if arch:
415434
print(" arch={}".format(arch), end="")
416-
print(" arch_flags={}".format(arch_flags), end="")
435+
if arch_flags:
436+
print(" arch_flags={}".format(",".join(arch_flags)), end="")
417437
if inlineasm_arch:
418438
print(" inlineasm={}".format(inlineasm_arch), end="")
419439
if thread:

0 commit comments

Comments
 (0)