Skip to content

Commit adfa6ef

Browse files
committed
Fix all natmod tests to run on x64
My testing sequence is ``` git clean -dxf examples arch=x64; make -C examples/natmod/features1 ARCH=$arch && make -C examples/natmod/features2 ARCH=$arch && make -C examples/natmod/btree ARCH=$arch && make -C examples/natmod/framebuf ARCH=$arch && make -C examples/natmod/uheapq ARCH=$arch && make -C examples/natmod/urandom ARCH=$arch && make -C examples/natmod/ure ARCH=$arch && make -C examples/natmod/uzlib ARCH=$arch (cd tests && ./run-natmodtests.py "$@" extmod/{btree*,framebuf*,uheapq*,ure*,uzlib*}.py) ```
1 parent 9ee9876 commit adfa6ef

File tree

10 files changed

+46
-23
lines changed

10 files changed

+46
-23
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ jobs:
7777
- name: Native mpy Tests
7878
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy --emit native -d basics float micropython
7979
working-directory: tests
80+
- name: Build native modules
81+
run: |
82+
make -C examples/natmod/features1
83+
make -C examples/natmod/features2
84+
make -C examples/natmod/btree
85+
make -C examples/natmod/framebuf
86+
make -C examples/natmod/uheapq
87+
make -C examples/natmod/urandom
88+
make -C examples/natmod/ure
89+
make -C examples/natmod/uzlib
90+
- name: Test native modules
91+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-natmodtests.py extmod/{btree*,framebuf*,uheapq*,ure*,uzlib*}.py
92+
working-directory: tests
8093
- name: Build mpy-cross.static-aarch64
8194
run: make -C mpy-cross -j2 -f Makefile.static-aarch64
8295
- uses: actions/upload-artifact@v2

examples/natmod/btree/btree_c.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ void *memmove(void *dest, const void *src, size_t n) {
1818
}
1919

2020
void *malloc(size_t n) {
21-
void *ptr = m_malloc(n);
21+
void *ptr = m_malloc(n, false);
2222
return ptr;
2323
}
2424
void *realloc(void *ptr, size_t n) {
2525
mp_printf(&mp_plat_print, "UNDEF %d\n", __LINE__);
2626
return NULL;
2727
}
2828
void *calloc(size_t n, size_t m) {
29-
void *ptr = m_malloc(n * m);
29+
void *ptr = m_malloc(n * m, false);
3030
// memory already cleared by conservative GC
3131
return ptr;
3232
}
@@ -51,7 +51,7 @@ int *__errno (void)
5151

5252
ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
5353
mp_obj_base_t* o = stream;
54-
const mp_stream_p_t *stream_p = o->type->protocol;
54+
const mp_stream_p_t *stream_p = o->type->ext[0].protocol;
5555
mp_uint_t out_sz = stream_p->write(MP_OBJ_FROM_PTR(stream), buf, len, &native_errno);
5656
if (out_sz == MP_STREAM_ERROR) {
5757
return -1;
@@ -62,7 +62,7 @@ ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
6262

6363
ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) {
6464
mp_obj_base_t* o = stream;
65-
const mp_stream_p_t *stream_p = o->type->protocol;
65+
const mp_stream_p_t *stream_p = o->type->ext[0].protocol;
6666
mp_uint_t out_sz = stream_p->read(MP_OBJ_FROM_PTR(stream), buf, len, &native_errno);
6767
if (out_sz == MP_STREAM_ERROR) {
6868
return -1;
@@ -73,7 +73,7 @@ ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) {
7373

7474
off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
7575
const mp_obj_base_t* o = stream;
76-
const mp_stream_p_t *stream_p = o->type->protocol;
76+
const mp_stream_p_t *stream_p = o->type->ext[0].protocol;
7777
struct mp_stream_seek_t seek_s;
7878
seek_s.offset = offset;
7979
seek_s.whence = whence;
@@ -86,15 +86,15 @@ off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
8686

8787
int mp_stream_posix_fsync(void *stream) {
8888
mp_obj_base_t* o = stream;
89-
const mp_stream_p_t *stream_p = o->type->protocol;
89+
const mp_stream_p_t *stream_p = o->type->ext[0].protocol;
9090
mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_FLUSH, 0, &native_errno);
9191
if (res == MP_STREAM_ERROR) {
9292
return -1;
9393
}
9494
return res;
9595
}
9696

97-
mp_obj_type_t btree_type;
97+
mp_obj_full_type_t btree_type;
9898

9999
#include "extmod/modbtree.c"
100100

@@ -123,12 +123,13 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
123123
MP_DYNRUNTIME_INIT_ENTRY
124124

125125
btree_type.base.type = (void*)&mp_fun_table.type_type;
126+
btree_type.flags = MP_TYPE_FLAG_EXTENDED;
126127
btree_type.name = MP_QSTR_btree;
127128
btree_type.print = btree_print;
128-
btree_type.getiter = btree_getiter;
129-
btree_type.iternext = btree_iternext;
130-
btree_type.binary_op = btree_binary_op;
131-
btree_type.subscr = btree_subscr;
129+
btree_type.ext[0].getiter = btree_getiter;
130+
btree_type.ext[0].iternext = btree_iternext;
131+
btree_type.ext[0].binary_op = btree_binary_op;
132+
btree_type.ext[0].subscr = btree_subscr;
132133
btree_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_close), MP_OBJ_FROM_PTR(&btree_close_obj) };
133134
btree_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_flush), MP_OBJ_FROM_PTR(&btree_flush_obj) };
134135
btree_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_get), MP_OBJ_FROM_PTR(&btree_get_obj) };

