Пример #1
0
    def parseCex(cls, cexFile):
        """
        sage: KLEE.parseCex("counterexample @ l8 @ 0 : 512 65")
        ('l8', '0', ('512', '65'))

        sage: KLEE.parseCex("counterexample @ l0 @ 0 + 1 > 0: 512 65")
        ('l0', '0 + 1 > 0', ('512', '65'))

        sage: KLEE.parseCex("counterexample @ l0 @ 0 + 1 > 0")
        ('l0', '0 + 1 > 0', None)

        __VERIFIER_nondet_int@2: 4294966300
        __VERIFIER_nondet_int@3: 0
        main::__CPAchecker_TMP_0@3: 1
        main::__CPAchecker_TMP_1@3: 1
        main::__CPAchecker_TMP_2@3: 1
        main::__CPAchecker_TMP_3@3: 1
        main::x@3: 4294966300
        main::y@3: 0
        mainQ::x@2: 4294966300
        mainQ::y@2: 0

        __VERIFIER_nondet_int@2: 2
        __VERIFIER_nondet_int@3: 2
        main::__CPAchecker_TMP_0@3: 1
        main::__CPAchecker_TMP_1@3: 1
        main::__CPAchecker_TMP_2@3: 1
        main::__CPAchecker_TMP_3@3: 1
        main::x@3: 2
        main::y@3: 2
        mainQ::a@3: 2
        mainQ::b@3: 2
        mainQ::p@3: 1
        mainQ::x@2: 2
        mainQ::y@2: 2

        """
        assert os.path.isfile(cexFile)

        def _parse(s):
            """
            main::x@3: 2 => x,2
            """
            s = s.split('::')[1]  #x@3:2
            vname, rest = s.split('@')
            vval = rest.split(':')[1].strip()
            return vname, vval

        inp = {}
        lines = list(CM.iread_strip(cexFile))
        for l in lines:
            if '__' in l:  #__CPAchecker_TMP_3@3: 1 ...
                continue
            if l.startswith("main::"):  #main::x@3: 7
                vname, vval = _parse(l)

                assert vname not in inp, '\n'.join(lines)
                inp[vname] = vval

        return inp
Пример #2
0
def read_exp_dir_pc(exp_dir):
    exp_files = [f for f in os.listdir(exp_dir)
                 if f.endswith('.exp') and "__v1." not in f]
    exp_files = sorted(exp_files)
    exp_files = [os.path.join(exp_dir,f) for f in exp_files]

    print("parse {} exp files from '{}'".format(len(exp_files),exp_dir))
    db = OrderedDict()
    for i,exp_file in enumerate(exp_files):
        print("{}/{}. '{}'".format(i+1,len(exp_files),exp_file))
        pathconds = read_exp_pc(CM.iread_strip(exp_file))
        db[exp_file] = pathconds
    return db
Пример #3
0
    def parse(cls, tracefile, invdecls):
        """
        parse trace for new traces
        """
        assert isinstance(tracefile, str), tracefile
        assert isinstance(invdecls, dict) and invdecls, invdecls

        dtraces = DTraces()
        for l in CM.iread_strip(tracefile):
            #l22: 8460 16 0 1 16 8460
            parts = l.split(':')
            assert len(parts) == 2, parts
            lineno = parts[0].strip()  #l22
            tracevals = parts[1].strip().split()
            trace = _Trace.parse(tracevals)
            dtraces.add(lineno, trace, invdecls)
        return dtraces
Пример #4
0
def get_dom(dom_file):
    assert os.path.isfile(dom_file), dom_file

    def get_lines(lines):
        rs = (line.split() for line in lines)
        rs_ = {}
        var_idx = 0
        for parts in rs:
            var = parts[0]
            vals = { "__id": var_idx }
            var_idx = var_idx + 1
            idx = 0
            for lbl in parts[1:]:
                vals[lbl] = idx;
                idx = idx + 1;
            rs_[var] = vals
        return rs_

    return get_lines(CM.iread_strip(dom_file))
Пример #5
0
    def parse(tracefile):
        """
        parse trace for file
        """
        assert isinstance(tracefile, str), tracefile

        dtraces = {}
        for l in CM.iread_strip(tracefile):
            if not l: continue

            #l22: 8460 16 0 1 16 8460
            parts = l.split(':')
            assert len(parts) == 2
            lineno = int(parts[0].strip()[1:])  #l22

            tracevals = parts[1].strip().split()
            tracevals = map(Miscs.ratOfStr, tracevals)

            if lineno not in dtraces:
                dtraces[lineno] = Traces()
            dtraces[lineno].add(tuple(tracevals))

        return dtraces
Пример #6
0
    def parse(cls, tracefile, invdecls):
        """
        parse trace for new traces
        """
        assert isinstance(tracefile, str), tracefile
        assert isinstance(invdecls, dict) and invdecls, invdecls

        dtraces = DTraces()
        for l in CM.iread_strip(tracefile):
            #l22: 8460 16 0 1 16 8460
            parts = l.split(':')
            assert len(parts) == 2
            lineno = parts[0].strip()  #l22
            assert lineno in invdecls, (lineno, invdecls)

            tracevals = parts[1].strip().split()
            tracevals = map(miscs.ratOfStr, tracevals)
            ss = invdecls[lineno].keys()
            assert len(ss) == len(tracevals)

            trace = cls(zip(ss, tracevals))
            dtraces.addToSet(lineno, trace)
        return dtraces
Пример #7
0
    def parse(cls, tracefile):
        """
        parse trace for new traces
        """
        assert isinstance(tracefile, str), tracefile

        dtraces = {}
        for l in CM.iread_strip(tracefile):
            #disproved x + y == 0 @ line 20: 924 9 0 1 9 924
            inv_s, trace_s = l.split(':')
            #lineno = parts[0].strip()  #l22

            #inv
            inv_s, line_s = inv_s.strip().split('@')
            inv = inv_s.replace('disproved', '').strip()

            #traces
            tracevals = trace_s.strip().split()
            tracevals = tuple(miscs.ratOfStr(t) for t in tracevals)
            if inv not in dtraces:
                dtraces[inv] = set()
            dtraces[inv].add(tracevals)
        return dtraces