diff --git a/infer/tests/codetoanalyze/java/incremental/BUCK b/infer/tests/codetoanalyze/java/incremental/BUCK index 7e40ea68d..4b04e0ca2 100644 --- a/infer/tests/codetoanalyze/java/incremental/BUCK +++ b/infer/tests/codetoanalyze/java/incremental/BUCK @@ -4,6 +4,7 @@ java_test( '//infer/tests/codetoanalyze/java/incremental/file_unchanged:file_unchanged', '//infer/tests/codetoanalyze/java/incremental/parent_changed:parent_changed', '//infer/tests/codetoanalyze/java/incremental/child_changed:child_changed', + '//infer/tests/codetoanalyze/java/incremental/changed_only_mode:changed_only_mode', ], visibility = [ 'PUBLIC' diff --git a/infer/tests/codetoanalyze/java/incremental/changed_only_mode/BUCK b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/BUCK new file mode 100644 index 000000000..354fd7237 --- /dev/null +++ b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/BUCK @@ -0,0 +1,47 @@ +v1_files = glob([ '**/*.java.v1']) +v2_files = glob(['**/*.java.v2']) +normal_files = glob(['**/*.java']) +sources = v1_files + v2_files + normal_files + +java_library( + name = 'changed_only_mode', + srcs = sources, + deps = [], + visibility = [ + 'PUBLIC' + ] +) + +def copy_files_strip_suffix_cmd(sfx, files): + return ' && '.join([' '.join(['cp', f, f.replace(sfx, '')]) for f in files]) + +out = 'out' +clean_cmd = ' '.join(['rm', '-rf', out]) +stripped_suffix_files = map(lambda f: f.replace('.v1', ''), v1_files) +to_compile = ' '.join(set(normal_files + stripped_suffix_files)) +infer_cmd = ' '.join([ + 'infer', + '-i', + '--changed-only', + '--absolute-paths', + '-o', out, + '-a', 'infer', + '--', + 'javac', + to_compile +]) +v1_copy_cmd = copy_files_strip_suffix_cmd('.v1', v1_files) +v2_copy_cmd = copy_files_strip_suffix_cmd('.v2', v2_files) +stats_copy_cmd = ' '.join(['cp', out + '/stats.json', '$OUT']) +command = ' && '.join([clean_cmd, v1_copy_cmd, infer_cmd, v2_copy_cmd, infer_cmd, stats_copy_cmd]) + +genrule( + name = 'analyze', + srcs = sources, + out = 'stats.json', + cmd = command, + deps = [':changed_only_mode'], + visibility = [ + 'PUBLIC', + ] +) diff --git a/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java new file mode 100644 index 000000000..9db8e7b26 --- /dev/null +++ b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +package codetoanalyze.java.incremental.changed_only_mode; + +class Child { + + Object bar() { + return null; + } + + Object dontReanalyze(Object o) { + return o; + } + +} diff --git a/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java.v1 b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java.v1 new file mode 100644 index 000000000..936cdc41e --- /dev/null +++ b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java.v1 @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +package codetoanalyze.java.incremental.changed_only_mode; + +class Child { + + Object bar() { + return new Object(); + } + + Object dontReanalyze(Object o) { + return o; + } + +} diff --git a/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java.v2 b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java.v2 new file mode 100644 index 000000000..9db8e7b26 --- /dev/null +++ b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Child.java.v2 @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +package codetoanalyze.java.incremental.changed_only_mode; + +class Child { + + Object bar() { + return null; + } + + Object dontReanalyze(Object o) { + return o; + } + +} diff --git a/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Parent.java b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Parent.java new file mode 100644 index 000000000..471dee254 --- /dev/null +++ b/infer/tests/codetoanalyze/java/incremental/changed_only_mode/Parent.java @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +package codetoanalyze.java.incremental.changed_only_mode; + +class Parent { + + Object foo() { + Child c = new Child(); + Object o = c.bar(); + return o; + } + + void dontReanalyze() { + Object o1 = new Object(); + } + +} diff --git a/infer/tests/endtoend/java/incremental/BUCK b/infer/tests/endtoend/java/incremental/BUCK index 92b5c5cd4..0bae701ce 100644 --- a/infer/tests/endtoend/java/incremental/BUCK +++ b/infer/tests/endtoend/java/incremental/BUCK @@ -11,6 +11,7 @@ java_test( '//infer/tests/codetoanalyze/java/incremental/file_unchanged:analyze', '//infer/tests/codetoanalyze/java/incremental/parent_changed:analyze', '//infer/tests/codetoanalyze/java/incremental/child_changed:analyze', + '//infer/tests/codetoanalyze/java/incremental/changed_only_mode:analyze', ], visibility=[ 'PUBLIC', diff --git a/infer/tests/endtoend/java/incremental/ChangedOnlyModeTest.java b/infer/tests/endtoend/java/incremental/ChangedOnlyModeTest.java new file mode 100644 index 000000000..d6d42f1d4 --- /dev/null +++ b/infer/tests/endtoend/java/incremental/ChangedOnlyModeTest.java @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +package endtoend.java.incremental; + +import static org.hamcrest.MatcherAssert.assertThat; +import static utils.matchers.NumberOfFilesAnalyzed.numberOfFilesAnalyzed; +import static utils.matchers.NumberOfProceduresAnalyzed.numberOfProceduresAnalyzed; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Paths; +import java.nio.file.Path; +import java.io.*; + +import utils.InferException; +import utils.InferStats; + +public class ChangedOnlyModeTest { + + public static final String SOURCE_DIR = + "/infer/tests/codetoanalyze/java/incremental/changed_only_mode/"; + + private static InferStats inferStats; + + @BeforeClass + public static void loadResults() throws InterruptedException, IOException { + inferStats = InferStats.loadInferStats(ChangedOnlyModeTest.class, SOURCE_DIR); + } + + @Test + public void onlyChangedFileReanalyzedInChangedOnlyMode() + throws IOException, InterruptedException, InferException { + assertThat( + "After changing the child file, parent should not be re-analyzed in changed-only mode", + inferStats, + numberOfFilesAnalyzed(1)); + } + + @Test + public void onlyChangedProcsReanalyzedInIncrementalMode() + throws IOException, InterruptedException, InferException { + assertThat( + "After changing a procedure, its callers should not be re-analyzed in changed-only mode", + inferStats, + numberOfProceduresAnalyzed(1)); + } + +}