diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-10 14:21:35 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-10 14:21:35 +0100 |
commit | 5bf60653d0dba3f1e0dd44f8403b478a2107b3bd (patch) | |
tree | 7aae6b64ec6113ad2e442ee9cf9072476595c2fd | |
parent | bd3da8396a3ee4e1768507827158b7cdce317603 (diff) |
update codegen + test for PTA attribute changes
-rw-r--r-- | lib/codegen.py | 12 | ||||
-rwxr-xr-x | test/test_codegen.py | 20 |
2 files changed, 16 insertions, 16 deletions
diff --git a/lib/codegen.py b/lib/codegen.py index 45a6871..6e94bee 100644 --- a/lib/codegen.py +++ b/lib/codegen.py @@ -180,7 +180,7 @@ class SimulatedStaticStateOnlyAccountingImmediateCalculation(SimulatedAccounting def sleep(self, duration_us): time = self._sleep_duration(duration_us) - power = int(self.current_state.power) + power = int(self.current_state.power.value) energy = self._energy_from_power_and_time(time, power) self.energy += energy @@ -203,14 +203,14 @@ class SimulatedStaticAccountingImmediateCalculation(SimulatedAccountingMethod): def sleep(self, duration_us): time = self._sleep_duration(duration_us) print('sleep duration is {}'.format(time)) - power = int(self.current_state.power) + power = int(self.current_state.power.value) print('power is {}'.format(power)) energy = self._energy_from_power_and_time(time, power) print('energy is {}'.format(energy)) self.energy += energy def pass_transition(self, transition: Transition): - self.energy += int(transition.energy) + self.energy += int(transition.energy.value) super().pass_transition(transition) @@ -245,9 +245,9 @@ class SimulatedStaticAccounting(SimulatedAccountingMethod): pta = self.pta energy = self.energy_class(0) for state in pta.state.values(): - energy += self._energy_from_power_and_time(self.time_in_state[state.name], int(state.power)) + energy += self._energy_from_power_and_time(self.time_in_state[state.name], int(state.power.value)) for i, transition in enumerate(pta.transitions): - energy += self.transition_count[i] * int(transition.energy) + energy += self.transition_count[i] * int(transition.energy.value) return energy.val @@ -275,7 +275,7 @@ class SimulatedStaticStateOnlyAccounting(SimulatedAccountingMethod): pta = self.pta energy = self.energy_class(0) for state in pta.state.values(): - energy += self._energy_from_power_and_time(self.time_in_state[state.name], int(state.power)) + energy += self._energy_from_power_and_time(self.time_in_state[state.name], int(state.power.value)) return energy.val diff --git a/test/test_codegen.py b/test/test_codegen.py index bdde484..fb0d387 100755 --- a/test/test_codegen.py +++ b/test/test_codegen.py @@ -91,12 +91,12 @@ class TestCG(unittest.TestCase): def test_statetransition_immediate(self): pta = PTA.from_json(example_json_1) pta.set_random_energy_model() - pta.state['IDLE'].power = 9 + pta.state['IDLE'].power.value = 9 cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t') cg.current_state = pta.state['IDLE'] cg.sleep(7) self.assertEqual(cg.get_energy(), 9 * 7) - pta.transitions[1].energy = 123 + pta.transitions[1].energy.value = 123 cg.pass_transition(pta.transitions[1]) self.assertEqual(cg.get_energy(), 9 * 7 + 123) cg.pass_transition(pta.transitions[1]) @@ -120,8 +120,8 @@ class TestCG(unittest.TestCase): cg.sleep(90) self.assertEqual(cg.get_energy(), 900) - pta.state['IDLE'].power = 9 # -> 90 uW - pta.transitions[1].energy = 1 # -> 100 pJ + pta.state['IDLE'].power.value = 9 # -> 90 uW + pta.transitions[1].energy.value = 1 # -> 100 pJ cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t', 1e-5, 1e-5, 1e-10) cg.current_state = pta.state['IDLE'] cg.sleep(10) # 10 us @@ -134,12 +134,12 @@ class TestCG(unittest.TestCase): def test_statetransition(self): pta = PTA.from_json(example_json_1) pta.set_random_energy_model() - pta.state['IDLE'].power = 9 + pta.state['IDLE'].power.value = 9 cg = get_simulated_accountingmethod('static_statetransition')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t') cg.current_state = pta.state['IDLE'] cg.sleep(7) self.assertEqual(cg.get_energy(), 9 * 7) - pta.transitions[1].energy = 123 + pta.transitions[1].energy.value = 123 cg.pass_transition(pta.transitions[1]) self.assertEqual(cg.get_energy(), 9 * 7 + 123) cg.pass_transition(pta.transitions[1]) @@ -148,12 +148,12 @@ class TestCG(unittest.TestCase): def test_state_immediate(self): pta = PTA.from_json(example_json_1) pta.set_random_energy_model() - pta.state['IDLE'].power = 9 + pta.state['IDLE'].power.value = 9 cg = get_simulated_accountingmethod('static_state_immediate')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t') cg.current_state = pta.state['IDLE'] cg.sleep(7) self.assertEqual(cg.get_energy(), 9 * 7) - pta.transitions[1].energy = 123 + pta.transitions[1].energy.value = 123 cg.pass_transition(pta.transitions[1]) self.assertEqual(cg.get_energy(), 9 * 7) cg.pass_transition(pta.transitions[1]) @@ -162,12 +162,12 @@ class TestCG(unittest.TestCase): def test_state(self): pta = PTA.from_json(example_json_1) pta.set_random_energy_model() - pta.state['IDLE'].power = 9 + pta.state['IDLE'].power.value = 9 cg = get_simulated_accountingmethod('static_state')(pta, 1000000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t') cg.current_state = pta.state['IDLE'] cg.sleep(7) self.assertEqual(cg.get_energy(), 9 * 7) - pta.transitions[1].energy = 123 + pta.transitions[1].energy.value = 123 cg.pass_transition(pta.transitions[1]) self.assertEqual(cg.get_energy(), 9 * 7) cg.pass_transition(pta.transitions[1]) |