Пример #1
0
 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].argument_values, [[0, 1]])
     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],
         ],
     )
Пример #2
0
 def test_normalization(self):
     pta = PTA.from_yaml(example_yaml_2)
     no_param = {"datarate": None, "txbytes": None, "txpower": None}
     param_tx3 = {"datarate": None, "txbytes": 3, "txpower": None}
     param_tx6 = {"datarate": None, "txbytes": 6, "txpower": None}
     param_txp10 = {"datarate": None, "txbytes": None, "txpower": -6}
     param_txp20 = {"datarate": None, "txbytes": None, "txpower": 4}
     param_txp30 = {"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)],
         ],
     )
Пример #3
0
 def test_from_yaml_dfs_param(self):
     pta = PTA.from_yaml(example_yaml_1)
     no_param = {"datarate": None, "txbytes": None, "txpower": None}
     param_tx3 = {"datarate": None, "txbytes": 3, "txpower": None}
     param_tx5 = {"datarate": None, "txbytes": 5, "txpower": None}
     param_txp10 = {"datarate": None, "txbytes": None, "txpower": 10}
     param_txp20 = {"datarate": None, "txbytes": None, "txpower": 20}
     param_txp30 = {"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)],
         ],
     )
Пример #4
0
#!/usr/bin/env python3

from dfatool.aspectc import Repo
from dfatool.codegen import MultipassDriver
from dfatool.automata import PTA
import yaml

with open("../multipass/model/driver/nrf24l01.dfa", "r") as f:
    driver_definition = yaml.safe_load(f)
    pta = PTA.from_yaml(driver_definition)
repo = Repo("../multipass/build/repo.acp")

enum = dict()

if "dummygen" in driver_definition and "enum" in driver_definition["dummygen"]:
    enum = driver_definition["dummygen"]["enum"]

drv = MultipassDriver("Nrf24l01",
                      pta,
                      repo.class_by_name["Nrf24l01"],
                      enum=enum)

with open("../multipass/src/driver/dummy.cc", "w") as f:
    f.write(drv.impl)
with open("../multipass/include/driver/dummy.h", "w") as f:
    f.write(drv.header)