summaryrefslogtreecommitdiff
path: root/test/test_codegen.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-09-19 08:25:30 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-09-19 08:25:30 +0200
commitae6c2f67c0537debc6a5446e301b210a95a38806 (patch)
tree08cfa25a9dda195b6938ed7dfa5039291be96a6b /test/test_codegen.py
parentd30c76189654b9b4ffb7e84decba8ab0e38345b8 (diff)
codegen / simulated accounting: respect granularity
Diffstat (limited to 'test/test_codegen.py')
-rwxr-xr-xtest/test_codegen.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/test_codegen.py b/test/test_codegen.py
index 2d54158..e1bb942 100755
--- a/test/test_codegen.py
+++ b/test/test_codegen.py
@@ -110,6 +110,26 @@ class TestCG(unittest.TestCase):
cg.sleep(90)
self.assertEqual(cg.get_energy(), 900 % 256)
+ cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 100000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint16_t')
+ cg.current_state = pta.state['IDLE']
+ cg.sleep(7)
+ self.assertEqual(cg.get_energy(), 0)
+ cg.sleep(15)
+ self.assertEqual(cg.get_energy(), 90)
+ cg.sleep(90)
+ self.assertEqual(cg.get_energy(), 900)
+
+ pta.state['IDLE'].power = 9 # -> 90 uW
+ pta.transitions[1].energy = 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
+ self.assertEqual(cg.get_energy(), 90 * 10)
+ cg.pass_transition(pta.transitions[1])
+ self.assertAlmostEqual(cg.get_energy(), 90 * 10 + 100, places=0)
+ cg.pass_transition(pta.transitions[1])
+ self.assertAlmostEqual(cg.get_energy(), 90 * 10 + 100 + 100, places=0)
+
def test_statetransition(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()