Ejemplo n.º 1
0
    def test_exception(self):
        """ Test the removal of exception from top-level callbacks
        """
        spec_list = Spec.get_specs_from_string(
            "SPEC FALSE[*] |- [CI] [ENTRY] void m2()")

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.assertFalse(cex is None)

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

        io_string = stringio.getvalue()
        self.assertTrue(
            "SPEC [CB] [ENTRY] [1] void m1() |- [CB] [EXIT] [1] void m1()" in
            io_string)
        self.assertTrue("Reached an error state in step 4" in io_string)
Ejemplo n.º 5
0
    def _accept_word(self, ts_enc, ts, word, final_states):
        """ Check if a particular word with a given final state
        is accepted by ts
        """

        # error is encoded in the final state
        bmc = BMC(ts_enc.helper, ts, TRUE())

        solver = Solver(name='z3', logic=QF_BOOL)
        all_vars = set(ts.state_vars)
        all_vars.update(ts.input_vars)

        bmc.encode_up_to_k(solver, all_vars, len(word))

        error = bmc.helper.get_formula_at_i(all_vars, final_states, len(word))
        solver.add_assertion(error)

        # encode the word
        for i in range(len(word)):
            w_formula = ts_enc.r2a.get_msg_eq(word[i])
            w_at_i = bmc.helper.get_formula_at_i(ts.input_vars, w_formula, i)
            solver.add_assertion(w_at_i)

        res = solver.solve()
        # if res:
        #     model = solver.get_model()
        #     print model
        return res
Ejemplo n.º 6
0
    def test_090_multiple_cbs(self):
        spec_list = Spec.get_specs_from_string("SPEC FALSE[*] |- [CI] [ENTRY] [l] void m4();" \
                                               "SPEC FALSE[*] |- [CB] [ENTRY] [l] void m3();" \
                                               "SPEC [CB] [ENTRY] [l1] void m1() |+ [CB] [ENTRY] [l2] void m3()")
        assert spec_list is not None

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

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

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

        io_string = stringio.getvalue()

        self.assertTrue("[4] [CB] [ENTRY] void m1()" in io_string)
        self.assertTrue("[5] [CI] [ENTRY] void m2()" in io_string)
        self.assertTrue("[6] [CB] [ENTRY] void m3()" in io_string)
        self.assertTrue("[7] [CI] [ENTRY] void m4()" in io_string)
Ejemplo n.º 7
0
    def run_bmc(self, depth, inc=False):
        ts_enc = TSEncoder(self.trace, self.spec_list, self.opts.simplify_trace,
                           self.stats)

        self.stats.start_timer(Stats.VERIFICATION_TIME)

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

        cex = bmc.find_bug(depth, inc)

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


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

        self.stats.start_timer(Stats.SIMULATION_TIME)

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

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

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

        return (step, trace, last_trace, ts_enc.mapback)
Ejemplo n.º 9
0
    def test_simulation(self):
        ctrace = CTrace()
        cb = CCallback(1, 1, "", "void m1()",
                       [TestGrounding._get_obj("1", "string")], None,
                       [TestGrounding._get_fmwkov("", "void m1()", False)])
        ctrace.add_msg(cb)
        ci = CCallin(1, 1, "", "void m2()",
                     [TestGrounding._get_obj("1", "string")], None)
        cb.add_msg(ci)
        ts_enc = TSEncoder(ctrace, [])  #spec_list)

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

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

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

        self.assertTrue(trace is not None)
Ejemplo n.º 10
0
    def test_cex_printer(self):
        ts_enc = self._get_sample_trace()
        ts = ts_enc.get_ts_encoding()
        error = ts_enc.error_prop
        bmc = BMC(ts_enc.helper, ts, error)
        cex = bmc.find_bug(2)
        cex = bmc.find_bug(2, 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() |- [CI] [ENTRY] [1] void m2()" in
            io_string)
        self.assertTrue("Reached an error state in step 2" in io_string)
Ejemplo n.º 11
0
    def test_init_state(self):
        """ Test if specification can force an initial value

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

        ctrace = CTrace()

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

        ts_enc = TSEncoder(ctrace, spec_list)
        ts = ts_enc.get_ts_encoding()
        bmc = BMC(ts_enc.helper, ts, ts_enc.error_prop)
        self.assertTrue(bmc.find_bug(2) is not None)
        self.assertTrue(bmc.find_bug(2, True) is not None)
Ejemplo n.º 12
0
    def test_encode(self):
        ts_enc = self._get_sample_trace()

        ts = ts_enc.get_ts_encoding()

        error = ts_enc.error_prop
        bmc = BMC(ts_enc.helper, ts, error)

        # not None == there is a bug
        self.assertTrue(bmc.find_bug(0) is None)
        self.assertTrue(bmc.find_bug(1) is None)
        self.assertTrue(bmc.find_bug(2) is not None)
        self.assertTrue(bmc.find_bug(3) is not None)

        self.assertTrue(bmc.find_bug(0, True) is None)
        self.assertTrue(bmc.find_bug(1, True) is None)
        self.assertTrue(bmc.find_bug(2, True) is not None)
        self.assertTrue(bmc.find_bug(3, True) is not None)