kopia lustrzana https://github.com/micropython/micropython
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.pull/3633/merge
rodzic
c3f1b22338
commit
c607b58efe
|
@ -169,14 +169,8 @@ STATIC mp_obj_t extra_coverage(void) {
|
||||||
gc_free(NULL);
|
gc_free(NULL);
|
||||||
gc_unlock();
|
gc_unlock();
|
||||||
|
|
||||||
// calling gc_realloc while GC is locked
|
|
||||||
void *p = gc_alloc(4, false);
|
|
||||||
gc_lock();
|
|
||||||
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 8, true));
|
|
||||||
gc_unlock();
|
|
||||||
|
|
||||||
// using gc_realloc to resize to 0, which means free the memory
|
// using gc_realloc to resize to 0, which means free the memory
|
||||||
p = gc_alloc(4, false);
|
void *p = gc_alloc(4, false);
|
||||||
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));
|
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));
|
||||||
|
|
||||||
// calling gc_nbytes with a non-heap pointer
|
// calling gc_nbytes with a non-heap pointer
|
||||||
|
|
|
@ -2,13 +2,24 @@
|
||||||
|
|
||||||
import micropython
|
import micropython
|
||||||
|
|
||||||
|
l = []
|
||||||
|
l2 = list(range(100))
|
||||||
|
|
||||||
micropython.heap_lock()
|
micropython.heap_lock()
|
||||||
|
|
||||||
|
# general allocation on the heap
|
||||||
try:
|
try:
|
||||||
print([])
|
print([])
|
||||||
except MemoryError:
|
except MemoryError:
|
||||||
print('MemoryError')
|
print('MemoryError')
|
||||||
|
|
||||||
|
# expansion of a heap block
|
||||||
|
try:
|
||||||
|
l.extend(l2)
|
||||||
|
except MemoryError:
|
||||||
|
print('MemoryError')
|
||||||
|
|
||||||
micropython.heap_unlock()
|
micropython.heap_unlock()
|
||||||
|
|
||||||
|
# check that allocation works after an unlock
|
||||||
print([])
|
print([])
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
MemoryError
|
MemoryError
|
||||||
|
MemoryError
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -16,7 +16,6 @@ abc
|
||||||
# GC
|
# GC
|
||||||
0
|
0
|
||||||
0
|
0
|
||||||
0
|
|
||||||
# vstr
|
# vstr
|
||||||
tests
|
tests
|
||||||
sts
|
sts
|
||||||
|
|
Ładowanie…
Reference in New Issue