summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-07-02 09:35:48 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-07-02 09:35:48 +0200
commitf1a9e8b419c3b0836989565fa462d7c67a4bc9b9 (patch)
treefc2560ee18f910636d1138f150da8782c59a44e8 /test
parent915826fd9144809f33a9ecdc8beb4b244581a045 (diff)
blacken test code
Diffstat (limited to 'test')
-rwxr-xr-xtest/test_codegen.py170
-rwxr-xr-xtest/test_pta.py917
-rwxr-xr-xtest/test_ptamodel.py505
-rwxr-xr-xtest/test_timingharness.py201
4 files changed, 1089 insertions, 704 deletions
diff --git a/test/test_codegen.py b/test/test_codegen.py
index 981117b..ce565d6 100755
--- a/test/test_codegen.py
+++ b/test/test_codegen.py
@@ -5,84 +5,74 @@ from dfatool.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,
- }
- },
- 'TX': {
- 'power': {
- 'static': 100,
- 'function': {
- 'raw': 'regression_arg(0) + regression_arg(1)'
- ' * parameter(txpower)',
- 'regression_args': [100, 2]
+ "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],
},
}
},
},
- 'transitions': [
+ "transitions": [
{
- 'name': 'init',
- 'origin': ['UNINITIALIZED', 'IDLE'],
- 'destination': 'IDLE',
- 'duration': {
- 'static': 50000,
- },
- 'set_param': {
- 'txpower': 10
- },
+ "name": "init",
+ "origin": ["UNINITIALIZED", "IDLE"],
+ "destination": "IDLE",
+ "duration": {"static": 50000,},
+ "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],
},
},
- }
+ },
],
}
@@ -91,9 +81,11 @@ 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.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']
+ 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.value = 123
@@ -102,8 +94,10 @@ class TestCG(unittest.TestCase):
cg.pass_transition(pta.transitions[1])
self.assertEqual(cg.get_energy(), (9 * 7 + 123 + 123) % 256)
- cg = get_simulated_accountingmethod('static_statetransition_immediate')(pta, 100000, 'uint8_t', 'uint8_t', 'uint8_t', 'uint8_t')
- cg.current_state = pta.state['IDLE']
+ cg = get_simulated_accountingmethod("static_statetransition_immediate")(
+ pta, 100000, "uint8_t", "uint8_t", "uint8_t", "uint8_t"
+ )
+ cg.current_state = pta.state["IDLE"]
cg.sleep(7)
self.assertEqual(cg.get_energy(), 0)
cg.sleep(15)
@@ -111,8 +105,10 @@ 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 = 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)
@@ -120,10 +116,12 @@ class TestCG(unittest.TestCase):
cg.sleep(90)
self.assertEqual(cg.get_energy(), 900)
- pta.state['IDLE'].power.value = 9 # -> 90 uW
+ 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 = 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])
@@ -134,9 +132,11 @@ class TestCG(unittest.TestCase):
def test_statetransition(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()
- 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']
+ 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.value = 123
@@ -148,9 +148,11 @@ 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.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']
+ 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.value = 123
@@ -162,9 +164,11 @@ class TestCG(unittest.TestCase):
def test_state(self):
pta = PTA.from_json(example_json_1)
pta.set_random_energy_model()
- 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']
+ 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.value = 123
@@ -173,8 +177,10 @@ class TestCG(unittest.TestCase):
cg.pass_transition(pta.transitions[1])
self.assertEqual(cg.get_energy(), 9 * 7)
- cg = get_simulated_accountingmethod('static_state')(pta, 1000000, 'uint8_t', 'uint16_t', 'uint16_t', 'uint16_t')
+ cg = get_simulated_accountingmethod("static_state")(
+ pta, 1000000, "uint8_t", "uint16_t", "uint16_t", "uint16_t"
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/test/test_pta.py b/test/test_pta.py
index 9f0778d..d43e702 100755
--- a/test/test_pta.py
+++ b/test/test_pta.py
@@ -5,88 +5,79 @@ import unittest
import yaml
example_json_1 = {
- 'parameters': ['datarate', 'txbytes', 'txpower'],
- 'initial_param_values': [None, None, None],
- 'state': {
- 'IDLE': {
- 'power': {
- 'static': 5,
- }
- },
- 'TX': {
- 'power': {
- 'static': 10000,
- 'function': {
- 'raw': 'regression_arg(0) + regression_arg(1)'
- ' * parameter(txpower)',
- 'regression_args': [10000, 2]
+ "parameters": ["datarate", "txbytes", "txpower"],
+ "initial_param_values": [None, None, None],
+ "state": {
+ "IDLE": {"power": {"static": 5,}},
+ "TX": {
+ "power": {
+ "static": 10000,
+ "function": {
+ "raw": "regression_arg(0) + regression_arg(1)"
+ " * parameter(txpower)",
+ "regression_args": [10000, 2],
},
}
},
},
- 'transitions': [
+ "transitions": [
{
- 'name': 'init',
- 'origin': ['UNINITIALIZED', 'IDLE'],
- 'destination': 'IDLE',
- 'duration': {
- 'static': 50000,
- },
- 'set_param': {
- 'txpower': 10
- },
+ "name": "init",
+ "origin": ["UNINITIALIZED", "IDLE"],
+ "destination": "IDLE",
+ "duration": {"static": 50000,},
+ "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],
},
},
- }
+ },
],
}
-example_yaml_1 = yaml.safe_load("""
+example_yaml_1 = yaml.safe_load(
+ """
codegen:
instance: cc1200
@@ -124,9 +115,11 @@ transition:
src: [TX]
dst: IDLE
is_interrupt: true
-""")
+"""
+)
-example_yaml_2 = yaml.safe_load("""
+example_yaml_2 = yaml.safe_load(
+ """
codegen:
instance: cc1200
@@ -169,9 +162,11 @@ transition:
src: [TX]
dst: IDLE
is_interrupt: true
-""")
+"""
+)
-example_yaml_3 = yaml.safe_load("""
+example_yaml_3 = yaml.safe_load(
+ """
codegen:
instance: nrf24l01
includes: ['driver/nrf24l01.h']
@@ -260,12 +255,17 @@ transition:
- name: blocking
values: [1, 1, 1, 1, 1, 1]
argument_combination: zip
-""")
+"""
+)
-def dfs_tran_to_name(runs: list, with_args: bool = False, with_param: bool = False) -> list:
+def dfs_tran_to_name(
+ runs: list, with_args: bool = False, with_param: bool = False
+) -> list:
if with_param:
- return list(map(lambda run: list(map(lambda x: (x[0].name, x[1], x[2]), run)), runs))
+ return list(
+ map(lambda run: list(map(lambda x: (x[0].name, x[1], x[2]), run)), runs)
+ )
if with_args:
return list(map(lambda run: list(map(lambda x: (x[0].name, x[1]), run)), runs))
return list(map(lambda run: list(map(lambda x: (x[0].name), run)), runs))
@@ -273,117 +273,175 @@ def dfs_tran_to_name(runs: list, with_args: bool = False, with_param: bool = Fal
class TestPTA(unittest.TestCase):
def test_dfs(self):
- pta = PTA(['IDLE', 'TX'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'TX', 'send')
- pta.add_transition('TX', 'IDLE', 'txComplete')
- self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [['init']])
- self.assertEqual(dfs_tran_to_name(pta.dfs(1), False), [['init', 'send']])
- self.assertEqual(dfs_tran_to_name(pta.dfs(2), False), [['init', 'send', 'txComplete']])
- self.assertEqual(dfs_tran_to_name(pta.dfs(3), False), [['init', 'send', 'txComplete', 'send']])
-
- pta = PTA(['IDLE'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'IDLE', 'set1')
- pta.add_transition('IDLE', 'IDLE', 'set2')
- self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [['init']])
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(1), False)), [['init', 'set1'], ['init', 'set2']])
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(2), False)), [['init', 'set1', 'set1'],
- ['init', 'set1', 'set2'],
- ['init', 'set2', 'set1'],
- ['init', 'set2', 'set2']])
+ pta = PTA(["IDLE", "TX"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "TX", "send")
+ pta.add_transition("TX", "IDLE", "txComplete")
+ self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [["init"]])
+ self.assertEqual(dfs_tran_to_name(pta.dfs(1), False), [["init", "send"]])
+ self.assertEqual(
+ dfs_tran_to_name(pta.dfs(2), False), [["init", "send", "txComplete"]]
+ )
+ self.assertEqual(
+ dfs_tran_to_name(pta.dfs(3), False),
+ [["init", "send", "txComplete", "send"]],
+ )
+
+ pta = PTA(["IDLE"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "IDLE", "set1")
+ pta.add_transition("IDLE", "IDLE", "set2")
+ self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [["init"]])
+ self.assertEqual(
+ sorted(dfs_tran_to_name(pta.dfs(1), False)),
+ [["init", "set1"], ["init", "set2"]],
+ )
+ self.assertEqual(
+ sorted(dfs_tran_to_name(pta.dfs(2), False)),
+ [
+ ["init", "set1", "set1"],
+ ["init", "set1", "set2"],
+ ["init", "set2", "set1"],
+ ["init", "set2", "set2"],
+ ],
+ )
def test_dfs_trace_filter(self):
- pta = PTA(['IDLE'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'IDLE', 'set1')
- pta.add_transition('IDLE', 'IDLE', 'set2')
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(2, trace_filter=[['init', 'set1', 'set2'], ['init', 'set2', 'set1']]), False)),
- [['init', 'set1', 'set2'], ['init', 'set2', 'set1']])
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(2, trace_filter=[['init', 'set1', '$'], ['init', 'set2', '$']]), False)),
- [['init', 'set1'], ['init', 'set2']])
+ pta = PTA(["IDLE"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "IDLE", "set1")
+ pta.add_transition("IDLE", "IDLE", "set2")
+ self.assertEqual(
+ sorted(
+ dfs_tran_to_name(
+ pta.dfs(
+ 2,
+ trace_filter=[
+ ["init", "set1", "set2"],
+ ["init", "set2", "set1"],
+ ],
+ ),
+ False,
+ )
+ ),
+ [["init", "set1", "set2"], ["init", "set2", "set1"]],
+ )
+ self.assertEqual(
+ sorted(
+ dfs_tran_to_name(
+ pta.dfs(
+ 2, trace_filter=[["init", "set1", "$"], ["init", "set2", "$"]]
+ ),
+ False,
+ )
+ ),
+ [["init", "set1"], ["init", "set2"]],
+ )
def test_dfs_accepting(self):
- pta = PTA(['IDLE', 'TX'], accepting_states=['IDLE'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'TX', 'send')
- pta.add_transition('TX', 'IDLE', 'txComplete')
- self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [['init']])
+ pta = PTA(["IDLE", "TX"], accepting_states=["IDLE"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "TX", "send")
+ pta.add_transition("TX", "IDLE", "txComplete")
+ self.assertEqual(dfs_tran_to_name(pta.dfs(0), False), [["init"]])
self.assertEqual(dfs_tran_to_name(pta.dfs(1), False), [])
- self.assertEqual(dfs_tran_to_name(pta.dfs(2), False), [['init', 'send', 'txComplete']])
+ self.assertEqual(
+ dfs_tran_to_name(pta.dfs(2), False), [["init", "send", "txComplete"]]
+ )
self.assertEqual(dfs_tran_to_name(pta.dfs(3), False), [])
def test_dfs_objects(self):
- pta = PTA(['IDLE', 'TX'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'TX', 'send')
- pta.add_transition('TX', 'IDLE', 'txComplete')
+ pta = PTA(["IDLE", "TX"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "TX", "send")
+ pta.add_transition("TX", "IDLE", "txComplete")
traces = list(pta.dfs(2))
self.assertEqual(len(traces), 1)
trace = traces[0]
self.assertEqual(len(trace), 3)
- self.assertEqual(trace[0][0].name, 'init')
- self.assertEqual(trace[1][0].name, 'send')
- self.assertEqual(trace[2][0].name, 'txComplete')
+ self.assertEqual(trace[0][0].name, "init")
+ self.assertEqual(trace[1][0].name, "send")
+ self.assertEqual(trace[2][0].name, "txComplete")
self.assertEqual(pta.get_transition_id(trace[0][0]), 0)
self.assertEqual(pta.get_transition_id(trace[1][0]), 1)
self.assertEqual(pta.get_transition_id(trace[2][0]), 2)
def test_dfs_with_sleep(self):
- pta = PTA(['IDLE', 'TX'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'TX', 'send')
- pta.add_transition('TX', 'IDLE', 'txComplete')
+ pta = PTA(["IDLE", "TX"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "TX", "send")
+ pta.add_transition("TX", "IDLE", "txComplete")
traces = list(pta.dfs(2, sleep=10))
self.assertEqual(len(traces), 1)
trace = traces[0]
self.assertEqual(len(trace), 6)
self.assertIsNone(trace[0][0])
- self.assertEqual(trace[1][0].name, 'init')
+ self.assertEqual(trace[1][0].name, "init")
self.assertIsNone(trace[2][0])
- self.assertEqual(trace[3][0].name, 'send')
+ self.assertEqual(trace[3][0].name, "send")
self.assertIsNone(trace[4][0])
- self.assertEqual(trace[5][0].name, 'txComplete')
+ self.assertEqual(trace[5][0].name, "txComplete")
self.assertEqual(pta.get_transition_id(trace[1][0]), 0)
self.assertEqual(pta.get_transition_id(trace[3][0]), 1)
self.assertEqual(pta.get_transition_id(trace[5][0]), 2)
def test_bfs(self):
- pta = PTA(['IDLE', 'TX'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'TX', 'send')
- pta.add_transition('TX', 'IDLE', 'txComplete')
- self.assertEqual(dfs_tran_to_name(pta.bfs(0), False), [['init']])
- self.assertEqual(dfs_tran_to_name(pta.bfs(1), False), [['init'], ['init', 'send']])
- self.assertEqual(dfs_tran_to_name(pta.bfs(2), False), [['init'], ['init', 'send'], ['init', 'send', 'txComplete']])
- self.assertEqual(dfs_tran_to_name(pta.bfs(3), False), [['init'], ['init', 'send'], ['init', 'send', 'txComplete'], ['init', 'send', 'txComplete', 'send']])
-
- pta = PTA(['IDLE'])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init')
- pta.add_transition('IDLE', 'IDLE', 'set1')
- pta.add_transition('IDLE', 'IDLE', 'set2')
- self.assertEqual(dfs_tran_to_name(pta.bfs(0), False), [['init']])
- self.assertEqual(sorted(dfs_tran_to_name(pta.bfs(1), False)), [['init'], ['init', 'set1'], ['init', 'set2']])
- self.assertEqual(sorted(dfs_tran_to_name(pta.bfs(2), False)), [['init'],
- ['init', 'set1'],
- ['init', 'set1', 'set1'],
- ['init', 'set1', 'set2'],
- ['init', 'set2'],
- ['init', 'set2', 'set1'],
- ['init', 'set2', 'set2']])
+ pta = PTA(["IDLE", "TX"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "TX", "send")
+ pta.add_transition("TX", "IDLE", "txComplete")
+ self.assertEqual(dfs_tran_to_name(pta.bfs(0), False), [["init"]])
+ self.assertEqual(
+ dfs_tran_to_name(pta.bfs(1), False), [["init"], ["init", "send"]]
+ )
+ self.assertEqual(
+ dfs_tran_to_name(pta.bfs(2), False),
+ [["init"], ["init", "send"], ["init", "send", "txComplete"]],
+ )
+ self.assertEqual(
+ dfs_tran_to_name(pta.bfs(3), False),
+ [
+ ["init"],
+ ["init", "send"],
+ ["init", "send", "txComplete"],
+ ["init", "send", "txComplete", "send"],
+ ],
+ )
+
+ pta = PTA(["IDLE"])
+ pta.add_transition("UNINITIALIZED", "IDLE", "init")
+ pta.add_transition("IDLE", "IDLE", "set1")
+ pta.add_transition("IDLE", "IDLE", "set2")
+ self.assertEqual(dfs_tran_to_name(pta.bfs(0), False), [["init"]])
+ self.assertEqual(
+ sorted(dfs_tran_to_name(pta.bfs(1), False)),
+ [["init"], ["init", "set1"], ["init", "set2"]],
+ )
+ self.assertEqual(
+ sorted(dfs_tran_to_name(pta.bfs(2), False)),
+ [
+ ["init"],
+ ["init", "set1"],
+ ["init", "set1", "set1"],
+ ["init", "set1", "set2"],
+ ["init", "set2"],
+ ["init", "set2", "set1"],
+ ["init", "set2", "set2"],
+ ],
+ )
def test_from_json(self):
pta = PTA.from_json(example_json_1)
- self.assertEqual(pta.parameters, ['datarate', 'txbytes', 'txpower'])
- self.assertEqual(pta.state['UNINITIALIZED'].name, 'UNINITIALIZED')
- self.assertEqual(pta.state['IDLE'].name, 'IDLE')
- self.assertEqual(pta.state['TX'].name, 'TX')
+ self.assertEqual(pta.parameters, ["datarate", "txbytes", "txpower"])
+ self.assertEqual(pta.state["UNINITIALIZED"].name, "UNINITIALIZED")
+ self.assertEqual(pta.state["IDLE"].name, "IDLE")
+ self.assertEqual(pta.state["TX"].name, "TX")
self.assertEqual(len(pta.transitions), 5)
- self.assertEqual(pta.transitions[0].name, 'init')
- self.assertEqual(pta.transitions[1].name, 'init')
- self.assertEqual(pta.transitions[2].name, 'setTxPower')
- self.assertEqual(pta.transitions[3].name, 'send')
- self.assertEqual(pta.transitions[4].name, 'txComplete')
+ self.assertEqual(pta.transitions[0].name, "init")
+ self.assertEqual(pta.transitions[1].name, "init")
+ self.assertEqual(pta.transitions[2].name, "setTxPower")
+ self.assertEqual(pta.transitions[3].name, "send")
+ self.assertEqual(pta.transitions[4].name, "txComplete")
# def test_to_json(self):
# pta = PTA.from_json(example_json_1)
@@ -394,368 +452,471 @@ class TestPTA(unittest.TestCase):
def test_from_json_dfs_arg(self):
pta = PTA.from_json(example_json_1)
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(1), False)), [['init', 'init'], ['init', 'send'], ['init', 'setTxPower']])
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(1, with_arguments=True), True)),
- [
- [('init', ()), ('init', ())],
- [('init', ()), ('send', ('"foo"', 3))],
- [('init', ()), ('send', ('"hodor"', 5))],
- [('init', ()), ('setTxPower', (10,))],
- [('init', ()), ('setTxPower', (20,))],
- [('init', ()), ('setTxPower', (30,))],
- ]
+ self.assertEqual(
+ sorted(dfs_tran_to_name(pta.dfs(1), False)),
+ [["init", "init"], ["init", "send"], ["init", "setTxPower"]],
+ )
+ self.assertEqual(
+ sorted(dfs_tran_to_name(pta.dfs(1, with_arguments=True), True)),
+ [
+ [("init", ()), ("init", ())],
+ [("init", ()), ("send", ('"foo"', 3))],
+ [("init", ()), ("send", ('"hodor"', 5))],
+ [("init", ()), ("setTxPower", (10,))],
+ [("init", ()), ("setTxPower", (20,))],
+ [("init", ()), ("setTxPower", (30,))],
+ ],
)
def test_from_json_dfs_param(self):
pta = PTA.from_json(example_json_1)
no_param = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 10,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 10,
}
param_tx3 = {
- 'datarate': None,
- 'txbytes': 3,
- 'txpower': 10,
+ "datarate": None,
+ "txbytes": 3,
+ "txpower": 10,
}
param_tx5 = {
- 'datarate': None,
- 'txbytes': 5,
- 'txpower': 10,
+ "datarate": None,
+ "txbytes": 5,
+ "txpower": 10,
}
param_txp10 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 10,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 10,
}
param_txp20 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 20,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 20,
}
param_txp30 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 30,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 30,
}
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(1, with_arguments=True, with_parameters=True), True, True)),
- [
- [('init', (), no_param), ('init', (), no_param)],
- [('init', (), no_param), ('send', ('"foo"', 3), param_tx3)],
- [('init', (), no_param), ('send', ('"hodor"', 5), param_tx5)],
- [('init', (), no_param), ('setTxPower', (10,), param_txp10)],
- [('init', (), no_param), ('setTxPower', (20,), param_txp20)],
- [('init', (), no_param), ('setTxPower', (30,), param_txp30)],
- ]
+ self.assertEqual(
+ sorted(
+ dfs_tran_to_name(
+ pta.dfs(1, with_arguments=True, with_parameters=True), True, True
+ )
+ ),
+ [
+ [("init", (), no_param), ("init", (), no_param)],
+ [("init", (), no_param), ("send", ('"foo"', 3), param_tx3)],
+ [("init", (), no_param), ("send", ('"hodor"', 5), param_tx5)],
+ [("init", (), no_param), ("setTxPower", (10,), param_txp10)],
+ [("init", (), no_param), ("setTxPower", (20,), param_txp20)],
+ [("init", (), no_param), ("setTxPower", (30,), param_txp30)],
+ ],
)
def test_from_json_function(self):
pta = PTA.from_json(example_json_1)
- self.assertEqual(pta.state['TX'].get_energy(1000, {'datarate': 10, 'txbytes': 6, 'txpower': 10}), 1000 * (10000 + 2 * 10))
- self.assertEqual(pta.transitions[4].get_timeout({'datarate': 10, 'txbytes': 6, 'txpower': 10}), 500 + 16 * 6)
+ self.assertEqual(
+ pta.state["TX"].get_energy(
+ 1000, {"datarate": 10, "txbytes": 6, "txpower": 10}
+ ),
+ 1000 * (10000 + 2 * 10),
+ )
+ self.assertEqual(
+ pta.transitions[4].get_timeout(
+ {"datarate": 10, "txbytes": 6, "txpower": 10}
+ ),
+ 500 + 16 * 6,
+ )
def test_from_yaml_dfs_param(self):
pta = PTA.from_yaml(example_yaml_1)
no_param = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': None,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": None,
}
param_tx3 = {
- 'datarate': None,
- 'txbytes': 3,
- 'txpower': None,
+ "datarate": None,
+ "txbytes": 3,
+ "txpower": None,
}
param_tx5 = {
- 'datarate': None,
- 'txbytes': 5,
- 'txpower': None,
+ "datarate": None,
+ "txbytes": 5,
+ "txpower": None,
}
param_txp10 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 10,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 10,
}
param_txp20 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 20,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 20,
}
param_txp30 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 30,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 30,
}
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(1, with_arguments=True, with_parameters=True), True, True)),
- [
- [('init', (), no_param), ('init', (), no_param)],
- [('init', (), no_param), ('send', ('"foo"', 3), param_tx3)],
- [('init', (), no_param), ('send', ('"hodor"', 5), param_tx5)],
- [('init', (), no_param), ('setTxPower', (10,), param_txp10)],
- [('init', (), no_param), ('setTxPower', (20,), param_txp20)],
- [('init', (), no_param), ('setTxPower', (30,), param_txp30)],
- ]
+ self.assertEqual(
+ sorted(
+ dfs_tran_to_name(
+ pta.dfs(1, with_arguments=True, with_parameters=True), True, True
+ )
+ ),
+ [
+ [("init", (), no_param), ("init", (), no_param)],
+ [("init", (), no_param), ("send", ('"foo"', 3), param_tx3)],
+ [("init", (), no_param), ("send", ('"hodor"', 5), param_tx5)],
+ [("init", (), no_param), ("setTxPower", (10,), param_txp10)],
+ [("init", (), no_param), ("setTxPower", (20,), param_txp20)],
+ [("init", (), no_param), ("setTxPower", (30,), param_txp30)],
+ ],
)
def test_normalization(self):
pta = PTA.from_yaml(example_yaml_2)
no_param = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': None,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": None,
}
param_tx3 = {
- 'datarate': None,
- 'txbytes': 3,
- 'txpower': None,
+ "datarate": None,
+ "txbytes": 3,
+ "txpower": None,
}
param_tx6 = {
- 'datarate': None,
- 'txbytes': 6,
- 'txpower': None,
+ "datarate": None,
+ "txbytes": 6,
+ "txpower": None,
}
param_txp10 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': -6,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": -6,
}
param_txp20 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 4,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 4,
}
param_txp30 = {
- 'datarate': None,
- 'txbytes': None,
- 'txpower': 14,
+ "datarate": None,
+ "txbytes": None,
+ "txpower": 14,
}
- self.assertEqual(sorted(dfs_tran_to_name(pta.dfs(1, with_arguments=True, with_parameters=True), True, True)),
- [
- [('init', (), no_param), ('init', (), no_param)],
- [('init', (), no_param), ('send', ('FOO',), param_tx3)],
- [('init', (), no_param), ('send', ('LONGER',), param_tx6)],
- [('init', (), no_param), ('setTxPower', (10,), param_txp10)],
- [('init', (), no_param), ('setTxPower', (20,), param_txp20)],
- [('init', (), no_param), ('setTxPower', (30,), param_txp30)],
- ]
+ self.assertEqual(
+ sorted(
+ dfs_tran_to_name(
+ pta.dfs(1, with_arguments=True, with_parameters=True), True, True
+ )
+ ),
+ [
+ [("init", (), no_param), ("init", (), no_param)],
+ [("init", (), no_param), ("send", ("FOO",), param_tx3)],
+ [("init", (), no_param), ("send", ("LONGER",), param_tx6)],
+ [("init", (), no_param), ("setTxPower", (10,), param_txp10)],
+ [("init", (), no_param), ("setTxPower", (20,), param_txp20)],
+ [("init", (), no_param), ("setTxPower", (30,), param_txp30)],
+ ],
)
def test_shrink(self):
pta = PTA.from_yaml(example_yaml_3)
pta.shrink_argument_values()
- self.assertEqual(pta.transitions[0].name, 'setAutoAck')
- self.assertEqual(pta.transitions[1].name, 'setPALevel')
- self.assertEqual(pta.transitions[2].name, 'setRetries')
- self.assertEqual(pta.transitions[3].name, 'setup')
- self.assertEqual(pta.transitions[4].name, 'setup')
- self.assertEqual(pta.transitions[5].name, 'write')
+ self.assertEqual(pta.transitions[0].name, "setAutoAck")
+ self.assertEqual(pta.transitions[1].name, "setPALevel")
+ self.assertEqual(pta.transitions[2].name, "setRetries")
+ self.assertEqual(pta.transitions[3].name, "setup")
+ self.assertEqual(pta.transitions[4].name, "setup")
+ self.assertEqual(pta.transitions[5].name, "write")
self.assertEqual(pta.transitions[0].argument_values, [[0, 1]])
- self.assertEqual(pta.transitions[1].argument_values, [['Nrf24l01::RF24_PA_MIN', 'Nrf24l01::RF24_PA_MAX']])
+ self.assertEqual(
+ pta.transitions[1].argument_values,
+ [["Nrf24l01::RF24_PA_MIN", "Nrf24l01::RF24_PA_MAX"]],
+ )
self.assertEqual(pta.transitions[2].argument_values, [[0, 15], [0, 15]])
- self.assertEqual(pta.transitions[5].argument_values, [['"foo"', '"foo"', '"foofoofoo"', '"foofoofoo"', '"123456789012345678901234567890"',
- '"123456789012345678901234567890"'], [3, 3, 9, 9, 30, 30], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1]])
+ self.assertEqual(
+ pta.transitions[5].argument_values,
+ [
+ [
+ '"foo"',
+ '"foo"',
+ '"foofoofoo"',
+ '"foofoofoo"',
+ '"123456789012345678901234567890"',
+ '"123456789012345678901234567890"',
+ ],
+ [3, 3, 9, 9, 30, 30],
+ [0, 1, 0, 1, 0, 1],
+ [1, 1, 1, 1, 1, 1],
+ ],
+ )
def test_simulation(self):
pta = PTA()
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', duration=50000)
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10)
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True)
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition("UNINITIALIZED", "IDLE", "init", duration=50000)
+ pta.add_transition("IDLE", "TX", "send", energy=3, duration=10)
+ pta.add_transition("TX", "IDLE", "txComplete", timeout=2000, is_interrupt=True)
trace = [
- ['init'],
+ ["init"],
[None, 10000000],
- ['send', 'foo', 3],
+ ["send", "foo", 3],
[None, 5000000],
- ['send', 'foo', 3]
+ ["send", "foo", 3],
]
- expected_energy = 5. * 10000000 + 3 + 100 * 2000 + 5 * 5000000 + 3 + 100 * 2000
+ expected_energy = 5.0 * 10000000 + 3 + 100 * 2000 + 5 * 5000000 + 3 + 100 * 2000
expected_duration = 50000 + 10000000 + 10 + 2000 + 5000000 + 10 + 2000
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
+ self.assertEqual(result.end_state.name, "IDLE")
self.assertEqual(result.parameters, {})
def test_simulation_param_none(self):
- pta = PTA(parameters=['txpower', 'length'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000)
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10)
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True)
+ pta = PTA(parameters=["txpower", "length"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition(
+ "UNINITIALIZED", "IDLE", "init", energy=500000, duration=50000
+ )
+ pta.add_transition("IDLE", "TX", "send", energy=3, duration=10)
+ pta.add_transition("TX", "IDLE", "txComplete", timeout=2000, is_interrupt=True)
trace = [
- ['init'],
+ ["init"],
]
expected_energy = 500000
expected_duration = 50000
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': None,
- 'length': None
- })
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": None, "length": None})
def test_simulation_param_update_function(self):
- pta = PTA(parameters=['txpower', 'length'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000)
- pta.add_transition('IDLE', 'IDLE', 'setTxPower', energy=10000, duration=120,
- param_update_function=lambda param, arg: {**param, 'txpower': arg[0]})
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10)
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True)
- trace = [
- ['init'],
- ['setTxPower', 10]
- ]
+ pta = PTA(parameters=["txpower", "length"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition(
+ "UNINITIALIZED", "IDLE", "init", energy=500000, duration=50000
+ )
+ pta.add_transition(
+ "IDLE",
+ "IDLE",
+ "setTxPower",
+ energy=10000,
+ duration=120,
+ param_update_function=lambda param, arg: {**param, "txpower": arg[0]},
+ )
+ pta.add_transition("IDLE", "TX", "send", energy=3, duration=10)
+ pta.add_transition("TX", "IDLE", "txComplete", timeout=2000, is_interrupt=True)
+ trace = [["init"], ["setTxPower", 10]]
expected_energy = 510000
expected_duration = 50120
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': 10,
- 'length': None
- })
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": 10, "length": None})
def test_simulation_arg_to_param_map(self):
- pta = PTA(parameters=['txpower', 'length'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000)
- pta.add_transition('IDLE', 'IDLE', 'setTxPower', energy=10000, duration=120,
- arg_to_param_map={0: 'txpower'})
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10)
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True)
- trace = [
- ['init'],
- ['setTxPower', 10]
- ]
+ pta = PTA(parameters=["txpower", "length"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition(
+ "UNINITIALIZED", "IDLE", "init", energy=500000, duration=50000
+ )
+ pta.add_transition(
+ "IDLE",
+ "IDLE",
+ "setTxPower",
+ energy=10000,
+ duration=120,
+ arg_to_param_map={0: "txpower"},
+ )
+ pta.add_transition("IDLE", "TX", "send", energy=3, duration=10)
+ pta.add_transition("TX", "IDLE", "txComplete", timeout=2000, is_interrupt=True)
+ trace = [["init"], ["setTxPower", 10]]
expected_energy = 510000
expected_duration = 50120
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': 10,
- 'length': None
- })
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": 10, "length": None})
def test_simulation_set_param(self):
- pta = PTA(parameters=['txpower', 'length'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000, set_param={'txpower': 10})
+ pta = PTA(parameters=["txpower", "length"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition(
+ "UNINITIALIZED",
+ "IDLE",
+ "init",
+ energy=500000,
+ duration=50000,
+ set_param={"txpower": 10},
+ )
trace = [
- ['init'],
+ ["init"],
]
expected_energy = 500000
expected_duration = 50000
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': 10,
- 'length': None
- })
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": 10, "length": None})
def test_simulation_arg_function(self):
- pta = PTA(parameters=['txpower', 'length'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000)
- pta.add_transition('IDLE', 'IDLE', 'setTxPower', energy=10000, duration=120,
- param_update_function=lambda param, arg: {**param, 'txpower': arg[0]})
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10,
- energy_function=lambda param, arg: 3 + 5 * arg[1],
- duration_function=lambda param, arg: 48 + 8 * arg[1])
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True)
+ pta = PTA(parameters=["txpower", "length"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition(
+ "UNINITIALIZED", "IDLE", "init", energy=500000, duration=50000
+ )
+ pta.add_transition(
+ "IDLE",
+ "IDLE",
+ "setTxPower",
+ energy=10000,
+ duration=120,
+ param_update_function=lambda param, arg: {**param, "txpower": arg[0]},
+ )
+ pta.add_transition(
+ "IDLE",
+ "TX",
+ "send",
+ energy=3,
+ duration=10,
+ energy_function=lambda param, arg: 3 + 5 * arg[1],
+ duration_function=lambda param, arg: 48 + 8 * arg[1],
+ )
+ pta.add_transition("TX", "IDLE", "txComplete", timeout=2000, is_interrupt=True)
trace = [
- ['init'],
- ['setTxPower', 10],
- ['send', 'foo', 3],
+ ["init"],
+ ["setTxPower", 10],
+ ["send", "foo", 3],
]
expected_energy = 500000 + 10000 + (3 + 5 * 3) + (2000 * 100)
expected_duration = 50000 + 120 + (48 + 8 * 3) + 2000
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': 10,
- 'length': None
- })
-
- pta = PTA(parameters=['txpower', 'length'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100)
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000)
- pta.add_transition('IDLE', 'IDLE', 'setTxPower', energy=10000, duration=120,
- param_update_function=lambda param, arg: {**param, 'txpower': arg[0]})
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10,
- energy_function=lambda param, arg: 3 + 5 * arg[1],
- duration_function=lambda param, arg: 48 + 8 * arg[1])
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True)
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": 10, "length": None})
+
+ pta = PTA(parameters=["txpower", "length"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state("TX", power=100)
+ pta.add_transition(
+ "UNINITIALIZED", "IDLE", "init", energy=500000, duration=50000
+ )
+ pta.add_transition(
+ "IDLE",
+ "IDLE",
+ "setTxPower",
+ energy=10000,
+ duration=120,
+ param_update_function=lambda param, arg: {**param, "txpower": arg[0]},
+ )
+ pta.add_transition(
+ "IDLE",
+ "TX",
+ "send",
+ energy=3,
+ duration=10,
+ energy_function=lambda param, arg: 3 + 5 * arg[1],
+ duration_function=lambda param, arg: 48 + 8 * arg[1],
+ )
+ pta.add_transition("TX", "IDLE", "txComplete", timeout=2000, is_interrupt=True)
trace = [
- ['init'],
- ['setTxPower', 10],
- ['send', 'foobar', 6],
+ ["init"],
+ ["setTxPower", 10],
+ ["send", "foobar", 6],
]
expected_energy = 500000 + 10000 + (3 + 5 * 6) + (2000 * 100)
expected_duration = 50000 + 120 + (48 + 8 * 6) + 2000
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': 10,
- 'length': None
- })
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": 10, "length": None})
def test_simulation_param_function(self):
- pta = PTA(parameters=['length', 'txpower'])
- pta.add_state('IDLE', power=5)
- pta.add_state('TX', power=100,
- power_function=lambda param, arg: 1000 + 2 * param[1])
- pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy=500000, duration=50000)
- pta.add_transition('IDLE', 'IDLE', 'setTxPower', energy=10000, duration=120,
- param_update_function=lambda param, arg: {**param, 'txpower': arg[0]})
- pta.add_transition('IDLE', 'TX', 'send', energy=3, duration=10,
- energy_function=lambda param, arg: 3 + 5 * arg[1],
- param_update_function=lambda param, arg: {**param, 'length': arg[1]})
- pta.add_transition('TX', 'IDLE', 'txComplete', timeout=2000, is_interrupt=True,
- timeout_function=lambda param, arg: 500 + 16 * param[0])
+ pta = PTA(parameters=["length", "txpower"])
+ pta.add_state("IDLE", power=5)
+ pta.add_state(
+ "TX", power=100, power_function=lambda param, arg: 1000 + 2 * param[1]
+ )
+ pta.add_transition(
+ "UNINITIALIZED", "IDLE", "init", energy=500000, duration=50000
+ )
+ pta.add_transition(
+ "IDLE",
+ "IDLE",
+ "setTxPower",
+ energy=10000,
+ duration=120,
+ param_update_function=lambda param, arg: {**param, "txpower": arg[0]},
+ )
+ pta.add_transition(
+ "IDLE",
+ "TX",
+ "send",
+ energy=3,
+ duration=10,
+ energy_function=lambda param, arg: 3 + 5 * arg[1],
+ param_update_function=lambda param, arg: {**param, "length": arg[1]},
+ )
+ pta.add_transition(
+ "TX",
+ "IDLE",
+ "txComplete",
+ timeout=2000,
+ is_interrupt=True,
+ timeout_function=lambda param, arg: 500 + 16 * param[0],
+ )
trace = [
- ['init'],
- ['setTxPower', 10],
- ['send', 'foo', 3],
+ ["init"],
+ ["setTxPower", 10],
+ ["send", "foo", 3],
]
- expected_energy = 500000 + 10000 + (3 + 5 * 3) + (1000 + 2 * 10) * (500 + 16 * 3)
+ expected_energy = (
+ 500000 + 10000 + (3 + 5 * 3) + (1000 + 2 * 10) * (500 + 16 * 3)
+ )
expected_duration = 50000 + 120 + 10 + (500 + 16 * 3)
result = pta.simulate(trace)
self.assertAlmostEqual(result.energy, expected_energy * 1e-12, places=12)
self.assertAlmostEqual(result.duration, expected_duration * 1e-6, places=6)
- self.assertEqual(result.end_state.name, 'IDLE')
- self.assertEqual(result.parameters, {
- 'txpower': 10,
- 'length': 3
- })
+ self.assertEqual(result.end_state.name, "IDLE")
+ self.assertEqual(result.parameters, {"txpower": 10, "length": 3})
def test_get_X_expensive_state(self):
pta = PTA.from_json(example_json_1)
- self.assertEqual(pta.get_least_expensive_state(), pta.state['IDLE'])
- self.assertEqual(pta.get_most_expensive_state(), pta.state['TX'])
+ self.assertEqual(pta.get_least_expensive_state(), pta.state["IDLE"])
+ self.assertEqual(pta.get_most_expensive_state(), pta.state["TX"])
# self.assertAlmostEqual(pta.min_duration_until_energy_overflow(), (2**32 - 1) * 1e-12 / 10e-3, places=9)
# self.assertAlmostEqual(pta.min_duration_until_energy_overflow(energy_granularity=1e-9), (2**32 - 1) * 1e-9 / 10e-3, places=9)
- self.assertAlmostEqual(pta.max_duration_until_energy_overflow(), (2**32 - 1) * 1e-12 / 5e-6, places=9)
- self.assertAlmostEqual(pta.max_duration_until_energy_overflow(energy_granularity=1e-9), (2**32 - 1) * 1e-9 / 5e-6, places=9)
+ self.assertAlmostEqual(
+ pta.max_duration_until_energy_overflow(),
+ (2 ** 32 - 1) * 1e-12 / 5e-6,
+ places=9,
+ )
+ self.assertAlmostEqual(
+ pta.max_duration_until_energy_overflow(energy_granularity=1e-9),
+ (2 ** 32 - 1) * 1e-9 / 5e-6,
+ places=9,
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/test/test_ptamodel.py b/test/test_ptamodel.py
index 7e398bd..3237450 100755
--- a/test/test_ptamodel.py
+++ b/test/test_ptamodel.py
@@ -8,241 +8,384 @@ import pytest
class TestModels(unittest.TestCase):
def test_model_singlefile_rf24(self):
- raw_data = RawData(['test-data/20170220_164723_RF24_int_A.tar'])
+ raw_data = RawData(["test-data/20170220_164723_RF24_int_A.tar"])
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = PTAModel(by_name, parameters, arg_count)
- self.assertEqual(model.states(), 'POWERDOWN RX STANDBY1 TX'.split(' '))
- self.assertEqual(model.transitions(), 'begin epilogue powerDown powerUp setDataRate_num setPALevel_num startListening stopListening write_nb'.split(' '))
+ self.assertEqual(model.states(), "POWERDOWN RX STANDBY1 TX".split(" "))
+ self.assertEqual(
+ model.transitions(),
+ "begin epilogue powerDown powerUp setDataRate_num setPALevel_num startListening stopListening write_nb".split(
+ " "
+ ),
+ )
static_model = model.get_static()
- self.assertAlmostEqual(static_model('POWERDOWN', 'power'), 0, places=0)
- self.assertAlmostEqual(static_model('RX', 'power'), 52254, places=0)
- self.assertAlmostEqual(static_model('STANDBY1', 'power'), 7, places=0)
- self.assertAlmostEqual(static_model('TX', 'power'), 18414, places=0)
- self.assertAlmostEqual(static_model('begin', 'energy'), 1652249, places=0)
- self.assertAlmostEqual(static_model('epilogue', 'energy'), 15449, places=0)
- self.assertAlmostEqual(static_model('powerDown', 'energy'), 4547, places=0)
- self.assertAlmostEqual(static_model('powerUp', 'energy'), 1641765, places=0)
- self.assertAlmostEqual(static_model('setDataRate_num', 'energy'), 7749, places=0)
- self.assertAlmostEqual(static_model('setPALevel_num', 'energy'), 4700, places=0)
- self.assertAlmostEqual(static_model('startListening', 'energy'), 4309602, places=0)
- self.assertAlmostEqual(static_model('stopListening', 'energy'), 193775, places=0)
- self.assertAlmostEqual(static_model('write_nb', 'energy'), 218339, places=0)
- self.assertAlmostEqual(static_model('begin', 'rel_energy_prev'), 1649571, places=0)
- self.assertAlmostEqual(static_model('epilogue', 'rel_energy_prev'), -744114, places=0)
- self.assertAlmostEqual(static_model('powerDown', 'rel_energy_prev'), 3854, places=0)
- self.assertAlmostEqual(static_model('powerUp', 'rel_energy_prev'), 1641381, places=0)
- self.assertAlmostEqual(static_model('setDataRate_num', 'rel_energy_prev'), 6777, places=0)
- self.assertAlmostEqual(static_model('setPALevel_num', 'rel_energy_prev'), 3728, places=0)
- self.assertAlmostEqual(static_model('startListening', 'rel_energy_prev'), 4307769, places=0)
- self.assertAlmostEqual(static_model('stopListening', 'rel_energy_prev'), -13533693, places=0)
- self.assertAlmostEqual(static_model('write_nb', 'rel_energy_prev'), 214618, places=0)
- self.assertAlmostEqual(static_model('begin', 'duration'), 19830, places=0)
- self.assertAlmostEqual(static_model('epilogue', 'duration'), 40, places=0)
- self.assertAlmostEqual(static_model('powerDown', 'duration'), 90, places=0)
- self.assertAlmostEqual(static_model('powerUp', 'duration'), 10030, places=0)
- self.assertAlmostEqual(static_model('setDataRate_num', 'duration'), 140, places=0)
- self.assertAlmostEqual(static_model('setPALevel_num', 'duration'), 90, places=0)
- self.assertAlmostEqual(static_model('startListening', 'duration'), 260, places=0)
- self.assertAlmostEqual(static_model('stopListening', 'duration'), 260, places=0)
- self.assertAlmostEqual(static_model('write_nb', 'duration'), 510, places=0)
-
- self.assertAlmostEqual(model.stats.param_dependence_ratio('POWERDOWN', 'power', 'datarate'), 0, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('POWERDOWN', 'power', 'txbytes'), 0, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('POWERDOWN', 'power', 'txpower'), 0, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('RX', 'power', 'datarate'), 0.99, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('RX', 'power', 'txbytes'), 0, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('RX', 'power', 'txpower'), 0.01, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('STANDBY1', 'power', 'datarate'), 0.04, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('STANDBY1', 'power', 'txbytes'), 0.35, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('STANDBY1', 'power', 'txpower'), 0.32, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('TX', 'power', 'datarate'), 1, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('TX', 'power', 'txbytes'), 0.09, places=2)
- self.assertAlmostEqual(model.stats.param_dependence_ratio('TX', 'power', 'txpower'), 1, places=2)
+ self.assertAlmostEqual(static_model("POWERDOWN", "power"), 0, places=0)
+ self.assertAlmostEqual(static_model("RX", "power"), 52254, places=0)
+ self.assertAlmostEqual(static_model("STANDBY1", "power"), 7, places=0)
+ self.assertAlmostEqual(static_model("TX", "power"), 18414, places=0)
+ self.assertAlmostEqual(static_model("begin", "energy"), 1652249, places=0)
+ self.assertAlmostEqual(static_model("epilogue", "energy"), 15449, places=0)
+ self.assertAlmostEqual(static_model("powerDown", "energy"), 4547, places=0)
+ self.assertAlmostEqual(static_model("powerUp", "energy"), 1641765, places=0)
+ self.assertAlmostEqual(
+ static_model("setDataRate_num", "energy"), 7749, places=0
+ )
+ self.assertAlmostEqual(static_model("setPALevel_num", "energy"), 4700, places=0)
+ self.assertAlmostEqual(
+ static_model("startListening", "energy"), 4309602, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("stopListening", "energy"), 193775, places=0
+ )
+ self.assertAlmostEqual(static_model("write_nb", "energy"), 218339, places=0)
+ self.assertAlmostEqual(
+ static_model("begin", "rel_energy_prev"), 1649571, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("epilogue", "rel_energy_prev"), -744114, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("powerDown", "rel_energy_prev"), 3854, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("powerUp", "rel_energy_prev"), 1641381, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("setDataRate_num", "rel_energy_prev"), 6777, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("setPALevel_num", "rel_energy_prev"), 3728, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("startListening", "rel_energy_prev"), 4307769, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("stopListening", "rel_energy_prev"), -13533693, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("write_nb", "rel_energy_prev"), 214618, places=0
+ )
+ self.assertAlmostEqual(static_model("begin", "duration"), 19830, places=0)
+ self.assertAlmostEqual(static_model("epilogue", "duration"), 40, places=0)
+ self.assertAlmostEqual(static_model("powerDown", "duration"), 90, places=0)
+ self.assertAlmostEqual(static_model("powerUp", "duration"), 10030, places=0)
+ self.assertAlmostEqual(
+ static_model("setDataRate_num", "duration"), 140, places=0
+ )
+ self.assertAlmostEqual(static_model("setPALevel_num", "duration"), 90, places=0)
+ self.assertAlmostEqual(
+ static_model("startListening", "duration"), 260, places=0
+ )
+ self.assertAlmostEqual(static_model("stopListening", "duration"), 260, places=0)
+ self.assertAlmostEqual(static_model("write_nb", "duration"), 510, places=0)
+
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("POWERDOWN", "power", "datarate"),
+ 0,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("POWERDOWN", "power", "txbytes"),
+ 0,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("POWERDOWN", "power", "txpower"),
+ 0,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("RX", "power", "datarate"),
+ 0.99,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("RX", "power", "txbytes"), 0, places=2
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("RX", "power", "txpower"), 0.01, places=2
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("STANDBY1", "power", "datarate"),
+ 0.04,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("STANDBY1", "power", "txbytes"),
+ 0.35,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("STANDBY1", "power", "txpower"),
+ 0.32,
+ places=2,
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("TX", "power", "datarate"), 1, places=2
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("TX", "power", "txbytes"), 0.09, places=2
+ )
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio("TX", "power", "txpower"), 1, places=2
+ )
param_model, param_info = model.get_fitted()
- self.assertEqual(param_info('POWERDOWN', 'power'), None)
- self.assertEqual(param_info('RX', 'power')['function']._model_str,
- '0 + regression_arg(0) + regression_arg(1) * np.sqrt(parameter(datarate))')
- self.assertAlmostEqual(param_info('RX', 'power')['function']._regression_args[0], 48530.7, places=0)
- self.assertAlmostEqual(param_info('RX', 'power')['function']._regression_args[1], 117, places=0)
- self.assertEqual(param_info('STANDBY1', 'power'), None)
- self.assertEqual(param_info('TX', 'power')['function']._model_str,
- '0 + regression_arg(0) + regression_arg(1) * 1/(parameter(datarate)) + regression_arg(2) * parameter(txpower) + regression_arg(3) * 1/(parameter(datarate)) * parameter(txpower)')
- self.assertEqual(param_info('epilogue', 'timeout')['function']._model_str,
- '0 + regression_arg(0) + regression_arg(1) * 1/(parameter(datarate))')
- self.assertEqual(param_info('stopListening', 'duration')['function']._model_str,
- '0 + regression_arg(0) + regression_arg(1) * 1/(parameter(datarate))')
-
- self.assertAlmostEqual(param_model('RX', 'power', param=[1, None, None]), 48647, places=-1)
+ self.assertEqual(param_info("POWERDOWN", "power"), None)
+ self.assertEqual(
+ param_info("RX", "power")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * np.sqrt(parameter(datarate))",
+ )
+ self.assertAlmostEqual(
+ param_info("RX", "power")["function"]._regression_args[0], 48530.7, places=0
+ )
+ self.assertAlmostEqual(
+ param_info("RX", "power")["function"]._regression_args[1], 117, places=0
+ )
+ self.assertEqual(param_info("STANDBY1", "power"), None)
+ self.assertEqual(
+ param_info("TX", "power")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * 1/(parameter(datarate)) + regression_arg(2) * parameter(txpower) + regression_arg(3) * 1/(parameter(datarate)) * parameter(txpower)",
+ )
+ self.assertEqual(
+ param_info("epilogue", "timeout")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * 1/(parameter(datarate))",
+ )
+ self.assertEqual(
+ param_info("stopListening", "duration")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * 1/(parameter(datarate))",
+ )
+
+ self.assertAlmostEqual(
+ param_model("RX", "power", param=[1, None, None]), 48647, places=-1
+ )
def test_model_singlefile_mmparam(self):
- raw_data = RawData(['test-data/20161221_123347_mmparam.tar'])
+ raw_data = RawData(["test-data/20161221_123347_mmparam.tar"])
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = PTAModel(by_name, parameters, arg_count)
- self.assertEqual(model.states(), 'OFF ON'.split(' '))
- self.assertEqual(model.transitions(), 'off setBrightness'.split(' '))
+ self.assertEqual(model.states(), "OFF ON".split(" "))
+ self.assertEqual(model.transitions(), "off setBrightness".split(" "))
static_model = model.get_static()
- self.assertAlmostEqual(static_model('OFF', 'power'), 7124, places=0)
- self.assertAlmostEqual(static_model('ON', 'power'), 17866, places=0)
- self.assertAlmostEqual(static_model('off', 'energy'), 268079197, places=0)
- self.assertAlmostEqual(static_model('setBrightness', 'energy'), 168912773, places=0)
- self.assertAlmostEqual(static_model('off', 'rel_energy_prev'), 105040198, places=0)
- self.assertAlmostEqual(static_model('setBrightness', 'rel_energy_prev'), 103745586, places=0)
- self.assertAlmostEqual(static_model('off', 'duration'), 9130, places=0)
- self.assertAlmostEqual(static_model('setBrightness', 'duration'), 9130, places=0)
+ self.assertAlmostEqual(static_model("OFF", "power"), 7124, places=0)
+ self.assertAlmostEqual(static_model("ON", "power"), 17866, places=0)
+ self.assertAlmostEqual(static_model("off", "energy"), 268079197, places=0)
+ self.assertAlmostEqual(
+ static_model("setBrightness", "energy"), 168912773, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("off", "rel_energy_prev"), 105040198, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("setBrightness", "rel_energy_prev"), 103745586, places=0
+ )
+ self.assertAlmostEqual(static_model("off", "duration"), 9130, places=0)
+ self.assertAlmostEqual(
+ static_model("setBrightness", "duration"), 9130, places=0
+ )
param_lut_model = model.get_param_lut()
- self.assertAlmostEqual(param_lut_model('OFF', 'power', param=[None, None]), 7124, places=0)
+ self.assertAlmostEqual(
+ param_lut_model("OFF", "power", param=[None, None]), 7124, places=0
+ )
with self.assertRaises(KeyError):
- param_lut_model('ON', 'power', param=[None, None])
- param_lut_model('ON', 'power', param=['a'])
- param_lut_model('ON', 'power', param=[0])
- self.assertTrue(param_lut_model('ON', 'power', param=[0, 0]))
+ param_lut_model("ON", "power", param=[None, None])
+ param_lut_model("ON", "power", param=["a"])
+ param_lut_model("ON", "power", param=[0])
+ self.assertTrue(param_lut_model("ON", "power", param=[0, 0]))
param_lut_model = model.get_param_lut(fallback=True)
- self.assertAlmostEqual(param_lut_model('ON', 'power', param=[None, None]), 17866, places=0)
+ self.assertAlmostEqual(
+ param_lut_model("ON", "power", param=[None, None]), 17866, places=0
+ )
def test_model_multifile_lm75x(self):
testfiles = [
- 'test-data/20170116_124500_LM75x.tar',
- 'test-data/20170116_131306_LM75x.tar',
+ "test-data/20170116_124500_LM75x.tar",
+ "test-data/20170116_131306_LM75x.tar",
]
raw_data = RawData(testfiles)
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = PTAModel(by_name, parameters, arg_count)
- self.assertEqual(model.states(), 'ACTIVE POWEROFF'.split(' '))
- self.assertEqual(model.transitions(), 'getTemp setHyst setOS shutdown start'.split(' '))
+ self.assertEqual(model.states(), "ACTIVE POWEROFF".split(" "))
+ self.assertEqual(
+ model.transitions(), "getTemp setHyst setOS shutdown start".split(" ")
+ )
static_model = model.get_static()
- self.assertAlmostEqual(static_model('ACTIVE', 'power'), 332, places=0)
- self.assertAlmostEqual(static_model('POWEROFF', 'power'), 7, places=0)
- self.assertAlmostEqual(static_model('getTemp', 'energy'), 26016748, places=0)
- self.assertAlmostEqual(static_model('setHyst', 'energy'), 22082226, places=0)
- self.assertAlmostEqual(static_model('setOS', 'energy'), 21774238, places=0)
- self.assertAlmostEqual(static_model('shutdown', 'energy'), 11808160, places=0)
- self.assertAlmostEqual(static_model('start', 'energy'), 12445302, places=0)
- self.assertAlmostEqual(static_model('getTemp', 'rel_energy_prev'), 21722720, places=0)
- self.assertAlmostEqual(static_model('setHyst', 'rel_energy_prev'), 19001499, places=0)
- self.assertAlmostEqual(static_model('setOS', 'rel_energy_prev'), 18693283, places=0)
- self.assertAlmostEqual(static_model('shutdown', 'rel_energy_prev'), 11746224, places=0)
- self.assertAlmostEqual(static_model('start', 'rel_energy_prev'), 12391462, places=0)
- self.assertAlmostEqual(static_model('getTemp', 'duration'), 12740, places=0)
- self.assertAlmostEqual(static_model('setHyst', 'duration'), 9140, places=0)
- self.assertAlmostEqual(static_model('setOS', 'duration'), 9140, places=0)
- self.assertAlmostEqual(static_model('shutdown', 'duration'), 6980, places=0)
- self.assertAlmostEqual(static_model('start', 'duration'), 6980, places=0)
+ self.assertAlmostEqual(static_model("ACTIVE", "power"), 332, places=0)
+ self.assertAlmostEqual(static_model("POWEROFF", "power"), 7, places=0)
+ self.assertAlmostEqual(static_model("getTemp", "energy"), 26016748, places=0)
+ self.assertAlmostEqual(static_model("setHyst", "energy"), 22082226, places=0)
+ self.assertAlmostEqual(static_model("setOS", "energy"), 21774238, places=0)
+ self.assertAlmostEqual(static_model("shutdown", "energy"), 11808160, places=0)
+ self.assertAlmostEqual(static_model("start", "energy"), 12445302, places=0)
+ self.assertAlmostEqual(
+ static_model("getTemp", "rel_energy_prev"), 21722720, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("setHyst", "rel_energy_prev"), 19001499, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("setOS", "rel_energy_prev"), 18693283, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("shutdown", "rel_energy_prev"), 11746224, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("start", "rel_energy_prev"), 12391462, places=0
+ )
+ self.assertAlmostEqual(static_model("getTemp", "duration"), 12740, places=0)
+ self.assertAlmostEqual(static_model("setHyst", "duration"), 9140, places=0)
+ self.assertAlmostEqual(static_model("setOS", "duration"), 9140, places=0)
+ self.assertAlmostEqual(static_model("shutdown", "duration"), 6980, places=0)
+ self.assertAlmostEqual(static_model("start", "duration"), 6980, places=0)
def test_model_multifile_sharp(self):
testfiles = [
- 'test-data/20170116_145420_sharpLS013B4DN.tar',
- 'test-data/20170116_151348_sharpLS013B4DN.tar',
+ "test-data/20170116_145420_sharpLS013B4DN.tar",
+ "test-data/20170116_151348_sharpLS013B4DN.tar",
]
raw_data = RawData(testfiles)
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = PTAModel(by_name, parameters, arg_count)
- self.assertEqual(model.states(), 'DISABLED ENABLED'.split(' '))
- self.assertEqual(model.transitions(), 'clear disable enable ioInit sendLine toggleVCOM'.split(' '))
+ self.assertEqual(model.states(), "DISABLED ENABLED".split(" "))
+ self.assertEqual(
+ model.transitions(),
+ "clear disable enable ioInit sendLine toggleVCOM".split(" "),
+ )
static_model = model.get_static()
- self.assertAlmostEqual(static_model('DISABLED', 'power'), 22, places=0)
- self.assertAlmostEqual(static_model('ENABLED', 'power'), 24, places=0)
- self.assertAlmostEqual(static_model('clear', 'energy'), 14059, places=0)
- self.assertAlmostEqual(static_model('disable', 'energy'), 0, places=0)
- self.assertAlmostEqual(static_model('enable', 'energy'), 0, places=0)
- self.assertAlmostEqual(static_model('ioInit', 'energy'), 0, places=0)
- self.assertAlmostEqual(static_model('sendLine', 'energy'), 37874, places=0)
- self.assertAlmostEqual(static_model('toggleVCOM', 'energy'), 30991, places=0)
- self.assertAlmostEqual(static_model('clear', 'rel_energy_prev'), 13329, places=0)
- self.assertAlmostEqual(static_model('disable', 'rel_energy_prev'), 0, places=0)
- self.assertAlmostEqual(static_model('enable', 'rel_energy_prev'), 0, places=0)
- self.assertAlmostEqual(static_model('ioInit', 'rel_energy_prev'), 0, places=0)
- self.assertAlmostEqual(static_model('sendLine', 'rel_energy_prev'), 33447, places=0)
- self.assertAlmostEqual(static_model('toggleVCOM', 'rel_energy_prev'), 30242, places=0)
- self.assertAlmostEqual(static_model('clear', 'duration'), 30, places=0)
- self.assertAlmostEqual(static_model('disable', 'duration'), 0, places=0)
- self.assertAlmostEqual(static_model('enable', 'duration'), 0, places=0)
- self.assertAlmostEqual(static_model('ioInit', 'duration'), 0, places=0)
- self.assertAlmostEqual(static_model('sendLine', 'duration'), 180, places=0)
- self.assertAlmostEqual(static_model('toggleVCOM', 'duration'), 30, places=0)
+ self.assertAlmostEqual(static_model("DISABLED", "power"), 22, places=0)
+ self.assertAlmostEqual(static_model("ENABLED", "power"), 24, places=0)
+ self.assertAlmostEqual(static_model("clear", "energy"), 14059, places=0)
+ self.assertAlmostEqual(static_model("disable", "energy"), 0, places=0)
+ self.assertAlmostEqual(static_model("enable", "energy"), 0, places=0)
+ self.assertAlmostEqual(static_model("ioInit", "energy"), 0, places=0)
+ self.assertAlmostEqual(static_model("sendLine", "energy"), 37874, places=0)
+ self.assertAlmostEqual(static_model("toggleVCOM", "energy"), 30991, places=0)
+ self.assertAlmostEqual(
+ static_model("clear", "rel_energy_prev"), 13329, places=0
+ )
+ self.assertAlmostEqual(static_model("disable", "rel_energy_prev"), 0, places=0)
+ self.assertAlmostEqual(static_model("enable", "rel_energy_prev"), 0, places=0)
+ self.assertAlmostEqual(static_model("ioInit", "rel_energy_prev"), 0, places=0)
+ self.assertAlmostEqual(
+ static_model("sendLine", "rel_energy_prev"), 33447, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("toggleVCOM", "rel_energy_prev"), 30242, places=0
+ )
+ self.assertAlmostEqual(static_model("clear", "duration"), 30, places=0)
+ self.assertAlmostEqual(static_model("disable", "duration"), 0, places=0)
+ self.assertAlmostEqual(static_model("enable", "duration"), 0, places=0)
+ self.assertAlmostEqual(static_model("ioInit", "duration"), 0, places=0)
+ self.assertAlmostEqual(static_model("sendLine", "duration"), 180, places=0)
+ self.assertAlmostEqual(static_model("toggleVCOM", "duration"), 30, places=0)
def test_model_multifile_mmstatic(self):
testfiles = [
- 'test-data/20170116_143516_mmstatic.tar',
- 'test-data/20170116_142654_mmstatic.tar',
+ "test-data/20170116_143516_mmstatic.tar",
+ "test-data/20170116_142654_mmstatic.tar",
]
raw_data = RawData(testfiles)
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = PTAModel(by_name, parameters, arg_count)
- self.assertEqual(model.states(), 'B G OFF R'.split(' '))
- self.assertEqual(model.transitions(), 'blue green off red'.split(' '))
+ self.assertEqual(model.states(), "B G OFF R".split(" "))
+ self.assertEqual(model.transitions(), "blue green off red".split(" "))
static_model = model.get_static()
- self.assertAlmostEqual(static_model('B', 'power'), 29443, places=0)
- self.assertAlmostEqual(static_model('G', 'power'), 29432, places=0)
- self.assertAlmostEqual(static_model('OFF', 'power'), 7057, places=0)
- self.assertAlmostEqual(static_model('R', 'power'), 49068, places=0)
- self.assertAlmostEqual(static_model('blue', 'energy'), 374440955, places=0)
- self.assertAlmostEqual(static_model('green', 'energy'), 372026027, places=0)
- self.assertAlmostEqual(static_model('off', 'energy'), 372999554, places=0)
- self.assertAlmostEqual(static_model('red', 'energy'), 378936634, places=0)
- self.assertAlmostEqual(static_model('blue', 'rel_energy_prev'), 105535587, places=0)
- self.assertAlmostEqual(static_model('green', 'rel_energy_prev'), 102999371, places=0)
- self.assertAlmostEqual(static_model('off', 'rel_energy_prev'), 103613698, places=0)
- self.assertAlmostEqual(static_model('red', 'rel_energy_prev'), 110474331, places=0)
- self.assertAlmostEqual(static_model('blue', 'duration'), 9140, places=0)
- self.assertAlmostEqual(static_model('green', 'duration'), 9140, places=0)
- self.assertAlmostEqual(static_model('off', 'duration'), 9140, places=0)
- self.assertAlmostEqual(static_model('red', 'duration'), 9140, places=0)
-
- @pytest.mark.skipif('TEST_SLOW' not in os.environ, reason="slow test, set TEST_SLOW=1 to run")
+ self.assertAlmostEqual(static_model("B", "power"), 29443, places=0)
+ self.assertAlmostEqual(static_model("G", "power"), 29432, places=0)
+ self.assertAlmostEqual(static_model("OFF", "power"), 7057, places=0)
+ self.assertAlmostEqual(static_model("R", "power"), 49068, places=0)
+ self.assertAlmostEqual(static_model("blue", "energy"), 374440955, places=0)
+ self.assertAlmostEqual(static_model("green", "energy"), 372026027, places=0)
+ self.assertAlmostEqual(static_model("off", "energy"), 372999554, places=0)
+ self.assertAlmostEqual(static_model("red", "energy"), 378936634, places=0)
+ self.assertAlmostEqual(
+ static_model("blue", "rel_energy_prev"), 105535587, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("green", "rel_energy_prev"), 102999371, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("off", "rel_energy_prev"), 103613698, places=0
+ )
+ self.assertAlmostEqual(
+ static_model("red", "rel_energy_prev"), 110474331, places=0
+ )
+ self.assertAlmostEqual(static_model("blue", "duration"), 9140, places=0)
+ self.assertAlmostEqual(static_model("green", "duration"), 9140, places=0)
+ self.assertAlmostEqual(static_model("off", "duration"), 9140, places=0)
+ self.assertAlmostEqual(static_model("red", "duration"), 9140, places=0)
+
+ @pytest.mark.skipif(
+ "TEST_SLOW" not in os.environ, reason="slow test, set TEST_SLOW=1 to run"
+ )
def test_model_multifile_cc1200(self):
testfiles = [
- 'test-data/20170125_125433_cc1200.tar',
- 'test-data/20170125_142420_cc1200.tar',
- 'test-data/20170125_144957_cc1200.tar',
- 'test-data/20170125_151149_cc1200.tar',
- 'test-data/20170125_151824_cc1200.tar',
- 'test-data/20170125_154019_cc1200.tar',
+ "test-data/20170125_125433_cc1200.tar",
+ "test-data/20170125_142420_cc1200.tar",
+ "test-data/20170125_144957_cc1200.tar",
+ "test-data/20170125_151149_cc1200.tar",
+ "test-data/20170125_151824_cc1200.tar",
+ "test-data/20170125_154019_cc1200.tar",
]
raw_data = RawData(testfiles)
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = PTAModel(by_name, parameters, arg_count)
- self.assertEqual(model.states(), 'IDLE RX SLEEP SLEEP_EWOR SYNTH_ON TX XOFF'.split(' '))
- self.assertEqual(model.transitions(), 'crystal_off eWOR idle init prepare_xmit receive send setSymbolRate setTxPower sleep txDone'.split(' '))
+ self.assertEqual(
+ model.states(), "IDLE RX SLEEP SLEEP_EWOR SYNTH_ON TX XOFF".split(" ")
+ )
+ self.assertEqual(
+ model.transitions(),
+ "crystal_off eWOR idle init prepare_xmit receive send setSymbolRate setTxPower sleep txDone".split(
+ " "
+ ),
+ )
static_model = model.get_static()
- self.assertAlmostEqual(static_model('IDLE', 'power'), 9500, places=0)
- self.assertAlmostEqual(static_model('RX', 'power'), 85177, places=0)
- self.assertAlmostEqual(static_model('SLEEP', 'power'), 143, places=0)
- self.assertAlmostEqual(static_model('SLEEP_EWOR', 'power'), 81801, places=0)
- self.assertAlmostEqual(static_model('SYNTH_ON', 'power'), 60036, places=0)
- self.assertAlmostEqual(static_model('TX', 'power'), 92461, places=0)
- self.assertAlmostEqual(static_model('XOFF', 'power'), 780, places=0)
- self.assertAlmostEqual(static_model('crystal_off', 'energy'), 114658, places=0)
- self.assertAlmostEqual(static_model('eWOR', 'energy'), 317556, places=0)
- self.assertAlmostEqual(static_model('idle', 'energy'), 717713, places=0)
- self.assertAlmostEqual(static_model('init', 'energy'), 23028941, places=0)
- self.assertAlmostEqual(static_model('prepare_xmit', 'energy'), 378552, places=0)
- self.assertAlmostEqual(static_model('receive', 'energy'), 380335, places=0)
- self.assertAlmostEqual(static_model('send', 'energy'), 4282597, places=0)
- self.assertAlmostEqual(static_model('setSymbolRate', 'energy'), 962060, places=0)
- self.assertAlmostEqual(static_model('setTxPower', 'energy'), 288701, places=0)
- self.assertAlmostEqual(static_model('sleep', 'energy'), 104445, places=0)
- self.assertEqual(static_model('txDone', 'energy'), 0)
+ self.assertAlmostEqual(static_model("IDLE", "power"), 9500, places=0)
+ self.assertAlmostEqual(static_model("RX", "power"), 85177, places=0)
+ self.assertAlmostEqual(static_model("SLEEP", "power"), 143, places=0)
+ self.assertAlmostEqual(static_model("SLEEP_EWOR", "power"), 81801, places=0)
+ self.assertAlmostEqual(static_model("SYNTH_ON", "power"), 60036, places=0)
+ self.assertAlmostEqual(static_model("TX", "power"), 92461, places=0)
+ self.assertAlmostEqual(static_model("XOFF", "power"), 780, places=0)
+ self.assertAlmostEqual(static_model("crystal_off", "energy"), 114658, places=0)
+ self.assertAlmostEqual(static_model("eWOR", "energy"), 317556, places=0)
+ self.assertAlmostEqual(static_model("idle", "energy"), 717713, places=0)
+ self.assertAlmostEqual(static_model("init", "energy"), 23028941, places=0)
+ self.assertAlmostEqual(static_model("prepare_xmit", "energy"), 378552, places=0)
+ self.assertAlmostEqual(static_model("receive", "energy"), 380335, places=0)
+ self.assertAlmostEqual(static_model("send", "energy"), 4282597, places=0)
+ self.assertAlmostEqual(
+ static_model("setSymbolRate", "energy"), 962060, places=0
+ )
+ self.assertAlmostEqual(static_model("setTxPower", "energy"), 288701, places=0)
+ self.assertAlmostEqual(static_model("sleep", "energy"), 104445, places=0)
+ self.assertEqual(static_model("txDone", "energy"), 0)
param_model, param_info = model.get_fitted()
- self.assertEqual(param_info('IDLE', 'power'), None)
- self.assertEqual(param_info('RX', 'power')['function']._model_str,
- '0 + regression_arg(0) + regression_arg(1) * np.log(parameter(symbolrate) + 1)')
- self.assertEqual(param_info('SLEEP', 'power'), None)
- self.assertEqual(param_info('SLEEP_EWOR', 'power'), None)
- self.assertEqual(param_info('SYNTH_ON', 'power'), None)
- self.assertEqual(param_info('XOFF', 'power'), None)
+ self.assertEqual(param_info("IDLE", "power"), None)
+ self.assertEqual(
+ param_info("RX", "power")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * np.log(parameter(symbolrate) + 1)",
+ )
+ self.assertEqual(param_info("SLEEP", "power"), None)
+ self.assertEqual(param_info("SLEEP_EWOR", "power"), None)
+ self.assertEqual(param_info("SYNTH_ON", "power"), None)
+ self.assertEqual(param_info("XOFF", "power"), None)
- self.assertAlmostEqual(param_info('RX', 'power')['function']._regression_args[0], 84415, places=0)
- self.assertAlmostEqual(param_info('RX', 'power')['function']._regression_args[1], 206, places=0)
+ self.assertAlmostEqual(
+ param_info("RX", "power")["function"]._regression_args[0], 84415, places=0
+ )
+ self.assertAlmostEqual(
+ param_info("RX", "power")["function"]._regression_args[1], 206, places=0
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/test/test_timingharness.py b/test/test_timingharness.py
index 9c49b46..29e21f8 100755
--- a/test/test_timingharness.py
+++ b/test/test_timingharness.py
@@ -7,89 +7,164 @@ import unittest
class TestModels(unittest.TestCase):
def test_model_singlefile_rf24(self):
- raw_data = TimingData(['test-data/20190815_111745_nRF24_no-rx.json'])
+ raw_data = TimingData(["test-data/20190815_111745_nRF24_no-rx.json"])
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
model = AnalyticModel(by_name, parameters, arg_count)
- self.assertEqual(model.names, 'setPALevel setRetries setup write'.split(' '))
+ self.assertEqual(model.names, "setPALevel setRetries setup write".split(" "))
static_model = model.get_static()
- self.assertAlmostEqual(static_model('setPALevel', 'duration'), 146, places=0)
- self.assertAlmostEqual(static_model('setRetries', 'duration'), 73, places=0)
- self.assertAlmostEqual(static_model('setup', 'duration'), 6533, places=0)
- self.assertAlmostEqual(static_model('write', 'duration'), 12634, places=0)
-
- for transition in 'setPALevel setRetries setup write'.split(' '):
- self.assertAlmostEqual(model.stats.param_dependence_ratio(transition, 'duration', 'channel'), 0, places=2)
+ self.assertAlmostEqual(static_model("setPALevel", "duration"), 146, places=0)
+ self.assertAlmostEqual(static_model("setRetries", "duration"), 73, places=0)
+ self.assertAlmostEqual(static_model("setup", "duration"), 6533, places=0)
+ self.assertAlmostEqual(static_model("write", "duration"), 12634, places=0)
+
+ for transition in "setPALevel setRetries setup write".split(" "):
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio(transition, "duration", "channel"),
+ 0,
+ places=2,
+ )
param_model, param_info = model.get_fitted()
- self.assertEqual(param_info('setPALevel', 'duration'), None)
- self.assertEqual(param_info('setRetries', 'duration'), None)
- self.assertEqual(param_info('setup', 'duration'), None)
- self.assertEqual(param_info('write', 'duration')['function']._model_str, '0 + regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay)')
-
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[0], 1163, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[1], 464, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[2], 1, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[3], 1, places=0)
+ self.assertEqual(param_info("setPALevel", "duration"), None)
+ self.assertEqual(param_info("setRetries", "duration"), None)
+ self.assertEqual(param_info("setup", "duration"), None)
+ self.assertEqual(
+ param_info("write", "duration")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay)",
+ )
+
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[0],
+ 1163,
+ places=0,
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[1],
+ 464,
+ places=0,
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[2], 1, places=0
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[3], 1, places=0
+ )
def test_dependent_parameter_pruning(self):
- raw_data = TimingData(['test-data/20190815_103347_nRF24_no-rx.json'])
+ raw_data = TimingData(["test-data/20190815_103347_nRF24_no-rx.json"])
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
prune_dependent_parameters(by_name, parameters)
model = AnalyticModel(by_name, parameters, arg_count)
- self.assertEqual(model.names, 'getObserveTx setPALevel setRetries setup write'.split(' '))
+ self.assertEqual(
+ model.names, "getObserveTx setPALevel setRetries setup write".split(" ")
+ )
static_model = model.get_static()
- self.assertAlmostEqual(static_model('getObserveTx', 'duration'), 75, places=0)
- self.assertAlmostEqual(static_model('setPALevel', 'duration'), 146, places=0)
- self.assertAlmostEqual(static_model('setRetries', 'duration'), 73, places=0)
- self.assertAlmostEqual(static_model('setup', 'duration'), 6533, places=0)
- self.assertAlmostEqual(static_model('write', 'duration'), 12634, places=0)
-
- for transition in 'getObserveTx setPALevel setRetries setup write'.split(' '):
- self.assertAlmostEqual(model.stats.param_dependence_ratio(transition, 'duration', 'channel'), 0, places=2)
+ self.assertAlmostEqual(static_model("getObserveTx", "duration"), 75, places=0)
+ self.assertAlmostEqual(static_model("setPALevel", "duration"), 146, places=0)
+ self.assertAlmostEqual(static_model("setRetries", "duration"), 73, places=0)
+ self.assertAlmostEqual(static_model("setup", "duration"), 6533, places=0)
+ self.assertAlmostEqual(static_model("write", "duration"), 12634, places=0)
+
+ for transition in "getObserveTx setPALevel setRetries setup write".split(" "):
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio(transition, "duration", "channel"),
+ 0,
+ places=2,
+ )
param_model, param_info = model.get_fitted()
- self.assertEqual(param_info('getObserveTx', 'duration'), None)
- self.assertEqual(param_info('setPALevel', 'duration'), None)
- self.assertEqual(param_info('setRetries', 'duration'), None)
- self.assertEqual(param_info('setup', 'duration'), None)
- self.assertEqual(param_info('write', 'duration')['function']._model_str, '0 + regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay)')
-
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[0], 1163, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[1], 464, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[2], 1, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[3], 1, places=0)
+ self.assertEqual(param_info("getObserveTx", "duration"), None)
+ self.assertEqual(param_info("setPALevel", "duration"), None)
+ self.assertEqual(param_info("setRetries", "duration"), None)
+ self.assertEqual(param_info("setup", "duration"), None)
+ self.assertEqual(
+ param_info("write", "duration")["function"]._model_str,
+ "0 + regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay)",
+ )
+
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[0],
+ 1163,
+ places=0,
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[1],
+ 464,
+ places=0,
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[2], 1, places=0
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[3], 1, places=0
+ )
def test_function_override(self):
- raw_data = TimingData(['test-data/20190815_122531_nRF24_no-rx.json'])
+ raw_data = TimingData(["test-data/20190815_122531_nRF24_no-rx.json"])
preprocessed_data = raw_data.get_preprocessed_data()
by_name, parameters, arg_count = pta_trace_to_aggregate(preprocessed_data)
- model = AnalyticModel(by_name, parameters, arg_count, function_override={('write', 'duration'): '(parameter(auto_ack!) * (regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay))) + ((1 - parameter(auto_ack!)) * regression_arg(4))'})
- self.assertEqual(model.names, 'setAutoAck setPALevel setRetries setup write'.split(' '))
+ model = AnalyticModel(
+ by_name,
+ parameters,
+ arg_count,
+ function_override={
+ (
+ "write",
+ "duration",
+ ): "(parameter(auto_ack!) * (regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay))) + ((1 - parameter(auto_ack!)) * regression_arg(4))"
+ },
+ )
+ self.assertEqual(
+ model.names, "setAutoAck setPALevel setRetries setup write".split(" ")
+ )
static_model = model.get_static()
- self.assertAlmostEqual(static_model('setAutoAck', 'duration'), 72, places=0)
- self.assertAlmostEqual(static_model('setPALevel', 'duration'), 146, places=0)
- self.assertAlmostEqual(static_model('setRetries', 'duration'), 73, places=0)
- self.assertAlmostEqual(static_model('setup', 'duration'), 6533, places=0)
- self.assertAlmostEqual(static_model('write', 'duration'), 1181, places=0)
-
- for transition in 'setAutoAck setPALevel setRetries setup write'.split(' '):
- self.assertAlmostEqual(model.stats.param_dependence_ratio(transition, 'duration', 'channel'), 0, places=2)
+ self.assertAlmostEqual(static_model("setAutoAck", "duration"), 72, places=0)
+ self.assertAlmostEqual(static_model("setPALevel", "duration"), 146, places=0)
+ self.assertAlmostEqual(static_model("setRetries", "duration"), 73, places=0)
+ self.assertAlmostEqual(static_model("setup", "duration"), 6533, places=0)
+ self.assertAlmostEqual(static_model("write", "duration"), 1181, places=0)
+
+ for transition in "setAutoAck setPALevel setRetries setup write".split(" "):
+ self.assertAlmostEqual(
+ model.stats.param_dependence_ratio(transition, "duration", "channel"),
+ 0,
+ places=2,
+ )
param_model, param_info = model.get_fitted()
- self.assertEqual(param_info('setAutoAck', 'duration'), None)
- self.assertEqual(param_info('setPALevel', 'duration'), None)
- self.assertEqual(param_info('setRetries', 'duration'), None)
- self.assertEqual(param_info('setup', 'duration'), None)
- self.assertEqual(param_info('write', 'duration')['function']._model_str, '(parameter(auto_ack!) * (regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay))) + ((1 - parameter(auto_ack!)) * regression_arg(4))')
-
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[0], 1162, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[1], 464, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[2], 1, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[3], 1, places=0)
- self.assertAlmostEqual(param_info('write', 'duration')['function']._regression_args[4], 1086, places=0)
-
-
-if __name__ == '__main__':
+ self.assertEqual(param_info("setAutoAck", "duration"), None)
+ self.assertEqual(param_info("setPALevel", "duration"), None)
+ self.assertEqual(param_info("setRetries", "duration"), None)
+ self.assertEqual(param_info("setup", "duration"), None)
+ self.assertEqual(
+ param_info("write", "duration")["function"]._model_str,
+ "(parameter(auto_ack!) * (regression_arg(0) + regression_arg(1) * parameter(max_retry_count) + regression_arg(2) * parameter(retry_delay) + regression_arg(3) * parameter(max_retry_count) * parameter(retry_delay))) + ((1 - parameter(auto_ack!)) * regression_arg(4))",
+ )
+
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[0],
+ 1162,
+ places=0,
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[1],
+ 464,
+ places=0,
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[2], 1, places=0
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[3], 1, places=0
+ )
+ self.assertAlmostEqual(
+ param_info("write", "duration")["function"]._regression_args[4],
+ 1086,
+ places=0,
+ )
+
+
+if __name__ == "__main__":
unittest.main()