Ejemplo n.º 1
0
    def test_cex_printer_exit(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [l] void m1() |- [CB] [EXIT] [l] void m1()")
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj(1, "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj(1, "string")], None)
        cb.add_msg(ci)
        ts_enc = TSEncoder(ctrace, spec_list)

        ts = ts_enc.get_ts_encoding()
        error = ts_enc.error_prop
        bmc = BMC(ts_enc.helper, ts, error)
        cex = bmc.find_bug(4)
        cex = bmc.find_bug(4, True)

        self.assertFalse(cex is None)

        stringio = StringIO()
        printer = CexPrinter(ts_enc.mapback, cex, stringio)
        printer.print_cex()

        io_string = stringio.getvalue()
        self.assertTrue(
            "SPEC [CB] [ENTRY] [1] void m1() |- [CB] [EXIT] [1] void m1()" in
            io_string)
        self.assertTrue("Reached an error state in step 4" in io_string)
Ejemplo n.º 2
0
    def test_simplify_exit_callin(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC [CB] [EXIT] [l] void m1() |- [CI] [ENTRY] [l] void m3()")
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m3()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)

        cb2 = CCallback(1, 1, "", "void m2()",
                        [TestGrounding._get_obj("1", "string")], None,
                        [TestGrounding._get_fmwkov("", "void m2()", False)])
        ctrace.add_msg(cb2)

        ts_enc = TSEncoder(ctrace, spec_list, True)
        ts_enc.trace.print_trace(sys.stdout)
        self.assertTrue(3 == ts_enc.trace_length)

        ts = ts_enc.get_ts_encoding()
        trace_enc = ts_enc.get_trace_encoding()
        print trace_enc
        self.assertTrue(len(trace_enc) == 3)
        bmc = BMC(ts_enc.helper, ts, FALSE())
        (step, cex, _) = bmc.simulate(trace_enc)
        self.assertTrue(cex is not None)
Ejemplo n.º 3
0
 def get_ground_specs(self, get_map = False):
     ts_enc = TSEncoder(self.trace, self.spec_list, False, self.stats)
     if not get_map:
         ground_specs = ts_enc.get_ground_spec()
     else:
         ground_specs = ts_enc.get_orig_ground_spec()
     return ground_specs
Ejemplo n.º 4
0
    def test_multiple_single_cb(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC FALSE[*] |- [CB] [ENTRY] [l] void m3(); SPEC FALSE[*] |- [CI] [ENTRY] [l] void m4()"
        )
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        cb = CCallback(1, 1, "", "void m5()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m5()", False)])
        ctrace.add_msg(cb)
        cb = CCallback(1, 1, "", "void m3()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m3()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m4()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)

        ts_enc = TSEncoder(ctrace, spec_list)
        ts = ts_enc.get_ts_encoding()
        error = ts_enc.error_prop
        bmc = BMC(ts_enc.helper, ts, error)
        cex = bmc.find_bug(2, True)
        self.assertTrue(cex is None)
Ejemplo n.º 5
0
    def test_exception(self):
        """ Test the removal of exception from top-level callbacks
        """
        spec_list = Spec.get_specs_from_string(
            "SPEC FALSE[*] |- [CI] [ENTRY] void m2()")

        ctrace = CTrace()
        cb1 = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()],
                        None,
                        [TestGrounding._get_fmwkov("", "void m1()", False)])

        cb1.exception = CTraceException("void m1()", "",
                                        "NullPointerException",
                                        "NullPointerException message")

        ci1 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None)
        cb1.add_msg(ci1)
        ctrace.add_msg(cb1)

        cb2 = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()],
                        None,
                        [TestGrounding._get_fmwkov("", "void m1()", False)])
        ci2 = CCallin(1, 1, "", "void m3()", [TestGrounding._get_null()], None)
        cb2.add_msg(ci2)
        ctrace.add_msg(cb2)

        ts_enc = TSEncoder(ctrace, spec_list)
        assert (1 == len(ts_enc.trace.children))
        ts = ts_enc.get_ts_encoding()
        bmc = BMC(ts_enc.helper, ts, ts_enc.error_prop)
        # if the first callback is removed, m2 cannot be called anymore
        self.assertTrue(bmc.find_bug(2) is None)
        self.assertTrue(bmc.find_bug(2, True) is None)
