コード例 #1
0
    def test_regexp_or(self):
        trace = CTrace()
        cb = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()],
                       None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ci1 = CCallin(1, 1, "", "void doA()", [TestGrounding._get_int(1)],
                      None)
        ci2 = CCallin(1, 1, "", "void doB()", [TestGrounding._get_int(2)],
                      None)
        ci3 = CCallin(1, 1, "", "void doC()", [TestGrounding._get_int(2)],
                      None)
        cb.add_msg(ci1)
        cb.add_msg(ci2)
        cb.add_msg(ci3)
        trace.add_msg(cb)

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC ([CI] [ENTRY] [l] void doA() | [CI] [ENTRY] [l] void doB()) |- [CI] [ENTRY] [f] void doC()"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [1] void doA() |- [CI] [ENTRY] [2] void doC();"
            +
            "SPEC [CI] [ENTRY] [2] void doB() |- [CI] [ENTRY] [2] void doC()")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))
コード例 #2
0
    def test_only_methods(self):
        trace = CTrace()
        cb = CCallback(1, 1, "", "void m1()", [TestGrounding._get_null()],
                       None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ci1 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None)
        ci2 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None)
        ci3 = CCallin(1, 1, "", "void m2()", [TestGrounding._get_null()], None)
        cb.add_msg(ci1)
        cb.add_msg(ci2)
        cb.add_msg(ci3)
        trace.add_msg(cb)

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] void m2() |- [CB] [EXIT] void m1()")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(1 == len(ground_specs))

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC ! ([CB] [ENTRY] void m3()) |- [CB] [ENTRY] void m1()")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(1 == len(ground_specs))
        self.assertTrue(
            new_star(new_true()) == get_regexp_node(ground_specs[0].ast))

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] void m3() |- [CB] [ENTRY] void m1()")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(0 == len(ground_specs))
コード例 #3
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)
コード例 #4
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())
コード例 #5
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)
コード例 #6
0
    def test_iss131_2(self):
        trace = CTrace()
        cb1 = CCallback(1, 1, "", "void doA()", [TestGrounding._get_int(2)],
                        None,
                        [TestGrounding._get_fmwkov("", "void doA()", False)])
        trace.add_msg(cb1)
        cb2 = CCallback(1, 1, "", "void doB()", [TestGrounding._get_int(1)],
                        None,
                        [TestGrounding._get_fmwkov("", "void doB()", False)])
        trace.add_msg(cb2)

        cb3 = CCallback(1, 1, "", "void doC()", [TestGrounding._get_int(1)],
                        None,
                        [TestGrounding._get_fmwkov("", "void doC()", False)])
        trace.add_msg(cb3)

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC ([CB] [ENTRY] [l] void doA() | [CB] [ENTRY] [l] void doB()) |- [CB] [ENTRY] [f] void doC()"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [2] void doA() |- [CB] [ENTRY] [1] void doC();"
            +
            "SPEC [CB] [ENTRY] [1] void doB() |- [CB] [ENTRY] [1] void doC()")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))
コード例 #7
0
    def test_iss161(self):
        trace = CTrace()
        cb1 = CCallback(1, 1, "", "void doA()", [TestGrounding._get_int(2)],
                        None,
                        [TestGrounding._get_fmwkov("", "void doA()", False)])
        trace.add_msg(cb1)
        cb2 = CCallback(1, 1, "", "void doB()", [TestGrounding._get_int(1)],
                        None,
                        [TestGrounding._get_fmwkov("", "void doB()", False)])
        trace.add_msg(cb2)
        cb3 = CCallback(1, 1, "", "void doA()", [TestGrounding._get_int(3)],
                        None,
                        [TestGrounding._get_fmwkov("", "void doA()", False)])
        trace.add_msg(cb3)

        gs = GroundSpecs(trace)
        #specs = Spec.get_specs_from_string("SPEC [CB] [ENTRY] [l] void doA(); (! [CB] [ENTRY] [l] void doA()) |- [CB] [ENTRY] [l2] void doB()")
        specs = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [l] void doA(); [CB] [ENTRY] [l] void doA() |- [CB] [ENTRY] [l2] void doB()"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [l] void doA(); (! [CB] [ENTRY] [l] void doA()) |- [CB] [ENTRY] [l] void doB()"
        )
        ground_specs = gs.ground_spec(specs[0])

        for g in ground_specs:
            g.print_spec(sys.stdout)
            print ""
