[Test determinator] Minor refactoring

Reviewed By: ddino

Differential Revision: D8160433

fbshipit-source-id: 6a80bcf
master
Martino Luca 7 years ago committed by Facebook Github Bot
parent 405928ad59
commit d803dc9048

@ -6,10 +6,11 @@
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*) *)
open! IStd
module L = Logging module L = Logging
module F = Format module F = Format
open JavaProfilerSamples module JPS = JavaProfilerSamples
open! IStd
(* a flag used to make the method search signature sensitive *) (* a flag used to make the method search signature sensitive *)
let use_method_signature = false let use_method_signature = false
@ -66,9 +67,9 @@ module MethodRangeMap = struct
if use_method_signature then signature if use_method_signature then signature
else else
(* When we should not use the signature we use 'void ()' *) (* When we should not use the signature we use 'void ()' *)
JavaProfilerSamples.JNI.void_method_with_no_arguments JPS.JNI.void_method_with_no_arguments
in in
let key = JavaProfilerSamples.create ~classname ~methodname ~signature in let key = JPS.create_procname ~classname ~methodname ~signature in
RangeMap.add key range acc RangeMap.add key range acc
| None -> | None ->
acc ) acc )
@ -139,8 +140,8 @@ 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) " (JPS.ProfilerSample.cardinal s) ;
ProfilerSample.iter (fun m -> F.fprintf fmt "@\n > %a " Typ.Procname.pp m) s JPS.ProfilerSample.iter (fun m -> F.fprintf fmt "@\n > %a " Typ.Procname.pp m) s
module TestSample = struct module TestSample = struct
@ -152,9 +153,7 @@ 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 = let ts = JPS.from_json_file test_samples_file ~use_signature:use_method_signature in
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"
@ -178,17 +177,17 @@ let affected_methods method_range_map file_changed_lines changed_lines =
&& List.exists ~f:(fun l -> in_range l range) changed_lines && List.exists ~f:(fun l -> in_range l range) changed_lines
then ( then (
L.progress "@\n ->Adding '%a' in affected methods...@\n" Typ.Procname.pp key ; L.progress "@\n ->Adding '%a' in affected methods...@\n" Typ.Procname.pp key ;
ProfilerSample.add key acc ) JPS.ProfilerSample.add key acc )
else acc ) else acc )
method_range_map ProfilerSample.empty method_range_map JPS.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: String.Map.fold changed_lines_map ~init:JPS.ProfilerSample.empty ~f:
(fun ~key:file_changed_lines ~data acc -> (fun ~key:file_changed_lines ~data acc ->
let am = affected_methods method_range_map file_changed_lines data in let am = affected_methods method_range_map file_changed_lines data in
ProfilerSample.union am acc ) JPS.ProfilerSample.union am acc )
in in
L.progress "@\n\n== Resulting Affected Methods ==%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 ;
@ -207,7 +206,7 @@ let compute_affected_methods_clang source_file changed_lines_map method_range_ma
affected_methods affected_methods
| None -> | None ->
L.progress "@\n%s not found in changed-line map. Nothing else to do for it.@\n" fname ; L.progress "@\n%s not found in changed-line map. Nothing else to do for it.@\n" fname ;
ProfilerSample.empty JPS.ProfilerSample.empty
let relevant_tests = ref [] let relevant_tests = ref []
@ -252,11 +251,11 @@ let _test_to_run_clang source_file cfg changed_lines_file test_samples_file =
(MethodRangeMap.method_range_map ()) (MethodRangeMap.method_range_map ())
in in
let test_to_run = let test_to_run =
if ProfilerSample.is_empty affected_methods then [] if JPS.ProfilerSample.is_empty affected_methods then []
else else
List.fold (TestSample.test_sample ()) ~init:[] ~f:(fun acc (label, profiler_samples) -> List.fold (TestSample.test_sample ()) ~init:[] ~f:(fun acc (label, profiler_samples) ->
let intersection = ProfilerSample.inter affected_methods profiler_samples in let intersection = JPS.ProfilerSample.inter affected_methods profiler_samples in
if ProfilerSample.is_empty intersection then acc else label :: acc ) if JPS.ProfilerSample.is_empty intersection then acc else label :: acc )
in in
relevant_tests := List.append test_to_run !relevant_tests relevant_tests := List.append test_to_run !relevant_tests
@ -270,10 +269,10 @@ let test_to_run_java changed_lines_file test_samples_file code_graph_file =
(MethodRangeMap.method_range_map ()) (MethodRangeMap.method_range_map ())
in in
let test_to_run = let test_to_run =
if ProfilerSample.is_empty affected_methods then [] if JPS.ProfilerSample.is_empty affected_methods then []
else else
List.fold (TestSample.test_sample ()) ~init:[] ~f:(fun acc (label, profiler_samples) -> List.fold (TestSample.test_sample ()) ~init:[] ~f:(fun acc (label, profiler_samples) ->
let intersection = ProfilerSample.inter affected_methods profiler_samples in let intersection = JPS.ProfilerSample.inter affected_methods profiler_samples in
if ProfilerSample.is_empty intersection then acc else label :: acc ) if JPS.ProfilerSample.is_empty intersection then acc else label :: acc )
in in
relevant_tests := List.append test_to_run !relevant_tests relevant_tests := List.append test_to_run !relevant_tests

@ -266,7 +266,7 @@ module JNI = struct
end end
end end
let create ~classname ~methodname ~signature = let create_procname ~classname ~methodname ~signature =
let name = Typ.Name.Java.from_string classname in let name = Typ.Name.Java.from_string classname in
let args, ret_typ = JNI.parse_method_str signature in let args, ret_typ = JNI.parse_method_str signature in
let java_type_args = List.map ~f:JNI.to_java_type args in let java_type_args = List.map ~f:JNI.to_java_type args in
@ -305,7 +305,7 @@ let from_json j ~use_signature =
; _ ] ; _ ]
:: tl -> :: tl ->
let signature = if use_signature then signature else JNI.void_method_with_no_arguments in 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_procname ~classname ~methodname ~signature in
parse_json tl (procname :: acc) parse_json tl (procname :: acc)
| [] -> | [] ->
acc acc

@ -51,4 +51,4 @@ val from_json_string : string -> use_signature:bool -> labeled_profiler_sample l
val from_json_file : string -> use_signature:bool -> 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_procname : classname:string -> methodname:string -> signature:string -> Typ.Procname.t

Loading…
Cancel
Save