diff --git a/src/global.ml b/src/global.ml index 24b13665..55914afd 100644 --- a/src/global.ml +++ b/src/global.ml @@ -566,6 +566,19 @@ let usage_function aligned usage_msg x = debug "usage: unknown option %s\n" x; Arg.usage aligned usage_msg; abort "usage" +(* Utility function to run a command and return its results as a string (from PLEAC). *) +let read_process command = + let buffer_size = 2048 in + let buffer = Buffer.create buffer_size in + let string = String.create buffer_size in + let in_channel = Unix.open_process_in command in + let chars_read = ref 1 in + while !chars_read <> 0 do + chars_read := input in_channel string 0 buffer_size; + Buffer.add_substring buffer string 0 !chars_read + done; + ignore (Unix.close_process_in in_channel); + Buffer.contents buffer (** Utility function to read 'command-line arguments' from a file. This allows us to avoid the old 'ldflags' file hackery, etc. *) diff --git a/src/main.ml b/src/main.ml index 39a28864..0af3b016 100644 --- a/src/main.ml +++ b/src/main.ml @@ -52,6 +52,7 @@ open Printf open Global open Population +let rep_out = ref "original" let representation = ref "" let time_at_start = Unix.gettimeofday () let describe_machine = ref false @@ -81,10 +82,16 @@ let _ = "--rep", Arg.Set_string representation, "X representation X (c,txt,java)" ; + "--orig-rep-out", Arg.Set_string rep_out, "X Output filename to which to print initial representation" ; + "--oracle-genome", Arg.Set_string oracle_genome, "X genome for oracle search, either string or binary file."; "--version", Arg.Set show_version, " print the version and exit"; + + "--disable-aslr", Arg.Set Rep.disable_aslr, + " Disable ASLR during test runtime"; + ] @@ -97,6 +104,7 @@ let _ = let process base ext (rep :('a,'b) Rep.representation) = (* load the rep, either from a cache or from source *) rep#load base; + rep#print_original_src !rep_out; rep#debug_info () ; (* load incoming population, if specified. We no longer have to do this diff --git a/src/minimization.ml b/src/minimization.ml index 47bf33ff..0f995dad 100644 --- a/src/minimization.ml +++ b/src/minimization.ml @@ -280,7 +280,11 @@ let delta_debugging orig to_minimize node_map = begin let minimized = delta_set_to_list minimized_script in let min_rep = orig#copy() in - min_rep#construct_rep (None) (Some((script_to_pair_list minimized), node_map)); + if !minimize_patch then + let script = lfoldl (fun acc str -> acc^" "^str) "" minimized in + min_rep#construct_rep (Some(script)) (None) + else + min_rep#construct_rep (None) (Some((script_to_pair_list minimized), node_map)); min_rep#output "Minimization_Files/minimized.c"; let output_name = "minimized.diffscript" in diff --git a/src/rep.ml b/src/rep.ml index de555dfa..fb67e442 100644 --- a/src/rep.ml +++ b/src/rep.ml @@ -490,6 +490,11 @@ class type ['gene,'code] representation = object('self_type) @return hashvalue for this variant.*) method hash : unit -> int + + method print_original_src : string -> unit + + method system_aslr : string -> Unix.process_status + end (** Test name to string *) @@ -547,10 +552,12 @@ let regen_paths = ref false let fault_scheme = ref "path" let fault_path = ref "coverage.path.neg" +let fault_path_per_test = ref false let fault_file = ref "" let fix_scheme = ref "default" let fix_path = ref "coverage.path.pos" +let fix_path_per_test = ref false let fix_file = ref "" let fix_oracle_file = ref "" let coverage_info = ref "" @@ -572,6 +579,8 @@ let sanity = ref "default" let ccfile = ref "" (* path to code clone file *) +let disable_aslr = ref false + let _ = options := !options @ [ @@ -636,6 +645,9 @@ let _ = "--fault-path", Arg.Set_string fault_path, "X Negative path file, for path-based localization. Default: coverage.path.neg"; + "--fault-path-per-test", Arg.Set fault_path_per_test, + "X Obtain Negative path coverage for each test. Default: coverage.path.neg."; + "--fault-file", Arg.Set_string fault_file, "X Fault localization file. e.g., Lines/weights if scheme is lines/weights."; @@ -645,6 +657,9 @@ let _ = "--fix-path", Arg.Set_string fix_path, "X Positive path file, for path-based localization. Default: coverage.path.pos"; + "--fix-path-per-test", Arg.Set fix_path_per_test, + "X Obtain Positive path coverage for each test. Default: coverage.path.pos."; + "--fix-file", Arg.Set_string fix_file, "X Fix localization information file, e.g., Lines/weights."; @@ -1237,6 +1252,25 @@ class virtual ['gene,'code] cachingRepresentation = object (self : ('gene,'code) | None -> [] (**/**) + method system_aslr cmd = + let local_cmd = + if not !disable_aslr then cmd + else "setarch "^(read_process "uname -m")^" -R "^(cmd) in + system local_cmd; + + + method print_original_src fname = + let original_filename = (fname) ^ if (!Global.extension <> "") + then !Global.extension + else "" in + self#output_source original_filename ; + (* note from pdreiter: + clearing already_sourced to ensure that the outputted file isn't removed + when cleanup () is called + *) + already_sourced := None ; + + (** ignores the return values of the unix system calls it uses, namely [system] and [unlink], and thus will fail silently if they do *) method cleanup () = @@ -1961,12 +1995,12 @@ class virtual ['gene,'code] faultlocRepresentation = object (self) end ; if TestSet.is_empty !set_of_all_tests then begin let answer = ref TestSet.empty in - for i = 1 to !pos_tests do - answer := TestSet.add (Positive i) !answer ; - done ; for i = 1 to !neg_tests do answer := TestSet.add (Negative i) !answer ; done ; + for i = 1 to !pos_tests do + answer := TestSet.add (Positive i) !answer ; + done ; set_of_all_tests := !answer ; !answer end else begin @@ -2100,7 +2134,7 @@ class virtual ['gene,'code] faultlocRepresentation = object (self) * localization involves finding all of the statements visited while * executing the negative test case(s) and removing/down-weighting * statements visited while executing the positive test case(s). *) - let run_tests test_maker max_test out_path expected = + let run_tests test_maker max_test out_path expected per_test_path = let stmts = lfoldl (fun stmts test -> @@ -2149,12 +2183,25 @@ class virtual ['gene,'code] faultlocRepresentation = object (self) * * Otherwise, we just union up all of the atoms visited * by all of the tests. *) - if !coverage_per_test then begin + if !coverage_per_test or !per_test_path then begin let visited_atom_set = List.fold_left (fun acc elt -> AtomSet.add elt acc ) (AtomSet.empty) !stmts' in debug "\t\tcovers %d atoms\n" (AtomSet.cardinal visited_atom_set) ; + (* + debug "\t\t test - %d \n" test; + AtomSet.iter (printf "%d ") visited_atom_set; + *) + if !per_test_path then begin + debug "coverage file: %s \n" (String.concat "." [out_path; string_of_int test]); + let fout = open_out (String.concat "." [out_path; string_of_int test]) in + AtomSet.iter + (fun stmt -> + let str = Printf.sprintf "%d\n" stmt in + output_string fout str) visited_atom_set; + close_out fout; + end; AtomSet.iter (fun atom -> let other_tests_visiting_this_atom = try @@ -2179,9 +2226,9 @@ class virtual ['gene,'code] faultlocRepresentation = object (self) close_out fout; stmts in debug "coverage negative:\n"; - ignore(run_tests (fun t -> Negative t) !neg_tests fault_path false); + ignore(run_tests (fun t -> Negative t) !neg_tests fault_path false fault_path_per_test); debug "coverage positive:\n"; - ignore(run_tests (fun t -> Positive t) !pos_tests fix_path true) ; + ignore(run_tests (fun t -> Positive t) !pos_tests fix_path true fix_path_per_test) ; if !coverage_per_test then begin let total_tests = ref 0 in