diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index 8299ef6b7..0050968c0 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -1214,4 +1214,6 @@ let main ~report_json = pp_json_report_by_report_kind formats_by_report_kind fname | None -> pp_summary_and_issues formats_by_report_kind issue_formats ) ; + if Config.test_determinator && Config.process_clang_ast then + TestDeterminator.merge_test_determinator_results () ; PerfStats.get_reporter PerfStats.Reporting () diff --git a/infer/src/backend/mergeCapture.ml b/infer/src/backend/mergeCapture.ml index df67acc21..7c9b147d0 100644 --- a/infer/src/backend/mergeCapture.ml +++ b/infer/src/backend/mergeCapture.ml @@ -56,13 +56,6 @@ let merge_changed_functions () = merge_all_json_results merge_changed_functions_json "changed functions" -let merge_test_determinator_results () = - let merge_test_determinator_json infer_out_src = - merge_json_results infer_out_src Config.test_determinator_output - in - merge_all_json_results merge_test_determinator_json "test determinator result" - - let merge_captured_targets () = let time0 = Mtime_clock.counter () in L.progress "Merging captured Buck targets...@\n%!" ; diff --git a/infer/src/backend/mergeCapture.mli b/infer/src/backend/mergeCapture.mli index 1724ee98c..c2b67953f 100644 --- a/infer/src/backend/mergeCapture.mli +++ b/infer/src/backend/mergeCapture.mli @@ -10,5 +10,3 @@ open! IStd val merge_captured_targets : unit -> unit val merge_changed_functions : unit -> unit - -val merge_test_determinator_results : unit -> unit diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 15f72cb58..adfe81dbd 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -296,6 +296,8 @@ let specs_files_suffix = ".specs" let starvation_issues_dir_name = "starvation_issues" +let test_determinator_results = "test_determinator_results" + (** Enable detailed tracing information during array abstraction *) let trace_absarray = false diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index b6f9a14cd..1fb110d81 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -179,6 +179,8 @@ val specs_files_suffix : string val starvation_issues_dir_name : string +val test_determinator_results : string + val trace_absarray : bool val trace_events_file : string diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index c01a87fc1..86fe953c6 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -412,8 +412,6 @@ let analyze_and_report ?suppress_console_report ~changed_files mode = in if should_merge then ( if Config.export_changed_functions then MergeCapture.merge_changed_functions () ; - if Config.test_determinator && Config.process_clang_ast then - MergeCapture.merge_test_determinator_results () ; MergeCapture.merge_captured_targets () ; RunState.set_merge_capture false ; RunState.store () ) ; diff --git a/infer/src/test_determinator/testDeterminator.ml b/infer/src/test_determinator/testDeterminator.ml index 004b7ff9b..187650125 100644 --- a/infer/src/test_determinator/testDeterminator.ml +++ b/infer/src/test_determinator/testDeterminator.ml @@ -9,6 +9,7 @@ open! IStd module L = Logging module F = Format module YB = Yojson.Basic +module YBU = Yojson.Basic.Util (* a flag used to make the method search signature sensitive *) let use_signature = false @@ -241,18 +242,47 @@ let clang_test_to_run ~clang_range_map ~source_file () = else acc ) -let emit_tests_to_run relevant_tests = +let emit_tests_to_run_java relevant_tests = let json = `List (List.map ~f:(fun t -> `String t) relevant_tests) in let outpath = Config.results_dir ^/ Config.test_determinator_output in YB.to_file outpath json +let emit_tests_to_run_clang source_file relevant_tests = + if not (List.is_empty relevant_tests) then ( + let json = `List (List.map ~f:(fun t -> `String t) relevant_tests) in + let abbrev_source_file = DB.source_file_encoding source_file in + let test_determinator_results_path = Config.results_dir ^/ Config.test_determinator_results in + let outpath = test_determinator_results_path ^/ abbrev_source_file ^ ".json" in + Utils.create_dir test_determinator_results_path ; + Utils.write_json_to_file outpath json ) + + let compute_and_emit_test_to_run ?clang_range_map ?source_file () = - let relevant_tests = - match (clang_range_map, source_file) with - | Some clang_range_map, Some source_file -> - clang_test_to_run ~clang_range_map ~source_file () - | _ -> - java_test_to_run () + match (clang_range_map, source_file) with + | Some clang_range_map, Some source_file -> + let relevant_tests = clang_test_to_run ~clang_range_map ~source_file () in + emit_tests_to_run_clang source_file relevant_tests + | _ -> + let relevant_tests = java_test_to_run () in + emit_tests_to_run_java relevant_tests + + +let merge_test_determinator_results () = + let main_results_list = ref [] in + let merge_json_results intermediate_result = + let changed_json = + try YB.from_file intermediate_result |> YBU.to_list with Sys_error _ -> [] + in + main_results_list := List.append changed_json !main_results_list + in + let test_determinator_results_path = Config.results_dir ^/ Config.test_determinator_results in + let main_results_file = Config.results_dir ^/ Config.test_determinator_output in + Utils.directory_iter merge_json_results test_determinator_results_path ; + let main_results_list_sorted = + List.dedup_and_sort + ~compare:(fun s1 s2 -> + match (s1, s2) with `String s1, `String s2 -> String.compare s1 s2 | _ -> 0 ) + !main_results_list in - emit_tests_to_run relevant_tests + YB.to_file main_results_file (`List main_results_list_sorted) diff --git a/infer/src/test_determinator/testDeterminator.mli b/infer/src/test_determinator/testDeterminator.mli index be1f7a3af..ed36242f3 100644 --- a/infer/src/test_determinator/testDeterminator.mli +++ b/infer/src/test_determinator/testDeterminator.mli @@ -17,3 +17,5 @@ val compute_and_emit_relevant_methods : clang_range_map:((Location.t * Location.t) * ClangProc.t option) Typ.Procname.Map.t -> source_file:SourceFile.t -> unit + +val merge_test_determinator_results : unit -> unit diff --git a/infer/tests/build_systems/buck_clang_test_determinator/Makefile b/infer/tests/build_systems/buck_clang_test_determinator/Makefile index bef220460..ca8522a40 100644 --- a/infer/tests/build_systems/buck_clang_test_determinator/Makefile +++ b/infer/tests/build_systems/buck_clang_test_determinator/Makefile @@ -11,8 +11,8 @@ B_C = src/b.c BUCK_TARGET = //src:test TEST_DETERMINATOR_RESULT = infer-out/test_determinator.json DIFF_OUTPUT = diff.mod.test -INFER_OPTIONS = --flavors --process-clang-ast --no-linters --no-capture --test-determinator \ - --modified-lines $(DIFF_OUTPUT) --project-root $(TESTS_DIR) --profiler-samples profiler_samples.json +INFER_OPTIONS = --buck-compilation-database no-deps --process-clang-ast --no-linters --no-capture --test-determinator \ + --modified-lines $(DIFF_OUTPUT) --profiler-samples profiler_samples.json $(DIFF_OUTPUT): $(QUIET)echo -n '$(A_C):' > diff.mod.test diff --git a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp index aecc7e34e..dfee7718f 100644 --- a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp +++ b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp @@ -1 +1 @@ -["label1_block","label1_objc_method","label1_c_function"] \ No newline at end of file +["label1_block","label1_c_function","label1_objc_method"] \ No newline at end of file diff --git a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp index 5ea829613..cd91799b1 100644 --- a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp +++ b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp @@ -1 +1 @@ -["label2_block","label2_objc_method","label2_c_function"] \ No newline at end of file +["label2_block","label2_c_function","label2_objc_method"] \ No newline at end of file