コード例 #8
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
コード例 #9
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))
コード例 #10
0
 def test_int(self):
     trace = CTrace()
     cb = CCallback(
         1, 1, "", "void m1(%s)" % TraceConverter.JAVA_INT,
         [TestGrounding._get_null(),
          TestGrounding._get_int(2)], None, [
              TestGrounding._get_fmwkov(
                  "", "void m1(%s)" % TraceConverter.JAVA_INT, False)
          ])
     trace.add_msg(cb)
     gs = GroundSpecs(trace)
     specs = Spec.get_specs_from_string(
         "SPEC TRUE |- [CB] [ENTRY] void m1(2 : %s)" %
         TraceConverter.JAVA_INT)
     ground_specs = gs.ground_spec(specs[0])
     self.assertTrue(1 == len(ground_specs))
コード例 #11
0
    def test_constants(self):
        trace = CTrace()
        cb = CCallback(1, 1, "edu.colorado.test",
                       "void inheritedMethodMethod(int)",
                       [TestGrounding._get_null(),
                        TestGrounding._get_int(2)], None, [
                            TestGrounding._get_fmwkov(
                                "android", "void inheritedMethod(int)", False)
                        ])
        trace.add_msg(cb)

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC ! ([CB] [ENTRY] void android.inheritedMethodA(3 : int)) |- [CB] [ENTRY] void android.inheritedMethod(2 : int)"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(len(ground_specs) == 1)
コード例 #12
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)
コード例 #13
0
        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
コード例 #14
0
    def test_method_assignment(self):
        trace = CTrace()

        cb = CCallback(
            1, 1, "edu.colorado.test", "int inheritedMethod()",
            [TestGrounding._get_obj("1", "android.widget.Button")], None, [
                TestGrounding._get_fmwkov("android.widget.Button",
                                          "int inheritedMethod()", False)
            ])
        trace.add_msg(cb)
        tmap = TraceMap(trace)

        cnode = new_call_entry(
            new_cb(), new_id("l"),
            new_id("int android.widget.Button.inheritedMethod"), new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding(
            [[[new_id('l'), (True, cnode)],
              [TestGrounding._get_obj("1", "android.widget.Button"), cb]]])
        self.assertTrue(res == res_2)
コード例 #15
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)
コード例 #16
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)
コード例 #17
0
ファイル: test_090.py プロジェクト: repohoarder/verivita
    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)
コード例 #18
0
    def get_trace(trace_str):
        trace = CTrace()

        index = 0
        for cb in trace_str.split(";"):
            if not cb:
                continue
            index = index + 1
            cb_name = cb[:cb.index("(")]
            cb_params = cb[cb.index("(") + 1:cb.index(")")].split(",")

            p_values = []
            signature = "void %s(" % cb_name
            first = True
            p_values.append(TestGrounding._get_int("1"))
            for p in cb_params:
                if not first:
                    signature = "%s," % signature
                first = False
                try:
                    x = int(p)
                    p_values.append(TestGrounding._get_int(x))
                    signature = "%s%s" % (signature, "int")
                except:
                    if (p == "#"):
                        p_values.append(new_dontcare())
                    else:
                        p_values.append(new_id(p))
                    signature = "%s%s" % (signature, "int")

            signature = "%s)" % signature

            cb = CCallback(index, 1, "", signature, p_values, None,
                           [TestGrounding._get_fmwkov("", signature, False)])

            trace.add_msg(cb)

        return trace
コード例 #19
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)
コード例 #20
0
 def test_slice(self):
     trace = CTrace()
     cb1 = CCallback(6, 1, "", "doSomethingCb()",
                     [self._get_obj("1","string")],
                     None, [self._get_fmwkov("","doSomethingCb()",False)])
     trace.add_msg(cb1)
     ci1 = CCallin(7, 1, "", "doSomethingCi()",
                   [self._get_obj("1","string"), self._get_obj('3','string')],
                   None)
     cb1.add_msg(ci1)
     ci2 = CCallin(9, 1, "", "doSomethingCi(string)",
                   [self._get_obj("1","string"),
                   self._get_obj('2',"string")],
                   None)
     cb1.add_msg(ci2)
     cb2 = CCallback(10,1,"","meh()", [self._get_obj('00','string')])
     trace.add_msg(cb2)
     i_slice(trace,"3")
     assert(cb1 in trace.children)
     assert(ci2 not in trace.children[0].children)
     assert(cb2 not in trace.children)
