diff options
| author | Alessandro Gatti <a.gatti@frob.it> | 2024-11-20 11:55:54 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-01-02 11:52:28 +1100 |
| commit | 931a768f5529649c43a65e999ab28f2820002c38 (patch) | |
| tree | fa4194c011762ff45a1c14fe050dc34155eb16f5 | |
| parent | 24482a93ef50dc0df1a704922f465d9c23e143c6 (diff) | |
tests/run-tests.py: Detect inlineasm support and add tests if needed.
This commit implements a method to detect at runtime if inline assembler
support is enabled, and if so which platform it targets.
This allows clean test runs even on modified version of ARM-based ports
where inline assembler support is disabled, running inline assembler tests
on ports that have such feature not enabled by default and manually
enabled, and allows to always run the correct inlineasm tests for ports
that support more than one architecture (esp32, qemu, rp2).
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
| -rw-r--r-- | ports/qemu/boards/MICROBIT.mk | 3 | ||||
| -rw-r--r-- | ports/qemu/boards/MPS2_AN385.mk | 3 | ||||
| -rw-r--r-- | ports/qemu/boards/NETDUINO2.mk | 3 | ||||
| -rw-r--r-- | ports/qemu/boards/SABRELITE.mk | 2 | ||||
| -rw-r--r-- | ports/qemu/boards/VIRT_RV32.mk | 3 | ||||
| -rw-r--r-- | tests/feature_check/inlineasm_rv32.py | 9 | ||||
| -rw-r--r-- | tests/feature_check/inlineasm_rv32.py.exp | 1 | ||||
| -rw-r--r-- | tests/feature_check/inlineasm_thumb.py | 9 | ||||
| -rw-r--r-- | tests/feature_check/inlineasm_thumb.py.exp | 1 | ||||
| -rw-r--r-- | tests/feature_check/inlineasm_xtensa.py | 9 | ||||
| -rw-r--r-- | tests/feature_check/inlineasm_xtensa.py.exp | 1 | ||||
| -rwxr-xr-x | tests/run-tests.py | 60 |
12 files changed, 68 insertions, 36 deletions
diff --git a/ports/qemu/boards/MICROBIT.mk b/ports/qemu/boards/MICROBIT.mk index d6cfd7e22..02eb0576c 100644 --- a/ports/qemu/boards/MICROBIT.mk +++ b/ports/qemu/boards/MICROBIT.mk @@ -11,6 +11,3 @@ LDSCRIPT = mcu/arm/nrf51.ld SRC_BOARD_O = shared/runtime/gchelper_native.o shared/runtime/gchelper_thumb1.o MPY_CROSS_FLAGS += -march=armv7m - -# These RV32 tests don't run on Thumb, so exclude them. -RUN_TESTS_ARGS = --exclude 'inlineasm/rv32' diff --git a/ports/qemu/boards/MPS2_AN385.mk b/ports/qemu/boards/MPS2_AN385.mk index 8d5c27df5..182d076eb 100644 --- a/ports/qemu/boards/MPS2_AN385.mk +++ b/ports/qemu/boards/MPS2_AN385.mk @@ -10,6 +10,3 @@ LDSCRIPT = mcu/arm/mps2.ld SRC_BOARD_O = shared/runtime/gchelper_native.o shared/runtime/gchelper_thumb2.o MPY_CROSS_FLAGS += -march=armv7m - -# These RV32 tests don't run on Thumb, so exclude them. -RUN_TESTS_ARGS = --exclude 'inlineasm/rv32' diff --git a/ports/qemu/boards/NETDUINO2.mk b/ports/qemu/boards/NETDUINO2.mk index f88ea32e7..ffa781f33 100644 --- a/ports/qemu/boards/NETDUINO2.mk +++ b/ports/qemu/boards/NETDUINO2.mk @@ -10,6 +10,3 @@ LDSCRIPT = mcu/arm/stm32.ld SRC_BOARD_O = shared/runtime/gchelper_native.o shared/runtime/gchelper_thumb2.o MPY_CROSS_FLAGS += -march=armv7m - -# These RV32 tests don't run on Thumb, so exclude them. -RUN_TESTS_ARGS = --exclude 'inlineasm/rv32' diff --git a/ports/qemu/boards/SABRELITE.mk b/ports/qemu/boards/SABRELITE.mk index d3f4e14d4..839b3d6ac 100644 --- a/ports/qemu/boards/SABRELITE.mk +++ b/ports/qemu/boards/SABRELITE.mk @@ -16,4 +16,4 @@ SRC_BOARD_O = shared/runtime/gchelper_generic.o MPY_CROSS_FLAGS += -march=armv6 # These tests don't work on Cortex-A9, so exclude them. -RUN_TESTS_ARGS = --exclude 'inlineasm/rv32|inlineasm/thumb/(asmdiv|asmspecialregs).py' +RUN_TESTS_ARGS = --exclude 'inlineasm/thumb/(asmdiv|asmspecialregs).py' diff --git a/ports/qemu/boards/VIRT_RV32.mk b/ports/qemu/boards/VIRT_RV32.mk index 80dd5d56f..dd9264800 100644 --- a/ports/qemu/boards/VIRT_RV32.mk +++ b/ports/qemu/boards/VIRT_RV32.mk @@ -10,7 +10,4 @@ SRC_BOARD_O += shared/runtime/gchelper_native.o shared/runtime/gchelper_rv32i.o MPY_CROSS_FLAGS += -march=rv32imc -# These Thumb tests don't run on RV32, so exclude them. -RUN_TESTS_ARGS = --exclude 'inlineasm/thumb' - RUN_NATMODTESTS_ARGS = --arch rv32imc diff --git a/tests/feature_check/inlineasm_rv32.py b/tests/feature_check/inlineasm_rv32.py new file mode 100644 index 000000000..21dd103b6 --- /dev/null +++ b/tests/feature_check/inlineasm_rv32.py @@ -0,0 +1,9 @@ +# check if RISC-V 32 inline asm is supported + + +@micropython.asm_rv32 +def f(): + add(a0, a0, a0) + + +print("rv32") diff --git a/tests/feature_check/inlineasm_rv32.py.exp b/tests/feature_check/inlineasm_rv32.py.exp new file mode 100644 index 000000000..5eecf09c2 --- /dev/null +++ b/tests/feature_check/inlineasm_rv32.py.exp @@ -0,0 +1 @@ +rv32 diff --git a/tests/feature_check/inlineasm_thumb.py b/tests/feature_check/inlineasm_thumb.py new file mode 100644 index 000000000..321eab0e2 --- /dev/null +++ b/tests/feature_check/inlineasm_thumb.py @@ -0,0 +1,9 @@ +# check if Thumb inline asm is supported + + +@micropython.asm_thumb +def f(): + nop() + + +print("thumb") diff --git a/tests/feature_check/inlineasm_thumb.py.exp b/tests/feature_check/inlineasm_thumb.py.exp new file mode 100644 index 000000000..bb48e1a2f --- /dev/null +++ b/tests/feature_check/inlineasm_thumb.py.exp @@ -0,0 +1 @@ +thumb diff --git a/tests/feature_check/inlineasm_xtensa.py b/tests/feature_check/inlineasm_xtensa.py new file mode 100644 index 000000000..2a24d3997 --- /dev/null +++ b/tests/feature_check/inlineasm_xtensa.py @@ -0,0 +1,9 @@ +# check if Xtensa inline asm is supported + + +@micropython.asm_xtensa +def f(): + ret_n() + + +print("xtensa") diff --git a/tests/feature_check/inlineasm_xtensa.py.exp b/tests/feature_check/inlineasm_xtensa.py.exp new file mode 100644 index 000000000..036142c50 --- /dev/null +++ b/tests/feature_check/inlineasm_xtensa.py.exp @@ -0,0 +1 @@ +xtensa diff --git a/tests/run-tests.py b/tests/run-tests.py index db5ebe34c..3dc0df029 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -232,6 +232,14 @@ def get_test_instance(test_instance, baudrate, user, password): return pyb +def detect_inline_asm_arch(pyb, args): + for arch in ("rv32", "thumb", "xtensa"): + output = run_feature_check(pyb, args, "inlineasm_{}.py".format(arch)) + if output.strip() == arch.encode(): + return arch + return None + + 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") @@ -240,15 +248,19 @@ def detect_test_platform(pyb, args): platform, arch = str(output, "ascii").strip().split() if arch == "None": arch = None + inlineasm_arch = detect_inline_asm_arch(pyb, args) args.platform = platform args.arch = arch if arch and not args.mpy_cross_flags: args.mpy_cross_flags = "-march=" + arch + args.inlineasm_arch = inlineasm_arch print("platform={}".format(platform), end="") if arch: print(" arch={}".format(arch), end="") + if inlineasm_arch: + print(" inlineasm={}".format(inlineasm_arch), end="") print() @@ -601,6 +613,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_io_module = False skip_fstring = False skip_endian = False + skip_inlineasm = False has_complex = True has_coverage = False @@ -661,20 +674,21 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if output != b"a=1\n": skip_fstring = True - # Check if @micropython.asm_thumb supports Thumb2 instructions, and skip such tests if it doesn't - output = run_feature_check(pyb, args, "inlineasm_thumb2.py") - if output != b"thumb2\n": - skip_tests.add("inlineasm/thumb/asmbcc.py") - skip_tests.add("inlineasm/thumb/asmbitops.py") - skip_tests.add("inlineasm/thumb/asmconst.py") - skip_tests.add("inlineasm/thumb/asmdiv.py") - skip_tests.add("inlineasm/thumb/asmfpaddsub.py") - skip_tests.add("inlineasm/thumb/asmfpcmp.py") - skip_tests.add("inlineasm/thumb/asmfpldrstr.py") - skip_tests.add("inlineasm/thumb/asmfpmuldiv.py") - skip_tests.add("inlineasm/thumb/asmfpsqrt.py") - skip_tests.add("inlineasm/thumb/asmit.py") - skip_tests.add("inlineasm/thumb/asmspecialregs.py") + if args.inlineasm_arch == "thumb": + # Check if @micropython.asm_thumb supports Thumb2 instructions, and skip such tests if it doesn't + output = run_feature_check(pyb, args, "inlineasm_thumb2.py") + if output != b"thumb2\n": + skip_tests.add("inlineasm/thumb/asmbcc.py") + skip_tests.add("inlineasm/thumb/asmbitops.py") + skip_tests.add("inlineasm/thumb/asmconst.py") + skip_tests.add("inlineasm/thumb/asmdiv.py") + skip_tests.add("inlineasm/thumb/asmfpaddsub.py") + skip_tests.add("inlineasm/thumb/asmfpcmp.py") + skip_tests.add("inlineasm/thumb/asmfpldrstr.py") + skip_tests.add("inlineasm/thumb/asmfpmuldiv.py") + skip_tests.add("inlineasm/thumb/asmfpsqrt.py") + skip_tests.add("inlineasm/thumb/asmit.py") + skip_tests.add("inlineasm/thumb/asmspecialregs.py") # Check if emacs repl is supported, and skip such tests if it's not t = run_feature_check(pyb, args, "repl_emacs_check.py") @@ -699,6 +713,8 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): ) skip_endian = upy_byteorder != cpy_byteorder + skip_inlineasm = args.inlineasm_arch is None + # These tests don't test slice explicitly but rather use it to perform the test misc_slice_tests = ( "builtin_range", @@ -852,6 +868,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): is_const = test_name.startswith("const") is_io_module = test_name.startswith("io_") is_fstring = test_name.startswith("string_fstring") + is_inlineasm = test_name.startswith("asm") skip_it = test_file in skip_tests skip_it |= skip_native and is_native @@ -865,6 +882,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_it |= skip_revops and "reverse_op" in test_name skip_it |= skip_io_module and is_io_module skip_it |= skip_fstring and is_fstring + skip_it |= skip_inlineasm and is_inlineasm if skip_it: print("skip ", test_file) @@ -1213,17 +1231,17 @@ the last matching regex is used: "misc", "extmod", ) + if args.inlineasm_arch is not None: + test_dirs += ("inlineasm/{}".format(args.inlineasm_arch),) if args.platform == "pyboard": # run pyboard tests - test_dirs += ("float", "stress", "inlineasm/thumb", "ports/stm32") + test_dirs += ("float", "stress", "ports/stm32") elif args.platform == "mimxrt": - test_dirs += ("float", "stress", "inlineasm/thumb") + test_dirs += ("float", "stress") elif args.platform == "renesas-ra": - test_dirs += ("float", "inlineasm/thumb", "ports/renesas-ra") + test_dirs += ("float", "ports/renesas-ra") elif args.platform == "rp2": test_dirs += ("float", "stress", "thread", "ports/rp2") - if "arm" in args.mpy_cross_flags: - test_dirs += ("inlineasm/thumb",) elif args.platform == "esp32": test_dirs += ("float", "stress", "thread") elif args.platform in ("esp8266", "minimal", "samd", "nrf"): @@ -1247,10 +1265,6 @@ the last matching regex is used: "float", "ports/qemu", ) - if args.arch == "rv32imc": - test_dirs += ("inlineasm/rv32",) - else: - test_dirs += ("inlineasm/thumb",) elif args.platform == "webassembly": test_dirs += ("float", "ports/webassembly") else: |
