diff --git a/.gitignore b/.gitignore index 4c4b0b93c..4622b5750 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ duplicates.txt /infer/tests/build_systems/differential_*/**/Diff*.java /infer/tests/build_systems/genrule/report.json /infer/tests/build_systems/incremental_analysis_remove_file/src +/infer/tests/build_systems/incremental_analysis_cost_change/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/Makefile b/Makefile index a66069cb2..5b2cbeddd 100644 --- a/Makefile +++ b/Makefile @@ -127,6 +127,7 @@ ifeq ($(BUILD_JAVA_ANALYZERS),yes) BUILD_SYSTEMS_TESTS += \ differential_interesting_paths_filter \ differential_of_costs_report \ + incremental_analysis_cost_change \ differential_skip_anonymous_class_renamings \ differential_skip_duplicated_types_on_filenames \ differential_skip_duplicated_types_on_filenames_with_renamings \ diff --git a/infer/tests/build_systems/incremental_analysis_change_procedure/Makefile b/infer/tests/build_systems/incremental_analysis_change_procedure/Makefile index 683fddf7d..f13705b4e 100644 --- a/infer/tests/build_systems/incremental_analysis_change_procedure/Makefile +++ b/infer/tests/build_systems/incremental_analysis_change_procedure/Makefile @@ -33,7 +33,7 @@ $(CURRENT_REPORT): $(INFER_CLANG_DEPS) $(SOURCES) $(PREVIOUS_REPORT): $(INFER_CLANG_DEPS) $(SOURCES) $(CURRENT_REPORT) $(QUIET)$(REMOVE_DIR) $(PREVIOUS_DIR) $(QUIET)$(COPY) -r $(CURRENT_DIR) $(PREVIOUS_DIR) - $(QUIET)$(REMOVE_DIR) $@ + $(QUIET)$(REMOVE) $@ $(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_cost_change/Makefile b/infer/tests/build_systems/incremental_analysis_cost_change/Makefile new file mode 100644 index 000000000..576e87bbb --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/Makefile @@ -0,0 +1,45 @@ +# 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/*.java src_before/*.java) +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) --cost-only --enable-issue-type INFINITE_EXECUTION_TIME -- javac src/*.java + +$(PREVIOUS_REPORT): $(INFER_CLANG_DEPS) $(SOURCES) $(CURRENT_REPORT) + $(QUIET)$(REMOVE_DIR) src + $(QUIET)$(MKDIR_P) src + $(QUIET)$(COPY) src_before/* src/ + $(QUIET)$(REMOVE_DIR) $(PREVIOUS_DIR) + $(QUIET)$(COPY) -r $(CURRENT_DIR) $(PREVIOUS_DIR) + $(QUIET)$(REMOVE) $@ + $(QUIET)$(INFER_BIN) -o $(PREVIOUS_DIR) $(INFER_OPTIONS) --cost-only --enable-issue-type INFINITE_EXECUTION_TIME -- javac src/*.java + $(QUIET)$(COPY) $(PREVIOUS_DIR)/reverse_analysis_callgraph.dot \ + reverse_analysis_callgraph.dot.test diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/changed_files.txt b/infer/tests/build_systems/incremental_analysis_cost_change/changed_files.txt new file mode 100644 index 000000000..a8186b0fc --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/changed_files.txt @@ -0,0 +1 @@ +src/Test.java \ No newline at end of file diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp b/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp new file mode 100644 index 000000000..bd944faed --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/costs_summary.json.exp @@ -0,0 +1 @@ +{"top":{"current":0,"previous":0},"zero":{"current":6,"previous":6},"degrees":[{"degree":0,"current":3,"previous":4},{"degree":100,"current":3,"previous":1},{"degree":200,"current":0,"previous":1}]} \ No newline at end of file diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/fixed.exp b/infer/tests/build_systems/incremental_analysis_cost_change/fixed.exp new file mode 100644 index 000000000..af78d8062 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/fixed.exp @@ -0,0 +1 @@ +EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/Test.java, Test.complexityDecrease(int):void, 0 diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/introduced.exp b/infer/tests/build_systems/incremental_analysis_cost_change/introduced.exp new file mode 100644 index 000000000..f51bc52bf --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/introduced.exp @@ -0,0 +1 @@ +EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/Test.java, Test.complexityIncrease(int):void, 0 diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/preexisting.exp b/infer/tests/build_systems/incremental_analysis_cost_change/preexisting.exp new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot b/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot new file mode 100644 index 000000000..db2b8e8db --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/reverse_analysis_callgraph.dot @@ -0,0 +1,26 @@ + +digraph callgraph { + N1 [ label = "Test.()", flag = true ]; + + N5 [ label = "void Test.main(java.lang.String[])", flag = true ]; + + N0 [ label = "Object.()", flag = false ]; + N0 -> N6 ; + N0 -> N1 ; + + N7 [ label = "void PrintStream.println(String)", flag = false ]; + N7 -> N2 ; + + N6 [ label = "Unchanged.()", flag = false ]; + + N4 [ label = "void Test.complexityIncrease(int)", flag = true ]; + N4 -> N5 ; + + N2 [ label = "void Unchanged.orderN(int)", flag = false ]; + N2 -> N4 ; + N2 -> N3 ; + + N3 [ label = "void Test.complexityDecrease(int)", flag = true ]; + N3 -> N5 ; + +} diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/src_after/Test.java b/infer/tests/build_systems/incremental_analysis_cost_change/src_after/Test.java new file mode 100644 index 000000000..ab3ad42cb --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/src_after/Test.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +class Test { + + public static void complexityDecrease(int n) { + Unchanged.orderN(n); + } + + public static void complexityIncrease(int n) { + Unchanged.orderN(n); + } + + public static void main(String args[]) { + complexityDecrease(10); + complexityIncrease(10); + } +} diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/src_after/Unchanged.java b/infer/tests/build_systems/incremental_analysis_cost_change/src_after/Unchanged.java new file mode 100644 index 000000000..0d1487b7f --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/src_after/Unchanged.java @@ -0,0 +1,15 @@ +/* + * 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. + */ + +class Unchanged { + + public static void orderN(int n) { + for (int i = 0; i < n; i++) { + System.out.println("hi"); + } + } +} diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/src_before/Test.java b/infer/tests/build_systems/incremental_analysis_cost_change/src_before/Test.java new file mode 100644 index 000000000..19602af54 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/src_before/Test.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +class Test { + + public static void complexityDecrease(int n) { + for (int i = 0; i < n; i++) { + Unchanged.orderN(i); + } + } + + public static void complexityIncrease(int n) { + Unchanged.orderN(1); + } + + public static void main(String args[]) { + complexityDecrease(10); + complexityIncrease(10); + } +} diff --git a/infer/tests/build_systems/incremental_analysis_cost_change/src_before/Unchanged.java b/infer/tests/build_systems/incremental_analysis_cost_change/src_before/Unchanged.java new file mode 100644 index 000000000..f26e855e5 --- /dev/null +++ b/infer/tests/build_systems/incremental_analysis_cost_change/src_before/Unchanged.java @@ -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. + */ +class Unchanged { + + public static void orderN(int n) { + for (int i = 0; i < n; i++) { + System.out.println("hi"); + } + } +}