From d803dc904837916fdbd8962a1f6eccba56b24534 Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Fri, 25 May 2018 03:37:06 -0700 Subject: [PATCH] [Test determinator] Minor refactoring Reviewed By: ddino Differential Revision: D8160433 fbshipit-source-id: 6a80bcf --- infer/src/integration/testDeterminator.ml | 39 +++++++++++------------ infer/src/java/JavaProfilerSamples.ml | 4 +-- infer/src/java/JavaProfilerSamples.mli | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/infer/src/integration/testDeterminator.ml b/infer/src/integration/testDeterminator.ml index 3a461b86f..3a190380d 100644 --- a/infer/src/integration/testDeterminator.ml +++ b/infer/src/integration/testDeterminator.ml @@ -6,10 +6,11 @@ * 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. *) + +open! IStd module L = Logging module F = Format -open JavaProfilerSamples -open! IStd +module JPS = JavaProfilerSamples (* a flag used to make the method search signature sensitive *) let use_method_signature = false @@ -66,9 +67,9 @@ module MethodRangeMap = struct if use_method_signature then signature else (* 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 - let key = JavaProfilerSamples.create ~classname ~methodname ~signature in + let key = JPS.create_procname ~classname ~methodname ~signature in RangeMap.add key range acc | None -> acc ) @@ -139,8 +140,8 @@ module DiffLines = struct end let pp_profiler_sample_set fmt s = - F.fprintf fmt " (size = %i) " (ProfilerSample.cardinal s) ; - ProfilerSample.iter (fun m -> F.fprintf fmt "@\n > %a " Typ.Procname.pp m) s + F.fprintf fmt " (size = %i) " (JPS.ProfilerSample.cardinal s) ; + JPS.ProfilerSample.iter (fun m -> F.fprintf fmt "@\n > %a " Typ.Procname.pp m) s module TestSample = struct @@ -152,9 +153,7 @@ module TestSample = struct match test_samples_file' with | Some test_samples_file -> L.progress "@\nReading Profiler Samples File '%s'...." test_samples_file ; - let ts = - JavaProfilerSamples.from_json_file test_samples_file ~use_signature:use_method_signature - in + let ts = JPS.from_json_file test_samples_file ~use_signature:use_method_signature in labeled_test_samples := ts | _ -> 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 then ( L.progress "@\n ->Adding '%a' in affected methods...@\n" Typ.Procname.pp key ; - ProfilerSample.add key acc ) + JPS.ProfilerSample.add key 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 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 -> let am = affected_methods method_range_map file_changed_lines data in - ProfilerSample.union am acc ) + JPS.ProfilerSample.union am acc ) in L.progress "@\n\n== Resulting Affected Methods ==%a@\n== End Affected Methods ==@\n" 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 | None -> 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 [] @@ -252,11 +251,11 @@ let _test_to_run_clang source_file cfg changed_lines_file test_samples_file = (MethodRangeMap.method_range_map ()) in let test_to_run = - if ProfilerSample.is_empty affected_methods then [] + if JPS.ProfilerSample.is_empty affected_methods then [] else List.fold (TestSample.test_sample ()) ~init:[] ~f:(fun acc (label, profiler_samples) -> - let intersection = ProfilerSample.inter affected_methods profiler_samples in - if ProfilerSample.is_empty intersection then acc else label :: acc ) + let intersection = JPS.ProfilerSample.inter affected_methods profiler_samples in + if JPS.ProfilerSample.is_empty intersection then acc else label :: acc ) in 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 ()) in let test_to_run = - if ProfilerSample.is_empty affected_methods then [] + if JPS.ProfilerSample.is_empty affected_methods then [] else List.fold (TestSample.test_sample ()) ~init:[] ~f:(fun acc (label, profiler_samples) -> - let intersection = ProfilerSample.inter affected_methods profiler_samples in - if ProfilerSample.is_empty intersection then acc else label :: acc ) + let intersection = JPS.ProfilerSample.inter affected_methods profiler_samples in + if JPS.ProfilerSample.is_empty intersection then acc else label :: acc ) in relevant_tests := List.append test_to_run !relevant_tests diff --git a/infer/src/java/JavaProfilerSamples.ml b/infer/src/java/JavaProfilerSamples.ml index 6650b89d2..88ff6c575 100644 --- a/infer/src/java/JavaProfilerSamples.ml +++ b/infer/src/java/JavaProfilerSamples.ml @@ -266,7 +266,7 @@ module JNI = struct end end -let create ~classname ~methodname ~signature = +let create_procname ~classname ~methodname ~signature = let name = Typ.Name.Java.from_string classname in let args, ret_typ = JNI.parse_method_str signature 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 -> 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) | [] -> acc diff --git a/infer/src/java/JavaProfilerSamples.mli b/infer/src/java/JavaProfilerSamples.mli index 65d865b03..e0c63cb85 100644 --- a/infer/src/java/JavaProfilerSamples.mli +++ b/infer/src/java/JavaProfilerSamples.mli @@ -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 create : classname:string -> methodname:string -> signature:string -> ProfilerSample.elt +val create_procname : classname:string -> methodname:string -> signature:string -> Typ.Procname.t