Skip to content

Commit 0bd1eb8

Browse files
jimmodpgeorge
authored andcommitted
qemu-arm: Add testing of frozen native modules.
- Split 'qemu-arm' from 'unix' for generating tests. - Add frozen module to the qemu-arm test build. - Add test that reproduces the requirement to half-word align native function data.
1 parent 4ab5156 commit 0bd1eb8

7 files changed

Lines changed: 54 additions & 13 deletions

File tree

ports/qemu-arm/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ OBJ = $(OBJ_COMMON) $(OBJ_RUN) $(OBJ_TEST)
114114
# List of sources for qstr extraction
115115
SRC_QSTR += $(SRC_COMMON_C) $(SRC_RUN_C) $(LIB_SRC_C)
116116

117+
ifneq ($(FROZEN_MPY_DIR),)
118+
# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and
119+
# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch).
120+
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
121+
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
122+
MPY_CROSS_FLAGS += -march=armv7m
123+
endif
124+
117125
all: run
118126

119127
run: $(BUILD)/firmware.elf

ports/qemu-arm/Makefile.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
LIB_SRC_C = lib/upytesthelper/upytesthelper.c
22

3+
FROZEN_MPY_DIR ?= test-frzmpy
4+
35
include Makefile
46

57
CFLAGS += -DTEST
@@ -8,7 +10,7 @@ CFLAGS += -DTEST
810

911
$(BUILD)/test_main.o: $(BUILD)/genhdr/tests.h
1012
$(BUILD)/genhdr/tests.h:
11-
(cd $(TOP)/tests; ./run-tests --write-exp)
13+
(cd $(TOP)/tests; ./run-tests --target=qemu-arm --write-exp)
1214
$(Q)echo "Generating $@";(cd $(TOP)/tests; ../tools/tinytest-codegen.py) > $@
1315

1416
$(BUILD)/tinytest.o:
@@ -18,7 +20,8 @@ $(BUILD)/firmware-test.elf: $(OBJ_COMMON) $(OBJ_TEST)
1820
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
1921
$(Q)$(SIZE) $@
2022

23+
# Note: Using timeout(1) to handle cases where qemu hangs (e.g. this can happen with alignment errors).
2124
test: $(BUILD)/firmware-test.elf
22-
qemu-system-arm -machine $(BOARD) $(QEMU_EXTRA) -nographic -monitor null -semihosting -kernel $< > $(BUILD)/console.out
25+
timeout --foreground -k 5s 30s qemu-system-arm -machine $(BOARD) $(QEMU_EXTRA) -nographic -monitor null -semihosting -kernel $< > $(BUILD)/console.out
2326
$(Q)tail -n2 $(BUILD)/console.out
2427
$(Q)tail -n1 $(BUILD)/console.out | grep -q "status: 0"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import micropython
2+
3+
@micropython.native
4+
def native_x(x):
5+
print(x + 1)
6+
7+
@micropython.native
8+
def native_y(x):
9+
print(x + 1)
10+
11+
@micropython.native
12+
def native_z(x):
13+
print(x + 1)

tests/qemu-arm/native_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import native_frozen_align
2+
3+
native_frozen_align.native_x(1)
4+
native_frozen_align.native_y(2)
5+
native_frozen_align.native_z(3)

tests/qemu-arm/native_test.py.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
3
3+
4

tests/run-tests

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def run_tests(pyb, tests, args, base_path="."):
349349
for t in tests:
350350
if t.startswith('basics/io_'):
351351
skip_tests.add(t)
352+
elif args.target == 'qemu-arm':
353+
skip_tests.add('misc/print_exception.py') # requires sys stdfiles
352354

353355
# Some tests are known to fail on 64-bit machines
354356
if pyb is None and platform.architecture()[0] == '64bit':
@@ -527,8 +529,9 @@ the last matching regex is used:
527529
cmd_parser.add_argument('files', nargs='*', help='input test files')
528530
args = cmd_parser.parse_args()
529531

532+
LOCAL_TARGETS = ('unix', 'qemu-arm',)
530533
EXTERNAL_TARGETS = ('pyboard', 'wipy', 'esp8266', 'esp32', 'minimal', 'nrf')
531-
if args.target == 'unix' or args.list_tests:
534+
if args.target in LOCAL_TARGETS or args.list_tests:
532535
pyb = None
533536
elif args.target in EXTERNAL_TARGETS:
534537
global pyboard
@@ -537,24 +540,28 @@ the last matching regex is used:
537540
pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password)
538541
pyb.enter_raw_repl()
539542
else:
540-
raise ValueError('target must be either %s or unix' % ", ".join(EXTERNAL_TARGETS))
543+
raise ValueError('target must be one of %s' % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS))
541544

542545
if len(args.files) == 0:
543546
if args.test_dirs is None:
547+
test_dirs = ('basics', 'micropython', 'misc', 'extmod',)
544548
if args.target == 'pyboard':
545549
# run pyboard tests
546-
test_dirs = ('basics', 'micropython', 'float', 'misc', 'stress', 'extmod', 'pyb', 'pybnative', 'inlineasm')
550+
test_dirs += ('float', 'stress', 'pyb', 'pybnative', 'inlineasm')
547551
elif args.target in ('esp8266', 'esp32', 'minimal', 'nrf'):
548-
test_dirs = ('basics', 'micropython', 'float', 'misc', 'extmod')
552+
test_dirs += ('float',)
549553
elif args.target == 'wipy':
550554
# run WiPy tests
551-
test_dirs = ('basics', 'micropython', 'misc', 'extmod', 'wipy')
552-
else:
555+
test_dirs += ('wipy',)
556+
elif args.target == 'unix':
553557
# run PC tests
554-
test_dirs = (
555-
'basics', 'micropython', 'float', 'import', 'io', 'misc',
556-
'stress', 'unicode', 'extmod', 'unix', 'cmdline',
557-
)
558+
test_dirs += ('float', 'import', 'io', 'stress', 'unicode', 'unix', 'cmdline',)
559+
elif args.target == 'qemu-arm':
560+
if not args.write_exp:
561+
raise ValueError('--target=qemu-arm must be used with --write-exp')
562+
# Generate expected output files for qemu run.
563+
# This list should match the test_dirs tuple in tinytest-codegen.py.
564+
test_dirs += ('float', 'inlineasm', 'qemu-arm',)
558565
else:
559566
# run tests from these directories
560567
test_dirs = args.test_dirs

tools/tinytest-codegen.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def script_to_map(test_file):
5454

5555
## XXX: may be we could have `--without <groups>` argument...
5656
# currently these tests are selected because they pass on qemu-arm
57-
test_dirs = ('basics', 'micropython', 'float', 'extmod', 'inlineasm') # 'import', 'io', 'misc')
57+
test_dirs = ('basics', 'micropython', 'misc', 'extmod', 'float', 'inlineasm', 'qemu-arm',) # 'import', 'io',)
5858
exclude_tests = (
5959
# pattern matching in .exp
6060
'basics/bytes_compare3.py',
@@ -81,6 +81,8 @@ def script_to_map(test_file):
8181
'micropython/heapalloc_traceback.py',
8282
# pattern matching in .exp
8383
'micropython/meminfo.py',
84+
# needs sys stdfiles
85+
'misc/print_exception.py',
8486
)
8587

8688
output = []

0 commit comments

Comments
 (0)