examples/natmod/framebuf/framebuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void *memset(void *s, int c, size_t n) {
88
}
99
#endif
1010

11-
mp_obj_type_t mp_type_framebuf;
11+
mp_obj_full_type_t mp_type_framebuf;
1212

1313
#include "extmod/modframebuf.c"
1414

@@ -19,9 +19,10 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
1919
MP_DYNRUNTIME_INIT_ENTRY
2020

2121
mp_type_framebuf.base.type = (void*)&mp_type_type;
22+
mp_type_framebuf.flags = MP_TYPE_FLAG_EXTENDED;
2223
mp_type_framebuf.name = MP_QSTR_FrameBuffer;
2324
mp_type_framebuf.make_new = framebuf_make_new;
24-
mp_type_framebuf.buffer_p.get_buffer = framebuf_get_buffer;
25+
mp_type_framebuf.ext[0].buffer_p.get_buffer = framebuf_get_buffer;
2526
framebuf_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill), MP_OBJ_FROM_PTR(&framebuf_fill_obj) };
2627
framebuf_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill_rect), MP_OBJ_FROM_PTR(&framebuf_fill_rect_obj) };
2728
framebuf_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_pixel), MP_OBJ_FROM_PTR(&framebuf_pixel_obj) };

examples/natmod/uzlib/uzlib.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ void *memset(void *s, int c, size_t n) {
88
}
99
#endif
1010

11-
mp_obj_type_t decompio_type;
11+
mp_obj_full_type_t decompio_type;
12+
mp_stream_p_t decompio_stream_p;
1213

1314
#include "extmod/moduzlib.c"
1415

@@ -18,10 +19,14 @@ STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
1819
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
1920
MP_DYNRUNTIME_INIT_ENTRY
2021

22+
decompio_stream_p.name = MP_QSTR_protocol_stream;
23+
decompio_stream_p.read = decompio_read;
24+
2125
decompio_type.base.type = mp_fun_table.type_type;
26+
decompio_type.flags = MP_TYPE_FLAG_EXTENDED;
2227
decompio_type.name = MP_QSTR_DecompIO;
2328
decompio_type.make_new = decompio_make_new;
24-
decompio_type.protocol = &decompio_stream_p;
29+
decompio_type.ext[0].protocol = &decompio_stream_p;
2530
decompio_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_read), MP_OBJ_FROM_PTR(&mp_stream_read_obj) };
2631
decompio_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readinto), MP_OBJ_FROM_PTR(&mp_stream_readinto_obj) };
2732
decompio_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readline), MP_OBJ_FROM_PTR(&mp_stream_unbuffered_readline_obj) };

extmod/modbtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void __dbpanic(DB *db) {
4747

4848
STATIC mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) {
4949
mp_obj_btree_t *o = m_new_obj(mp_obj_btree_t);
50-
o->base.type = &btree_type;
50+
o->base.type = (mp_obj_type_t *)&btree_type;
5151
o->stream = stream;
5252
o->db = db;
5353
o->start_key = mp_const_none;

extmod/modframebuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
622622
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
623623
STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args) {
624624
mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t);
625-
o->base.type = &mp_type_framebuf;
625+
o->base.type = (mp_obj_type_t *)&mp_type_framebuf;
626626

627627
mp_buffer_info_t bufinfo;
628628
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_WRITE);

extmod/moduzlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
114114
STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
115115
#endif
116116

117+
#if !MICROPY_ENABLE_DYNRUNTIME
117118
STATIC const mp_stream_p_t decompio_stream_p = {
118119
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
119120
.read = decompio_read,
120121
};
121122

122-
#if !MICROPY_ENABLE_DYNRUNTIME
123123
STATIC const mp_obj_type_t decompio_type = {
124124
{ &mp_type_type },
125125
.flags = MP_TYPE_FLAG_EXTENDED,

py/dynruntime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ static inline mp_obj_t mp_obj_cast_to_native_base_dyn(mp_obj_t self_in, mp_const
141141
if (MP_OBJ_FROM_PTR(self_type) == native_type) {
142142
return self_in;
143143
}
144-
mp_parent_t parent = mp_type_get_parent_slot(self_type);
145-
if (parent != native_type) {
144+
if (self_type->parent != native_type) {
146145
// The self_in object is not a direct descendant of native_type, so fail the cast.
147146
// This is a very simple version of mp_obj_is_subclass_fast that could be improved.
148147
return MP_OBJ_NULL;

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ black
2121

2222
# for combining the Nordic SoftDevice with CircuitPython
2323
intelhex
24+
25+
# for building & testing natmods
26+
pyelftools

tests/run-natmodtests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import sys
1010
import argparse
1111

12-
sys.path.append("../tools")
13-
import pyboard
14-
1512
# Paths for host executables
1613
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
1714
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/micropython-coverage")
@@ -178,6 +175,10 @@ def main():
178175
target_truth = TargetSubprocess([CPYTHON3])
179176

180177
if args.pyboard:
178+
global pyboard
179+
sys.path.append("../tools")
180+
import pyboard
181+
181182
target = TargetPyboard(pyboard.Pyboard(args.device))
182183
else:
183184
target = TargetSubprocess([MICROPYTHON])

0 commit comments

Comments
 (0)