[Test determinator] Improving the search of affected methods and dealing with signature

Reviewed By: martinoluca

Differential Revision: D8135233

fbshipit-source-id: 4479016
master
Dino Distefano 7 years ago committed by Facebook Github Bot
parent fecabb3bf3
commit 405928ad59

@ -11,6 +11,9 @@ module F = Format
open JavaProfilerSamples open JavaProfilerSamples
open! IStd open! IStd
(* a flag used to make the method search signature sensitive *)
let use_method_signature = false
module RangeMap = Caml.Map.Make (struct module RangeMap = Caml.Map.Make (struct
type t = Typ.Procname.t type t = Typ.Procname.t
@ -59,6 +62,12 @@ module MethodRangeMap = struct
let classname, methodname = split_class_method_name decl.method_name in let classname, methodname = split_class_method_name decl.method_name in
match decl.signature with match decl.signature with
| Some signature -> | Some signature ->
let signature =
if use_method_signature then signature
else
(* When we should not use the signature we use 'void ()' *)
JavaProfilerSamples.JNI.void_method_with_no_arguments
in
let key = JavaProfilerSamples.create ~classname ~methodname ~signature in let key = JavaProfilerSamples.create ~classname ~methodname ~signature in
RangeMap.add key range acc RangeMap.add key range acc
| None -> | None ->
@ -104,7 +113,7 @@ module DiffLines = struct
match changed_lines_file' with match changed_lines_file' with
| Some changed_lines_file | Some changed_lines_file
-> ( -> (
L.progress "@\n Initializing modified lines map from file '%s'... " changed_lines_file ; L.progress "@\nInitializing modified lines map from file '%s'... " changed_lines_file ;
match Utils.read_file changed_lines_file with match Utils.read_file changed_lines_file with
| Ok cl_list -> | Ok cl_list ->
let changed_lines = let changed_lines =
@ -130,7 +139,7 @@ module DiffLines = struct
end end
let pp_profiler_sample_set fmt s = let pp_profiler_sample_set fmt s =
F.fprintf fmt "size = %i" (ProfilerSample.cardinal s) ; F.fprintf fmt " (size = %i) " (ProfilerSample.cardinal s) ;
ProfilerSample.iter (fun m -> F.fprintf fmt "@\n > %a " Typ.Procname.pp m) s ProfilerSample.iter (fun m -> F.fprintf fmt "@\n > %a " Typ.Procname.pp m) s
@ -143,7 +152,9 @@ module TestSample = struct
match test_samples_file' with match test_samples_file' with
| Some test_samples_file -> | Some test_samples_file ->
L.progress "@\nReading Profiler Samples File '%s'...." test_samples_file ; L.progress "@\nReading Profiler Samples File '%s'...." test_samples_file ;
let ts = JavaProfilerSamples.from_json_file test_samples_file in let ts =
JavaProfilerSamples.from_json_file test_samples_file ~use_signature:use_method_signature
in
labeled_test_samples := ts labeled_test_samples := ts
| _ -> | _ ->
L.die UserError "Missing profiler samples argument" L.die UserError "Missing profiler samples argument"
@ -157,35 +168,41 @@ end
let in_range l range = l >= (fst range).Location.line && l <= (snd range).Location.line let in_range l range = l >= (fst range).Location.line && l <= (snd range).Location.line
let affected_methods method_range_map changed_lines = let affected_methods method_range_map file_changed_lines changed_lines =
L.progress "@\nLooking for affected methods in file '%s' " file_changed_lines ;
RangeMap.fold RangeMap.fold
(fun key range acc -> (fun key ((l1, _) as range) acc ->
if List.exists ~f:(fun l -> in_range l range) changed_lines then let method_file = SourceFile.to_string l1.Location.file in
(*L.progress "@\n ADDING '%a' in affected methods..." Typ.Procname.pp key ; *) if
ProfilerSample.add key acc String.equal method_file file_changed_lines
&& List.exists ~f:(fun l -> in_range l range) changed_lines
then (
L.progress "@\n ->Adding '%a' in affected methods...@\n" Typ.Procname.pp key ;
ProfilerSample.add key acc )
else acc ) else acc )
method_range_map ProfilerSample.empty method_range_map ProfilerSample.empty
let compute_affected_methods_java changed_lines_map method_range_map = let compute_affected_methods_java changed_lines_map method_range_map =
let affected_methods = let affected_methods =
String.Map.fold changed_lines_map ~init:ProfilerSample.empty ~f:(fun ~key:_ ~data acc -> String.Map.fold changed_lines_map ~init:ProfilerSample.empty ~f:
let am = affected_methods method_range_map data in (fun ~key:file_changed_lines ~data acc ->
let am = affected_methods method_range_map file_changed_lines data in
ProfilerSample.union am acc ) ProfilerSample.union am acc )
in in
L.progress "== Resulting Affected Methods ==@\n%a@\n== End Affected Methods ==@\n" L.progress "@\n\n== Resulting Affected Methods ==%a@\n== End Affected Methods ==@\n"
pp_profiler_sample_set affected_methods ; pp_profiler_sample_set affected_methods ;
affected_methods affected_methods
let compute_affected_methods_clang source_file changed_lines_map method_range_map = let compute_affected_methods_clang source_file changed_lines_map method_range_map =
let fname = SourceFile.to_rel_path source_file in let fname = SourceFile.to_rel_path source_file in
L.progress "@\n Looking for file %s in changed-line map..." fname ; L.progress "@\nLooking for file %s in changed-line map..." fname ;
match String.Map.find changed_lines_map fname with match String.Map.find changed_lines_map fname with
| Some changed_lines -> | Some changed_lines ->
L.progress " found!@\n" ; L.progress " found!@\n" ;
let affected_methods = affected_methods method_range_map changed_lines in let affected_methods = affected_methods method_range_map fname changed_lines in
L.progress "== Resulting Affected Methods ==@\n%a@\n== End Affected Methods ==@\n" L.progress "@\n\n== Resulting Affected Methods ==@\n%a@\n== End Affected Methods ==@\n"
pp_profiler_sample_set affected_methods ; pp_profiler_sample_set affected_methods ;
affected_methods affected_methods
| None -> | None ->
@ -198,7 +215,7 @@ let relevant_tests = ref []
let _get_relevant_test_to_run () = !relevant_tests let _get_relevant_test_to_run () = !relevant_tests
let print_test_to_run () = let print_test_to_run () =
L.progress "@\n [TEST DETERMINATOR] Relevant Tests to run = [" ; L.progress "@\n[TEST DETERMINATOR] Relevant Tests to run = [" ;
List.iter ~f:(L.progress " %s ") !relevant_tests ; List.iter ~f:(L.progress " %s ") !relevant_tests ;
L.progress " ] @\n" ; L.progress " ] @\n" ;
let json = `List (List.map ~f:(fun t -> `String t) !relevant_tests) in let json = `List (List.map ~f:(fun t -> `String t) !relevant_tests) in
@ -227,7 +244,7 @@ let init_java changed_lines_file test_samples_file code_graph_file =
(* test_to_run = { n | Affected_Method /\ ts_n != 0 } *) (* test_to_run = { n | Affected_Method /\ ts_n != 0 } *)
let _test_to_run_clang source_file cfg changed_lines_file test_samples_file = let _test_to_run_clang source_file cfg changed_lines_file test_samples_file =
L.progress "@\n ***** Start Test Determinator for %s ***** @\n" L.progress "@\n****** Start Test Determinator for %s ***** @\n"
(SourceFile.to_string source_file) ; (SourceFile.to_string source_file) ;
if is_test_determinator_init () then () else init_clang cfg changed_lines_file test_samples_file ; if is_test_determinator_init () then () else init_clang cfg changed_lines_file test_samples_file ;
let affected_methods = let affected_methods =
@ -245,7 +262,7 @@ let _test_to_run_clang source_file cfg changed_lines_file test_samples_file =
let test_to_run_java changed_lines_file test_samples_file code_graph_file = let test_to_run_java changed_lines_file test_samples_file code_graph_file =
L.progress "@\n ***** Start Test Determinator ***** @\n" ; L.progress "@\n***** Start Test Determinator ***** @\n" ;
if is_test_determinator_init () then () if is_test_determinator_init () then ()
else init_java changed_lines_file test_samples_file code_graph_file ; else init_java changed_lines_file test_samples_file code_graph_file ;
let affected_methods = let affected_methods =

