Пример #1
0
    def __init__(self, opts):
        self.opts = opts

        self.stats = Stats()
        self.stats.enable()

        # Parse the trace
        try:
            self.stats.start_timer(Stats.PARSING_TIME)
            self.trace = CTraceSerializer.read_trace_file_name(self.opts.tracefile,
                                                               self.opts.traceformat == "json",
                                                               self.opts.allow_exception)
            self.stats.stop_timer(Stats.PARSING_TIME)
            self.stats.write_times(sys.stdout, Stats.PARSING_TIME)
        except MalformedTraceException as e:
            raise
        except TraceEndsInErrorException as e:
            raise
        except Exception as e:
            raise Exception("An error happened reading the trace in %s (%s)" % (self.opts.tracefile,
                                                                                e.message))


        # Parse the specs
        self.spec_list = Spec.get_specs_from_files(self.opts.spec_file_list)
        if self.spec_list is None:
            raise Exception("Error parsing the specification file!")
Пример #2
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))
Пример #3
0
if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description=
        'Combine possible method names with types in subexpressions (REGEXP)')
    parser.add_argument('--trace',
                        type=str,
                        help="Trace to scan",
                        required=True)
    parser.add_argument(
        '--disallow',
        type=str,
        help="Spec files associated with this disallow colon separated")

    args = parser.parse_args()

    spec_list = Spec.get_specs_from_files(args.disallow.split(":"))

    disallows = set()
    for spec in spec_list:
        rhs = ast.get_spec_rhs(spec.ast)
        if rhs[0] == ast.CALL_ENTRY:
            if rhs[1][0] == ast.CI:
                identifier = rhs[3][1]
                methodname = identifier.split(".")[-1]
                classname = ".".join(identifier.split(" ")[1].split(".")[:-1])
                disallows.add((classname, methodname))

    #read trace file into ctrace TODO
    trace = CTraceSerializer.read_trace_file_name(args.trace, False, False)
    for cmt in disallows:
        callbacks = getCallbacksForCallin([], cmt, trace)