Ejemplo n.º 6
0
    def test_090_multiple_cbs(self):
        spec_list = Spec.get_specs_from_string("SPEC FALSE[*] |- [CI] [ENTRY] [l] void m4();" \
                                               "SPEC FALSE[*] |- [CB] [ENTRY] [l] void m3();" \
                                               "SPEC [CB] [ENTRY] [l1] void m1() |+ [CB] [ENTRY] [l2] void m3()")
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(2, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        ci = CCallin(3, 1, "", "void m6()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        cb = CCallback(4, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(5, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        cb = CCallback(6, 1, "", "void m3()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m3()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(7, 1, "", "void m4()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)

        ts_enc = TSEncoder(ctrace, spec_list)
        ts = ts_enc.get_ts_encoding()
        error = ts_enc.error_prop
        bmc = BMC(ts_enc.helper, ts, error)
        cex = bmc.find_bug(6)
        self.assertTrue(cex is not None)

        stringio = StringIO()
        printer = CexPrinter(ts_enc.mapback, cex, stringio)
        printer.print_cex()

        io_string = stringio.getvalue()

        self.assertTrue("[4] [CB] [ENTRY] void m1()" in io_string)
        self.assertTrue("[5] [CI] [ENTRY] void m2()" in io_string)
        self.assertTrue("[6] [CB] [ENTRY] void m3()" in io_string)
        self.assertTrue("[7] [CI] [ENTRY] void m4()" in io_string)
Ejemplo n.º 7
0
    def to_smv(self, smv_file_name):
        ts_enc = TSEncoder(self.trace, self.spec_list,
                           self.opts.simplify_trace,
                           self.stats)
        ts = ts_enc.get_ts_encoding()
        ts2smv = SmvTranslator(ts_enc.pysmt_env,
                               ts.state_vars,
                               ts.input_vars,
                               ts.init,
                               ts.trans,
                               Not(ts_enc.error_prop))

        with open(smv_file_name, "wt") as f:
            ts2smv.to_smv(f)
            f.close()
Ejemplo n.º 8
0
    def test_get_ground_spec_ts(self):
        def _encode_error(accepting, final):
            f_error = FALSE()
            for f in accepting:
                f_error = Or(f, f_error)
            f_error = And(f_error, final)
            return f_error

        spec_list = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [l] void m1() |- [CI] [ENTRY] [l] void m2()")
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)

        ground_s = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [1] void m1() |- [CI] [ENTRY] [1] void m2()")[0]

        ts_enc = TSEncoder(ctrace, [])
        ts_var = ts_enc._encode_vars()

        accepting = []
        gs_ts = ts_enc._get_ground_spec_ts(ground_s, 0, accepting)
        gs_ts.product(ts_var)

        error = _encode_error(accepting, TRUE())
        self.assertTrue(
            self._accept_word(ts_enc, gs_ts, ["[CB]_[ENTRY]_void m1()(1)"],
                              error))
        self.assertFalse(
            self._accept_word(ts_enc, gs_ts, ["[CI]_[ENTRY]_void m2()(1)"],
                              error))

        # check the disable
        error = _encode_error(
            accepting, TSEncoder._get_state_var("[CI]_[ENTRY]_void m2()(1)"))
        self.assertFalse(
            self._accept_word(ts_enc, gs_ts, ["[CB]_[ENTRY]_void m1()(1)"],
                              error))
        self.assertFalse(
            self._accept_word(ts_enc, gs_ts, ["[CI]_[ENTRY]_void m2()(1)"],
                              error))
Ejemplo n.º 9
0
    def test_simplify_2(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC FALSE[*] |- [CB] [ENTRY] [l] void m3(); SPEC FALSE[*] |- [CI] [ENTRY] [l] void m4()"
        )
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        cb = CCallback(1, 1, "", "void m5()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m5()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m4()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        cb = CCallback(1, 1, "", "void m3()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m3()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m4()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)

        ts_enc = TSEncoder(ctrace, spec_list, True)

        self.assertTrue(4 == ts_enc.trace.get_total_msg())
Ejemplo n.º 10
0
    def run_ic3(self, nuxmv_path, ic3_frames):
        ts_enc = TSEncoder(self.trace, self.spec_list,
                           self.opts.simplify_trace,
                           self.stats)
        ts = ts_enc.get_ts_encoding()

        self.stats.start_timer(Stats.VERIFICATION_TIME,True)

        nuxmv_driver = NuXmvDriver(ts_enc.pysmt_env, ts, nuxmv_path)
        (result, trace) = nuxmv_driver.ic3(Not(ts_enc.error_prop),
                                           ic3_frames)

        self.stats.stop_timer(Stats.VERIFICATION_TIME,True)
        self.stats.write_times(sys.stdout, Stats.VERIFICATION_TIME)

        return (result, trace, ts_enc.mapback)
Ejemplo n.º 11
0
    def run_bmc(self, depth, inc=False):
        ts_enc = TSEncoder(self.trace, self.spec_list, self.opts.simplify_trace,
                           self.stats)

        self.stats.start_timer(Stats.VERIFICATION_TIME)

        bmc = BMC(ts_enc.helper,
                  ts_enc.get_ts_encoding(),
                  ts_enc.error_prop)

        cex = bmc.find_bug(depth, inc)

        self.stats.stop_timer(Stats.VERIFICATION_TIME)
        self.stats.write_times(sys.stdout, Stats.VERIFICATION_TIME)


        return (cex, ts_enc.mapback)
Ejemplo n.º 12
0
    def run_simulation(self, cb_sequence = None): 
        ts_enc = TSEncoder(self.trace, self.spec_list,
                           self.opts.simplify_trace,
                           self.stats)

        self.stats.start_timer(Stats.SIMULATION_TIME)

        bmc = BMC(ts_enc.helper,
                  ts_enc.get_ts_encoding(),
                  ts_enc.error_prop)

        trace_enc = ts_enc.get_trace_encoding(cb_sequence)
        (step, trace, last_trace) = bmc.simulate(trace_enc)

        self.stats.stop_timer(Stats.SIMULATION_TIME)
        self.stats.write_times(sys.stdout, Stats.SIMULATION_TIME)

        return (step, trace, last_trace, ts_enc.mapback)
Ejemplo n.º 13
0
    def test_get_value_key(self):
        obj = TestGrounding._get_obj("1", "string")
        res = TSEncoder.get_value_key(obj)
        self.assertTrue(res == "1")

        obj = TestGrounding._get_obj("1", "string")
        obj.is_null = True
        res = TSEncoder.get_value_key(obj)
        self.assertTrue(res == "NULL")

        value = TestGrounding._get_int("1")
        res = TSEncoder.get_value_key(value)
        self.assertTrue(res == "1")

        value = TestGrounding._get_int("1")
        value.is_null = True
        res = TSEncoder.get_value_key(value)
        self.assertTrue(res == "NULL")
Ejemplo n.º 14
0
    def test_simulation(self):
        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        ts_enc = TSEncoder(ctrace, [])  #spec_list)

        ts = ts_enc.get_ts_encoding()
        trace_enc = ts_enc.get_trace_encoding()

        bmc = BMC(ts_enc.helper, ts, FALSE())

        (step, trace, _) = bmc.simulate(trace_enc)

        self.assertTrue(trace is not None)
Ejemplo n.º 15
0
    def test_get_key(self):
        """ Test the retrieval for the key of the message """

        self.assertTrue(
            "[CB]_[ENTRY]_method(int,int,int)(1,2,3)" == TSEncoder.get_key(
                None, "CB", TSEncoder.ENTRY, "method(int,int,int)",
                ["1", "2", "3"]))
        self.assertTrue("[CI]_[ENTRY]_method()()" == TSEncoder.get_key(
            None, "CI", TSEncoder.ENTRY, "method()", []))
        self.assertTrue(
            "1=[CB]_[EXIT]_method(int,int)(1,2)" == TSEncoder.get_key(
                "1", "CB", TSEncoder.EXIT, "method(int,int)", ["1", "2"]))

        with self.assertRaises(AssertionError):
            TSEncoder.get_key(False, "CI", TSEncoder.ENTRY, "", [])
        with self.assertRaises(AssertionError):
            TSEncoder.get_key(False, "CI", TSEncoder.ENTRY, None, [])
        with self.assertRaises(AssertionError):
            TSEncoder.get_key(False, "CA", TSEncoder.ENTRY, "method", [])
Ejemplo n.º 16
0
    def test_init_state(self):
        """ Test if specification can force an initial value

          - m2 is disabled in the initial state
          - the trace try to call m1 and then m2, causing an exception
        """
        spec_list = Spec.get_specs_from_string(
            "SPEC FALSE[*] |- [CI] [ENTRY] void m2()")

        ctrace = CTrace()

        cb = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()],
                       None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ci = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None)
        cb.add_msg(ci)
        ctrace.add_msg(cb)

        ts_enc = TSEncoder(ctrace, spec_list)
        ts = ts_enc.get_ts_encoding()
        bmc = BMC(ts_enc.helper, ts, ts_enc.error_prop)
        self.assertTrue(bmc.find_bug(2) is not None)
        self.assertTrue(bmc.find_bug(2, True) is not None)
