-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmemgr_test.py
50 lines (40 loc) · 1.42 KB
/
cmemgr_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import utest
from highord import *
from uinspect import main_module
import cmemgr
import pyb
from utilities import Indicator
from ucollections import namedtuple
class TestCMEMgr(utest.TestCase):
@utest.cond(equals(1))
def test_mapper_single_thread(self):
def caller(func):
setattr(main_module, 'invoke', func)
def my_func():
with Indicator(1):
pyb.delay(30)
cmemgr.Mapper(caller, my_func)
print('type invoke() to call my_func')
@utest.cond(equals(2))
def test_mapper_single_interrupt(self):
tim = pyb.Timer(1)
tim.init(freq=2)
@cmemgr.map_to_thread(tim.callback)
def led_blink():
with Indicator(1):
pyb.delay(30)
@utest.cond(equals(3))
def test_mapper_multi_interrupts(self):
TiTuple = namedtuple('TiTuple', ('tim', 'id'))
for info in [TiTuple(pyb.Timer(tim_id, freq=tim_id + 1), tim_id) for tim_id in (1, 2, 4)]:
@cmemgr.map_to_thread(info.tim.callback, info.id)
def led_blink(led_id):
with Indicator(led_id):
pyb.delay(30)
if __name__ == '__main__':
print('tests list:')
print('1. test for single thread')
print('2. test for single interrupt')
print('3. test for multi interrupts')
x = int(input('please choose one: '))
utest.main(x)