From d001db1e94fc2995ac2bb50459a02295574db3f7 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Tue, 22 Oct 2019 03:50:41 -0700 Subject: [PATCH] [test determinator] Merge test determinator results under buck capture all flavours, add test Reviewed By: skcho Differential Revision: D18039141 fbshipit-source-id: 3faef0615 --- .gitignore | 1 + Makefile | 1 + infer/src/backend/mergeCapture.ml | 29 +++++++++---- infer/src/backend/mergeCapture.mli | 2 + infer/src/integration/Driver.ml | 2 + .../buck_clang_test_determinator/.buckconfig | 0 .../buck_clang_test_determinator/.buckversion | 1 + .../buck_clang_test_determinator/Makefile | 41 +++++++++++++++++++ .../profiler_samples.json | 35 ++++++++++++++++ .../buck_clang_test_determinator/src/BUCK | 6 +++ .../buck_clang_test_determinator/src/a.c | 13 ++++++ .../buck_clang_test_determinator/src/b.c | 12 ++++++ .../buck_clang_test_determinator/src/mod-a.c | 14 +++++++ .../buck_clang_test_determinator/src/mod-b.c | 12 ++++++ .../test_determinator.json.exp | 1 + 15 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/.buckconfig create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/.buckversion create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/Makefile create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/profiler_samples.json create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/src/BUCK create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/src/a.c create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/src/b.c create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/src/mod-a.c create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/src/mod-b.c create mode 100644 infer/tests/build_systems/buck_clang_test_determinator/test_determinator.json.exp diff --git a/.gitignore b/.gitignore index 61f4e89a5..81924a978 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ duplicates.txt *.ast.biniou /infer/tests/build_systems/buck_flavors_deterministic/capture_hash-*.sha /infer/tests/build_systems/buck_flavors_diff/src/hello.c +/infer/tests/build_systems/buck_clang_test_determinator/diff.mod.test /infer/tests/build_systems/buck_export_changed_functions/diff.mod.test /infer/tests/build_systems/clang_compilation_db_escaped/compile_commands.json /infer/tests/build_systems/clang_compilation_db_relpath/compile_commands.json diff --git a/Makefile b/Makefile index a91942073..265993aef 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,7 @@ ifneq ($(BUCK),no) BUILD_SYSTEMS_TESTS += \ buck_blacklist \ buck-clang-db \ + buck_clang_test_determinator \ buck_flavors \ buck_flavors_diff \ buck_flavors_run \ diff --git a/infer/src/backend/mergeCapture.ml b/infer/src/backend/mergeCapture.ml index 641b99309..df67acc21 100644 --- a/infer/src/backend/mergeCapture.ml +++ b/infer/src/backend/mergeCapture.ml @@ -27,9 +27,9 @@ let merge_global_tenvs infer_deps_file = L.progress "Merging type environments took %a@." Mtime.Span.pp (Mtime_clock.count time0) -let merge_changed_functions_json infer_out_src = - let main_changed_fs_file = Config.results_dir ^/ Config.export_changed_functions_output in - let changed_fs_file = infer_out_src ^/ Config.export_changed_functions_output in +let merge_json_results infer_out_src json_file_name = + let main_changed_fs_file = Config.results_dir ^/ json_file_name in + let changed_fs_file = infer_out_src ^/ json_file_name in let main_json = try YB.from_file main_changed_fs_file |> YBU.to_list with Sys_error _ -> [] in let changed_json = try YB.from_file changed_fs_file |> YBU.to_list with Sys_error _ -> [] in let all_fs = @@ -42,12 +42,25 @@ let merge_changed_functions_json infer_out_src = YB.to_file main_changed_fs_file all_fs -let merge_changed_functions () = - L.progress "Merging changed functions files...@." ; +let merge_all_json_results merge_results results_json_str = + L.progress "Merging %s files...@." results_json_str ; let infer_deps_file = Config.(results_dir ^/ buck_infer_deps_file_name) in - Utils.iter_infer_deps ~project_root:Config.project_root ~f:merge_changed_functions_json - infer_deps_file ; - L.progress "Done merging changed functions files@." + Utils.iter_infer_deps ~project_root:Config.project_root ~f:merge_results infer_deps_file ; + L.progress "Done merging %s files@." results_json_str + + +let merge_changed_functions () = + let merge_changed_functions_json infer_out_src = + merge_json_results infer_out_src Config.export_changed_functions_output + in + 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 () = diff --git a/infer/src/backend/mergeCapture.mli b/infer/src/backend/mergeCapture.mli index c2b67953f..1724ee98c 100644 --- a/infer/src/backend/mergeCapture.mli +++ b/infer/src/backend/mergeCapture.mli @@ -10,3 +10,5 @@ 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/integration/Driver.ml b/infer/src/integration/Driver.ml index 86fe953c6..c01a87fc1 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -412,6 +412,8 @@ 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/tests/build_systems/buck_clang_test_determinator/.buckconfig b/infer/tests/build_systems/buck_clang_test_determinator/.buckconfig new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/buck_clang_test_determinator/.buckversion b/infer/tests/build_systems/buck_clang_test_determinator/.buckversion new file mode 100644 index 000000000..9a34dd379 --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/.buckversion @@ -0,0 +1 @@ +3a1d93f2ea0699f9177b11a09cfafcb02f96a902 \ No newline at end of file diff --git a/infer/tests/build_systems/buck_clang_test_determinator/Makefile b/infer/tests/build_systems/buck_clang_test_determinator/Makefile new file mode 100644 index 000000000..bef220460 --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/Makefile @@ -0,0 +1,41 @@ +# 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. + +TESTS_DIR = ../.. +include $(TESTS_DIR)/base.make + +A_C = src/a.c +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 + +$(DIFF_OUTPUT): + $(QUIET)echo -n '$(A_C):' > diff.mod.test + $(QUIET)(diff -N --unchanged-line-format="U" --old-line-format="O" --new-line-format="N" \ + $(A_C) src/mod-a.c || [ $$? = 1 ]) >> diff.mod.test + $(QUIET)echo >> diff.mod.test + $(QUIET)echo -n '$(B_C):' >> diff.mod.test + $(QUIET)(diff -N --unchanged-line-format="U" --old-line-format="O" --new-line-format="N" \ + $(B_C) src/mod-b.c || [ $$? = 1 ]) >> diff.mod.test + $(QUIET)echo >> diff.mod.test + +$(TEST_DETERMINATOR_RESULT): $(DIFF_OUTPUT) + $(QUIET)$(call silent_on_success,Testing test-determinator for clang with set of changes,\ + $(INFER_BIN) $(INFER_OPTIONS) -- buck build --no-cache $(BUCK_TARGET)) + +.PHONY: test +test: $(TEST_DETERMINATOR_RESULT) + $(QUIET)$(call check_no_diff,test_determinator.json.exp,$(TEST_DETERMINATOR_RESULT)) + +.PHONY: replace +replace: $(TEST_DETERMINATOR_RESULT) + $(COPY) $(TEST_DETERMINATOR_RESULT) test_determinator.json.exp + +.PHONY: clean +clean: + $(REMOVE_DIR) *.test infer-out* buck-out* diff --git a/infer/tests/build_systems/buck_clang_test_determinator/profiler_samples.json b/infer/tests/build_systems/buck_clang_test_determinator/profiler_samples.json new file mode 100644 index 000000000..91e2c329d --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/profiler_samples.json @@ -0,0 +1,35 @@ +[ + { + "field1": {}, + "test": "label_a", + "field2": {}, + "native_symbols": [ + { + "name": "a_test" + }, + { + "name": "example_function10", + "mangled_name" : "example_function10" + } + ], + "field3": {} + }, + { + "field1": {}, + "field2": {}, + "field3": {}, + "test": "label_b", + "field4": {}, + "native_symbols": [ + { + "name": "b_test" + }, + { + "name": "example_function20", + "mangled_name" : "example_function20" + } + ], + "field5": {}, + "field6": {} + } + ] diff --git a/infer/tests/build_systems/buck_clang_test_determinator/src/BUCK b/infer/tests/build_systems/buck_clang_test_determinator/src/BUCK new file mode 100644 index 000000000..973e10dca --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/src/BUCK @@ -0,0 +1,6 @@ +cxx_library( + name = 'test', + srcs = [ + 'a.c', 'b.c', + ], +) diff --git a/infer/tests/build_systems/buck_clang_test_determinator/src/a.c b/infer/tests/build_systems/buck_clang_test_determinator/src/a.c new file mode 100644 index 000000000..ffa49bb19 --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/src/a.c @@ -0,0 +1,13 @@ +/* + * 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. + */ + +#include + +void a_test() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_clang_test_determinator/src/b.c b/infer/tests/build_systems/buck_clang_test_determinator/src/b.c new file mode 100644 index 000000000..df1b3e627 --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/src/b.c @@ -0,0 +1,12 @@ +/* + * 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. + */ +#include + +void b_test() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_clang_test_determinator/src/mod-a.c b/infer/tests/build_systems/buck_clang_test_determinator/src/mod-a.c new file mode 100644 index 000000000..c5f7a5f20 --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/src/mod-a.c @@ -0,0 +1,14 @@ +/* + * 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. + */ + +#include + +/* comment */ +void a_test() { + int* s = NULL; + *s = 42 + 1; +} diff --git a/infer/tests/build_systems/buck_clang_test_determinator/src/mod-b.c b/infer/tests/build_systems/buck_clang_test_determinator/src/mod-b.c new file mode 100644 index 000000000..b246952ea --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/src/mod-b.c @@ -0,0 +1,12 @@ +/* + * 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. + */ +#include + +void b_test() { + int* s = NULL; + *s = 42 + 3; +} diff --git a/infer/tests/build_systems/buck_clang_test_determinator/test_determinator.json.exp b/infer/tests/build_systems/buck_clang_test_determinator/test_determinator.json.exp new file mode 100644 index 000000000..49ec9fe21 --- /dev/null +++ b/infer/tests/build_systems/buck_clang_test_determinator/test_determinator.json.exp @@ -0,0 +1 @@ +["label_a","label_b"] \ No newline at end of file