Ejemplo n.º 1
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.º 2
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.º 3
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)