def test_generate_path_offset_zero(self):
        # when offset is 0 path is just your regular path

        # - test 1 - just the initial state
        regular = bmcutils.BmcModel().path(0)
        tool = diagnosability.generate_path(0, 0)
        self.assertEqual(regular, tool)

        # - test 2 - more steps unrolled
        regular = bmcutils.BmcModel().path(3)
        tool = diagnosability.generate_path(0, 3)
        self.assertEqual(regular, tool)
예제 #2
0
    def test_model_problem(self):
        with tests.Configure(self, __file__, "/example.smv"):
            enc = self.enc
            # no step taken
            bound = 0

            tool = gen.model_problem(self.befsm, bound)
            manual = enc.shift_to_time(self.befsm.init, 0)

            nusmv = bmcutils.BmcModel().path(bound, with_init=True)

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_nusmv)
            self.assertEqual(s_tool, s_manual)

            # one step taken
            bound = 1

            tool = gen.model_problem(self.befsm, bound)
            manual= enc.shift_to_time(self.befsm.trans,0) &\
                    enc.shift_to_time(self.befsm.init, 0)

            nusmv = bmcutils.BmcModel().path(bound, with_init=True)

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)

            # two steps
            bound = 2

            tool = gen.model_problem(self.befsm, bound)
            manual= enc.shift_to_time(self.befsm.init, 0) &\
                    enc.shift_to_time(self.befsm.trans,0) &\
                    enc.shift_to_time(self.befsm.trans,1)

            nusmv = bmcutils.BmcModel().path(bound, with_init=True)

            s_tool = tests.canonical_cnf(tool)
            s_manual = tests.canonical_cnf(manual)
            s_nusmv = tests.canonical_cnf(nusmv)

            self.assertEqual(s_tool, s_manual)
            self.assertEqual(s_tool, s_nusmv)
