summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-03-02 10:59:09 +1100
committerDamien George <damien.p.george@gmail.com>2018-03-02 10:59:09 +1100
commitc607b58efe9333ab92e1b721dcd974e35a9d393e (patch)
tree217edaa81ad111f7ad0ef898b1dbeca8283e3c35
parentc3f1b2233865f4e7f3016ca22a65ef9f4d4ec4db (diff)
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.
-rw-r--r--ports/unix/coverage.c8
-rw-r--r--tests/micropython/heap_lock.py11
-rw-r--r--tests/micropython/heap_lock.py.exp1
-rw-r--r--tests/unix/extra_coverage.py.exp1
4 files changed, 13 insertions, 8 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c
index db97f4f77..33533ad86 100644
--- a/ports/unix/coverage.c
+++ b/ports/unix/coverage.c
@@ -169,14 +169,8 @@ STATIC mp_obj_t extra_coverage(void) {
gc_free(NULL);
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
- p = gc_alloc(4, false);
+ void *p = gc_alloc(4, false);
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));
// calling gc_nbytes with a non-heap pointer
diff --git a/tests/micropython/heap_lock.py b/tests/micropython/heap_lock.py
index 0f0a70eff..ca3f5806a 100644
--- a/tests/micropython/heap_lock.py
+++ b/tests/micropython/heap_lock.py
@@ -2,13 +2,24 @@
import micropython
+l = []
+l2 = list(range(100))
+
micropython.heap_lock()
+# general allocation on the heap
try:
print([])
except MemoryError:
print('MemoryError')
+# expansion of a heap block
+try:
+ l.extend(l2)
+except MemoryError:
+ print('MemoryError')
+
micropython.heap_unlock()
+# check that allocation works after an unlock
print([])
diff --git a/tests/micropython/heap_lock.py.exp b/tests/micropython/heap_lock.py.exp
index 67b208cfc..819c32663 100644
--- a/tests/micropython/heap_lock.py.exp
+++ b/tests/micropython/heap_lock.py.exp
@@ -1,2 +1,3 @@
MemoryError
+MemoryError
[]
diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp
index a686e7161..d2e557fdc 100644
--- a/tests/unix/extra_coverage.py.exp
+++ b/tests/unix/extra_coverage.py.exp
@@ -16,7 +16,6 @@ abc
# GC
0
0
-0
# vstr
tests
sts