diff options
author | Damien George <damien.p.george@gmail.com> | 2016-10-14 00:32:34 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-10-14 00:32:34 +1100 |
commit | 34d0b3f85c9926d854acd7723b9e057744916ee0 (patch) | |
tree | 8ed2b83c3bbc735799db21ac1bd4bdf8bb090a9a | |
parent | 6a4c6fc023292b42502b67b4ec3ece62d188ac14 (diff) | |
download | micropython-34d0b3f85c9926d854acd7723b9e057744916ee0.tar.gz micropython-34d0b3f85c9926d854acd7723b9e057744916ee0.zip |
tests/micropython: Add tests for heap_lock, and emergency exceptions.
-rw-r--r-- | tests/micropython/emg_exc.py | 20 | ||||
-rw-r--r-- | tests/micropython/emg_exc.py.exp | 1 | ||||
-rw-r--r-- | tests/micropython/heap_lock.py | 14 | ||||
-rw-r--r-- | tests/micropython/heap_lock.py.exp | 2 | ||||
-rw-r--r-- | tests/micropython/heapalloc.py | 13 |
5 files changed, 41 insertions, 9 deletions
diff --git a/tests/micropython/emg_exc.py b/tests/micropython/emg_exc.py new file mode 100644 index 0000000000..d228e6faab --- /dev/null +++ b/tests/micropython/emg_exc.py @@ -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() diff --git a/tests/micropython/emg_exc.py.exp b/tests/micropython/emg_exc.py.exp new file mode 100644 index 0000000000..82b10b5f54 --- /dev/null +++ b/tests/micropython/emg_exc.py.exp @@ -0,0 +1 @@ +ValueError: diff --git a/tests/micropython/heap_lock.py b/tests/micropython/heap_lock.py new file mode 100644 index 0000000000..0f0a70eff1 --- /dev/null +++ b/tests/micropython/heap_lock.py @@ -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([]) diff --git a/tests/micropython/heap_lock.py.exp b/tests/micropython/heap_lock.py.exp new file mode 100644 index 0000000000..67b208cfc5 --- /dev/null +++ b/tests/micropython/heap_lock.py.exp @@ -0,0 +1,2 @@ +MemoryError +[] diff --git a/tests/micropython/heapalloc.py b/tests/micropython/heapalloc.py index 2dc7fa5e7e..a651158ca5 100644 --- a/tests/micropython/heapalloc.py +++ b/tests/micropython/heapalloc.py @@ -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() |