tests/micropython: Add tests for heap_lock, and emergency exceptions.
This commit is contained in:
parent
6a4c6fc023
commit
34d0b3f85c
|
@ -0,0 +1,20 @@
|
|||
# test that emergency exceptions work
|
||||
|
||||
import micropython
|
||||
import sys
|
||||
|
||||
# some ports need to allocate heap for the emg exc
|
||||
try:
|
||||
micropython.alloc_emergency_exception_buf(256)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def f():
|
||||
micropython.heap_lock()
|
||||
try:
|
||||
raise ValueError(1)
|
||||
except ValueError as er:
|
||||
sys.print_exception(er)
|
||||
micropython.heap_unlock()
|
||||
|
||||
f()
|
|
@ -0,0 +1 @@
|
|||
ValueError:
|
|
@ -0,0 +1,14 @@
|
|||
# check that heap_lock/heap_unlock work as expected
|
||||
|
||||
import micropython
|
||||
|
||||
micropython.heap_lock()
|
||||
|
||||
try:
|
||||
print([])
|
||||
except MemoryError:
|
||||
print('MemoryError')
|
||||
|
||||
micropython.heap_unlock()
|
||||
|
||||
print([])
|
|
@ -0,0 +1,2 @@
|
|||
MemoryError
|
||||
[]
|
|
@ -1,6 +1,6 @@
|
|||
# check that we can do certain things without allocating heap memory
|
||||
|
||||
import gc
|
||||
import micropython
|
||||
|
||||
def f1(a):
|
||||
print(a)
|
||||
|
@ -28,12 +28,7 @@ def test():
|
|||
f2(i, i) # 2 args
|
||||
f3(1, 2, 3, 4) # function with lots of local state
|
||||
|
||||
# call h with heap allocation disabled and all memory used up
|
||||
gc.disable()
|
||||
try:
|
||||
while True:
|
||||
'a'.lower # allocates 1 cell for boundmeth
|
||||
except MemoryError:
|
||||
pass
|
||||
# call test() with heap allocation disabled
|
||||
micropython.heap_lock()
|
||||
test()
|
||||
gc.enable()
|
||||
micropython.heap_unlock()
|
||||
|
|
Loading…
Reference in New Issue