@ -31,6 +31,8 @@ module JNI = struct
let equal = [%compare.equal : t] let equal = [%compare.equal : t]
let void_method_with_no_arguments = "()V"
type non_terminal_symbol = SymArray | SymMethodOpen | SymMethodClose | SymMethod of t list type non_terminal_symbol = SymArray | SymMethodOpen | SymMethodClose | SymMethod of t list
type symbol = Terminal of t | NonTerminal of non_terminal_symbol type symbol = Terminal of t | NonTerminal of non_terminal_symbol
@ -284,7 +286,7 @@ type labeled_profiler_sample = string * ProfilerSample.t [@@deriving compare]
let equal_labeled_profiler_sample = [%compare.equal : labeled_profiler_sample] let equal_labeled_profiler_sample = [%compare.equal : labeled_profiler_sample]
let from_json j = let from_json j ~use_signature =
let parse_profiler_result label result = let parse_profiler_result label result =
let methods = let methods =
match result with match result with
@ -302,6 +304,7 @@ let from_json j =
; ("signature", `String signature) ; ("signature", `String signature)
; _ ] ; _ ]
:: tl -> :: tl ->
let signature = if use_signature then signature else JNI.void_method_with_no_arguments in
let procname = create ~classname ~methodname ~signature in let procname = create ~classname ~methodname ~signature in
parse_json tl (procname :: acc) parse_json tl (procname :: acc)
| [] -> | [] ->
@ -318,6 +321,6 @@ let from_json j =
L.(die UserError "Unexpected JSON input for the list of profiler results") L.(die UserError "Unexpected JSON input for the list of profiler results")
let from_json_string str = from_json (Yojson.Basic.from_string str) let from_json_string str ~use_signature = from_json (Yojson.Basic.from_string str) ~use_signature
let from_json_file file = from_json (Yojson.Basic.from_file file) let from_json_file file ~use_signature = from_json (Yojson.Basic.from_file file) ~use_signature

