Skip to content

New Features: ASLR Disabling, Minimization bug fix, Coverage per test #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down
8 changes: 8 additions & 0 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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";

]


Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/minimization.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 54 additions & 7 deletions src/rep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down Expand Up @@ -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 ""
Expand All @@ -572,6 +579,8 @@ let sanity = ref "default"

let ccfile = ref "" (* path to code clone file *)

let disable_aslr = ref false

let _ =
options := !options @
[
Expand Down Expand Up @@ -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.<test id>";

"--fault-file", Arg.Set_string fault_file,
"X Fault localization file. e.g., Lines/weights if scheme is lines/weights.";

Expand All @@ -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.<test id>";

"--fix-file", Arg.Set_string fix_file,
"X Fix localization information file, e.g., Lines/weights.";

Expand Down Expand Up @@ -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 () =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down