qemu: Add test_natmod target for RV32 and use as part of CI pipeline.

This commit brings the natmod tests in the CI build process for the RV32
platform.  Not all example natmods are tested at the moment, as
`features` requires soft-float support, and `btree` needs thread-local
storage support in `mpy_ld.py` when built with the CI's toolchain.

Co-authored-by: Damien George <damien@micropython.org>
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
Alessandro Gatti
2024-12-22 00:27:03 +01:00
committed by Damien George
parent 4bf087b272
commit 7ca6e5eb68
4 changed files with 34 additions and 5 deletions

View File

@@ -168,6 +168,12 @@ test: $(BUILD)/firmware.elf
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && ./run-tests.py -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../$(DIRNAME)/$<" $(RUN_TESTS_ARGS) $(RUN_TESTS_EXTRA)
.PHONY: test_natmod
test_natmod: $(BUILD)/firmware.elf
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
# "btree" cannot build against Picolibc right now.
cd $(TOP)/tests && ./run-natmodtests.py -p -d execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../$(DIRNAME)/$<" $(RUN_NATMODTESTS_ARGS) extmod/{deflate,framebuf,heapq,random_basic,re}*.py
$(BUILD)/firmware.elf: $(LDSCRIPT) $(OBJ)
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
$(Q)$(SIZE) $@

View File

@@ -71,8 +71,9 @@ To access the REPL directly use:
$ make repl
This will start `qemu-system-arm` with the UART redirected to stdio. It's also
possible to redirect the UART to a pty device using:
This will start `qemu-system-arm` (or `qemu-system-riscv32`) with the UART
redirected to stdio. It's also possible to redirect the UART to a pty device
using:
$ make run
@@ -84,7 +85,7 @@ for example `mpremote`:
You can disconnect and reconnect to the serial device multiple times. Once you
are finished, stop the `make run` command by pressing Ctrl-C where that command
was started (or execute `machine.reset()` at the REPL).
was started (or execute `import machine; machine.reset()` at the REPL).
The test suite can be run against the firmware by using the UART redirection.
You can either do this automatically using the single command:
@@ -97,6 +98,17 @@ tests against the serial device, for example:
$ cd ../../tests
$ ./run-tests.py -t /dev/pts/1
Selected native modules that come as examples with the MicroPython source tree
can also be tested with this command (this is currently supported only for the
`VIRT_RV32` board):
$ make test_natmod
The same remarks about manually running the tests apply for native modules, but
`run-natmodtests.py` should be run instead of `run-tests.py`. In this case you
also have to explicitly pass the architecture you are running native modules to
`run-natmodtests.py` ("--arch rv32imc" for the `VIRT_RV32` board).
Extra make options
------------------

View File

@@ -12,3 +12,5 @@ MPY_CROSS_FLAGS += -march=rv32imc
# These Thumb tests don't run on RV32, so exclude them.
RUN_TESTS_ARGS = --exclude 'inlineasm|qemu/asm_test'
RUN_NATMODTESTS_ARGS = --arch rv32imc

View File

@@ -273,6 +273,7 @@ function ci_qemu_setup_arm {
}
function ci_qemu_setup_rv32 {
ci_mpy_format_setup
ci_gcc_riscv_setup
sudo apt-get update
sudo apt-get install qemu-system
@@ -292,6 +293,10 @@ function ci_qemu_build_rv32 {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV32 submodules
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV32 test
# Test building and running native .mpy with rv32imc architecture.
ci_native_mpy_modules_build rv32imc
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV32 test_natmod
}
########################################################################################
@@ -476,10 +481,14 @@ function ci_native_mpy_modules_build {
arch=$1
fi
make -C examples/natmod/features1 ARCH=$arch
make -C examples/natmod/features2 ARCH=$arch
if [ $arch != rv32imc ]; then
# This requires soft-float support on rv32imc.
make -C examples/natmod/features2 ARCH=$arch
# This requires thread local storage support on rv32imc.
make -C examples/natmod/btree ARCH=$arch
fi
make -C examples/natmod/features3 ARCH=$arch
make -C examples/natmod/features4 ARCH=$arch
make -C examples/natmod/btree ARCH=$arch
make -C examples/natmod/deflate ARCH=$arch
make -C examples/natmod/framebuf ARCH=$arch
make -C examples/natmod/heapq ARCH=$arch