@ -12,6 +12,8 @@ open! IStd
module ProfilerSample : Caml.Set.S with type elt = Typ.Procname.t module ProfilerSample : Caml.Set.S with type elt = Typ.Procname.t
module JNI : sig module JNI : sig
val void_method_with_no_arguments : string
module VISIBLE_FOR_TESTING_DO_NOT_USE_DIRECTLY : sig module VISIBLE_FOR_TESTING_DO_NOT_USE_DIRECTLY : sig
type t = type t =
| Boolean | Boolean
@ -45,8 +47,8 @@ type labeled_profiler_sample = string * ProfilerSample.t [@@deriving compare]
val equal_labeled_profiler_sample : labeled_profiler_sample -> labeled_profiler_sample -> bool val equal_labeled_profiler_sample : labeled_profiler_sample -> labeled_profiler_sample -> bool
val from_json_string : string -> labeled_profiler_sample list val from_json_string : string -> use_signature:bool -> labeled_profiler_sample list
val from_json_file : string -> labeled_profiler_sample list val from_json_file : string -> use_signature:bool -> labeled_profiler_sample list
val create : classname:string -> methodname:string -> signature:string -> ProfilerSample.elt val create : classname:string -> methodname:string -> signature:string -> ProfilerSample.elt

@ -159,7 +159,7 @@ let test_jni_to_java_type_with_invalid_input =
let test_from_json_string_with_valid_input = let test_from_json_string_with_valid_input =
let create_test input expected _ = let create_test input expected _ =
let found = JavaProfilerSamples.from_json_string input in let found = JavaProfilerSamples.from_json_string input ~use_signature:true in
assert_equal assert_equal
~cmp:(List.equal ~equal:JavaProfilerSamples.equal_labeled_profiler_sample) ~cmp:(List.equal ~equal:JavaProfilerSamples.equal_labeled_profiler_sample)
expected found expected found
@ -227,7 +227,7 @@ let test_from_json_string_with_valid_input =
let test_from_json_string_with_invalid_input = let test_from_json_string_with_invalid_input =
let create_test input expected_exception _ = let create_test input expected_exception _ =
let run () = JavaProfilerSamples.from_json_string input in let run () = JavaProfilerSamples.from_json_string input ~use_signature:true in
assert_raises expected_exception run assert_raises expected_exception run
in in
[ ( "test_from_json_string_1" [ ( "test_from_json_string_1"

Loading…
Cancel
Save