Skip to content

Commit 7ca6e5e

Browse files
agattidpgeorge
andcommitted
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 <[email protected]> Signed-off-by: Alessandro Gatti <[email protected]>
1 parent 4bf087b commit 7ca6e5e

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

ports/qemu/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ test: $(BUILD)/firmware.elf
168168
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
169169
cd $(TOP)/tests && ./run-tests.py -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../$(DIRNAME)/$<" $(RUN_TESTS_ARGS) $(RUN_TESTS_EXTRA)
170170

171+
.PHONY: test_natmod
172+
test_natmod: $(BUILD)/firmware.elf
173+
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
174+
# "btree" cannot build against Picolibc right now.
175+
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
176+
171177
$(BUILD)/firmware.elf: $(LDSCRIPT) $(OBJ)
172178
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
173179
$(Q)$(SIZE) $@

ports/qemu/README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ To access the REPL directly use:
7171

7272
$ make repl
7373

74-
This will start `qemu-system-arm` with the UART redirected to stdio. It's also
75-
possible to redirect the UART to a pty device using:
74+
This will start `qemu-system-arm` (or `qemu-system-riscv32`) with the UART
75+
redirected to stdio. It's also possible to redirect the UART to a pty device
76+
using:
7677

7778
$ make run
7879

@@ -84,7 +85,7 @@ for example `mpremote`:
8485

8586
You can disconnect and reconnect to the serial device multiple times. Once you
8687
are finished, stop the `make run` command by pressing Ctrl-C where that command
87-
was started (or execute `machine.reset()` at the REPL).
88+
was started (or execute `import machine; machine.reset()` at the REPL).
8889

8990
The test suite can be run against the firmware by using the UART redirection.
9091
You can either do this automatically using the single command:
@@ -97,6 +98,17 @@ tests against the serial device, for example:
9798
$ cd ../../tests
9899
$ ./run-tests.py -t /dev/pts/1
99100

101+
Selected native modules that come as examples with the MicroPython source tree
102+
can also be tested with this command (this is currently supported only for the
103+
`VIRT_RV32` board):
104+
105+
$ make test_natmod
106+
107+
The same remarks about manually running the tests apply for native modules, but
108+
`run-natmodtests.py` should be run instead of `run-tests.py`. In this case you
109+
also have to explicitly pass the architecture you are running native modules to
110+
`run-natmodtests.py` ("--arch rv32imc" for the `VIRT_RV32` board).
111+
100112
Extra make options
101113
------------------
102114

ports/qemu/boards/VIRT_RV32.mk

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ MPY_CROSS_FLAGS += -march=rv32imc
1212

1313
# These Thumb tests don't run on RV32, so exclude them.
1414
RUN_TESTS_ARGS = --exclude 'inlineasm|qemu/asm_test'
15+
16+
RUN_NATMODTESTS_ARGS = --arch rv32imc

tools/ci.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ function ci_qemu_setup_arm {
273273
}
274274

275275
function ci_qemu_setup_rv32 {
276+
ci_mpy_format_setup
276277
ci_gcc_riscv_setup
277278
sudo apt-get update
278279
sudo apt-get install qemu-system
@@ -292,6 +293,10 @@ function ci_qemu_build_rv32 {
292293
make ${MAKEOPTS} -C mpy-cross
293294
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV32 submodules
294295
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV32 test
296+
297+
# Test building and running native .mpy with rv32imc architecture.
298+
ci_native_mpy_modules_build rv32imc
299+
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV32 test_natmod
295300
}
296301

297302
########################################################################################
@@ -476,10 +481,14 @@ function ci_native_mpy_modules_build {
476481
arch=$1
477482
fi
478483
make -C examples/natmod/features1 ARCH=$arch
479-
make -C examples/natmod/features2 ARCH=$arch
484+
if [ $arch != rv32imc ]; then
485+
# This requires soft-float support on rv32imc.
486+
make -C examples/natmod/features2 ARCH=$arch
487+
# This requires thread local storage support on rv32imc.
488+
make -C examples/natmod/btree ARCH=$arch
489+
fi
480490
make -C examples/natmod/features3 ARCH=$arch
481491
make -C examples/natmod/features4 ARCH=$arch
482-
make -C examples/natmod/btree ARCH=$arch
483492
make -C examples/natmod/deflate ARCH=$arch
484493
make -C examples/natmod/framebuf ARCH=$arch
485494
make -C examples/natmod/heapq ARCH=$arch

0 commit comments

Comments
 (0)