예제 #3
0
    def test_apply_inlining_for_incremental_algo(self):
        load_from_string("""
            MODULE main
            VAR     v : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            v = enc.by_name['v'].boolean_expression

            cond = v & v & v | v
            self.assertEqual(
                cond.inline(True),
                bmcutils.apply_inlining_for_incremental_algo(cond))

            cond = v | -v
            self.assertEqual(
                cond.inline(True),
                bmcutils.apply_inlining_for_incremental_algo(cond))

            cond = v & -v
            self.assertEqual(
                cond.inline(True),
                bmcutils.apply_inlining_for_incremental_algo(cond))
예제 #4
0
def mk_cnf_no_formula(bound):
    '''
    :return: a `BeCnf` expression representing the model + `bound` steps of 
    unrolled transition relation
    '''
    import pynusmv.bmc.utils as _utils
    
    model = _utils.BmcModel()
    cnf   = model.path(bound).to_cnf()
    return cnf
예제 #5
0
    def verify_invariants_constraint(self, bound):
        model = bmcutils.BmcModel()

        manual = Be.true(self.mgr)
        for i in range(bound + 1):
            manual &= model.invar[i]

        tool = gen.invariants_constraint(self.befsm, bound)

        self.assertEqual(tests.canonical_cnf(tool),
                         tests.canonical_cnf(manual))
예제 #6
0
def generate_path(offset, length):
    """
    Returns a boolean expression representing a path of length `length` in the
    fsm described by the loaded model.

    :param length: the length of the path in the fsm
    :param offset: the offset at which the path should be starting
    :return: a boolean expression representing a path of length `length` in the
        loaded fsm.
    """
    model = bmcutils.BmcModel()
    path  = model.init[offset] & model.unrolling(offset, offset + length)
    return path
    def test_constraint_same_observations(self):
        observable = diagnosability.mk_observable_vars(["mouse"])
        constraint = diagnosability.constraint_same_observations(
            observable, 0, 5, 5)
        model = bmcutils.BmcModel()

        manual = Be.true(model._fsm.encoding.manager)
        for i in range(6):  # because we want to go from 0 through 5
            for v in model._fsm.encoding.input_variables:
                v_1 = v.at_time[i].boolean_expression
                v_2 = v.at_time[5 + i].boolean_expression
                manual &= v_1.iff(v_2)

        self.assertEqual(manual, constraint)
예제 #8
0
    def test_loop_condition_single_var(self):
        # test case 1: model with one single var
        load_from_string("""
            MODULE main
            VAR     v : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            cond = bmcutils.loop_condition(enc, 3, 1)

            v3 = enc.by_name['v'].at_time[3].boolean_expression
            v1 = enc.by_name['v'].at_time[1].boolean_expression

            cond2 = v1.iff(v3)

            self.assertEqual(cond, cond2)
예제 #9
0
    def verify_fairness_constraint(self):
        # must be true
        tool = bmcutils.fairness_constraint(self.befsm, 0, 0)
        self.assertEqual(tool, Be.true(self.mgr))

        # loop position does not matter if not feasible
        with self.assertRaises(ValueError):
            bmcutils.fairness_constraint(self.befsm, 0, 1)

        model = bmcutils.BmcModel()
        # step 0
        tool = bmcutils.fairness_constraint(self.befsm, 1, 0)
        smv = model.fairness(1, 0)
        self.assertEqual(tool, smv)

        # step 1
        tool = bmcutils.fairness_constraint(self.befsm, 2, 1)
        smv = model.fairness(2, 1)
        self.assertEqual(tool, smv)
예제 #10
0
 def test_loop_condition_consistent_values(self):
     # test case 3: only the state variables are considered
     load_from_string("""
         MODULE main
         IVAR    i : boolean;
         VAR     v : boolean;
                 w : boolean;
         ASSIGN  init(v) := TRUE; 
                 next(v) := !v;
         """)
     with BmcSupport():
         mdl = bmcutils.BmcModel()
         enc = mdl._fsm.encoding
         # loop and bound must be consistent (bound >= 0)
         with self.assertRaises(ValueError):
             bmcutils.loop_condition(enc, -5, 1)
         # loop and bound must be consistent (loop <= bound)
         with self.assertRaises(ValueError):
             bmcutils.loop_condition(enc, 2, 5)
예제 #11
0
    def test_apply_inlining(self):
        load_from_string("""
            MODULE main
            VAR     v : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            mgr = enc.manager
            v = enc.by_name['v'].boolean_expression

            cond = v & v & v | v
            self.assertEqual(v, bmcutils.apply_inlining(cond))

            cond = v | -v
            self.assertEqual(Be.true(mgr), bmcutils.apply_inlining(cond))

            cond = v & -v
            self.assertEqual(Be.false(mgr), bmcutils.apply_inlining(cond))
예제 #12
0
    def test_loop_condition_two_var(self):
        # test case 1: model with one more variables
        load_from_string("""
            MODULE main
            VAR     v : boolean;
                    w : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            cond = bmcutils.loop_condition(enc, 3, 1)

            v = enc.by_name['v']
            w = enc.by_name['w']

            cond2 = (v.at_time[1].boolean_expression.iff(
                v.at_time[3].boolean_expression)
                     & w.at_time[1].boolean_expression.iff(
                         w.at_time[3].boolean_expression))

            self.assertEqual(cond, cond2)
예제 #13
0
    def test_loop_condition_not_only_state(self):
        # test case 3: only the state variables are considered
        load_from_string("""
            MODULE main
            IVAR    i : boolean;
            VAR     v : boolean;
                    w : boolean;
            ASSIGN  init(v) := TRUE; 
                    next(v) := !v;
            """)
        with BmcSupport():
            mdl = bmcutils.BmcModel()
            enc = mdl._fsm.encoding
            cond = bmcutils.loop_condition(enc, 3, 1)

            v = enc.by_name['v']
            w = enc.by_name['w']

            cond2 = (v.at_time[1].boolean_expression.iff(
                v.at_time[3].boolean_expression)
                     & w.at_time[1].boolean_expression.iff(
                         w.at_time[3].boolean_expression))

            self.assertEqual(cond, cond2)
 def test_generate_path_offset_x(self):
     # must combine an initial state w/ 'length' unrolling
     model = bmcutils.BmcModel()
     manual = model.init[5] & model.unrolling(5, 10)
     tool = diagnosability.generate_path(5, 5)
     self.assertEqual(manual, tool)