Skip to content

Commit d2de1bb

Browse files
committed
qemu-riscv: Consolidate Makefile.test into main Makefile.
Signed-off-by: Damien George <damien@micropython.org>
1 parent a2b5208 commit d2de1bb

File tree

6 files changed

+38
-39
lines changed

6 files changed

+38
-39
lines changed

ports/qemu-riscv/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
TESTS_PROFILE = $(dir $(abspath $(firstword $(MAKEFILE_LIST))))/tests_profile.txt
2+
13
include ../../py/mkenv.mk
24
-include mpconfigport.mk
35

@@ -86,6 +88,7 @@ SRC_RUN_C = \
8688
SRC_TEST_C = \
8789
test_main.c \
8890
lib/tinytest/tinytest.c \
91+
shared/upytesthelper/upytesthelper.c \
8992

9093
LIB_SRC_C += $(SRC_LIB_LIBM_C)
9194
LIB_SRC_C += $(SRC_LIB_LIBM_SQRT_SW_C)
@@ -125,4 +128,27 @@ $(BUILD)/firmware.elf: $(LDSCRIPT) $(ALL_OBJ_RUN)
125128
$(Q)$(LD) $(LDFLAGS) -o $@ $(ALL_OBJ_RUN) $(LIBS)
126129
$(Q)$(SIZE) $@
127130

131+
$(BUILD)/firmware-test.elf: $(LDSCRIPT) $(ALL_OBJ_TEST)
132+
$(Q)$(LD) $(LDFLAGS) -o $@ $(ALL_OBJ_TEST) $(LIBS)
133+
$(Q)$(SIZE) $@
134+
135+
$(BUILD)/test_main.o: $(BUILD)/genhdr/tests.h
136+
137+
.PHONY: $(BUILD)/genhdr/tests.h
138+
$(BUILD)/genhdr/tests.h:
139+
(cd $(TOP)/tests; ./run-tests.py --target=qemu-riscv --write-exp)
140+
$(Q)echo "Generating $@";(cd $(TOP)/tests; ../tools/tinytest-codegen.py --profile $(TESTS_PROFILE) $(addprefix --exclude ,$(TESTS_EXCLUDE))) > $@
141+
142+
$(BUILD)/lib/tinytest/tinytest.o: CFLAGS += -DNO_FORKING
143+
144+
# Note: Using timeout(1) to handle cases where qemu hangs (e.g. this can happen with alignment errors).
145+
test: $(BUILD)/firmware-test.elf
146+
timeout --foreground -k 5s 60s qemu-system-riscv32 -machine $(BOARD) -bios none $(QEMU_EXTRA) -nographic -monitor null -semihosting -kernel $< > $(BUILD)/console.out
147+
$(Q)tail -n2 $(BUILD)/console.out
148+
$(Q)tail -n1 $(BUILD)/console.out | grep -q "status: 0"
149+
150+
# `make debugtest` will block QEMU until a debugger is connected to port 1234.
151+
debugtest: $(BUILD)/firmware-test.elf
152+
qemu-system-riscv32 -machine $(BOARD) -bios none $(QEMU_EXTRA) -nographic -monitor null -semihosting -serial mon:stdio -S -s -kernel $<
153+
128154
include $(TOP)/py/mkrules.mk

ports/qemu-riscv/Makefile.test

Lines changed: 0 additions & 31 deletions
This file was deleted.

ports/qemu-riscv/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ Linux distribution's package manager, or independently packaged ones like
2626

2727
To build and run the image with builtin testsuite:
2828

29-
make -f Makefile.test test
29+
make test

ports/qemu-riscv/mpconfigport.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <stddef.h>
2728
#include <stdint.h>
2829

2930
// options to control how MicroPython is built
@@ -70,8 +71,7 @@ typedef long mp_off_t;
7071
// We need to provide a declaration/definition of alloca()
7172
#include <alloca.h>
7273

73-
#ifdef TEST
74-
#include "shared/upytesthelper/upytesthelper.h"
75-
#undef MP_PLAT_PRINT_STRN
76-
#define MP_PLAT_PRINT_STRN(str, len) upytest_output(str, len)
77-
#endif
74+
// All printing is passed through a custom function to check test output.
75+
#define MP_PLAT_PRINT_STRN(str, len) qemu_print_strn(str, len)
76+
77+
void qemu_print_strn(const char *str, size_t len);

ports/qemu-riscv/test_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "py/gc.h"
3434
#include "py/mperrno.h"
3535
#include "shared/runtime/gchelper.h"
36+
#include "shared/upytesthelper/upytesthelper.h"
3637
#include "lib/tinytest/tinytest.h"
3738
#include "lib/tinytest/tinytest_macros.h"
3839

@@ -64,3 +65,7 @@ void nlr_jump_fail(void *val) {
6465
printf("uncaught NLR\n");
6566
exit(1);
6667
}
68+
69+
void qemu_print_strn(const char *str, size_t len) {
70+
upytest_output(str, len);
71+
}

tools/ci.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ function ci_qemu_riscv_build {
278278
make ${MAKEOPTS} -C ports/qemu-riscv submodules
279279
make ${MAKEOPTS} -C ports/qemu-riscv
280280
make ${MAKEOPTS} -C ports/qemu-riscv clean
281-
make ${MAKEOPTS} -C ports/qemu-riscv -f Makefile.test submodules
282-
make ${MAKEOPTS} -C ports/qemu-riscv -f Makefile.test test
281+
make ${MAKEOPTS} -C ports/qemu-riscv test
283282
}
284283

285284
########################################################################################

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy