Exemple #1
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))
Exemple #2
0
    def test_regexp_and(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(1)],
                      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] [1] void doB()) |- [CI] [ENTRY] [2] void doC()"
        )
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))
Exemple #3
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))
Exemple #4
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 ""
Exemple #5
0
    def test_instantiate_regexp(self):
        spec_string = "REGEXP pollo(x,y) = [[CB] [ENTRY] [x] type methodName(y : boolean)]; SPEC pollo(1,2) |- pollo(x,y)"
        res = "SPEC [CB] [ENTRY] [1] type methodName(2 : boolean) |- [CB] [ENTRY] [x] type methodName(y : boolean)"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)

        spec_string = "REGEXP pollo(x,y) = [[CB] [ENTRY] [x] type methodName(z : boolean)]; SPEC pollo(1,2) |- pollo(x,y)"
        res = "SPEC [CB] [ENTRY] [1] type methodName(z : boolean) |- [CB] [ENTRY] [x] type methodName(z : boolean)"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)

        spec_string = """REGEXP pollo1(x,y) = [[CB] [ENTRY] [x] type methodName1(y : boolean)]; 
REGEXP pollo2(x,y) = [[CB] [ENTRY] [x] type methodName2(y : boolean)];
SPEC pollo1(1,2) |- pollo2(x,y)"""
        res = "SPEC [CB] [ENTRY] [1] type methodName1(2 : boolean) |- [CB] [ENTRY] [x] type methodName2(y : boolean)"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)

        with self.assertRaises(Exception):
            # pollo with 1 arguments is not declared
            spec_string = "REGEXP pollo(x) = [[CB] [ENTRY] [x] type methodName(z : boolean)]; SPEC pollo(1,2) |- pollo(x)"
            specs = Spec.get_specs_from_string(spec_string)

        spec_list = Spec.get_specs_from_string("""
REGEXP pollo(x) = [[CI] [ENTRY] [x] void method_name()];
SPEC pollo(l) |- TRUE ALIASES method_name = [subs1]""")
        res = "SPEC [CI] [ENTRY] [l] void subs1() |- TRUE"
        self.assertTrue(len(spec_list) == 1)
        self.assertTrue(str(spec_list[0]) == res)
Exemple #6
0
    def test_aliasing(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void method_name() |- TRUE ALIASES method_name = [subs1]"
        )
        res = "SPEC [CI] [ENTRY] [l] void subs1() |- TRUE"
        self.assertTrue(len(spec_list) == 1)
        self.assertTrue(str(spec_list[0]) == res)

        spec_list = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void method_name2(); " +
            "     [CI] [ENTRY] [l] void method_name(); " +
            "     [CI] [ENTRY] [l] void method_name()  " +
            "     |- [CI] [ENTRY] [l] void method_name() " +
            "ALIASES method_name = [subs1]")

        res = [
            "SPEC (([CI] [ENTRY] [l] void method_name2(); " +
            "[CI] [ENTRY] [l] void subs1()); [CI] [ENTRY] [l] void subs1()) |- "
            + "[CI] [ENTRY] [l] void subs1()"
        ]
        self.assertTrue(len(spec_list) == len(res))
        for i in range(len(res)):
            self.assertTrue(str(spec_list[i]) in res)

        spec_list = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void method_name() |- TRUE " +
            "ALIASES method_name = [subs1, subs2]")
        res = [
            "SPEC [CI] [ENTRY] [l] void subs1() |- TRUE",
            "SPEC [CI] [ENTRY] [l] void subs2() |- TRUE"
        ]
        self.assertTrue(len(spec_list) == len(res))
        for i in range(len(res)):
            self.assertTrue(str(spec_list[i]) in res)

        spec_list = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void method_name() |- " +
            "[CI] [ENTRY] [l] void method_name2() " +
            "ALIASES method_name = [subs1, subs2], method_name2 = [subs3, subs4]"
        )

        res = [
            "SPEC [CI] [ENTRY] [l] void subs1() |- [CI] [ENTRY] [l] void subs3()",
            "SPEC [CI] [ENTRY] [l] void subs1() |- [CI] [ENTRY] [l] void subs4()",
            "SPEC [CI] [ENTRY] [l] void subs2() |- [CI] [ENTRY] [l] void subs3()",
            "SPEC [CI] [ENTRY] [l] void subs2() |- [CI] [ENTRY] [l] void subs4()"
        ]

        self.assertTrue(len(spec_list) == len(res))
        for i in range(len(res)):
            self.assertTrue(str(spec_list[i]) in res)
Exemple #7
0
    def check_sg(test):
        (r, t, expected_specs_str) = test

        trace = TestGrounding.get_trace(t)

        gs = GroundSpecs(trace)
        specs = Spec.get_specs_from_string(r)
        ground_specs = gs.ground_spec(specs[0])

        expected_ground_specs = Spec.get_specs_from_string(expected_specs_str)

        if expected_ground_specs is None:
            expected_ground_specs = []
        assert (TestGrounding._eq_specs(ground_specs, expected_ground_specs))
Exemple #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))
Exemple #9
0
    def _test_parse(self, spec, same_out=True):
        res = spec_parser.parse(spec)
        self.assertTrue(res is not None)

        # test the printing of the spec ast
        stringio = StringIO()
        pretty_print(res, stringio)

        # print "---"
        # print spec
        # pretty_print(res, sys.stdout)
        # print "\n---"

        self.assertTrue((not same_out) or stringio.getvalue() == spec)

        Spec.get_specs_from_string(stringio.getvalue())
Exemple #10
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)
Exemple #11
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())
Exemple #12
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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
0
 def test_spec_creation(self):
     spec_list = Spec.get_specs_from_string(
         "SPEC [CI] [ENTRY] [l] void method_name() |- TRUE; " +
         "SPEC [CI] [EXIT] [l] void method_name() |- TRUE;" +
         "SPEC [CI] [ENTRY] [b] void android.widget.Button.setOnClickListener(l : type) |+ [CB] [ENTRY] [l] void onClick(b : type);"
         +
         "SPEC TRUE[*]; [CI] [EXIT] [b] void android.widget.Button.setOnClickListener(l : type) |+ [CB] [ENTRY] [l] void onClick(b : type)"
     )
     self.assertTrue(len(spec_list) == 4)
Exemple #16
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)
Exemple #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
Exemple #18
0
    def test_instantiate_regexp_nested(self):
        spec_string = """REGEXP pollo(x) = [[CB] [ENTRY] [x] type methodName()];
        REGEXP pollo2(z) = [pollo(z)];
        SPEC pollo2(1) |- pollo(1)
        """
        res = "SPEC [CB] [ENTRY] [1] type methodName() |- [CB] [ENTRY] [1] type methodName()"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)

        spec_string = """REGEXP pollo(x,y) = [[CB] [ENTRY] [x] type methodName(y : boolean)];
        REGEXP pollo2(x,y) = [pollo(y,x)];
        SPEC pollo2(1,2) |- pollo(1,2)
        """
        res = "SPEC [CB] [ENTRY] [2] type methodName(1 : boolean) |- [CB] [ENTRY] [1] type methodName(2 : boolean)"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)

        spec_string = """REGEXP pollo(x) = [[CB] [ENTRY] [x] type methodName(y : boolean)];
        REGEXP pollo2(x,y) = [pollo(x)];
        SPEC pollo2(1,2) |- pollo2(1,2)
        """
        res = "SPEC [CB] [ENTRY] [1] type methodName(y : boolean) |- [CB] [ENTRY] [1] type methodName(y : boolean)"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)

        spec_string = """REGEXP pollo(x) = [[CB] [ENTRY] [x] type methodName(y : boolean)];
        REGEXP pollo2(x,y) = [pollo(x)];
        SPEC pollo2(1,2) |- pollo2(1,2)
        """
        res = "SPEC [CB] [ENTRY] [1] type methodName(y : boolean) |- [CB] [ENTRY] [1] type methodName(y : boolean)"
        specs = Spec.get_specs_from_string(spec_string)
        self.assertTrue(len(specs) == 1)
        self.assertTrue(str(specs[0]) == res)
Exemple #19
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))
Exemple #20
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)
Exemple #21
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)
def cycle_lines(in_file, out_file):
    with open(in_file, 'r') as f:
        for line in f:
            if line is not None and len(line) > 2 and line[0] != '/':

                line2 = line.strip()
                if line2[-1] == ";":
                    trimedLine = line2[:-1]
                else:
                    trimedLine = line2
                parsedspec = Spec.get_specs_from_string(trimedLine)
                assert (len(parsedspec) == 1)
                spec = parsedspec[0].ast
                aliasList = get_aliases_for_spec(spec)
                assert (len(aliasList) > 0)
                for alias in aliasList:
                    spec = add_alias(spec, alias[0], alias[1])
                pretty_print(spec)
                print ";"
            else:
                print line
Exemple #23
0
    def test_call_set(self):
        spec_list = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [l] void method_name() |- TRUE; " +
            "SPEC [CI] [ENTRY] [l] void method_name() |- TRUE;" +
            "SPEC [CI] [ENTRY] [b] void android.widget.Button.setOnClickListener(l : type) |+ [CB] [ENTRY] [l] void onClick(b : type);"
            +
            "SPEC TRUE[*]; [CI] [EXIT] [b] void android.widget.Button.setOnClickListener(l : type) |+ [CB] [ENTRY] [l] void onClick(b : type);"
            +
            "SPEC [CI] [EXIT] [b] void android.widget.Button.setOnClickListener(l : type); "
            +
            "[CB] [ENTRY] [b] void android.widget.Button.setOnClickListener(l : type); "
            +
            "[CI] [EXIT] [b] void android.widget.Button.setOnClickListener(l : type) |+ [CB] [ENTRY] [l] void onClick(b : type)"
        )

        self.assertTrue(len(spec_list) == 5)
        self.assertTrue(1 == len(spec_list[0].get_spec_calls()))
        self.assertTrue(1 == len(spec_list[1].get_spec_calls()))
        self.assertTrue(2 == len(spec_list[2].get_spec_calls()))
        self.assertTrue(2 == len(spec_list[3].get_spec_calls()))
        self.assertTrue(3 == len(spec_list[4].get_spec_calls()))
Exemple #24
0
    def test_array_types(self):
        test_path = os.path.dirname(cbverifier.test.examples.__file__)

        t1 = os.path.join(test_path, "trace_array.json")
        trace = CTraceSerializer.read_trace_file_name(t1, True)
        self.assertTrue(trace is not None)

        spec_file_path = os.path.join(test_path, "spec_array.spec")
        specs = Spec.get_specs_from_files([spec_file_path])
        self.assertTrue(specs is not None)
        self.assertTrue(len(specs) == 1)

        real_ground_spec = Spec.get_specs_from_string(
            "SPEC [CI] [ENTRY] [1] java.lang.String android.app.Activity.getString(2131427336 : int,4fe67f6 : java.lang.Object[],efe45f6 : java.lang.Test[][]) |- [CI] [ENTRY] [1] java.lang.String android.app.Activity.getString(2131427336 : int, 4fe67f6 : java.lang.Object[],efe45f6 : java.lang.Test[][])"
        )
        self.assertTrue(real_ground_spec is not None)

        gs = GroundSpecs(trace)
        ground_specs = gs.ground_spec(specs[0])
        self.assertTrue(ground_specs is not None)
        self.assertTrue(1 == len(ground_specs))
        self.assertTrue(TestGrounding._eq_specs(ground_specs,
                                                real_ground_spec))
Exemple #25
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)
Exemple #26
0
    def test_regexptoauto_exit(self):
        auto_env = AutoEnv.get_global_auto_env()
        cenc = CounterEnc(auto_env.pysmt_env)
        alphabet = set(
            ["[CB]_[ENTRY]_void m1()(1)", "[CB]_[EXIT]_void m1()(1)"])
        r2a = RegExpToAuto(cenc, alphabet,
                           TSMapback(auto_env.pysmt_env, None, None), auto_env)
        env = r2a.auto_env

        l_m1_entry = r2a.get_msg_eq("[CB]_[ENTRY]_void m1()(1)")
        l_m1_exit = r2a.get_msg_eq("[CB]_[EXIT]_void m1()(1)")

        spec_list = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [1] void m1() |- TRUE; " +
            "SPEC [CB] [EXIT] [1] void m1() |- TRUE; " +
            "SPEC [CB] [ENTRY] [1] void m1() & [CB] [EXIT] [1] void m1() |- TRUE"
        )
        assert spec_list is not None

        # Test l.m1()
        regexp = get_regexp_node(spec_list[0].ast)
        auto = r2a.get_from_regexp(regexp)
        res = Automaton.get_singleton(env.new_label(l_m1_entry))
        self.assertTrue(auto.is_equivalent(res))

        # Test l.m1_exit()
        regexp = get_regexp_node(spec_list[1].ast)
        auto = r2a.get_from_regexp(regexp)
        res = Automaton.get_singleton(env.new_label(l_m1_exit))
        self.assertTrue(auto.is_equivalent(res))

        # Test l.m1() and l.m2()
        regexp = get_regexp_node(spec_list[2].ast)
        auto = r2a.get_from_regexp(regexp)
        res = Automaton.get_singleton(env.new_label(And(l_m1_entry,
                                                        l_m1_exit)))
        self.assertTrue(auto.is_equivalent(res))
