summaryrefslogtreecommitdiff
path: root/tests/micropython/heap_lock.py
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2019-06-28 16:35:51 +1000
committerDamien George <damien.p.george@gmail.com>2020-03-11 16:54:16 +1100
commit86bfabec11456b892fadd47cecab12157bbd8c0e (patch)
tree3eeb9c66bc8df735d7be67c4e2153bae680482b8 /tests/micropython/heap_lock.py
parent7eea0d8b6c8ac97a585ed96ead7e1ffef0687c63 (diff)
py/modmicropython: Add heap_locked function to test state of heap.
This commit adds micropython.heap_locked() which returns the current lock-depth of the heap, and can be used by Python code to check if the heap is locked or not. This new function is configured via MICROPY_PY_MICROPYTHON_HEAP_LOCKED and is disabled by default. This commit also changes the return value of micropython.heap_unlock() so it returns the current lock-depth as well.
Diffstat (limited to 'tests/micropython/heap_lock.py')
-rw-r--r--tests/micropython/heap_lock.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/micropython/heap_lock.py b/tests/micropython/heap_lock.py
index ca3f5806a..6d770d9ec 100644
--- a/tests/micropython/heap_lock.py
+++ b/tests/micropython/heap_lock.py
@@ -6,6 +6,7 @@ l = []
l2 = list(range(100))
micropython.heap_lock()
+micropython.heap_lock()
# general allocation on the heap
try:
@@ -19,6 +20,14 @@ try:
except MemoryError:
print('MemoryError')
+print(micropython.heap_unlock())
+
+# Should still fail
+try:
+ print([])
+except MemoryError:
+ print('MemoryError')
+
micropython.heap_unlock()
# check that allocation works after an unlock