summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-03-04 15:15:54 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-03-04 15:16:10 +0100
commit4e37798145fa03bd90880f4ac315529190472eaf (patch)
treed6051e435941d9a4a9ea21f81624d87be1d818b9
parent9abd39d11da2db4d5804d4e8199578bfa3aa9164 (diff)
generate PTA from YAML model, support several types of test harness
-rwxr-xr-xbin/generate-dfa-benchmark.py29
-rwxr-xr-xlib/automata.py32
-rw-r--r--lib/harness.py70
3 files changed, 121 insertions, 10 deletions
diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py
index 1eb5073..87cb662 100755
--- a/bin/generate-dfa-benchmark.py
+++ b/bin/generate-dfa-benchmark.py
@@ -4,7 +4,9 @@ import getopt
import json
import re
import sys
+import yaml
from automata import PTA
+from harness import TransitionHarness
opt = {}
@@ -37,30 +39,37 @@ if __name__ == '__main__':
modelfile = args[0]
with open(modelfile, 'r') as f:
- pta = PTA.from_json(json.load(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('ptalog.startBenchmark(0);')
+ print(harness.start_benchmark())
for run in pta.dfs(opt['depth'], with_arguments = True):
- print('ptalog.reset();')
+ print(harness.start_run())
for transition, arguments in run:
print('// {} -> {}'.format(transition.origin.name, transition.destination.name))
- print('ptalog.passTransition({:d});'.format(pta.get_transition_id(transition)))
if transition.is_interrupt:
print('// wait for {} interrupt'.format(transition.name))
- print('// TODO add startTransition / stopTransition calls to interrupt routine')
+ transition_code = '// TODO add startTransition / stopTransition calls to interrupt routine'
else:
- print('ptalog.startTransition();')
if 'instance' in opt:
- print('{}.{}({});'.format(opt['instance'], transition.name, ', '.join(arguments)))
+ transition_code = '{}.{}({});'.format(opt['instance'], transition.name, ', '.join(map(str, arguments)))
else:
- print('{}({});'.format(transition.name, ', '.join(arguments)))
- print('ptalog.stopTransition();')
+ transition_code = '{}({});'.format(transition.name, ', '.join(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('ptalog.dump();')
+ print(harness.stop_run())
print()
+ print(harness.stop_benchmark())
sys.exit(0)
diff --git a/lib/automata.py b/lib/automata.py
index 922cdaf..96a724e 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -365,6 +365,38 @@ class PTA:
return pta
+ @classmethod
+ def from_yaml(cls, yaml_input: dict):
+ """Return a PTA created from the YAML DFA format (passed as dict)."""
+
+ kwargs = dict()
+
+ if 'parameters' in yaml_input:
+ kwargs['parameters'] = yaml_input['parameters']
+
+ if 'initial_param_values' in yaml_input:
+ kwargs['initial_param_values'] = yaml_input['initial_param_values']
+
+ if 'states' in yaml_input:
+ kwargs['state_names'] = yaml_input['states']
+
+ pta = cls(**kwargs)
+
+ for trans_name in sorted(yaml_input['transition'].keys()):
+ transition = yaml_input['transition'][trans_name]
+ arguments = list()
+ argument_values = list()
+ is_interrupt = False
+ if 'arguments' in transition:
+ for argument in transition['arguments']:
+ arguments.append(argument['name'])
+ argument_values.append(argument['values'])
+ for origin in transition['src']:
+ pta.add_transition(origin, transition['dst'], trans_name,
+ arguments = arguments, argument_values = argument_values)
+
+ return pta
+
def to_json(self) -> dict:
"""
Return JSON encoding of this PTA.
diff --git a/lib/harness.py b/lib/harness.py
new file mode 100644
index 0000000..c03406c
--- /dev/null
+++ b/lib/harness.py
@@ -0,0 +1,70 @@
+"""
+Harnesses for various types of benchmark logs.
+
+tbd
+"""
+
+class OnboardTimerHarness:
+ def __init__(self, gpio_pin = None):
+ self.gpio_pin = gpio_pin
+ pass
+
+ def global_code(self):
+ ret = '#include "driver/counter.h"\n'
+ ret += '#define PTALOG_TIMING\n'
+ if self.gpio_pin != None:
+ ret += '#define PTALOG_GPIO {}\n'.format(self.gpio_pin)
+ ret += '#include "object/ptalog.h"\n'
+ return ret
+
+ def start_benchmark(self):
+ return 'ptalog.startBenchmark(0);\n'
+
+ def start_run(self):
+ return 'ptalog.reset();\n'
+
+ def pass_transition(self, transition_id, transition_code):
+ ret = 'ptalog.passTransition({:d});\n'.format(transition_id)
+ ret += 'ptalog.startTransition();\n'
+ ret += 'counter.start();\n'
+ ret += '{}\n'.format(transition_code)
+ ret += 'counter.stop();\n'
+ ret += 'ptalog.stopTransition(counter);\n'
+ return ret
+
+ def stop_run(self):
+ return 'ptalog.dump();\n'
+
+ def stop_benchmark(self):
+ return ''
+
+class TransitionHarness:
+ def __init__(self, gpio_pin = None):
+ self.gpio_pin = gpio_pin
+ pass
+
+ def global_code(self):
+ ret = ''
+ if self.gpio_pin != None:
+ ret += '#define PTALOG_GPIO {}\n'.format(self.gpio_pin)
+ ret += '#include "object/ptalog.h"\n'
+ return ret
+
+ def start_benchmark(self):
+ return 'ptalog.startBenchmark(0);\n'
+
+ def start_run(self):
+ return 'ptalog.reset();\n'
+
+ def pass_transition(self, transition_id, transition_code):
+ ret = 'ptalog.passTransition({:d});\n'.format(transition_id)
+ ret += 'ptalog.startTransition();\n'
+ ret += '{}\n'.format(transition_code)
+ ret += 'ptalog.stopTransition();\n'
+ return ret
+
+ def stop_run(self):
+ return 'ptalog.dump();\n'
+
+ def stop_benchmark(self):
+ return ''