Exemple #27
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))
Exemple #28
0
    def test_mapback(self):
        def get_def_model(formula, vars_list, val):
            model_sat = get_model(formula)

            assert model_sat is not None

            model = {}
            for v in vars_list:
                if v not in model_sat:
                    model[v] = val
                else:
                    if model_sat.get_value(v) == TRUE():
                        model[v] = True
                    else:
                        model[v] = False

            return model

        pysmt_env = get_env()
        cenc = CounterEnc(pysmt_env)

        all_vars = []

        msg_ivar = "msg_ivar"
        cenc.add_var(msg_ivar, 10)
        all_vars.extend(cenc.get_counter_var(msg_ivar))

        pc_counter = "pc_counter"
        cenc.add_var(pc_counter, 10)
        all_vars.extend(cenc.get_counter_var(pc_counter))

        msg_vars_text = ["m_%d" % v for v in range(10)]
        msg_vars = [Symbol(v, BOOL) for v in msg_vars_text]
        all_vars.extend(msg_vars)

        auto_counters = ["a_%d" % v for v in range(2)]
        auto_counters_vars = []
        for c in auto_counters:
            cenc.add_var(c, 10)
            all_vars.extend(cenc.get_counter_var(c))

        # Fake spec (it is not important to test the mapback)
        specs = Spec.get_specs_from_string("SPEC [CB] [ENTRY] [l] void m1() |- [CI] [ENTRY] [l] void m2();" \
                                           "SPEC [CB] [ENTRY] [l] void m1() |- [CI] [ENTRY] [l] void m2()")

        mapback = TSMapback(pysmt_env, msg_ivar, pc_counter)

        mapback.add_encoder(msg_ivar, cenc)
        mapback.add_encoder(pc_counter, cenc)

        for i in range(10):
            mapback.add_vars2msg(i, "void m_%d()" % i)
        for i in range(10):
            mapback.add_pc2trace(i, i + 1, "trace_%d" % i, "void m_0()")

        c0 = Or(cenc.eq_val(auto_counters[0], 0),
                cenc.eq_val(auto_counters[0], 1))
        mapback.add_var2spec(msg_vars[0], True, specs[0], c0, specs[0])

        c1 = Or(cenc.eq_val(auto_counters[1], 2),
                cenc.eq_val(auto_counters[1], 3))
        mapback.add_var2spec(msg_vars[1], True, specs[1], c1, specs[1])

        for i in range(10):
            m = get_def_model(cenc.eq_val(msg_ivar, i), all_vars, False)
            res = mapback.get_trans_label(m)
            self.assertTrue("void m_%d()" % i == res)

        for i in range(10):
            m = get_def_model(And(msg_vars[i], cenc.eq_val(pc_counter, i)),
                              all_vars, False)
            m_next = get_def_model(cenc.eq_val(pc_counter, i + 1), all_vars,
                                   False)
            res = mapback.get_fired_trace_msg(m, m_next)
            self.assertTrue("trace_%d" % i == res)

        current_m = get_def_model(TRUE(), all_vars, False)
        next_m = get_def_model(And([msg_vars[0], c0, Not(c1)]), all_vars,
                               False)
        fired_specs = mapback.get_fired_spec(current_m, next_m, False)
        self.assertTrue(fired_specs == [(specs[0], specs[0])])

        current_m = get_def_model(TRUE(), all_vars, False)
        next_m = get_def_model(And([Not(msg_vars[0]), c0,
                                    Not(c1)]), all_vars, False)
        fired_specs = mapback.get_fired_spec(current_m, next_m, False)
        self.assertTrue(fired_specs == [])

        current_m = get_def_model(TRUE(), all_vars, False)
        next_m = get_def_model(And([msg_vars[1], c1, Not(c0)]), all_vars,
                               False)
        fired_specs = mapback.get_fired_spec(current_m, next_m, False)
        self.assertTrue(fired_specs == [(specs[1], specs[1])])

        # changes msg_vars[0]
        current_m = get_def_model(Not(msg_vars[0]), all_vars, False)
        next_m = get_def_model(And([msg_vars[0], c0, Not(c1)]), all_vars,
                               False)
        fired_specs = mapback.get_fired_spec(current_m, next_m, True)
        self.assertTrue(fired_specs == [(specs[0], specs[0])])

        current_m = get_def_model(msg_vars[0], all_vars, False)
        next_m = get_def_model(And([msg_vars[0], c0, Not(c1)]), all_vars,
                               False)
        fired_specs = mapback.get_fired_spec(current_m, next_m, True)
        self.assertTrue(fired_specs == [])
