Skip to content

Commit d70f87a

Browse files
committed
tests/micropython: Add test for creating traceback without allocation.
1 parent 21d8242 commit d70f87a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/micropython/heapalloc.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# check that we can do certain things without allocating heap memory
22

33
import micropython
4+
import sys
45

56
def f1(a):
67
print(a)
@@ -17,8 +18,15 @@ def f3(a, b, c, d):
1718

1819
global_var = 1
1920

21+
# preallocate exception instance with some room for a traceback
22+
global_exc = StopIteration()
23+
try:
24+
raise global_exc
25+
except:
26+
pass
27+
2028
def test():
21-
global global_var
29+
global global_var, global_exc
2230
global_var = 2 # set an existing global variable
2331
for i in range(2): # for loop
2432
f1(i) # function call
@@ -28,6 +36,13 @@ def test():
2836
f2(i, i) # 2 args
2937
f3(1, 2, 3, 4) # function with lots of local state
3038

39+
# test that we can generate a traceback without allocating
40+
global_exc.__traceback__ = None
41+
try:
42+
raise global_exc
43+
except StopIteration as e:
44+
sys.print_exception(e)
45+
3146
# call test() with heap allocation disabled
3247
micropython.heap_lock()
3348
test()

tests/micropython/heapalloc.py.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
1 2
1010
1 1
1111
1 2 3 4 10
12+
Traceback (most recent call last):
13+
File "micropython/heapalloc.py", line 42, in test
14+
StopIteration:

0 commit comments

Comments
 (0)