Esempio n. 1
0
    def test_parse_ltl2ba_output__skip(self):
        text = """
            never { /* F(r && !g) */
            T0_init :    /* init */
                if
                :: (1) -> goto T0_init
                :: (r && !g) -> goto accept_all
                fi;
            accept_all :    /* 1 */
                skip
            }"""
        sig_g = Signal('g')
        sig_r = Signal('r')
        signal_by_name = {'r': sig_r, 'g': sig_g}
        initial_nodes, rejecting_nodes, nodes = parse_ltl2ba_ba(text, signal_by_name, '')

        assert len(initial_nodes) == 1, str(len(initial_nodes))
        assert len(rejecting_nodes) == 1, str(len(rejecting_nodes))
        assert len(nodes) == 2, str(nodes)

        accept_all_node = [n for n in nodes if n.name == 'accept_all'][0]

        assert rejecting_nodes == {accept_all_node}
        assert len(accept_all_node.transitions) == 1

        label, node_flag_pairs = list(accept_all_node.transitions.items())[0]
        dst, is_rejecting = set(node_flag_pairs).pop()
        assert dst == accept_all_node, str(dst)
        assert label == {}, str(label)
Esempio n. 2
0
    def test_parse_ltl2ba_output__or(self):
        text = """
            never {
            T0_init :    /* init */
                if
                :: (1) -> goto T0_init
                :: (r) || (!g) -> goto accept_all
                fi;
            accept_all :    /* 1 */
                skip
            }"""
        sig_g = Signal('g')
        sig_r = Signal('r')
        signal_by_name = {'r': sig_r, 'g': sig_g}
        initial_nodes, rejecting_nodes, nodes = parse_ltl2ba_ba(text, signal_by_name, '')

        assert len(initial_nodes) == 1, str(len(initial_nodes))
        assert len(rejecting_nodes) == 1, str(len(rejecting_nodes))
        assert len(nodes) == 2, str(nodes)

        init_node = [n for n in nodes if n.name == 'T0_init'][0]

        assert len(init_node.transitions) == 3, len(init_node.transitions)

        for label, node_flag_pairs in init_node.transitions.items():
            for dst, is_rejecting in node_flag_pairs:
                assert (label == {} and dst == init_node) \
                           or (label == {sig_r: True} and dst != init_node) \
                           or (label == {sig_g: False} and dst != init_node)
Esempio n. 3
0
    def test_parse_ltl2ba_output(self):
        text = """
            never { /* !([](r -> <>g)) */
            T0_init :    /* init */
                if
                :: (1) -> goto T0_init
                :: (!g && r) -> goto accept_S2
                fi;
            accept_S2 :    /* 1 */
                if
                :: (!g) -> goto accept_S2
                fi;
            }"""

        sig_g = Signal('g')
        sig_r = Signal('r')
        signal_by_name = {'r': sig_r, 'g': sig_g}

        initial_nodes, rejecting_nodes, nodes = parse_ltl2ba_ba(text, signal_by_name, '')

        assert len(initial_nodes) == 1, str(len(initial_nodes))
        assert len(rejecting_nodes) == 1, str(len(rejecting_nodes))
        assert len(nodes) == 2, str(nodes)

        for n in nodes:
            if n.name == 'T0_init':
                assert n not in rejecting_nodes
                assert n in initial_nodes
                assert len(n.transitions) == 2

                for label, node_flag_pairs in n.transitions.items():
                    for dst, is_rejecting in node_flag_pairs:
                        assert (dst.name == 'T0_init' and label == {}) or \
                               (dst.name == 'accept_S2' and label == {sig_g: False, sig_r: True}), \
                            'unknown transition: {0} {1}'.format(label, str(dst))

            elif n.name == 'accept_S2':
                assert n in rejecting_nodes
                assert n not in initial_nodes
                assert len(n.transitions) == 1

                for label, node_flag_pairs in n.transitions.items():
                    dst, is_rejecting = set(node_flag_pairs).pop()
                    assert dst.name == 'accept_S2' and label == {sig_g: False}
            else:
                assert False, 'unknown node: {0}'.format(str(n))
Esempio n. 4
0
    def convert_raw(self, property:str, signal_by_name:dict, states_prefix, timeout=None) -> Automaton:
        """
        :param property: in the LTL2BA format (we do NOT negate it!)
        """

        rc, ba, err = execute_shell('{0} "{1}"'.format(self._execute_cmd, property), timeout=timeout)
        assert rc == 0, str(rc) + ', err: ' + str(err) + ', out: ' + str(ba)
        assert (err == '') or err is None, err
        logging.debug(ba)

        initial_nodes, rejecting_nodes, nodes = parse_ltl2ba_ba(ba, signal_by_name, states_prefix)

        assert set(rejecting_nodes).issubset(set(nodes)) and set(initial_nodes).issubset(set(nodes))

        _assert_are_signals_in_labels(nodes)

        automaton = Automaton(initial_nodes, rejecting_nodes, nodes, name=str(property))

        return automaton
Esempio n. 5
0
    def test_parse_ltl2ba_output_names_with_if_fi(self):
        text = """
            never { /* F(r && !g) */
            T0_if_init :    /* init */
                if
                :: (1) -> goto T0_if_init
                :: (r && !g) -> goto accept_if_fi_all
                fi;
            accept_if_fi_all :    /* 1 */
                skip
            }"""
        sig_g = Signal('g')
        sig_r = Signal('r')
        signal_by_name = {'r': sig_r, 'g': sig_g}
        initial_nodes, _, nodes = parse_ltl2ba_ba(text, signal_by_name, '')

        assert len(initial_nodes) == 1, str(len(initial_nodes))
        assert len(nodes) == 2, str(nodes)

        assert len(list(initial_nodes)[0].transitions) == 2