From a857fec1f3d7c4052b92bb024d622f95f56f571b Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 26 Jul 2019 07:37:26 -0700 Subject: [PATCH] [increr] test incremental analysis Summary: A test that records the expected output of: - reverse analysis call graph - introduced/pre-existing/fixed issues - cost analysis results Currently only the call graph is non-empty. Reviewed By: PhoebeMay Differential Revision: D16495470 fbshipit-source-id: f186d73d2 --- .gitignore | 2 + .../incremental_analysis/Makefile | 43 +++++++++++++++++++ .../incremental_analysis/changed_files.txt | 1 + .../costs_summary.json.exp | 1 + .../incremental_analysis/fixed.exp | 0 .../incremental_analysis/introduced.exp | 0 .../incremental_analysis/preexisting.exp | 0 .../reverse_analysis_callgraph.dot | 17 ++++++++ .../incremental_analysis/src_after/a_and_c.c | 10 +++++ .../incremental_analysis/src_after/a_and_c.h | 8 ++++ .../incremental_analysis/src_after/b_and_d.c | 10 +++++ .../incremental_analysis/src_after/b_and_d.h | 8 ++++ .../incremental_analysis/src_after/main.c | 12 ++++++ .../incremental_analysis/src_before/a_and_c.h | 8 ++++ .../incremental_analysis/src_before/b_and_d.c | 10 +++++ .../incremental_analysis/src_before/b_and_d.h | 8 ++++ .../incremental_analysis/src_before/main.c | 12 ++++++ 17 files changed, 150 insertions(+) create mode 100644 infer/tests/build_systems/incremental_analysis/Makefile create mode 100644 infer/tests/build_systems/incremental_analysis/changed_files.txt create mode 100644 infer/tests/build_systems/incremental_analysis/costs_summary.json.exp create mode 100644 infer/tests/build_systems/incremental_analysis/fixed.exp create mode 100644 infer/tests/build_systems/incremental_analysis/introduced.exp create mode 100644 infer/tests/build_systems/incremental_analysis/preexisting.exp create mode 100644 infer/tests/build_systems/incremental_analysis/reverse_analysis_callgraph.dot create mode 100644 infer/tests/build_systems/incremental_analysis/src_after/a_and_c.c create mode 100644 infer/tests/build_systems/incremental_analysis/src_after/a_and_c.h create mode 100644 infer/tests/build_systems/incremental_analysis/src_after/b_and_d.c create mode 100644 infer/tests/build_systems/incremental_analysis/src_after/b_and_d.h create mode 100644 infer/tests/build_systems/incremental_analysis/src_after/main.c create mode 100644 infer/tests/build_systems/incremental_analysis/src_before/a_and_c.h create mode 100644 infer/tests/build_systems/incremental_analysis/src_before/b_and_d.c create mode 100644 infer/tests/build_systems/incremental_analysis/src_before/b_and_d.h create mode 100644 infer/tests/build_systems/incremental_analysis/src_before/main.c diff --git a/.gitignore b/.gitignore index cebd23c5d..83a86ea1b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ /infer/tests/codetoanalyze/java/*/codetoanalyze _build_infer *.exp.test* +*.dot.test *.test.dot *.test.txt duplicates.txt @@ -43,6 +44,7 @@ duplicates.txt /infer/tests/build_systems/differential_*/**/*.class /infer/tests/build_systems/differential_*/**/Diff*.java /infer/tests/build_systems/genrule/report.json +/infer/tests/build_systems/incremental_analysis/src /infer/tests/build_systems/java_test_determinator/*.test /infer/tests/codetoanalyze/java/classloads/*.loads /infer/tests/codetoanalyze/java/classloads/loads.exp diff --git a/infer/tests/build_systems/incremental_analysis/Makefile b/infer/tests/build_systems/incremental_analysis/Makefile new file mode 100644 index 000000000..5e2eb043d --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/Makefile @@ -0,0 +1,43 @@ +# 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. + +# E2E test involving the interesting_paths_filter function + +TESTS_DIR = ../.. + +MODIFIED_FILES_FILE = changed_files.txt +SOURCES = $(wildcard src_after/*.c src_after/*.h src_before/*.c src_before/*.h) +INFER_OPTIONS = --changed-files-index $(MODIFIED_FILES_FILE) \ + --incremental-analysis \ + --debug-level-analysis 1 + +include $(TESTS_DIR)/differential.make + +.PHONY: compare_cg +compare_cg: $(PREVIOUS_REPORT) + $(QUIET)$(call check_no_diff,\ + reverse_analysis_callgraph.dot,\ + reverse_analysis_callgraph.dot.test) + +replace_cg: $(PREVIOUS_REPORT) + $(COPY) reverse_analysis_callgraph.dot.test reverse_analysis_callgraph.dot + +test: compare_cg +replace: replace_cg + +$(CURRENT_REPORT): $(INFER_CLANG_DEPS) $(SOURCES) + $(QUIET)$(REMOVE_DIR) src + $(QUIET)$(MKDIR_P) src + $(QUIET)$(COPY) src_after/* src/ + $(QUIET)$(INFER_BIN) -o $(CURRENT_DIR) -- clang -c src/*.c + +$(PREVIOUS_REPORT): $(INFER_CLANG_DEPS) $(SOURCES) $(CURRENT_REPORT) + $(QUIET)$(REMOVE_DIR) src + $(QUIET)$(MKDIR_P) src + $(QUIET)$(COPY) src_before/* src/ + $(QUIET)$(COPY) -r $(CURRENT_DIR) $(PREVIOUS_DIR) + $(QUIET)$(INFER_BIN) -o $(PREVIOUS_DIR) $(INFER_OPTIONS) -- clang -c src/*.c + $(QUIET)$(COPY) $(PREVIOUS_DIR)/reverse_analysis_callgraph.dot \ + reverse_analysis_callgraph.dot.test diff --git a/infer/tests/build_systems/incremental_analysis/changed_files.txt b/infer/tests/build_systems/incremental_analysis/changed_files.txt new file mode 100644 index 000000000..ddf861391 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/changed_files.txt @@ -0,0 +1 @@ +src/a_and_c.c diff --git a/infer/tests/build_systems/incremental_analysis/costs_summary.json.exp b/infer/tests/build_systems/incremental_analysis/costs_summary.json.exp new file mode 100644 index 000000000..d04696a0c --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/costs_summary.json.exp @@ -0,0 +1 @@ +{"top":{"current":0,"previous":0},"zero":{"current":0,"previous":0},"degrees":[]} \ No newline at end of file diff --git a/infer/tests/build_systems/incremental_analysis/fixed.exp b/infer/tests/build_systems/incremental_analysis/fixed.exp new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/incremental_analysis/introduced.exp b/infer/tests/build_systems/incremental_analysis/introduced.exp new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/incremental_analysis/preexisting.exp b/infer/tests/build_systems/incremental_analysis/preexisting.exp new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/incremental_analysis/reverse_analysis_callgraph.dot b/infer/tests/build_systems/incremental_analysis/reverse_analysis_callgraph.dot new file mode 100644 index 000000000..c6b411cab --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/reverse_analysis_callgraph.dot @@ -0,0 +1,17 @@ + +digraph callgraph { + N1 [ label = "a", flag = true ]; + N1 -> N4 ; + + N0 [ label = "b", flag = true ]; + N0 -> N1 ; + + N4 [ label = "main", flag = true ]; + + N2 [ label = "c", flag = true ]; + N2 -> N0 ; + + N3 [ label = "d", flag = false ]; + N3 -> N2 ; + +} diff --git a/infer/tests/build_systems/incremental_analysis/src_after/a_and_c.c b/infer/tests/build_systems/incremental_analysis/src_after/a_and_c.c new file mode 100644 index 000000000..aa5131740 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_after/a_and_c.c @@ -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. + */ +#include "b_and_d.h" + +void a() { b(); } +void c() { d(); } diff --git a/infer/tests/build_systems/incremental_analysis/src_after/a_and_c.h b/infer/tests/build_systems/incremental_analysis/src_after/a_and_c.h new file mode 100644 index 000000000..cb4f1160b --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_after/a_and_c.h @@ -0,0 +1,8 @@ +/* + * 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. + */ +void a(); +void c(); diff --git a/infer/tests/build_systems/incremental_analysis/src_after/b_and_d.c b/infer/tests/build_systems/incremental_analysis/src_after/b_and_d.c new file mode 100644 index 000000000..d4f2684c0 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_after/b_and_d.c @@ -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. + */ +#include "a_and_c.h" + +void b() { c(); } +void d() {} diff --git a/infer/tests/build_systems/incremental_analysis/src_after/b_and_d.h b/infer/tests/build_systems/incremental_analysis/src_after/b_and_d.h new file mode 100644 index 000000000..5aecea262 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_after/b_and_d.h @@ -0,0 +1,8 @@ +/* + * 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. + */ +void b(); +void d(); diff --git a/infer/tests/build_systems/incremental_analysis/src_after/main.c b/infer/tests/build_systems/incremental_analysis/src_after/main.c new file mode 100644 index 000000000..42e79c551 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_after/main.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 "a_and_c.h" + +int main() { + a(); + return 0; +} diff --git a/infer/tests/build_systems/incremental_analysis/src_before/a_and_c.h b/infer/tests/build_systems/incremental_analysis/src_before/a_and_c.h new file mode 100644 index 000000000..cb4f1160b --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_before/a_and_c.h @@ -0,0 +1,8 @@ +/* + * 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. + */ +void a(); +void c(); diff --git a/infer/tests/build_systems/incremental_analysis/src_before/b_and_d.c b/infer/tests/build_systems/incremental_analysis/src_before/b_and_d.c new file mode 100644 index 000000000..d4f2684c0 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_before/b_and_d.c @@ -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. + */ +#include "a_and_c.h" + +void b() { c(); } +void d() {} diff --git a/infer/tests/build_systems/incremental_analysis/src_before/b_and_d.h b/infer/tests/build_systems/incremental_analysis/src_before/b_and_d.h new file mode 100644 index 000000000..5aecea262 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_before/b_and_d.h @@ -0,0 +1,8 @@ +/* + * 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. + */ +void b(); +void d(); diff --git a/infer/tests/build_systems/incremental_analysis/src_before/main.c b/infer/tests/build_systems/incremental_analysis/src_before/main.c new file mode 100644 index 000000000..42e79c551 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis/src_before/main.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 "a_and_c.h" + +int main() { + a(); + return 0; +}