Exemple #29
0
    def test_regexptoauto(self):
        auto_env = AutoEnv.get_global_auto_env()
        # auto_env = AutoEnv(get_env(), True)
        cenc = CounterEnc(auto_env.pysmt_env)
        alphabet = set([
            "[CB]_[ENTRY]_void m1()(1)", "[CI]_[ENTRY]_void m2()(1)",
            "[CB]_[ENTRY]_void m3()(1)"
        ])

        r2a = RegExpToAuto(cenc, alphabet,
                           TSMapback(auto_env.pysmt_env, None, None), auto_env)
        env = r2a.auto_env

        l1 = r2a.get_msg_eq("[CB]_[ENTRY]_void m1()(1)")
        l2 = r2a.get_msg_eq("[CI]_[ENTRY]_void m2()(1)")
        l3 = r2a.get_msg_eq("[CB]_[ENTRY]_void m3()(1)")

        spec_list = Spec.get_specs_from_string(
            "SPEC [CB] [ENTRY] [1] void m1() |- TRUE; " +
            "SPEC ([CB] [ENTRY] [1] void m1() & [CI] [ENTRY] [1] void m2()) |- TRUE; "
            +
            "SPEC ([CB] [ENTRY] [1] void m1() | [CI] [ENTRY] [1] void m2()) |- TRUE; "
            + "SPEC (! [CB] [ENTRY] [1] void m1()) |- TRUE; " +
            "SPEC [CB] [ENTRY] [1] void m1(); [CI] [ENTRY] [1] void m2() |- TRUE; "
            + "SPEC [CB] [ENTRY] [1] void m1()[*] |- TRUE;" +
            "SPEC ([CB] [ENTRY] [1] void m1() & ([CI] [ENTRY] [1] void m2(); [CB] [ENTRY] [1] void m3())) |- TRUE "
        )
        assert spec_list is not None

        # Test l.m1()
        regexp = get_regexp_node(spec_list[0].ast)
        auto = r2a.get_from_regexp(regexp)
        label = env.new_label(l1)
        res = Automaton.get_singleton(label, auto_env)
        self.assertTrue(auto.is_equivalent(res))

        # Test l.m1() and l.m2()
        regexp = get_regexp_node(spec_list[1].ast)
        auto = r2a.get_from_regexp(regexp)
        res = Automaton.get_singleton(env.new_label(And(l1, l2)), auto_env)
        self.assertTrue(auto.is_equivalent(res))

        # Test l.m1() or l.m2()
        regexp = get_regexp_node(spec_list[2].ast)
        auto = r2a.get_from_regexp(regexp)
        res = Automaton.get_singleton(env.new_label(Or(l1, l2)), auto_env)
        self.assertTrue(auto.is_equivalent(res))

        # Test not l.m1()
        regexp = get_regexp_node(spec_list[3].ast)
        auto = r2a.get_from_regexp(regexp)
        l1_aut = Automaton.get_singleton(env.new_label(l1), auto_env)
        res = l1_aut.complement()

        self.assertTrue(auto.is_equivalent(res))

        # Test l.m1(); l.m1()
        regexp = get_regexp_node(spec_list[4].ast)
        auto = r2a.get_from_regexp(regexp)
        r1 = Automaton.get_singleton(env.new_label(l1), auto_env)
        r2 = Automaton.get_singleton(env.new_label(l2), auto_env)
        res = r1.concatenate(r2)
        self.assertTrue(auto.is_equivalent(res))

        # Test l.m1()[*]
        regexp = get_regexp_node(spec_list[5].ast)
        auto = r2a.get_from_regexp(regexp)
        r1 = Automaton.get_singleton(env.new_label(l1), auto_env)
        res = r1.klenee_star()
        self.assertTrue(auto.is_equivalent(res))

        # intersection of different regexpes
        regexp = get_regexp_node(spec_list[6].ast)
        auto = r2a.get_from_regexp(regexp)
        res = Automaton.get_singleton(env.new_label(FALSE()), auto_env)
        self.assertTrue(auto.is_equivalent(res))
Exemple #30
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))