From 825c7af581a7e5653fa6117a23522a01827d5503 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Fri, 20 Sep 2019 06:45:01 -0700 Subject: [PATCH] [test determinator] Continuation of refactoring the test determinator code Reviewed By: ngorogiannis Differential Revision: D17499359 fbshipit-source-id: e4bd91eb1 --- infer/src/clang/Capture.ml | 7 ++----- infer/src/clang/ProcessAST.ml | 23 ++++++++++++++++++++++ infer/src/clang/ProcessAST.mli | 10 ++++++++++ infer/src/infer.ml | 5 +---- infer/src/integration/testDeterminator.ml | 17 ++++++++-------- infer/src/integration/testDeterminator.mli | 9 ++------- 6 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 infer/src/clang/ProcessAST.ml create mode 100644 infer/src/clang/ProcessAST.mli diff --git a/infer/src/clang/Capture.ml b/infer/src/clang/Capture.ml index 145c622a7..04b4abdfa 100644 --- a/infer/src/clang/Capture.ml +++ b/infer/src/clang/Capture.ml @@ -99,11 +99,8 @@ let run_clang_frontend ast_source = L.(debug Capture Medium) "Start %s of AST from %a@\n" Config.clang_frontend_action_string pp_ast_filename ast_source ; if Config.linters then AL.do_frontend_checks trans_unit_ctx ast_decl ; - ( if Config.export_changed_functions then - let source_file = trans_unit_ctx.CFrontend_config.source_file in - let clang_range_map = AstToRangeMap.process_ast ast_decl source_file in - TestDeterminator.compute_and_emit_relevant_methods ~clang_range_map ~source_file - ~changed_lines_file:Config.modified_lines ) ; + if Config.export_changed_functions then + ProcessAST.export_changed_functions trans_unit_ctx ast_decl ; if Config.capture then CFrontend.do_source_file trans_unit_ctx ast_decl ; L.(debug Capture Medium) "End %s of AST file %a... OK!@\n" Config.clang_frontend_action_string pp_ast_filename diff --git a/infer/src/clang/ProcessAST.ml b/infer/src/clang/ProcessAST.ml new file mode 100644 index 000000000..d6a4b3ba1 --- /dev/null +++ b/infer/src/clang/ProcessAST.ml @@ -0,0 +1,23 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) +open! IStd +module F = Format + +let export_changed_functions trans_unit_ctx ast_decl = + let source_file = trans_unit_ctx.CFrontend_config.source_file in + let f () = + if Config.export_changed_functions then + let clang_range_map = AstToRangeMap.process_ast ast_decl source_file in + TestDeterminator.compute_and_emit_relevant_methods ~clang_range_map ~source_file + in + let call_f () = + CFrontend_errors.protect trans_unit_ctx + ~recover:(fun () -> ()) + ~pp_context:(fun f () -> F.fprintf f "Error when processing %a" SourceFile.pp source_file) + ~f + in + call_f () diff --git a/infer/src/clang/ProcessAST.mli b/infer/src/clang/ProcessAST.mli new file mode 100644 index 000000000..824778b39 --- /dev/null +++ b/infer/src/clang/ProcessAST.mli @@ -0,0 +1,10 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) +open! IStd + +val export_changed_functions : + CFrontend_config.translation_unit_context -> Clang_ast_t.decl -> unit diff --git a/infer/src/infer.ml b/infer/src/infer.ml index d2bd71373..239fec105 100644 --- a/infer/src/infer.ml +++ b/infer/src/infer.ml @@ -147,10 +147,7 @@ let () = if Config.debug_mode && CLOpt.is_originator then ( L.progress "Logs in %s@." (Config.results_dir ^/ Config.log_file) ; L.progress "Execution ID %Ld@." Config.execution_id ) ; - ( if Config.test_determinator then - TestDeterminator.compute_and_emit_test_to_run ~changed_lines_file:Config.modified_lines - ~test_samples_file:Config.profiler_samples ~code_graph_file:Config.method_decls_info - ?clang_range_map:None ?source_file:None + ( if Config.test_determinator then TestDeterminator.compute_and_emit_test_to_run () else match Config.command with | Analyze -> diff --git a/infer/src/integration/testDeterminator.ml b/infer/src/integration/testDeterminator.ml index 5749ddb78..c5d7f6828 100644 --- a/infer/src/integration/testDeterminator.ml +++ b/infer/src/integration/testDeterminator.ml @@ -157,7 +157,8 @@ let emit_relevant_methods relevant_methods = YB.to_file outpath json -let compute_and_emit_relevant_methods ~clang_range_map ~source_file ~changed_lines_file = +let compute_and_emit_relevant_methods ~clang_range_map ~source_file = + let changed_lines_file = Config.modified_lines in let changed_lines_map = DiffLines.create_changed_lines_map changed_lines_file in let relevant_methods = compute_affected_methods_clang ~clang_range_map ~source_file ~changed_lines_map @@ -166,8 +167,10 @@ let compute_and_emit_relevant_methods ~clang_range_map ~source_file ~changed_lin (* test_to_run = { n | Affected_Method /\ ts_n != 0 } *) -let test_to_run ?clang_range_map ?source_file ~code_graph_file ~changed_lines_file - ~test_samples_file = +let test_to_run ?clang_range_map ?source_file () = + let test_samples_file = Config.profiler_samples in + let code_graph_file = Config.method_decls_info in + let changed_lines_file = Config.modified_lines in let changed_lines_map = DiffLines.create_changed_lines_map changed_lines_file in let affected_methods = match (clang_range_map, source_file) with @@ -191,10 +194,6 @@ let emit_tests_to_run relevant_tests = YB.to_file outpath json -let compute_and_emit_test_to_run ?clang_range_map ?source_file ~code_graph_file ~changed_lines_file - ~test_samples_file = - let relevant_tests = - test_to_run ?clang_range_map ~code_graph_file ?source_file ~changed_lines_file - ~test_samples_file - in +let compute_and_emit_test_to_run ?clang_range_map ?source_file () = + let relevant_tests = test_to_run ?clang_range_map ?source_file () in emit_tests_to_run relevant_tests diff --git a/infer/src/integration/testDeterminator.mli b/infer/src/integration/testDeterminator.mli index c35e57b68..00e2c7f41 100644 --- a/infer/src/integration/testDeterminator.mli +++ b/infer/src/integration/testDeterminator.mli @@ -10,13 +10,8 @@ open! IStd val compute_and_emit_test_to_run : ?clang_range_map:(Location.t * Location.t) Typ.Procname.Map.t -> ?source_file:SourceFile.t - -> code_graph_file:string option - -> changed_lines_file:string option - -> test_samples_file:string option + -> unit -> unit val compute_and_emit_relevant_methods : - clang_range_map:(Location.t * Location.t) Typ.Procname.Map.t - -> source_file:SourceFile.t - -> changed_lines_file:string option - -> unit + clang_range_map:(Location.t * Location.t) Typ.Procname.Map.t -> source_file:SourceFile.t -> unit