summaryrefslogtreecommitdiff
path: root/test/test_codegen.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_codegen.py')
-rwxr-xr-xtest/test_codegen.py119
1 files changed, 60 insertions, 59 deletions
diff --git a/test/test_codegen.py b/test/test_codegen.py
index e9b4067..bdde484 100755
--- a/test/test_codegen.py
+++ b/test/test_codegen.py
@@ -5,87 +5,88 @@ from codegen import get_simulated_accountingmethod
import unittest
example_json_1 = {
- 'parameters' : ['datarate', 'txbytes', 'txpower'],
- 'initial_param_values' : [None, None, None],
- 'state' : {
- 'IDLE' : {
- 'power' : {
- 'static' : 5,
+ 'parameters': ['datarate', 'txbytes', 'txpower'],
+ 'initial_param_values': [None, None, None],
+ 'state': {
+ 'IDLE': {
+ 'power': {
+ 'static': 5,
}
},
- 'TX' : {
- 'power' : {
- 'static' : 100,
- 'function' : {
- 'raw' : 'regression_arg(0) + regression_arg(1)'
- ' * parameter(txpower)',
- 'regression_args' : [ 100, 2 ]
+ 'TX': {
+ 'power': {
+ 'static': 100,
+ 'function': {
+ 'raw': 'regression_arg(0) + regression_arg(1)'
+ ' * parameter(txpower)',
+ 'regression_args': [100, 2]
},
}
},
},
- 'transitions' : [
+ 'transitions': [
{
- 'name' : 'init',
- 'origin' : ['UNINITIALIZED', 'IDLE'],
- 'destination' : 'IDLE',
- 'duration' : {
- 'static' : 50000,
+ 'name': 'init',
+ 'origin': ['UNINITIALIZED', 'IDLE'],
+ 'destination': 'IDLE',
+ 'duration': {
+ 'static': 50000,
},
- 'set_param' : {
- 'txpower' : 10
+ 'set_param': {
+ 'txpower': 10
},
},
{
- 'name' : 'setTxPower',
- 'origin' : 'IDLE',
- 'destination' : 'IDLE',
- 'duration' : { 'static' : 120 },
- 'energy ' : { 'static' : 10000 },
- 'arg_to_param_map' : { 0: 'txpower'},
- 'argument_values' : [ [10, 20, 30] ],
+ 'name': 'setTxPower',
+ 'origin': 'IDLE',
+ 'destination': 'IDLE',
+ 'duration': {'static': 120},
+ 'energy ': {'static': 10000},
+ 'arg_to_param_map': {0: 'txpower'},
+ 'argument_values': [[10, 20, 30]],
},
{
- 'name' : 'send',
- 'origin' : 'IDLE',
- 'destination' : 'TX',
- 'duration' : {
- 'static' : 10,
- 'function' : {
- 'raw' : 'regression_arg(0) + regression_arg(1)'
- ' * function_arg(1)',
- 'regression_args' : [48, 8],
+ 'name': 'send',
+ 'origin': 'IDLE',
+ 'destination': 'TX',
+ 'duration': {
+ 'static': 10,
+ 'function': {
+ 'raw': 'regression_arg(0) + regression_arg(1)'
+ ' * function_arg(1)',
+ 'regression_args': [48, 8],
},
},
- 'energy' : {
- 'static' : 3,
- 'function' : {
- 'raw' : 'regression_arg(0) + regression_arg(1)'
- ' * function_arg(1)',
- 'regression_args' : [3, 5],
+ 'energy': {
+ 'static': 3,
+ 'function': {
+ 'raw': 'regression_arg(0) + regression_arg(1)'
+ ' * function_arg(1)',
+ 'regression_args': [3, 5],
},
},
- 'arg_to_param_map' : { 1: 'txbytes'},
- 'argument_values' : [ ['"foo"', '"hodor"'], [3, 5] ],
- 'argument_combination' : 'zip',
+ 'arg_to_param_map': {1: 'txbytes'},
+ 'argument_values': [['"foo"', '"hodor"'], [3, 5]],
+ 'argument_combination': 'zip',
},
{
- 'name' : 'txComplete',
- 'origin' : 'TX',
- 'destination' : 'IDLE',
- 'is_interrupt' : 1,
- 'timeout' : {
- 'static' : 2000,
- 'function' : {
- 'raw' : 'regression_arg(0) + regression_arg(1)'
- ' * parameter(txbytes)',
- 'regression_args' : [ 500, 16 ],
+ 'name': 'txComplete',
+ 'origin': 'TX',
+ 'destination': 'IDLE',
+ 'is_interrupt': 1,
+ 'timeout': {
+ 'static': 2000,
+ 'function': {
+ 'raw': 'regression_arg(0) + regression_arg(1)'
+ ' * parameter(txbytes)',
+ 'regression_args': [500, 16],
},
},
}
],
}
+
class TestCG(unittest.TestCase):
def test_statetransition_immediate(self):
pta = PTA.from_json(example_json_1)
@@ -119,11 +120,11 @@ 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 = 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
+ 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)