Skip to content

Commit

Permalink
qemu: Add test_natmod target for RV32 and use as part of CI pipeline.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Alessandro Gatti <[email protected]>
  • Loading branch information
agatti and dpgeorge committed Dec 22, 2024
1 parent 4bf087b commit 7ca6e5e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ports/qemu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) $@
Expand Down
18 changes: 15 additions & 3 deletions ports/qemu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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
------------------

Expand Down
2 changes: 2 additions & 0 deletions ports/qemu/boards/VIRT_RV32.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

########################################################################################
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7ca6e5e

Please sign in to comment.