Skip to content

Commit c607b58

Browse files
committed
tests: Move heap-realloc-while-locked test from C to Python.
This test for calling gc_realloc() while the GC is locked can be done in pure Python, so better to do it that way since it can then be tested on more ports.
1 parent c3f1b22 commit c607b58

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

ports/unix/coverage.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,8 @@ STATIC mp_obj_t extra_coverage(void) {
169169
gc_free(NULL);
170170
gc_unlock();
171171

172-
// calling gc_realloc while GC is locked
173-
void *p = gc_alloc(4, false);
174-
gc_lock();
175-
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 8, true));
176-
gc_unlock();
177-
178172
// using gc_realloc to resize to 0, which means free the memory
179-
p = gc_alloc(4, false);
173+
void *p = gc_alloc(4, false);
180174
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));
181175

182176
// calling gc_nbytes with a non-heap pointer

tests/micropython/heap_lock.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22

33
import micropython
44

5+
l = []
6+
l2 = list(range(100))
7+
58
micropython.heap_lock()
69

10+
# general allocation on the heap
711
try:
812
print([])
913
except MemoryError:
1014
print('MemoryError')
1115

16+
# expansion of a heap block
17+
try:
18+
l.extend(l2)
19+
except MemoryError:
20+
print('MemoryError')
21+
1222
micropython.heap_unlock()
1323

24+
# check that allocation works after an unlock
1425
print([])

tests/micropython/heap_lock.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
MemoryError
2+
MemoryError
23
[]

tests/unix/extra_coverage.py.exp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ abc
1616
# GC
1717
0
1818
0
19-
0
2019
# vstr
2120
tests
2221
sts

0 commit comments

Comments
 (0)