Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 34d0b3f

Browse files
committed
tests/micropython: Add tests for heap_lock, and emergency exceptions.
1 parent 6a4c6fc commit 34d0b3f

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

tests/micropython/emg_exc.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# test that emergency exceptions work
2+
3+
import micropython
4+
import sys
5+
6+
# some ports need to allocate heap for the emg exc
7+
try:
8+
micropython.alloc_emergency_exception_buf(256)
9+
except AttributeError:
10+
pass
11+
12+
def f():
13+
micropython.heap_lock()
14+
try:
15+
raise ValueError(1)
16+
except ValueError as er:
17+
sys.print_exception(er)
18+
micropython.heap_unlock()
19+
20+
f()

tests/micropython/emg_exc.py.exp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ValueError:

tests/micropython/heap_lock.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# check that heap_lock/heap_unlock work as expected
2+
3+
import micropython
4+
5+
micropython.heap_lock()
6+
7+
try:
8+
print([])
9+
except MemoryError:
10+
print('MemoryError')
11+
12+
micropython.heap_unlock()
13+
14+
print([])

tests/micropython/heap_lock.py.exp

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MemoryError
2+
[]

tests/micropython/heapalloc.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# check that we can do certain things without allocating heap memory
22

3-
import gc
3+
import micropython
44

55
def f1(a):
66
print(a)
@@ -28,12 +28,7 @@ def test():
2828
f2(i, i) # 2 args
2929
f3(1, 2, 3, 4) # function with lots of local state
3030

31-
# call h with heap allocation disabled and all memory used up
32-
gc.disable()
33-
try:
34-
while True:
35-
'a'.lower # allocates 1 cell for boundmeth
36-
except MemoryError:
37-
pass
31+
# call test() with heap allocation disabled
32+
micropython.heap_lock()
3833
test()
39-
gc.enable()
34+
micropython.heap_unlock()

0 commit comments

Comments
 (0)