tests/heapalloc_exc_raise.py: Heap alloc test for raising/catching exc.

This commit is contained in:
Paul Sokolovsky 2017-02-20 04:22:32 +03:00
parent 3d739eb398
commit 6fc6f10b1e
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# Test that we can raise and catch (preallocated) exception
# without memory allocation.
import micropython
e = ValueError("error")
def func():
try:
# This works as is because traceback is not allocated
# if not possible (heap is locked, no memory). If heap
# is not locked, this would allocate a traceback entry.
# To avoid that, traceback should be warmed up (by raising
# it once after creation) and then cleared before each
# raise with:
# e.__traceback__ = None
raise e
except Exception as e2:
print(e2)
micropython.heap_lock()
func()
print("ok")
micropython.heap_unlock()

View File

@ -0,0 +1,2 @@
error
ok