tests/run-tests.py: Detect threading and automatically run thread tests.

When detecting the target platform, also check if it has threading and
whether the GIL is enabled or not (using the new attribute
`sys.implementation._thread`).  If threading is available, add the thread
tests to the set of tests to run (unless the set of tests is explicitly
given).

With this change, the unix port no longer needs to explicitly run the set
of thread tests, so that line has been removed from the Makefile.

This change will make sure thread tests are run with other testing
combinations.  In particular, thread tests are now run:
- on the unix port with the native emitter
- on macOS builds
- on unix qemu, the architectures MIPS, ARM and RISCV-64

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-07-10 16:19:17 +10:00
parent 377924b443
commit 167c888df9
3 changed files with 15 additions and 7 deletions

View File

@@ -259,7 +259,6 @@ test: $(BUILD)/$(PROG) $(TOP)/tests/run-tests.py
test_full_no_native: $(BUILD)/$(PROG) $(TOP)/tests/run-tests.py
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(BUILD)/$(PROG) ./run-tests.py
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(BUILD)/$(PROG) ./run-tests.py -d thread
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(BUILD)/$(PROG) ./run-tests.py --via-mpy $(RUN_TESTS_MPY_CROSS_FLAGS) -d basics float micropython
cat $(TOP)/tests/basics/0prelim.py | ./$(BUILD)/$(PROG) | grep -q 'abc'

View File

@@ -20,4 +20,6 @@ arch = [
"xtensawin",
"rv32imc",
][sys_mpy >> 10]
print(platform, arch)
thread = getattr(sys.implementation, "_thread", None)
print(platform, arch, thread)

View File

@@ -251,22 +251,27 @@ def detect_test_platform(pyb, args):
output = run_feature_check(pyb, args, "target_info.py")
if output.endswith(b"CRASH"):
raise ValueError("cannot detect platform: {}".format(output))
platform, arch = str(output, "ascii").strip().split()
platform, arch, thread = str(output, "ascii").strip().split()
if arch == "None":
arch = None
inlineasm_arch = detect_inline_asm_arch(pyb, args)
if thread == "None":
thread = None
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
args.thread = thread
print("platform={}".format(platform), end="")
if arch:
print(" arch={}".format(arch), end="")
if inlineasm_arch:
print(" inlineasm={}".format(inlineasm_arch), end="")
if thread:
print(" thread={}".format(thread), end="")
print()
@@ -810,8 +815,8 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
skip_tests.add("cmdline/repl_sys_ps1_ps2.py")
skip_tests.add("extmod/ssl_poll.py")
# Skip thread mutation tests on targets that don't have the GIL.
if args.platform in PC_PLATFORMS + ("rp2",):
# Skip thread mutation tests on targets that have unsafe threading behaviour.
if args.thread == "unsafe":
for t in tests:
if t.startswith("thread/mutate_"):
skip_tests.add(t)
@@ -1329,6 +1334,8 @@ the last matching regex is used:
)
if args.inlineasm_arch is not None:
test_dirs += ("inlineasm/{}".format(args.inlineasm_arch),)
if args.thread is not None:
test_dirs += ("thread",)
if args.platform == "pyboard":
# run pyboard tests
test_dirs += ("float", "stress", "ports/stm32")
@@ -1337,9 +1344,9 @@ the last matching regex is used:
elif args.platform == "renesas-ra":
test_dirs += ("float", "ports/renesas-ra")
elif args.platform == "rp2":
test_dirs += ("float", "stress", "thread", "ports/rp2")
test_dirs += ("float", "stress", "ports/rp2")
elif args.platform == "esp32":
test_dirs += ("float", "stress", "thread")
test_dirs += ("float", "stress")
elif args.platform in ("esp8266", "minimal", "samd", "nrf"):
test_dirs += ("float",)
elif args.platform == "WiPy":