2016-10-13 15:32:34 +02:00
|
|
|
# check that heap_lock/heap_unlock work as expected
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
|
2018-03-02 00:59:09 +01:00
|
|
|
l = []
|
|
|
|
l2 = list(range(100))
|
|
|
|
|
2019-06-28 08:35:51 +02:00
|
|
|
micropython.heap_lock()
|
2016-10-13 15:32:34 +02:00
|
|
|
micropython.heap_lock()
|
|
|
|
|
2018-03-02 00:59:09 +01:00
|
|
|
# general allocation on the heap
|
2016-10-13 15:32:34 +02:00
|
|
|
try:
|
|
|
|
print([])
|
|
|
|
except MemoryError:
|
|
|
|
print("MemoryError")
|
|
|
|
|
2018-03-02 00:59:09 +01:00
|
|
|
# expansion of a heap block
|
|
|
|
try:
|
|
|
|
l.extend(l2)
|
|
|
|
except MemoryError:
|
|
|
|
print("MemoryError")
|
|
|
|
|
2019-06-28 08:35:51 +02:00
|
|
|
print(micropython.heap_unlock())
|
|
|
|
|
|
|
|
# Should still fail
|
|
|
|
try:
|
|
|
|
print([])
|
|
|
|
except MemoryError:
|
|
|
|
print("MemoryError")
|
|
|
|
|
2016-10-13 15:32:34 +02:00
|
|
|
micropython.heap_unlock()
|
|
|
|
|
2018-03-02 00:59:09 +01:00
|
|
|
# check that allocation works after an unlock
|
2016-10-13 15:32:34 +02:00
|
|
|
print([])
|