Ejemplo n.º 17
0
    def _get_sample_trace(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [l] void m1() |- [CI] [ENTRY] [l] void m2()")
        assert spec_list is not None

        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        ts_enc = TSEncoder(ctrace, spec_list)
        return ts_enc
Ejemplo n.º 18
0
    def test_get_key_from_call(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC TRUE |- [CI] [ENTRY] [1] void m1(); " +
            "SPEC TRUE |- [CI] [ENTRY] [1] void m1(2 : int,1 : int,2 : int);" +
            "SPEC TRUE |- 3 = [CI] [EXIT] [1] void m1(2 : int,1 : int,2 : int)"
        )
        assert spec_list is not None

        ci1 = CCallin(1, 1, "", "void m1()",
                      [TestGrounding._get_obj("1", "string")], None)
        ci2 = CCallin(1, 1, "", "void m1(int,int,int)", [
            TestGrounding._get_obj("1", "string"),
            TestGrounding._get_int(2),
            TestGrounding._get_int(1),
            TestGrounding._get_int(2),
        ], None)
        ci3 = CCallin(1, 1, "", "void m1(int,int,int)", [
            TestGrounding._get_obj("1", "string"),
            TestGrounding._get_int(2),
            TestGrounding._get_int(1),
            TestGrounding._get_int(2),
        ], TestGrounding._get_int(3))

        calls_nodes = []
        for s in spec_list:
            msg = get_spec_rhs(s.ast)
            assert get_node_type(msg) == CALL_ENTRY or get_node_type(
                msg) == CALL_EXIT
            calls_nodes.append(msg)
        assert (len(calls_nodes) == len(spec_list))

        res = TSEncoder.get_key_from_call(calls_nodes[0])
        res2 = TSEncoder.get_key_from_msg(ci1, TSEncoder.ENTRY)
        self.assertTrue("[CI]_[ENTRY]_void m1()(1)" == res)
        self.assertTrue(res == res2)

        res = TSEncoder.get_key_from_call(calls_nodes[1])
        res2 = TSEncoder.get_key_from_msg(ci2, TSEncoder.ENTRY)
        self.assertTrue("[CI]_[ENTRY]_void m1(int,int,int)(1,2,1,2)" == res)
        self.assertTrue(res == res2)

        res = TSEncoder.get_key_from_call(calls_nodes[2])
        res2 = TSEncoder.get_key_from_msg(ci3, TSEncoder.EXIT)
        self.assertTrue("3=[CI]_[EXIT]_void m1(int,int,int)(1,2,1,2)" == res)
        self.assertTrue(res == res2)
Ejemplo n.º 19
0
    def test_encode_ground_specs(self):
        ts_enc = self._get_sample_trace()
        vars_ts = ts_enc._encode_vars()
        (ts, disabled_ci, accepting) = ts_enc._encode_ground_specs()
        ts.product(vars_ts)

        accepting_states = FALSE()
        for k, v in accepting.iteritems():
            for state in v:
                accepting_states = Or(accepting_states, state)

        assert (disabled_ci == set(["[CI]_[ENTRY]_void m2()(1)"]))

        self.assertTrue(
            self._accept_word(ts_enc, ts, ["[CB]_[ENTRY]_void m1()(1)"],
                              accepting_states))
        self.assertFalse(
            self._accept_word(ts_enc, ts, ["[CI]_[ENTRY]_void m2()(1)"],
                              accepting_states))
        error = And(accepting_states,
                    TSEncoder._get_state_var("[CI]_[ENTRY]_void m2()(1)"))
        self.assertFalse(
            self._accept_word(ts_enc, ts, ["[CB]_[ENTRY]_void m1()(1)"],
                              error))
Ejemplo n.º 20
0
    def test_get_key_from_msg(self):
        fmwk_over = TestGrounding._get_fmwkov("", "doSomethingCb", False)

        cb = CCallback(1, 1, "", "type doSomethingCb",
                       [TestGrounding._get_obj("1", "string")], None,
                       [fmwk_over])
        res = TSEncoder.get_key_from_msg(cb, TSEncoder.ENTRY)
        self.assertTrue("[CB]_[ENTRY]_type doSomethingCb(1)" == res)
        res = TSEncoder.get_key_from_msg(cb, TSEncoder.EXIT)
        self.assertTrue("[CB]_[EXIT]_type doSomethingCb(1)" == res)

        cb = CCallback(1, 1, "", "void doSomethingCb",
                       [TestGrounding._get_obj("1", "string")],
                       TestGrounding._get_obj("1", "string"), [fmwk_over])
        res = TSEncoder.get_key_from_msg(cb, TSEncoder.ENTRY)
        self.assertTrue("[CB]_[ENTRY]_void doSomethingCb(1)" == res)
        res = TSEncoder.get_key_from_msg(cb, TSEncoder.EXIT)
        self.assertTrue("1=[CB]_[EXIT]_void doSomethingCb(1)" == res)

        cb = CCallback(
            1, 1, "pippo.Class", "void doSomethingCb(int,int)",
            [TestGrounding._get_obj("1", "string"),
             TestGrounding._get_int(1)], None,
            [TestGrounding._get_fmwkov("pippo.Class", "doSomethingCb", False)])
        res = TSEncoder.get_key_from_msg(cb, TSEncoder.ENTRY)
        self.assertTrue(
            "[CB]_[ENTRY]_void pippo.Class.doSomethingCb(int,int)(1,1)" == res)

        ci = CCallin(1, 1, "a.Class", "void doSomethingCi(string)",
                     [TestGrounding._get_obj("1", "string")], None)
        res = TSEncoder.get_key_from_msg(ci, TSEncoder.ENTRY)
        self.assertTrue(
            "[CI]_[ENTRY]_void a.Class.doSomethingCi(string)(1)" == res)

        ci = CCallin(1, 1, "", "void doSomethingCi", [], None)
        res = TSEncoder.get_key_from_msg(ci, TSEncoder.ENTRY)
        self.assertTrue("[CI]_[ENTRY]_void doSomethingCi()" == res)
Ejemplo n.º 21
0
    def test_encode_vars(self):
        fmwk_over = TestGrounding._get_fmwkov("", "cb", False)
        trace = CTrace()

        fmwk_over_cb = TestGrounding._get_fmwkov("", "cb", False)
        fmwk_over_cb1 = TestGrounding._get_fmwkov("", "cb1", False)

        cb = CCallback(1, 1, "", "cb", [], None, [fmwk_over_cb])
        cb1 = CCallback(1, 1, "", "cb1", [], None, [fmwk_over_cb1])
        ci = CCallin(1, 1, "", "ci", [], None)
        cb.add_msg(cb1)
        cb1.add_msg(ci)
        trace.add_msg(cb)

        cb = CCallback(1, 1, "", "cb", [], None, [fmwk_over_cb])
        cb1 = CCallback(1, 1, "", "cb1", [], None, [fmwk_over_cb1])
        ci = CCallin(1, 1, "", "ci", [], None)
        cb.add_msg(cb1)
        cb1.add_msg(ci)
        trace.add_msg(cb)

        ts_enc = TSEncoder(trace, [])

        ts_var = ts_enc._encode_vars()

        self.assertTrue(len(ts_var.state_vars) == 6)

        trans = TRUE()
        l = [cb, cb1, ci]
        for m in l:
            for entry in [TSEncoder.ENTRY, TSEncoder.EXIT]:
                var = TSEncoder._get_state_var(
                    TSEncoder.get_key_from_msg(m, entry))
                ivar = ts_enc.r2a.get_msg_eq(
                    TSEncoder.get_key_from_msg(m, entry))
                trans = And(trans, Implies(ivar, var))

        self.assertTrue(is_valid(Iff(ts_var.init, TRUE())))
        self.assertTrue(is_valid(Iff(ts_var.trans, trans)))
Ejemplo n.º 22
0
    def test_trace_stats(self):
        def _test_eq(ts_enc, length, msgs, fmwk_contr, app_contr):
            self.assertTrue(ts_enc.trace_length == length
                            and ts_enc.msgs == msgs
                            and ts_enc.fmwk_contr == fmwk_contr
                            and ts_enc.app_contr == app_contr)

        ts_enc = TSEncoder(CTrace(), [])
        _test_eq(ts_enc, 0, set(), set(), set())

        fmwk_over = TestGrounding._get_fmwkov("", "doSomethingCb", False)

        trace = CTrace()
        cb = CCallback(1, 1, "", "doSomethingCb", [], None, [fmwk_over])
        trace.add_msg(cb)
        ts_enc = TSEncoder(trace, [])
        _test_eq(
            ts_enc, 2,
            set([
                "[CB]_[ENTRY]_doSomethingCb()", "[CB]_[EXIT]_doSomethingCb()"
            ]), set(["[CB]_[ENTRY]_doSomethingCb()"]),
            set(["[CB]_[EXIT]_doSomethingCb()"]))

        trace = CTrace()
        cb = CCallback(1, 1, "", "doSomethingCb", [], None, [fmwk_over])
        trace.add_msg(cb)
        ci = CCallin(1, 1, "", "doSomethingCi", [], None)
        cb.add_msg(ci)
        cb = CCallback(1, 1, "", "doSomethingCb", [], None, [fmwk_over])
        trace.add_msg(cb)
        ci = CCallin(1, 1, "", "doSomethingCi", [], None)
        cb.add_msg(ci)

        ts_enc = TSEncoder(trace, [])
        _test_eq(
            ts_enc, 8,
            set([
                "[CB]_[ENTRY]_doSomethingCb()", "[CB]_[EXIT]_doSomethingCb()",
                "[CI]_[ENTRY]_doSomethingCi()", "[CI]_[EXIT]_doSomethingCi()"
            ]),
            set([
                "[CB]_[ENTRY]_doSomethingCb()", "[CI]_[EXIT]_doSomethingCi()"
            ]),
            set([
                "[CI]_[ENTRY]_doSomethingCi()", "[CB]_[EXIT]_doSomethingCb()"
            ]))

        trace = CTrace()

        fmwk_over_cb = TestGrounding._get_fmwkov("", "cb", False)
        fmwk_over_cb1 = TestGrounding._get_fmwkov("", "cb1", False)
        cb = CCallback(1, 1, "", "cb", [], None, [fmwk_over_cb])
        cb1 = CCallback(1, 1, "", "cb1", [], None, [fmwk_over_cb1])
        ci = CCallin(1, 1, "", "ci", [], None)
        cb.add_msg(cb1)
        cb1.add_msg(ci)
        trace.add_msg(cb)

        cb = CCallback(1, 1, "", "cb", [], None, [fmwk_over_cb])
        cb1 = CCallback(1, 1, "", "cb1", [], None, [fmwk_over_cb1])
        ci = CCallin(1, 1, "", "ci", [], None)
        cb.add_msg(cb1)
        cb1.add_msg(ci)
        trace.add_msg(cb)

        ts_enc = TSEncoder(trace, [])
        _test_eq(
            ts_enc, 12,
            set([
                "[CB]_[ENTRY]_cb()", "[CB]_[EXIT]_cb()", "[CB]_[ENTRY]_cb1()",
                "[CB]_[EXIT]_cb1()", "[CI]_[ENTRY]_ci()", "[CI]_[EXIT]_ci()"
            ]),
            set([
                "[CB]_[ENTRY]_cb()", "[CB]_[ENTRY]_cb1()", "[CI]_[EXIT]_ci()"
            ]),
            set(["[CB]_[EXIT]_cb()", "[CB]_[EXIT]_cb1()",
                 "[CI]_[ENTRY]_ci()"]))
Ejemplo n.º 23
0
    def test_encode_cbs(self):
        def cb(name):
            fmwk_over = TestGrounding._get_fmwkov("", name, False)

            cb = CCallback(1, 1, "", name, [], None, [fmwk_over])
            return cb

        def ci(name):
            ci = CCallin(1, 1, "", name, [], None)
            return ci

        def new_trace(tree_trace_list):
            def add_rec(parent, children):
                for (child, lchildren) in children:
                    parent.add_msg(child)
                    add_rec(child, lchildren)

            ctrace = CTrace()
            add_rec(ctrace, tree_trace_list)

            return ctrace

        trace_tree = [(cb("cb1"), [(ci("ci1"), [])]),
                      (cb("cb2"), [(ci("ci2"), [])])]
        ctrace = new_trace(trace_tree)
        ctrace.print_trace(sys.stdout)

        # ctrace.print_trace(sys.stdout)
        ts_enc = TSEncoder(ctrace, [])
        vars_ts = ts_enc._encode_vars()

        (ts, errors) = ts_enc._encode_cbs(set())
        ts.product(vars_ts)
        self.assertTrue(len(errors) == 0)

        cb_1_seq = [
            "[CB]_[ENTRY]_cb1()", "[CI]_[ENTRY]_ci1()", "[CI]_[EXIT]_ci1()",
            "[CB]_[EXIT]_cb1()"
        ]
        cb_2_seq = [
            "[CB]_[ENTRY]_cb2()", "[CI]_[ENTRY]_ci2()", "[CI]_[EXIT]_ci2()",
            "[CB]_[EXIT]_cb2()"
        ]
        cb_11 = [
            "[CB]_[ENTRY]_cb1()", "[CI]_[ENTRY]_ci1()", "[CI]_[EXIT]_ci1()",
            "[CB]_[EXIT]_cb1()", "[CB]_[ENTRY]_cb1()", "[CI]_[ENTRY]_ci1()",
            "[CI]_[EXIT]_ci1()", "[CB]_[EXIT]_cb1()"
        ]
        cb_12 = [
            "[CB]_[ENTRY]_cb1()", "[CI]_[ENTRY]_ci1()", "[CI]_[EXIT]_ci1()",
            "[CB]_[EXIT]_cb1()", "[CB]_[ENTRY]_cb2()", "[CI]_[ENTRY]_ci2()",
            "[CI]_[EXIT]_ci2()", "[CB]_[EXIT]_cb2()"
        ]
        cb_22 = [
            "[CB]_[ENTRY]_cb2()", "[CI]_[ENTRY]_ci2()", "[CI]_[EXIT]_ci2()",
            "[CB]_[EXIT]_cb2()", "[CB]_[ENTRY]_cb2()", "[CI]_[ENTRY]_ci2()",
            "[CI]_[EXIT]_ci2()", "[CB]_[EXIT]_cb2()"
        ]

        accepting_traces = [cb_1_seq, cb_2_seq, cb_11, cb_12, cb_22]

        for seq in accepting_traces:
            self.assertTrue(self._accept_word(ts_enc, ts, seq, TRUE()))

        deadlock_traces = [["[CI]_[ENTRY]_ci1()"], ["[CI]_[ENTRY]_ci2()"],
                           [
                               "[CB]_[ENTRY]_cb1()", "[CI]_[ENTRY]_ci1()",
                               "[CI]_[EXIT]_ci1()", "[CB]_[EXIT]_cb1()",
                               "[CI]_[ENTRY]_ci2()", "[CI]_[EXIT]_ci2()"
                           ],
                           [
                               "[CB]_[ENTRY]_cb2()", "[CI]_[ENTRY]_ci1()",
                               "[CB]_[EXIT]_cb1()"
                           ]]
        for seq in deadlock_traces:
            self.assertFalse(self._accept_word(ts_enc, ts, seq, TRUE()))

        ts_enc = TSEncoder(ctrace, [])
        vars_ts = ts_enc._encode_vars()
        (ts, errors) = ts_enc._encode_cbs(set(["[CI]_[ENTRY]_ci1()"]))
        ts.product(vars_ts)
        self.assertTrue(len(errors) == 1)
        self.assertTrue(
            is_sat(
                And(errors[0],
                    Not(TSEncoder._get_state_var("[CI]_[ENTRY_]ci1()")))))

        ts_enc = TSEncoder(ctrace, [])
        vars_ts = ts_enc._encode_vars()
        (ts, errors) = ts_enc._encode_cbs(set(["[CB]_[EXIT]_cb1()"]))
        ts.product(vars_ts)
        self.assertTrue(len(errors) == 1)
        self.assertTrue(
            is_sat(
                And(errors[0],
                    Not(TSEncoder._get_state_var("[CB]_[EXIT]_cb1()")))))

        ts_enc = TSEncoder(ctrace, [])
        vars_ts = ts_enc._encode_vars()
        (ts, errors) = ts_enc._encode_cbs(
            set(["[CI]_[ENTRY]_ci1()", "[CI]_[ENTRY]_ci2()"]))
        ts.product(vars_ts)
        self.assertTrue(len(errors) == 1)

        self.assertTrue(
            is_sat(
                And([
                    errors[0],
                    Not(TSEncoder._get_state_var("[CI]_[ENTRY]_ci1()")),
                    Not(TSEncoder._get_state_var("[CI]_[ENTRY]_ci2()"))
                ])))