コード例 #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)))
コード例 #22
0
 def test_boolean(self):
     trace = CTrace()
     cb = CCallback(
         1, 1, "", "void m1(%s)" % TraceConverter.JAVA_BOOLEAN,
         [TestGrounding._get_null(),
          TestGrounding._get_true()], None, [
              TestGrounding._get_fmwkov(
                  "", "void m1(%s)" % TraceConverter.JAVA_BOOLEAN, False)
          ])
     trace.add_msg(cb)
     cb = CCallback(
         1, 1, "", "void m2(%s)" % TraceConverter.JAVA_BOOLEAN,
         [TestGrounding._get_null(),
          TestGrounding._get_false()], None, [
              TestGrounding._get_fmwkov(
                  "", "void m2(%s)" % TraceConverter.JAVA_BOOLEAN, False)
          ])
     trace.add_msg(cb)
     gs = GroundSpecs(trace)
     specs = Spec.get_specs_from_string(
         "SPEC TRUE |- [CB] [ENTRY] void m2(FALSE : %s)" %
         (TraceConverter.JAVA_BOOLEAN))
     ground_specs = gs.ground_spec(specs[0])
     self.assertTrue(1 == len(ground_specs))
コード例 #23
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()"]))
コード例 #24
0
    def test_trace_map(self):
        trace = CTrace()
        cb1 = CCallback(
            1, 1, "", "doSomethingCb()",
            [TestGrounding._get_obj("1", "string")], None,
            [TestGrounding._get_fmwkov("", "doSomethingCb()", False)])
        trace.add_msg(cb1)
        ci1 = CCallin(1, 1, "", "doSomethingCi()",
                      [TestGrounding._get_obj("1", "string")], None)
        cb1.add_msg(ci1)
        ci2 = CCallin(
            1, 1, "", "doSomethingCi(int)",
            [TestGrounding._get_obj("1", "string"),
             TestGrounding._get_int(2)], None)
        cb1.add_msg(ci2)
        cb2 = CCallback(
            2, 1, "", "doSomethingCb()", [], None,
            [TestGrounding._get_fmwkov("", "doSomethingCb()", False)])
        trace.add_msg(cb2)
        cb3 = CCallback(
            3, 1, "", "doSomethingCb()",
            [TestGrounding._get_obj("2", "string")], None,
            [TestGrounding._get_fmwkov("", "doSomethingCb()", False)])
        trace.add_msg(cb3)

        cb4 = CCallback(
            4, 1, "", "doSomethingCb()",
            [TestGrounding._get_obj("2", "string")],
            TestGrounding._get_obj("3", "string"),
            [TestGrounding._get_fmwkov("", "doSomethingCb()", False)])
        trace.add_msg(cb4)

        cb5 = CCallback(5, 1, "package.MyClass", "testClassName()",
                        [TestGrounding._get_obj("2", "string")],
                        TestGrounding._get_obj("3", "string"), [
                            TestGrounding._get_fmwkov("package.MyClass",
                                                      "testClassName()", False)
                        ])
        trace.add_msg(cb5)

        cb6 = CCallback(
            6, 1, "package.MyClass",
            "testAssignConstant()", [TestGrounding._get_obj("2", "string")],
            TestGrounding._get_int(3), [
                TestGrounding._get_fmwkov("package.MyClass",
                                          "testAssignConstant()", False)
            ])
        trace.add_msg(cb6)

        # Test first framework type
        cb7 = CCallback(
            7, 1, "package.MyClass", "testClassName()",
            [TestGrounding._get_obj("2", "string")],
            TestGrounding._get_obj("3", "string"), [
                TestGrounding._get_fmwkov("android.Button", "testClassName()",
                                          False),
                TestGrounding._get_fmwkov("android.ButtonInterface",
                                          "testClassName()", True),
                TestGrounding._get_fmwkov("android.ButtonInner",
                                          "testClassName()", False)
            ])
        trace.add_msg(cb7)

        tmap = TraceMap(trace)

        assert (len(tmap.lookup_methods(True, new_ci(), "other()", 0,
                                        False)) == 0)
        assert (len(
            tmap.lookup_methods(True, new_cb(), "doSomethingCb()", 0,
                                False)) == 1)
        assert (len(
            tmap.lookup_methods(True, new_cb(), "doSomethingCb()", 1,
                                False)) == 3)
        assert (len(
            tmap.lookup_methods(True, new_ci(), "doSomethingCi()", 1,
                                False)) == 1)
        assert (len(
            tmap.lookup_methods(True, new_cb(), "doSomethingCi()", 1,
                                False)) == 0)
        assert (len(
            tmap.lookup_methods(True, new_ci(), "doSomethingCi(int)", 2,
                                False)) == 1)

        assert (len(
            tmap.lookup_methods(False, new_cb(), "doSomethingCb()", 1,
                                True)) == 1)

        assert (len(
            tmap.lookup_methods(True, new_cb(),
                                "package.MyClass.testClassName()", 1,
                                False)) == 1)
        assert (len(
            tmap.lookup_methods(False, new_cb(),
                                "package.MyClass.testClassName()", 1,
                                True)) == 1)

        assert (len(
            tmap.lookup_methods(True, new_cb(),
                                "android.Button.testClassName()", 1,
                                False)) == 1)
        assert (len(
            tmap.lookup_methods(False, new_cb(),
                                "android.Button.testClassName()", 1,
                                True)) == 1)

        assert (len(
            tmap.lookup_methods(True, new_cb(),
                                "android.ButtonInner.testClassName()", 1,
                                False)) == 0)
        assert (len(
            tmap.lookup_methods(False, new_cb(),
                                "android.ButtonInner.testClassName()", 1,
                                True)) == 0)

        assert (len(
            tmap.lookup_methods(True, new_cb(),
                                "android.ButtonInterface.testClassName()", 1,
                                False)) == 1)
        assert (len(
            tmap.lookup_methods(False, new_cb(),
                                "android.ButtonInterface.testClassName()", 1,
                                True)) == 1)

        assert (len(
            tmap.lookup_methods(True, new_cb(),
                                "package.MyClass.testAssignConstant()", 1,
                                False)) == 1)
        assert (len(
            tmap.lookup_methods(False, new_cb(),
                                "package.MyClass.testAssignConstant()", 1,
                                True)) == 1)

        cnode = new_call_entry(new_cb(), new_id("l"), new_id("doSomethingCb"),
                               new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding(
            [[[new_id('l'), (True, cnode)],
              [TestGrounding._get_obj("1", "string"), cb1]],
             [[new_id('l'), (True, cnode)],
              [TestGrounding._get_obj("2", "string"), cb3]],
             [[new_id('l'), (True, cnode)],
              [TestGrounding._get_obj("2", "string"), cb4]]])
        self.assertTrue(res == res_2)

        cnode = new_call_exit(new_nil(), new_cb(), new_id("l"),
                              new_id("doSomethingCb"), new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding(
            [[[new_id('l'), (False, cnode)],
              [TestGrounding._get_obj("1", "string"), cb1]],
             [[new_id('l'), (False, cnode)],
              [TestGrounding._get_obj("2", "string"), cb3]]])
        self.assertTrue(res == res_2)

        cnode = new_call_exit(new_nil(), new_cb(), new_dontcare(),
                              new_id("doSomethingCb"), new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding([[[(False, cnode)], [cb1]],
                                          [[(False, cnode)], [cb3]]])
        self.assertTrue(res == res_2)

        cnode = new_call_entry(
            new_ci(), new_dontcare(), new_id("doSomethingCi"),
            new_param(new_id('z'), new_id("int"), new_nil()))
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding([[[new_id('z'), (True, cnode)],
                                           [TestGrounding._get_int(2), ci2]]])
        self.assertTrue(res == res_2)

        cnode = new_call_exit(new_nil(), new_ci(), new_dontcare(),
                              new_id("doSomethingCi"),
                              new_param(new_id('z'), new_id("int"), new_nil()))
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding([[[new_id('z'), (False, cnode)],
                                           [TestGrounding._get_int(2), ci2]]])
        self.assertTrue(res == res_2)

        cnode = new_call_exit(new_id("z"), new_cb(), new_id("l"),
                              new_id("doSomethingCb"), new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding(
            [[[new_id('z'), new_id('l'), (False, cnode)],
              [
                  TestGrounding._get_obj("3", "string"),
                  TestGrounding._get_obj("2", "string"), cb4
              ]]])
        self.assertTrue(res == res_2)

        cnode = new_call_exit(new_id("z"), new_cb(), new_id("l"),
                              new_id("package.MyClass.testClassName"),
                              new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding(
            [[[new_id('z'), new_id('l'), (False, cnode)],
              [
                  TestGrounding._get_obj("3", "string"),
                  TestGrounding._get_obj("2", "string"), cb5
              ]]])
        self.assertTrue(res == res_2)

        cnode = new_call_exit(new_int(3), new_cb(), new_id("l"),
                              new_id("package.MyClass.testAssignConstant"),
                              new_nil())
        res = tmap.lookup_assignments(cnode)
        res_2 = TestGrounding.newBinding(
            [[[new_id('l'), (False, cnode)],
              [TestGrounding._get_obj("2", "string"), cb6]]])
        assert (res == res_2)
コード例 #25
0
    def test_ground_bindings(self):
        trace = CTrace()
        cb1 = CCallback(
            1, 1, "", "void doSomethingCb()",
            [TestGrounding._get_obj("1", "string")], None,
            [TestGrounding._get_fmwkov("", "void doSomethingCb()", False)])
        trace.add_msg(cb1)

        ci1 = CCallin(1, 1, "", "void doSomethingCi(string)", [
            TestGrounding._get_obj("1", "string"),
            TestGrounding._get_obj("2", "string")
        ], None)
        cb1.add_msg(ci1)

        ci2 = CCallin(1, 1, "", "void otherCi(string)", [
            TestGrounding._get_obj("4", "string"),
            TestGrounding._get_obj("1", "string")
        ], None)
        cb1.add_msg(ci2)

        ci3 = CCallin(1, 1, "", "void doSomethingCi(string)", [
            TestGrounding._get_obj("1", "string"),
            TestGrounding._get_obj("4", "string")
        ], None)
        cb1.add_msg(ci3)

        cb2 = CCallback(
            1, 1, "", "void doSomethingCb2()",
            [TestGrounding._get_obj("1", "string")],
            TestGrounding._get_obj("1", "string"),
            [TestGrounding._get_fmwkov("", "void doSomethingCb2()", False)])
        trace.add_msg(cb2)

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void doSomethingCi(z : string) |- [CI] [ENTRY] [z] void otherCi(f  : string)"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [1] void doSomethingCi(4 : string) |- [CI] [ENTRY] [4] void otherCi(1  : string)"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))

        # WARNING: the results is sensitive to the order of the atoms in the OR
        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void doSomethingCi(# : string) |- [CI] [ENTRY] [#] void otherCi(# : string)"
        )
        real_ground_spec_1 = Spec.get_specs_from_string(
            "SPEC ([CI] [ENTRY] [1] void doSomethingCi(4 : string) | " +
            "[CI] [ENTRY] [1] void doSomethingCi(2 : string)) " +
            "|- [CI] [ENTRY] [4] void otherCi(1 : string)")
        real_ground_spec_2 = Spec.get_specs_from_string(
            "SPEC ([CI] [ENTRY] [1] void doSomethingCi(2 : string) | " +
            "[CI] [ENTRY] [1] void doSomethingCi(4 : string)) " +
            "|- [CI] [ENTRY] [4] void otherCi(1 : string)")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(
            TestGrounding._eq_specs(ground_specs, real_ground_spec_1)
            or TestGrounding._eq_specs(ground_specs, real_ground_spec_2))

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [l] void doSomethingCb() |- [CI] [ENTRY] [#] void otherCi(l : string)"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [1] void doSomethingCb() |- [CI] [ENTRY] [4] void otherCi(1 : string)"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC TRUE |- [CI] [ENTRY] [l1] void doSomethingCi(l1 : string)")
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs, []))

        # doSomethingCi will be instantiated to FALSE
        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l1] void doSomethingCi(l1 : string) |- [CI] [ENTRY] [z] void otherCi(l : string)"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs, []))

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC [CB] [EXIT] [l] void doSomethingCb() |- [CI] [EXIT] [#] void otherCi(l : string)"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CB] [EXIT] [1] void doSomethingCb() |- [CI] [EXIT] [4] void otherCi(1 : string)"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(
            "SPEC m = [CB] [EXIT] [l] void doSomethingCb2() |- m = [CB] [EXIT] [l] void doSomethingCb2()"
        )
        real_ground_spec = Spec.get_specs_from_string(
            "SPEC 1 = [CB] [EXIT] [1] void doSomethingCb2() |- 1 = [CB] [EXIT] [1] void doSomethingCb2()"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))