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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/usr/bin/env python3
import getopt
import json
import re
import sys
import yaml
from automata import PTA
from harness import TransitionHarness
opt = {}
if __name__ == '__main__':
try:
optspec = (
'depth= '
'instance= '
'sleep= '
)
raw_opts, args = getopt.getopt(sys.argv[1:], "", optspec.split(' '))
for option, parameter in raw_opts:
optname = re.sub(r'^--', '', option)
opt[optname] = parameter
if 'depth' in opt:
opt['depth'] = int(opt['depth'])
else:
opt['depth'] = 3
if 'sleep' in opt:
opt['sleep'] = int(opt['sleep'])
except getopt.GetoptError as err:
print(err)
sys.exit(2)
modelfile = args[0]
with open(modelfile, 'r') as f:
if '.json' in modelfile:
pta = PTA.from_json(json.load(f))
else:
pta = PTA.from_yaml(yaml.safe_load(f))
harness = TransitionHarness('GPIO::p1_0')
print('#include "arch.h"')
print(harness.global_code())
print(harness.start_benchmark())
class_prefix = ''
if 'instance' in opt:
class_prefix = '{}.'.format(opt['instance'])
elif pta.instance:
class_prefix = '{}.'.format(pta.instance)
for run in pta.dfs(opt['depth'], with_arguments = True):
print(harness.start_run())
for transition, arguments in run:
print('// {} -> {}'.format(transition.origin.name, transition.destination.name))
if transition.is_interrupt:
print('// wait for {} interrupt'.format(transition.name))
transition_code = '// TODO add startTransition / stopTransition calls to interrupt routine'
else:
transition_code = '{}{}({});'.format(class_prefix, transition.name, ', '.join(map(str, arguments)))
print(harness.pass_transition(pta.get_transition_id(transition), transition_code))
if 'sleep' in opt:
print('arch.delay_ms({:d});'.format(opt['sleep']))
print(harness.stop_run())
print()
print(harness.stop_benchmark())
sys.exit(0)
|