diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-03-12 16:32:55 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-03-12 16:32:55 +0100 |
commit | bc3f8634c5bd821482bd80b904d001e43c191728 (patch) | |
tree | 01ba65abf31aed24346979e152c171448f8d6fe3 | |
parent | 6a51bd8ef0ec4e05bf0c7620953584c280d182e6 (diff) |
harness: Use inheritance for common code
-rw-r--r-- | lib/harness.py | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/lib/harness.py b/lib/harness.py index 67a9f7d..1eb294b 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -4,14 +4,13 @@ Harnesses for various types of benchmark logs. tbd """ -class OnboardTimerHarness: +class TransitionHarness: 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' + ret = '' if self.gpio_pin != None: ret += '#define PTALOG_GPIO {}\n'.format(self.gpio_pin) ret += '#include "object/ptalog.h"\n' @@ -22,11 +21,7 @@ class OnboardTimerHarness: return ret def start_benchmark(self): - ret = 'counter.start();\n' - ret += 'counter.stop();\n' - ret += 'ptalog.passNop(counter);\n' - ret += 'ptalog.startBenchmark(0);\n' - return ret + return 'ptalog.startBenchmark(0);\n' def start_run(self): return 'ptalog.reset();\n' @@ -34,10 +29,8 @@ class OnboardTimerHarness: 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' + ret += 'ptalog.stopTransition();\n' return ret def stop_run(self): @@ -46,37 +39,28 @@ class OnboardTimerHarness: def stop_benchmark(self): return '' -class TransitionHarness: +class OnboardTimerHarness(TransitionHarness): def __init__(self, gpio_pin = None): - self.gpio_pin = gpio_pin - pass + super().__init__(gpio_pin = gpio_pin) 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' - if self.gpio_pin != None: - ret += 'PTALog ptalog({});\n'.format(self.gpio_pin) - else: - ret += 'PTALog ptalog;\n' + ret = '#include "driver/counter.h"\n' + ret += '#define PTALOG_TIMING\n' + ret += super().global_code() return ret def start_benchmark(self): - return 'ptalog.startBenchmark(0);\n' - - def start_run(self): - return 'ptalog.reset();\n' + ret = 'counter.start();\n' + ret += 'counter.stop();\n' + ret += 'ptalog.passNop(counter);\n' + ret += super().start_benchmark() + return ret 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 += 'ptalog.stopTransition();\n' + ret += 'counter.stop();\n' + ret += 'ptalog.stopTransition(counter);\n' return ret - - def stop_run(self): - return 'ptalog.dump();\n' - - def stop_benchmark(self): - return '' |