diff --git a/.buckconfig b/.buckconfig index 584977746..cea37ddba 100644 --- a/.buckconfig +++ b/.buckconfig @@ -1,10 +1,3 @@ -[alias] - java = //infer/tests/endtoend:java_endtoend_tests - java_libraries = //dependencies/java:java_libraries - -# TODO: this line exists only to support buck integration in infer/tests/build_systems/build_integration_tests.py - infer = //infer/tests/endtoend/java/infer:infer - [project] ignore = .git, .ml, .mli diff --git a/Makefile b/Makefile index b5ea36499..de2ad7ce3 100644 --- a/Makefile +++ b/Makefile @@ -9,18 +9,17 @@ ROOT_DIR = . include $(ROOT_DIR)/Makefile.config DIRECT_TESTS= -TARGETS_TO_TEST= ifeq ($(BUILD_C_ANALYZERS),yes) DIRECT_TESTS += c_infer_test c_frontend_test cpp_infer_test cpp_frontend_test endif ifeq ($(BUILD_JAVA_ANALYZERS),yes) -TARGETS_TO_TEST += java -DIRECT_TESTS += java_checkers_test java_eradicate_test java_infer_test java_tracing_test java_quandary_test +DIRECT_TESTS += \ + java_checkers_test java_eradicate_test java_infer_test java_tracing_test \ + java_quandary_test java_crashcontext_test java_harness_test endif ifneq ($(XCODE_SELECT),no) DIRECT_TESTS += objc_frontend_test objc_infer_test objc_linters objcpp_frontend_test objcpp_linters endif -TARGETS_TO_TEST := $(shell echo $(TARGETS_TO_TEST)) all: infer inferTraceBugs @@ -120,9 +119,15 @@ cpp_infer_test: java_checkers_test: make -C ./infer/tests/codetoanalyze/java/checkers test +java_crashcontext_test: + make -C ./infer/tests/codetoanalyze/java/crashcontext test + java_eradicate_test: make -C ./infer/tests/codetoanalyze/java/eradicate test +java_harness_test: + make -C ./infer/tests/codetoanalyze/java/harness test + java_infer_test: make -C ./infer/tests/codetoanalyze/java/infer test @@ -154,18 +159,15 @@ objcpp_linters: make -C ./infer/tests/codetoanalyze/objcpp/linters test direct_tests: - make $(DIRECT_TESTS) + time make -j $(NCPU) -l $(NCPU) $(DIRECT_TESTS) buck_test: infer make direct_tests - NO_BUCKD=1 buck clean - MAKEFLAGS= NO_BUCKD=1 buck test -j $(NCPU) -L $(NCPU) $(TARGETS_TO_TEST) NO_BUCKD=1 ./infer/tests/build_systems/build_integration_tests.py buck_test_xml: infer make direct_tests - NO_BUCKD=1 buck clean - NO_BUCKD=1 buck test -j $(NCPU) -L $(NCPU) --xml test.xml $(TARGETS_TO_TEST) + buck test --xml test.xml # TODO: generate test.xml with test results NO_BUCKD=1 ./infer/tests/build_systems/build_integration_tests.py inferTraceBugs_test: infer diff --git a/infer/tests/build_systems/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py index 123153df6..c0242aac9 100755 --- a/infer/tests/build_systems/build_integration_tests.py +++ b/infer/tests/build_systems/build_integration_tests.py @@ -344,9 +344,10 @@ class BuildIntegrationTest(unittest.TestCase): env=env) def test_buck_integration(self): + target = '//infer/tests/codetoanalyze/java/infer:analyze' test('buck', 'Buck', ROOT_DIR, - [{'compile': ['buck', 'build', 'infer']}], + [{'compile': ['buck', 'build', target]}], clean_commands=[['buck', 'clean']], available=lambda: is_tool_available(['buck', '--version'])) diff --git a/infer/tests/codetoanalyze/java/BUCK b/infer/tests/codetoanalyze/java/BUCK deleted file mode 100644 index d02ee457e..000000000 --- a/infer/tests/codetoanalyze/java/BUCK +++ /dev/null @@ -1,8 +0,0 @@ -export_file( - name = 'inferconfig', - src = '.inferconfig', - out = '.inferconfig', - visibility = [ - 'PUBLIC' - ] -) diff --git a/infer/tests/codetoanalyze/java/crashcontext/BUCK b/infer/tests/codetoanalyze/java/crashcontext/BUCK deleted file mode 100644 index d043cdde4..000000000 --- a/infer/tests/codetoanalyze/java/crashcontext/BUCK +++ /dev/null @@ -1,82 +0,0 @@ -sources = glob(['**/*.java','**/*.json']) - -dependencies = [ - '//dependencies/java/android/support/v4:android-support-v4', - '//infer/annotations:annotations', - '//infer/lib/java/android:android', -] - -java_library( - name = 'checkers', - srcs = sources, - deps = dependencies, - visibility = [ - 'PUBLIC' - ] -) - -out = 'infer-out' -inferconfig_file = '$(location //infer/tests/codetoanalyze/java:inferconfig)' -copy_inferconfig = ' '.join(['cp', inferconfig_file, '$SRCDIR']) -clean_cmd = ' '.join(['rm', '-rf', out]) -classpath = ':'.join([('$(classpath ' + path + ')') for path in dependencies]) - -def mk_infer_cmd(tag, srcs, stacktrace): - infer_cmd_main = ' '.join([ - 'infer', - '--no-progress-bar', - '--absolute-paths', - '-a', 'crashcontext', - '--stacktrace', stacktrace, - '--', - 'javac', - '-cp', classpath, - srcs]) - out_rename = ' '.join(['cp', - out + '/crashcontext/crashcontext.json', - '$OUT' + "." + tag]) - return ' && '.join([infer_cmd_main, out_rename]) - -infer_cmds = [ - mk_infer_cmd( - "MinimalCrashExample", - "MinimalCrashExample.java", - "MinimalCrashExample.stacktrace.json" - ), - mk_infer_cmd( - "MultiStackFrameCrashExample", - "MultiStackFrameCrashExample.java", - "MultiStackFrameCrashExample.stacktrace.json" - ), - mk_infer_cmd( - "BranchingCallsExample", - "BranchingCallsExample.java", - "BranchingCallsExample.stacktrace.json" - ), - mk_infer_cmd( - "MethodNameClashExample", - "MethodNameClashExample.java", - "MethodNameClashExample.stacktrace.json" - ), - mk_infer_cmd( - "NativeMethodExample", - "NativeMethodExample.java", - "NativeMethodExample.stacktrace.json" - ) -] - -# Copy the last crashcontext.json because buck expects it as the output file. -# This will only contain the results for the last run infer_cmd above. -copy_cmd = ' '.join(['cp', out + '/crashcontext/crashcontext.json', '$OUT']) -command = ' && '.join([clean_cmd, copy_inferconfig, ' && '.join(infer_cmds), copy_cmd]) - -genrule( - name = 'analyze', - srcs = sources, - out = 'crashcontext.json', - cmd = command, - deps = dependencies + [':checkers'], - visibility = [ - 'PUBLIC', - ] -) diff --git a/infer/tests/codetoanalyze/java/crashcontext/BranchingCallsExample.exp b/infer/tests/codetoanalyze/java/crashcontext/BranchingCallsExample.exp new file mode 100644 index 000000000..337b87d5b --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/BranchingCallsExample.exp @@ -0,0 +1 @@ +{"stack":[{"method_name":"codetoanalyze.java.crashcontext.BranchingCallsExample.bar():void","location":{"location_type":"call_site","file":"BranchingCallsExample.java","line":24,"blame_range":[{"start_line":22,"end_line":24}]},"callees":[{"method_name":"java.lang.String.toString():java.lang.String","callees":[]}]},{"method_name":"codetoanalyze.java.crashcontext.BranchingCallsExample.foo():void","location":{"location_type":"call_site","file":"BranchingCallsExample.java","line":29,"blame_range":[{"start_line":27,"end_line":30}]},"callees":[{"method_name":"codetoanalyze.java.crashcontext.BranchingCallsExample.bar():void","location":{"location_type":"proc_start","file":"BranchingCallsExample.java","line":22,"blame_range":[{"start_line":22,"end_line":24}]},"callees":[]},{"method_name":"codetoanalyze.java.crashcontext.BranchingCallsExample.pre_bar():void","location":{"location_type":"proc_start","file":"BranchingCallsExample.java","line":14,"blame_range":[{"start_line":14,"end_line":15}]},"callees":[]}]},{"method_name":"codetoanalyze.java.crashcontext.BranchingCallsExample.main(java.lang.String[]):void","location":{"location_type":"call_site","file":"BranchingCallsExample.java","line":34,"blame_range":[{"start_line":33,"end_line":34}]},"callees":[{"method_name":"codetoanalyze.java.crashcontext.BranchingCallsExample.foo():void","location":{"location_type":"proc_start","file":"BranchingCallsExample.java","line":27,"blame_range":[{"start_line":27,"end_line":30}]},"callees":[]}]}]} \ No newline at end of file diff --git a/infer/tests/codetoanalyze/java/crashcontext/Makefile b/infer/tests/codetoanalyze/java/crashcontext/Makefile new file mode 100644 index 000000000..cd8839e16 --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/Makefile @@ -0,0 +1,42 @@ +# Copyright (c) 2016 - 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. + +include ../Makefile + + +ANALYZER = crashcontext + +FILES = \ + BranchingCallsExample \ + MethodNameClashExample \ + MinimalCrashExample \ + MultiStackFrameCrashExample \ + NativeMethodExample \ + +compile: + for file in $(FILES) ; do \ + javac -cp $(CLASSPATH) $$file.java ; \ + done + +analyze: + for file in $(FILES) ; do \ + $(INFER_BIN) -a $(ANALYZER) --stacktrace $$file.stacktrace.json -- javac -cp $(CLASSPATH) $$file.java >/dev/null 2>/dev/null ; \ + cp infer-out/crashcontext/crashcontext.json $$file.exp.test ; \ + done + +# overwrite +print: + +# overwrite +test: analyze + set -e; \ + for file in $(FILES) ; do \ + diff -u $$file.exp $$file.exp.test ; \ + rm $$file.exp.test ; \ + done + make clean + diff --git a/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.exp b/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.exp new file mode 100644 index 000000000..0f0813fb4 --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.exp @@ -0,0 +1 @@ +{"stack":[{"method_name":"codetoanalyze.java.crashcontext.MethodNameClashExample$A.foo():void","location":{"location_type":"call_site","file":"MethodNameClashExample.java","line":18,"blame_range":[{"start_line":16,"end_line":18}]},"callees":[{"method_name":"java.lang.String.toString():java.lang.String","callees":[]}]},{"method_name":"codetoanalyze.java.crashcontext.MethodNameClashExample$B.foo():void","location":{"location_type":"call_site","file":"MethodNameClashExample.java","line":26,"blame_range":[{"start_line":26,"end_line":26}]},"callees":[{"method_name":"codetoanalyze.java.crashcontext.MethodNameClashExample$A.foo():void","location":{"location_type":"proc_start","file":"MethodNameClashExample.java","line":16,"blame_range":[{"start_line":16,"end_line":18}]},"callees":[]}]},{"method_name":"codetoanalyze.java.crashcontext.MethodNameClashExample.main(java.lang.String[]):void","location":{"location_type":"call_site","file":"MethodNameClashExample.java","line":32,"blame_range":[{"start_line":31,"end_line":32}]},"callees":[{"method_name":"codetoanalyze.java.crashcontext.MethodNameClashExample$B.foo():void","location":{"location_type":"proc_start","file":"MethodNameClashExample.java","line":26,"blame_range":[{"start_line":26,"end_line":26}]},"callees":[]}]}]} \ No newline at end of file diff --git a/infer/tests/codetoanalyze/java/crashcontext/MinimalCrashExample.exp b/infer/tests/codetoanalyze/java/crashcontext/MinimalCrashExample.exp new file mode 100644 index 000000000..d71d793b4 --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/MinimalCrashExample.exp @@ -0,0 +1 @@ +{"stack":[{"method_name":"codetoanalyze.java.crashcontext.MinimalCrashExample.main(java.lang.String[]):void","location":{"location_type":"call_site","file":"MinimalCrashExample.java","line":16,"blame_range":[{"start_line":14,"end_line":16}]},"callees":[{"method_name":"java.lang.String.toString():java.lang.String","callees":[]}]}]} \ No newline at end of file diff --git a/infer/tests/codetoanalyze/java/crashcontext/MultiStackFrameCrashExample.exp b/infer/tests/codetoanalyze/java/crashcontext/MultiStackFrameCrashExample.exp new file mode 100644 index 000000000..88988ada6 --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/MultiStackFrameCrashExample.exp @@ -0,0 +1 @@ +{"stack":[{"method_name":"codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.bar():void","location":{"location_type":"call_site","file":"MultiStackFrameCrashExample.java","line":16,"blame_range":[{"start_line":14,"end_line":16}]},"callees":[{"method_name":"java.lang.String.toString():java.lang.String","callees":[]}]},{"method_name":"codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.foo():void","location":{"location_type":"call_site","file":"MultiStackFrameCrashExample.java","line":20,"blame_range":[{"start_line":19,"end_line":20}]},"callees":[{"method_name":"codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.bar():void","location":{"location_type":"proc_start","file":"MultiStackFrameCrashExample.java","line":14,"blame_range":[{"start_line":14,"end_line":16}]},"callees":[]}]},{"method_name":"codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.main(java.lang.String[]):void","location":{"location_type":"call_site","file":"MultiStackFrameCrashExample.java","line":24,"blame_range":[{"start_line":23,"end_line":24}]},"callees":[{"method_name":"codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.foo():void","location":{"location_type":"proc_start","file":"MultiStackFrameCrashExample.java","line":19,"blame_range":[{"start_line":19,"end_line":20}]},"callees":[]}]}]} \ No newline at end of file diff --git a/infer/tests/codetoanalyze/java/crashcontext/NativeMethodExample.exp b/infer/tests/codetoanalyze/java/crashcontext/NativeMethodExample.exp new file mode 100644 index 000000000..3ee9cfa53 --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/NativeMethodExample.exp @@ -0,0 +1 @@ +{"stack":[{"method_name":"codetoanalyze.java.crashcontext.NativeMethodExample.foo():void","location":{"location_type":"call_site","file":"NativeMethodExample.java","line":18,"blame_range":[{"start_line":16,"end_line":18}]},"callees":[{"method_name":"java.lang.String.toString():java.lang.String","callees":[]}]},{"method_name":"sun.reflect.NativeMethodAccessorImpl.invoke0","location":{"location_type":"call_site","file":"Native Method","blame_range":[]},"callees":[]},{"method_name":"sun.reflect.NativeMethodAccessorImpl.invoke","location":{"location_type":"call_site","file":"NativeMethodAccessorImpl.java","line":62,"blame_range":[]},"callees":[]},{"method_name":"sun.reflect.DelegatingMethodAccessorImpl.invoke","location":{"location_type":"call_site","file":"DelegatingMethodAccessorImpl.java","line":43,"blame_range":[]},"callees":[]},{"method_name":"java.lang.reflect.Method.invoke","location":{"location_type":"call_site","file":"Method.java","line":497,"blame_range":[]},"callees":[]},{"method_name":"codetoanalyze.java.crashcontext.NativeMethodExample.main(java.lang.String[]):void","location":{"location_type":"call_site","file":"NativeMethodExample.java","line":27,"blame_range":[{"start_line":21,"end_line":29}]},"callees":[{"method_name":"java.lang.Class.getDeclaredMethod(java.lang.String,java.lang.Class[]):java.lang.reflect.Method","callees":[]},{"method_name":"java.lang.reflect.Method.invoke(java.lang.Object,java.lang.Object[]):java.lang.Object","callees":[]},{"method_name":"__new_array","callees":[]}]}]} \ No newline at end of file diff --git a/infer/tests/codetoanalyze/java/harness/Makefile b/infer/tests/codetoanalyze/java/harness/Makefile new file mode 100644 index 000000000..451801763 --- /dev/null +++ b/infer/tests/codetoanalyze/java/harness/Makefile @@ -0,0 +1,19 @@ +# Copyright (c) 2016 - 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. + +include ../Makefile + +ANALYZER = infer + +FILES = \ + BasicHarnessActivity.java \ + +compile: + javac -cp $(CLASSPATH) $(FILES) + +analyze: + $(INFER_BIN) -a $(ANALYZER) --android-harness -- javac -cp $(CLASSPATH) $(FILES) >/dev/null 2>/dev/null diff --git a/infer/tests/codetoanalyze/java/harness/issues.exp b/infer/tests/codetoanalyze/java/harness/issues.exp new file mode 100644 index 000000000..725207760 --- /dev/null +++ b/infer/tests/codetoanalyze/java/harness/issues.exp @@ -0,0 +1 @@ +BasicHarnessActivity.java, codetoanalyze.java.harness.BasicHarnessActivity.InferGeneratedHarness(), -1, NULL_DEREFERENCE diff --git a/infer/tests/codetoanalyze/java/infer/BUCK b/infer/tests/codetoanalyze/java/infer/BUCK index 0ad06f27c..615ad8051 100644 --- a/infer/tests/codetoanalyze/java/infer/BUCK +++ b/infer/tests/codetoanalyze/java/infer/BUCK @@ -19,8 +19,6 @@ java_library( def analysis_cmd(analyzer): out = 'out' - inferconfig_file = '$(location //infer/tests/codetoanalyze/java:inferconfig)' - copy_inferconfig = ' '.join(['cp', inferconfig_file, '$SRCDIR']) clean_cmd = ' '.join(['rm', '-rf', out]) classpath = ':'.join([('$(classpath ' + path + ')') for path in dependencies]) infer_cmd = ' '.join([ @@ -36,7 +34,7 @@ def analysis_cmd(analyzer): '$SRCS', ]) copy_cmd = ' '.join(['cp', out + '/report.csv', '$OUT']) - return ' && '.join([clean_cmd, copy_inferconfig, infer_cmd, copy_cmd]) + return ' && '.join([clean_cmd, infer_cmd, copy_cmd]) genrule( name = 'analyze', diff --git a/infer/tests/codetoanalyze/objc/linters/Makefile b/infer/tests/codetoanalyze/objc/linters/Makefile index 77e97c092..501cce324 100644 --- a/infer/tests/codetoanalyze/objc/linters/Makefile +++ b/infer/tests/codetoanalyze/objc/linters/Makefile @@ -12,7 +12,7 @@ OPTIONS = -x objective-c -fobjc-arc -c ANALYZER = linters FILES = \ - **.m \ + *.m \ */*.m \ compile: diff --git a/infer/tests/endtoend/BUCK b/infer/tests/endtoend/BUCK deleted file mode 100644 index 875c2e756..000000000 --- a/infer/tests/endtoend/BUCK +++ /dev/null @@ -1,24 +0,0 @@ -tests_dependencies = [ - '//infer/lib/java/android:android', - '//dependencies/java/guava:guava', - '//dependencies/java/junit:hamcrest', - '//dependencies/java/jackson:jackson', - '//dependencies/java/jsr-305:jsr-305', - '//dependencies/java/junit:junit', - '//dependencies/java/opencsv:opencsv', - '//infer/tests/utils:utils', - '//infer/tests/codetoanalyze/java/crashcontext:crashcontext', - '//infer/tests/codetoanalyze/java/infer:infer', -] - -# ############### Java endtoend tests ######################## -java_test( - name='java_endtoend_tests', - deps=[ - '//infer/tests/endtoend/java/crashcontext:crashcontext', - '//infer/tests/endtoend/java/harness:harness', - ], - visibility=[ - 'PUBLIC', - ], -) diff --git a/infer/tests/endtoend/java/crashcontext/BUCK b/infer/tests/endtoend/java/crashcontext/BUCK deleted file mode 100644 index 4c42188f0..000000000 --- a/infer/tests/endtoend/java/crashcontext/BUCK +++ /dev/null @@ -1,16 +0,0 @@ -java_test( - name='crashcontext', - srcs=glob(['*.java']), - deps=[ - '//dependencies/java/guava:guava', - '//dependencies/java/junit:hamcrest', - '//dependencies/java/junit:junit', - '//infer/tests/utils:utils', - ], - resources=[ - '//infer/tests/codetoanalyze/java/crashcontext:analyze', - ], - visibility=[ - 'PUBLIC', - ], -) diff --git a/infer/tests/endtoend/java/crashcontext/BranchingCallsTest.java b/infer/tests/endtoend/java/crashcontext/BranchingCallsTest.java deleted file mode 100644 index b4eed297e..000000000 --- a/infer/tests/endtoend/java/crashcontext/BranchingCallsTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2016 - 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.crashcontext; - -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.CrashContextResults; - -public class BranchingCallsTest { - - public static final String TAG = "BranchingCallsExample"; - public static final String FILENAME = "BranchingCallsExample.java"; - - public static final String MAIN_METHOD = - "codetoanalyze.java.crashcontext.BranchingCallsExample.main(java.lang.String[]):void"; - public static final int MAIN_METHOD_LOC_START = 33; - public static final int MAIN_METHOD_LOC_LINE = 34; - public static final int MAIN_METHOD_LOC_END = 34; - - public static final String FOO_METHOD = - "codetoanalyze.java.crashcontext.BranchingCallsExample.foo():void"; - public static final int FOO_METHOD_LOC_START = 27; - public static final int FOO_METHOD_LOC_LINE = 27; - public static final int FOO_METHOD_LOC_END = 30; - - public static final String PRE_BAR_METHOD = - "codetoanalyze.java.crashcontext.BranchingCallsExample.pre_bar():void"; - public static final int PRE_BAR_METHOD_LOC_START = 14; - public static final int PRE_BAR_METHOD_LOC_LINE = 14; - public static final int PRE_BAR_METHOD_LOC_END = 15; - - public static final String BAR_METHOD = - "codetoanalyze.java.crashcontext.BranchingCallsExample.bar():void"; - public static final int BAR_METHOD_LOC_START = 22; - public static final int BAR_METHOD_LOC_LINE = 24; - public static final int BAR_METHOD_LOC_END = 24; - - public static final String POST_BAR_METHOD = - "codetoanalyze.java.crashcontext.BranchingCallsExample.post_bar():void"; - - public static final String TO_STRING_METHOD = - "java.lang.String.toString():java.lang.String"; - - private static CrashContextResults crashcontext; - - @BeforeClass - public static void loadResults() throws IOException { - crashcontext = - CrashContextResults.loadJSONResults(TAG); - } - - @Test - public void shapeOfTheStack() { - assertThat("The stack trace should contain " + BAR_METHOD, - crashcontext.hasStackFrame(BAR_METHOD, 0)); - assertThat("The stack trace should contain " + FOO_METHOD, - crashcontext.hasStackFrame(FOO_METHOD, 1)); - assertThat("The stack trace should contain " + MAIN_METHOD, - crashcontext.hasStackFrame(MAIN_METHOD, 2)); - } - - @Test - public void toStringMethodIsFound() { - assertThat("Method " + TO_STRING_METHOD + " should be part of the context", - crashcontext.hasMethod(TO_STRING_METHOD)); - assertThat("Method " + TO_STRING_METHOD + " should be reachable in the " + - "context tree from " + BAR_METHOD, - crashcontext.hasPath(BAR_METHOD, TO_STRING_METHOD)); - } - - @Test - public void preBarMethodIsFound() { - assertThat("Method " + PRE_BAR_METHOD + " should be part of the context", - crashcontext.hasMethod(PRE_BAR_METHOD)); - assertThat("Method " + PRE_BAR_METHOD + " should be reachable in the " + - "context tree from " + FOO_METHOD, - crashcontext.hasPath(FOO_METHOD, PRE_BAR_METHOD)); - } - - @Test - public void postBarMethodIsOmitted() { - assertThat("Method " + POST_BAR_METHOD + " shouldn't be part of the context", - crashcontext.hasNotMethod(POST_BAR_METHOD)); - } - - @Test - public void sourceFileLocations() { - assertThat("Method " + MAIN_METHOD + " should have the following " + - "location information: {file: " + FILENAME + - ", critical line: " + MAIN_METHOD_LOC_LINE + - ", range start: " + MAIN_METHOD_LOC_START + - ", range end: " + MAIN_METHOD_LOC_END + "}", - crashcontext.hasMethodWithLocation(MAIN_METHOD, - FILENAME, - MAIN_METHOD_LOC_LINE, - MAIN_METHOD_LOC_START, - MAIN_METHOD_LOC_END)); - assertThat("Method " + FOO_METHOD + " should have the following " + - "location information: {file: " + FILENAME + - ", critical line: " + FOO_METHOD_LOC_LINE + - ", range start: " + FOO_METHOD_LOC_START + - ", range end: " + FOO_METHOD_LOC_END + "}", - crashcontext.hasMethodWithLocation(FOO_METHOD, - FILENAME, - FOO_METHOD_LOC_LINE, - FOO_METHOD_LOC_START, - FOO_METHOD_LOC_END)); - assertThat("Method " + BAR_METHOD + " should have the following " + - "location information: {file: " + FILENAME + - ", critical line: " + BAR_METHOD_LOC_LINE + - ", range start: " + BAR_METHOD_LOC_START + - ", range end: " + BAR_METHOD_LOC_END + "}", - crashcontext.hasMethodWithLocation(BAR_METHOD, - FILENAME, - BAR_METHOD_LOC_LINE, - BAR_METHOD_LOC_START, - BAR_METHOD_LOC_END)); - assertThat("Method " + PRE_BAR_METHOD + " should have the following " + - "location information: {file: " + FILENAME + - ", critical line: " + PRE_BAR_METHOD_LOC_LINE + - ", range start: " + PRE_BAR_METHOD_LOC_START + - ", range end: " + PRE_BAR_METHOD_LOC_END + "}", - crashcontext.hasMethodWithLocation(PRE_BAR_METHOD, - FILENAME, - PRE_BAR_METHOD_LOC_LINE, - PRE_BAR_METHOD_LOC_START, - PRE_BAR_METHOD_LOC_END)); - } - -} diff --git a/infer/tests/endtoend/java/crashcontext/MethodNameClashTest.java b/infer/tests/endtoend/java/crashcontext/MethodNameClashTest.java deleted file mode 100644 index 5976ef090..000000000 --- a/infer/tests/endtoend/java/crashcontext/MethodNameClashTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2016 - 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.crashcontext; - -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.CrashContextResults; - -public class MethodNameClashTest { - - public static final String TAG = "MethodNameClashExample"; - - public static final String MAIN_METHOD = - "codetoanalyze.java.crashcontext.MethodNameClashExample.main(java.lang.String[]):void"; - - public static final String A_FOO_METHOD = - "codetoanalyze.java.crashcontext.MethodNameClashExample$A.foo():void"; - - public static final String B_FOO_METHOD = - "codetoanalyze.java.crashcontext.MethodNameClashExample$B.foo():void"; - - private static CrashContextResults crashcontext; - - @BeforeClass - public static void loadResults() throws IOException { - crashcontext = - CrashContextResults.loadJSONResults(TAG); - } - - @Test - public void shapeOfTheStack() { - assertThat("The stack trace should contain " + A_FOO_METHOD, - crashcontext.hasStackFrame(A_FOO_METHOD, 0)); - assertThat("The stack trace should contain " + B_FOO_METHOD, - crashcontext.hasStackFrame(B_FOO_METHOD, 1)); - assertThat("The stack trace should contain " + MAIN_METHOD, - crashcontext.hasStackFrame(MAIN_METHOD, 2)); - } - -} diff --git a/infer/tests/endtoend/java/crashcontext/MinimalCrashTest.java b/infer/tests/endtoend/java/crashcontext/MinimalCrashTest.java deleted file mode 100644 index 5ce1d1943..000000000 --- a/infer/tests/endtoend/java/crashcontext/MinimalCrashTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2016 - 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.crashcontext; - -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.CrashContextResults; - -public class MinimalCrashTest { - - public static final String TAG = "MinimalCrashExample"; - - public static final String MAIN_METHOD = - "codetoanalyze.java.crashcontext.MinimalCrashExample.main(java.lang.String[]):void"; - - public static final String TO_STRING_METHOD = - "java.lang.String.toString():java.lang.String"; - - private static CrashContextResults crashcontext; - - @BeforeClass - public static void loadResults() throws IOException { - crashcontext = - CrashContextResults.loadJSONResults(TAG); - } - - @Test - public void shapeOfTheStack() { - assertThat("The stack trace should contain " + MAIN_METHOD, - crashcontext.hasStackFrame(MAIN_METHOD, 0)); - } - - @Test - public void toStringMethodIsDetected() { - assertThat("Method " + TO_STRING_METHOD + " should be part of the context", - crashcontext.hasMethod(TO_STRING_METHOD)); - assertThat("Method " + TO_STRING_METHOD + " should be reachable in the " + - "context tree from " + MAIN_METHOD, - crashcontext.hasPath(MAIN_METHOD, TO_STRING_METHOD)); - } - -} diff --git a/infer/tests/endtoend/java/crashcontext/MultiStackFrameCrashTest.java b/infer/tests/endtoend/java/crashcontext/MultiStackFrameCrashTest.java deleted file mode 100644 index 0711842bd..000000000 --- a/infer/tests/endtoend/java/crashcontext/MultiStackFrameCrashTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2016 - 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.crashcontext; - -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.CrashContextResults; - -public class MultiStackFrameCrashTest { - - public static final String TAG = "MultiStackFrameCrashExample"; - - public static final String MAIN_METHOD = - "codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.main(java.lang.String[]):void"; - - public static final String FOO_METHOD = - "codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.foo():void"; - - public static final String BAR_METHOD = - "codetoanalyze.java.crashcontext.MultiStackFrameCrashExample.bar():void"; - - public static final String TO_STRING_METHOD = - "java.lang.String.toString():java.lang.String"; - - private static CrashContextResults crashcontext; - - @BeforeClass - public static void loadResults() throws IOException { - crashcontext = - CrashContextResults.loadJSONResults(TAG); - } - - @Test - public void shapeOfTheStack() { - assertThat("The stack trace should contain " + BAR_METHOD, - crashcontext.hasStackFrame(BAR_METHOD, 0)); - assertThat("The stack trace should contain " + FOO_METHOD, - crashcontext.hasStackFrame(FOO_METHOD, 1)); - assertThat("The stack trace should contain " + MAIN_METHOD, - crashcontext.hasStackFrame(MAIN_METHOD, 2)); - } - - @Test - public void toStringMethodIsFound() { - assertThat("Method " + TO_STRING_METHOD + " should be part of the context", - crashcontext.hasMethod(TO_STRING_METHOD)); - assertThat("Method " + TO_STRING_METHOD + " should be reachable in the " + - "context tree from " + BAR_METHOD, - crashcontext.hasPath(BAR_METHOD, TO_STRING_METHOD)); - } - -} diff --git a/infer/tests/endtoend/java/crashcontext/NativeMethodTest.java b/infer/tests/endtoend/java/crashcontext/NativeMethodTest.java deleted file mode 100644 index e6ed3612c..000000000 --- a/infer/tests/endtoend/java/crashcontext/NativeMethodTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2016 - 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.crashcontext; - -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.CrashContextResults; - -public class NativeMethodTest { - - public static final String TAG = "NativeMethodExample"; - - public static final String MAIN_METHOD = - "codetoanalyze.java.crashcontext.NativeMethodExample.main(java.lang.String[]):void"; - - // Currently, native methods are missing their arguments lists. - public static final String REFLECTION_INVOKE_METHOD = - "sun.reflect.NativeMethodAccessorImpl.invoke0"; - - public static final String FOO_METHOD = - "codetoanalyze.java.crashcontext.NativeMethodExample.foo():void"; - - private static CrashContextResults crashcontext; - - @BeforeClass - public static void loadResults() throws IOException { - crashcontext = - CrashContextResults.loadJSONResults(TAG); - } - - @Test - public void shapeOfTheStack() { - assertThat("The stack trace should contain " + FOO_METHOD, - crashcontext.hasStackFrame(FOO_METHOD)); - assertThat("The trace should contain at least one native method ", - crashcontext.hasNativeMethodOnStack()); - assertThat("The stack trace should contain " + REFLECTION_INVOKE_METHOD, - crashcontext.hasStackFrame(REFLECTION_INVOKE_METHOD)); - assertThat("The stack trace should contain " + MAIN_METHOD, - crashcontext.hasStackFrame(MAIN_METHOD)); - } - -} diff --git a/infer/tests/endtoend/java/harness/BUCK b/infer/tests/endtoend/java/harness/BUCK deleted file mode 100644 index b422c24e5..000000000 --- a/infer/tests/endtoend/java/harness/BUCK +++ /dev/null @@ -1,13 +0,0 @@ -java_test( - name='harness', - srcs=glob(['*.java']), - deps=[ - '//dependencies/java/guava:guava', - '//dependencies/java/junit:hamcrest', - '//dependencies/java/junit:junit', - '//infer/tests/utils:utils', - ], - visibility=[ - 'PUBLIC', - ], -) diff --git a/infer/tests/endtoend/java/harness/InhabitTest.java b/infer/tests/endtoend/java/harness/InhabitTest.java deleted file mode 100644 index e9fd35a35..000000000 --- a/infer/tests/endtoend/java/harness/InhabitTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2013 - 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.harness; - - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsErrorNoFilename.contains; - -import com.google.common.collect.ImmutableList; - -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; - -import java.io.IOException; - -import utils.DebuggableTemporaryFolder; -import utils.InferException; -import utils.InferResults; -import utils.InferRunner; - -public class InhabitTest { - - public static final String TrickyParamsActivity = - "infer/tests/codetoanalyze/java/harness/TrickyParamsActivity.java"; - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - @ClassRule - public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); - - private static ImmutableList inferCmd; - - - @BeforeClass - public static void runInfer() throws IOException { - inferCmd = InferRunner.createJavaInferHarnessCommand(folder, TrickyParamsActivity); - } - - @Test - public void canInhabitTrickyParams() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferJava(inferCmd); - assertThat( - "Results should contain NPE", - inferResults, - contains( - NULL_DEREFERENCE, - "java.harness.TrickyParamsActivity.InferGeneratedHarness" - ) - ); - } - -} diff --git a/infer/tests/endtoend/java/harness/LifecycleTest.java b/infer/tests/endtoend/java/harness/LifecycleTest.java deleted file mode 100644 index 820d8a580..000000000 --- a/infer/tests/endtoend/java/harness/LifecycleTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2013 - 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.harness; - - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsErrorNoFilename.contains; - -import com.google.common.collect.ImmutableList; - -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; - -import java.io.IOException; - -import utils.DebuggableTemporaryFolder; -import utils.InferException; -import utils.InferResults; -import utils.InferRunner; - -public class LifecycleTest { - - public static final String BasicHarnessActivity = - "infer/tests/codetoanalyze/java/harness/BasicHarnessActivity.java"; - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - @ClassRule - public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); - - private static ImmutableList inferCmd; - - - @BeforeClass - public static void runInfer() throws IOException { - inferCmd = InferRunner.createJavaInferHarnessCommand(folder, BasicHarnessActivity); - } - - @Test - public void harnessRevealsNpe() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferJava(inferCmd); - assertThat( - "Results should contain NPE", - inferResults, - contains( - NULL_DEREFERENCE, - "java.harness.BasicHarnessActivity.InferGeneratedHarness" - ) - ); - } - -} diff --git a/infer/tests/endtoend/java/infer/BUCK b/infer/tests/endtoend/java/infer/BUCK deleted file mode 100644 index d2580c8b2..000000000 --- a/infer/tests/endtoend/java/infer/BUCK +++ /dev/null @@ -1,17 +0,0 @@ -# TODO: this file exists only to support buck integration in infer/tests/build_systems/build_integration_tests.py -java_test( - name='infer', - srcs=glob(['*.java']), - deps=[ - '//dependencies/java/guava:guava', - '//dependencies/java/junit:hamcrest', - '//dependencies/java/junit:junit', - '//infer/tests/utils:utils', - ], - resources=[ - '//infer/tests/codetoanalyze/java/infer:analyze', - ], - visibility=[ - 'PUBLIC', - ], -) diff --git a/infer/tests/endtoend/objcpp/infer/BUCK b/infer/tests/endtoend/objcpp/infer/BUCK deleted file mode 100644 index 33652388a..000000000 --- a/infer/tests/endtoend/objcpp/infer/BUCK +++ /dev/null @@ -1,35 +0,0 @@ -tests_dependencies = [ - '//infer/lib/java/android:android', - '//dependencies/java/guava:guava', - '//dependencies/java/junit:hamcrest', - '//dependencies/java/jackson:jackson', - '//dependencies/java/jsr-305:jsr-305', - '//dependencies/java/junit:junit', - '//dependencies/java/opencsv:opencsv', - '//infer/tests/utils:utils', -] - -objcpp_infer_test_sources = glob(['*.java']) -objcpp_infer_test_deps = [] -for test_source in objcpp_infer_test_sources: - target_name = test_source.replace("/", "_")[:-len(".java")] - objcpp_infer_test_deps.append(target_name) - - java_test( - name=target_name, - srcs=[test_source], - deps=tests_dependencies, - visibility=[ - 'PUBLIC', - ], - source='7', - target='7', - ) - -java_test( - name='infer', - deps=[':' + x for x in objcpp_infer_test_deps], - visibility=[ - 'PUBLIC', - ], -) diff --git a/infer/tests/utils/BUCK b/infer/tests/utils/BUCK deleted file mode 100644 index 3792baf39..000000000 --- a/infer/tests/utils/BUCK +++ /dev/null @@ -1,18 +0,0 @@ -java_library( - name='utils', - srcs=glob(['**/*.java']), - deps=[ - '//infer/lib/java/android:android', - '//dependencies/java/guava:guava', - '//dependencies/java/junit:hamcrest', - '//dependencies/java/jackson:jackson', - '//dependencies/java/jsr-305:jsr-305', - '//dependencies/java/junit:junit', - '//dependencies/java/opencsv:opencsv' - ], - visibility = [ - 'PUBLIC', - ], - source='7', - target='7', -) diff --git a/infer/tests/utils/CrashContextResults.java b/infer/tests/utils/CrashContextResults.java deleted file mode 100644 index f75b4a206..000000000 --- a/infer/tests/utils/CrashContextResults.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2016 - 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 utils; - -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.google.common.io.ByteStreams; - -public class CrashContextResults { - - private static final String CRASHCONTEXT_JSON = - "/buck-out/gen/infer/tests/codetoanalyze/java/crashcontext/analyze/crashcontext.json"; - - private JsonNode json; - private String filename; - - private CrashContextResults(String tag) throws IOException { - String path = - System.getProperty("user.dir") + CRASHCONTEXT_JSON + "." + tag; - byte[] jsonData = ByteStreams.toByteArray(new FileInputStream(path)); - ObjectMapper objectMapper = new ObjectMapper(); - json = objectMapper.readTree(jsonData); - } - - public boolean hasStackFrame(String methodSignature, int pos) { - return methodSignature.equals( - json.path("stack").get(pos).path("method_name").asText()); - } - - public boolean hasStackFrame(String methodSignature) { - for (JsonNode frame : json.path("stack")) { - if (methodSignature.equals(frame.path("method_name").asText())) { - return true; - } - } - return false; - } - - public boolean hasLocationOnStack(String filename, int line) { - for (JsonNode frame : json.path("stack")) { - if (filename.equals(frame.path("location").path("file").asText()) && - line == frame.path("location").path("line").asInt()) { - return true; - } - } - return false; - } - - public boolean hasNativeMethodOnStack() { - for (JsonNode frame : json.path("stack")) { - if (frame.path("location").path("file").asText() - .equals("Native Method")) { - return true; - } - } - return false; - } - - private List findNodesForMethod(JsonNode node, - String methodSignature, - List accumulator) { - if (methodSignature.equals(node.path("method_name").asText())) { - accumulator.add(node); - } - for (JsonNode callee : node.path("callees")) { - findNodesForMethod(callee, methodSignature, accumulator); - } - return accumulator; - } - - private List findNodesForMethod(String methodSignature) { - List accumulator = new ArrayList(); - for (JsonNode frame : json.path("stack")) { - findNodesForMethod(frame, methodSignature, accumulator); - } - return accumulator; - } - - public boolean hasMethod(String methodSignature) { - return !findNodesForMethod(methodSignature).isEmpty(); - } - - public boolean hasNotMethod(String methodSignature) { - return findNodesForMethod(methodSignature).isEmpty(); - } - - public boolean hasPath(String methodFrom, String methodTo) { - for (JsonNode from : findNodesForMethod(methodFrom)) { - if (!findNodesForMethod(from, methodTo, new ArrayList()).isEmpty()) { - return true; - } - } - return false; - } - - public boolean hasMethodWithLocation(String methodSignature, String filename, - int line, int start, int end) { - for (JsonNode frame : findNodesForMethod(methodSignature)) { - if (frame.path("location").path("file").asText().endsWith(filename) && - line == frame.path("location").path("line").asInt()) { - for (JsonNode blameRange : frame.path("location").path("blame_range")) { - if (blameRange.path("start_line").asInt() == start && - blameRange.path("end_line").asInt() == end) { - return true; - } - } - } - } - return false; - } - - public static CrashContextResults loadJSONResults(String tag) throws IOException { - return new CrashContextResults(tag); - } - -} diff --git a/infer/tests/utils/DebuggableTemporaryFolder.java b/infer/tests/utils/DebuggableTemporaryFolder.java deleted file mode 100644 index af03c1873..000000000 --- a/infer/tests/utils/DebuggableTemporaryFolder.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012-present Facebook, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package utils; - -import org.junit.rules.TemporaryFolder; - -import java.util.Map; - -import javax.annotation.Nullable; - - -public class DebuggableTemporaryFolder extends TemporaryFolder { - - private - @Nullable - String name; - private boolean doNotDeleteOnExit; - - public DebuggableTemporaryFolder() { - Map env = System.getenv(); - if (env.get("INFER_KEEP_FOLDER") != null) { - doNotDeleteOnExit = true; - } - } - - /** - * If invoked, the directory created by this {@link org.junit.rules.TemporaryFolder} will not be - * deleted when the test finishes. - * - * @return {@code this} - */ - public DebuggableTemporaryFolder doNotDeleteOnExit() { - this.doNotDeleteOnExit = true; - return this; - } - - /** - * Name to use to identify this {@link org.junit.rules.TemporaryFolder} when writing log messages - * to stdout. - * - * @return {@code this} - */ - public DebuggableTemporaryFolder setName(String name) { - this.name = name; - return this; - } - - @Override - public void after() { - if (doNotDeleteOnExit) { - String name = this.name == null ? "TemporaryFolder" : this.name; - System.out.printf("%s available at %s.\n", name, getRoot()); - } else { - super.after(); - } - } -} diff --git a/infer/tests/utils/InferError.java b/infer/tests/utils/InferError.java deleted file mode 100644 index d45a0514b..000000000 --- a/infer/tests/utils/InferError.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2013 - 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 utils; - -import java.nio.file.Path; -import java.io.IOException; - -public class InferError { - - private String errorType; - private Path errorFile; - private String errorMethod; - private int errorLine; - - public InferError(String errorType, Path errorFile, String errorMethod, int errorLine) { - this.errorType = errorType; - this.errorMethod = errorMethod; - this.errorLine = errorLine; - try { - this.errorFile = errorFile.toRealPath(); - } catch (IOException e) { - this.errorFile = errorFile; - } - } - - public InferError(String errorType, Path errorFile, String errorMethod) { - this.errorType = errorType; - this.errorFile = errorFile; - this.errorMethod = errorMethod; - this.errorLine = -1; - } - - public static InferError inferError(String errorMethod, Path errorFile, String errorType) { - return new InferError(errorMethod, errorFile, errorType); - } - - public String getErrorType() { - return errorType; - } - - public String getErrorMethod() { - return errorMethod; - } - - public Path getErrorFile() { - return errorFile; - } - - public int getErrorLine() { - return errorLine; - } - - public String toStringNoLine() { - return errorType + " at " + errorFile + ", method " + errorMethod; - } - - public String toString() { - if (errorLine > 0) - return toStringNoLine() + " (line " + errorLine + ")"; - else return toStringNoLine(); - } - - public String toStringFileMethod() { - return errorFile + ", method " + errorMethod; - } - - public String toStringErrorTypeMethod() { - return errorType + " at " + errorMethod; - } - - public boolean matchType(String type) { - return this.errorType.equals(type); - } - - public boolean matchFile(Path file) { - Path realFile; - try { - realFile = file.toRealPath(); - } catch (IOException e) { - realFile = file; - } - return this.errorFile.equals(realFile); - } - - public boolean matchMethod(String method) { - return this.errorMethod.equals(method); - } - - public boolean matchLine(int line) { - return this.errorLine < 0 || line < 0 - || (this.errorLine == line); - } - -} diff --git a/infer/tests/utils/InferException.java b/infer/tests/utils/InferException.java deleted file mode 100644 index a4843f9d2..000000000 --- a/infer/tests/utils/InferException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2013 - 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 utils; - - -public class InferException extends RuntimeException { - - public InferException(String message) { - super(message); - } - - @Override - public String toString() { - return ""; - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/infer/tests/utils/InferResults.java b/infer/tests/utils/InferResults.java deleted file mode 100644 index 943cb6c3d..000000000 --- a/infer/tests/utils/InferResults.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2013 - 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 utils; - - -import com.google.common.base.Joiner; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import au.com.bytecode.opencsv.CSVReader; - -public class InferResults { - - private ImmutableList inferCmd; - - public static final Pattern JAVA_METHOD_NAME = Pattern.compile("(\\.)(.*)(\\()"); - public static final Pattern C_FUNCTION_NAME = Pattern.compile("(\")(.*)(\")"); - public static final Pattern OBJC_FUNCTION_NAME = Pattern.compile("(.*)_(.*)"); - - private Vector errors = new Vector(); - - InferResults() { - this.inferCmd = ImmutableList.of(""); - } - - InferResults(ImmutableList inferCmd) { - this.inferCmd = inferCmd; - } - - public void parseInferResultsFromString(Pattern pattern, String errorString) - throws IOException, InferException { - - try (CSVReader reader = new CSVReader(new StringReader(errorString))) { - List lines = reader.readAll(); - Path root = Paths.get(System.getProperty("user.dir")); - - for (String[] items : lines) { - String errorKind = items[1].trim(); - String errorType = items[2].trim(); - if (errorKind.equals("ERROR") || - errorType.equals("ASSIGN_POINTER_WARNING") || - errorType.equals("STRONG_DELEGATE_WARNING") || - errorType.equals("DIRECT_ATOMIC_PROPERTY_ACCESS") || - errorType.equals("CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK") || - errorType.equals("REGISTERED_OBSERVER_BEING_DEALLOCATED") || - errorType.equals("GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL") || - errorType.equals("IMMUTABLE_CAST") || - errorType.equals("PARAMETER_NOT_NULL_CHECKED") || - errorType.equals("DANGLING_POINTER_DEREFERENCE") || - errorType.equals("IVAR_NOT_NULL_CHECKED") || - errorType.equals("BAD_POINTER_COMPARISON") || - errorType.equals("Bad_footprint") || - errorType.equals("MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE")) { - Integer errorLine = Integer.parseInt(items[5].trim()); - String procedure = items[6]; - Path path = Paths.get(items[8]); - if (path.isAbsolute()) { - path = root.relativize(Paths.get(items[8])); - } - Matcher methodMatcher = pattern.matcher(procedure); - boolean matching = methodMatcher.find(); - if (matching) { - procedure = methodMatcher.group(2); - if (procedure == null) { - throw new InferException("Unexpected method name structure."); - } - } - procedure = procedure.trim(); - InferError error = new InferError(errorType, path, procedure, errorLine); - errors.add(error); - } - } - } - } - - public void parseJavaInferResultsFromString(String errorString) - throws IOException, InferException { - parseInferResultsFromString(JAVA_METHOD_NAME, errorString); - } - - public void parseCInferResultsFromString(String errorString) - throws IOException, InferException { - parseInferResultsFromString(C_FUNCTION_NAME, errorString); - } - - public void parseObjCInferResultsFromString(String errorString) - throws IOException, InferException { - parseInferResultsFromString(OBJC_FUNCTION_NAME, errorString); - } - - public Vector getErrors() { - return errors; - } - - public String inferCmdToString() { - return "Infer command: " + Joiner.on(' ').join(inferCmd); - } - - public String toString() { - String s = ""; - for (InferError e : errors) { - s = s + "\n" + e.toString(); - } - if (s.length() == 0) return "No results."; - return s; - } - - public void filter(String filename) { - Vector filtered_errors = new Vector(); - for (InferError error : errors) { - if (error.getErrorFile().endsWith(filename)) { - filtered_errors.add(error); - } - } - errors = filtered_errors; - } - - public static InferResults loadResultsFromReader( - BufferedReader reader, - String sourceFile, - Pattern pattern) { - InferResults inferResults = new InferResults(); - String resultString = ""; - try { - String line = reader.readLine(); - while (line != null) { - resultString += line + "\n"; - line = reader.readLine(); - } - inferResults.parseInferResultsFromString( - pattern, - resultString); - } catch (IOException e) { - throw new RuntimeException(e.toString()); - } - inferResults.filter(sourceFile); - return inferResults; - } - - private static InferResults loadResultsFromPath(Class currentClass, String sourceFile, - String csvPath, Pattern procnamePattern) { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream(csvPath))); - return loadResultsFromReader( - Preconditions.checkNotNull(reader), - sourceFile, - procnamePattern); - } - - public static InferResults loadInferResults(Class currentClass, String sourceFile) { - return loadResultsFromPath( - currentClass, - sourceFile, - "/infer/tests/codetoanalyze/java/infer/report.csv", - InferResults.JAVA_METHOD_NAME); - } - - public static InferResults loadTracingResults(Class currentClass, String sourceFile) { - return loadResultsFromPath( - currentClass, - sourceFile, - "/infer/tests/codetoanalyze/java/tracing/report.csv", - InferResults.JAVA_METHOD_NAME); - } - - public static InferResults loadTracingComparisonResults(Class currentClass, String sourceFile) { - return loadResultsFromPath( - currentClass, - sourceFile, - "/infer/tests/codetoanalyze/java/infer/comparison_report.csv", - InferResults.JAVA_METHOD_NAME); - } - - public static InferResults loadCInferResults(Class currentClass, String sourceFile) { - return loadResultsFromPath( - currentClass, - sourceFile, - "/infer/tests/codetoanalyze/c/errors/report.csv", - InferResults.C_FUNCTION_NAME); - } - -} diff --git a/infer/tests/utils/InferRunner.java b/infer/tests/utils/InferRunner.java deleted file mode 100644 index e1c7e2c49..000000000 --- a/infer/tests/utils/InferRunner.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2013 - 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 utils; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; - -import org.junit.rules.TemporaryFolder; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; - -public class InferRunner { - - public static final String BUGS_FILE_NAME = "report.csv"; - - public static final String DOT_FILE_NAME = "icfg.dot"; - - public static final String CAPTURED_FOLDER = "captured"; - - private static File bugsFile; - - @Nullable - private static File dotFile; - - private static File resultsDir; - - private static final ImmutableList EMPTY_ARGS = ImmutableList.of(); - - private static final String ANDROID = - "/infer/lib/java/android/android-19.jar"; - - private static final String[] LIBRARIES = { - "/infer/lib/java/models.jar", - "/infer/annotations/annotations.jar", - "/dependencies/java/guava/guava-10.0.1-fork.jar", - "/dependencies/java/jackson/jackson-2.2.3.jar", - }; - - private static HashMap inferResultsMap = - new HashMap(); - - private static String getXcodeRoot() throws IOException, InterruptedException { - ProcessBuilder pb = new ProcessBuilder("xcode-select", "-p"); - Process process = pb.start(); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - String line = br.readLine(); - process.waitFor(); - return line; - } - - private static String getXCodeVersion() throws IOException, InterruptedException { - ProcessBuilder pb = new ProcessBuilder("xcodebuild", "-version"); - Process process = pb.start(); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - String line = br.readLine(); - process.waitFor(); - return line; - } - - private static ImmutableList createInferJavaCommand( - TemporaryFolder folder, - ImmutableList sourceFiles, - String analyzer, - ImmutableList args) { - try { - File resultsDir = createResultsDir(folder); - String resultsDirName = resultsDir.getAbsolutePath(); - InferRunner.bugsFile = new File(resultsDir, BUGS_FILE_NAME); - - ImmutableList javacCmd = createJavacCommand( - folder, - sourceFiles); - - return new ImmutableList.Builder() - .add("infer") - .add("--no-progress-bar") - .add("--no-filtering") - .addAll(args) - .add("-o") - .add(resultsDirName) - .add("-a") - .add(analyzer) - .add("--") - .addAll(javacCmd) - .build(); - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - return ImmutableList.of(); // unreachable - } - } - - private static ImmutableList createJavacCommand( - TemporaryFolder folder, - ImmutableList sourceFiles) - throws IOException { - File classesDir = folder.newFolder("classes_out"); - String classesDirName = classesDir.getAbsolutePath(); - - ImmutableList javacCmd = new ImmutableList.Builder() - .add("javac") - .add("-classpath") - .add(getClasspath()) - .add("-bootclasspath") - .add(getBootClasspath()) - .add("-d") - .add(classesDirName) - .addAll(sourceFiles).build(); - return javacCmd; - } - - public static ImmutableList createJavaInferHarnessCommand( - TemporaryFolder folder, - ImmutableList sourceFiles) { - ImmutableList args = new ImmutableList.Builder() - .add("--android-harness") - .build(); - return createInferJavaCommand(folder, sourceFiles, "infer", args); - } - - public static ImmutableList createJavaInferHarnessCommand( - TemporaryFolder folder, - String sourceFile) { - return createJavaInferHarnessCommand(folder, ImmutableList.of(sourceFile)); - } - - public static ImmutableList createJavaInferAngelicHarnessCommand( - TemporaryFolder folder, - ImmutableList sourceFiles) { - ImmutableList args = (new ImmutableList.Builder()) - .add("--android-harness") - .build(); - return createInferJavaCommand(folder, sourceFiles, "infer", args); - } - - private static InferResults runInfer( - ImmutableList inferCmd, - Language lang) - throws IOException, InterruptedException, InferException { - String inferCmdString = Joiner.on(' ').join(inferCmd); - InferResults results = inferResultsMap.get(inferCmdString); - if (results == null) { - if (lang == Language.Java) checkLibraries(); - - runCommand(inferCmd, TestType.END_TO_END); - String errorString = getErrors(bugsFile); - results = new InferResults(inferCmd); - if (lang == Language.Java) - results.parseJavaInferResultsFromString(errorString); - else if (lang == Language.C || lang == Language.CPP || lang == Language.ObjCPP) - results.parseCInferResultsFromString(errorString); - else if (lang == Language.ObjC) - results.parseObjCInferResultsFromString(errorString); - inferResultsMap.put(inferCmdString, results); - } - return results; - } - - public static InferResults runInferJava(ImmutableList inferCmd) - throws IOException, InterruptedException, InferException { - return runInfer(inferCmd, Language.Java); - } - - public static InferResults runInferC(ImmutableList inferCmd) - throws IOException, InterruptedException, InferException { - return runInfer(inferCmd, Language.C); - } - - public static InferResults runInferCPP(ImmutableList inferCmd) - throws IOException, InterruptedException, InferException { - return runInfer(inferCmd, Language.CPP); - } - - public static InferResults runInferObjC(ImmutableList inferCmd) - throws IOException, InterruptedException, InferException { - return runInfer(inferCmd, Language.ObjC); - } - - public static InferResults runInferObjCPP(ImmutableList inferCmd) - throws IOException, InterruptedException, InferException { - return runInfer(inferCmd, Language.ObjCPP); - } - - - private static void runCommand( - ImmutableList inferCmd, - TestType testType) - throws IOException, InterruptedException, InferException { - ProcessBuilder pb = new ProcessBuilder(inferCmd); - - Map env = pb.environment(); - env.put("INFER_REPORT_CUSTOM_ERROR", "1"); - - Process process = pb.start(); - StringBuilder stderr = new StringBuilder(); - try (BufferedReader bufferedReader = - new BufferedReader( - new InputStreamReader( - process.getErrorStream()))) { - String line = null; - while ((line = bufferedReader.readLine()) != null) { - stderr.append(line + "\n"); - } - } - process.waitFor(); - - File file = null; - if (testType == TestType.END_TO_END) { - file = bugsFile; - } else if (testType == TestType.FRONTEND) { - getDotFile(); - file = dotFile; - } - if (file == null || !file.exists()) { - String fileNotFoundMessage = file == null ? - "" : "\n\nFile " + file + " not found."; - throw new InferException( - "There was an error while calling Infer." + - "\n\nCommand output:\n" + stderr + - "\nCommand: " + Joiner.on(' ').join(inferCmd) + - fileNotFoundMessage + - "\n=========================================================================="); - } - } - - static String getErrors(File file) throws IOException { - String s = ""; - String line = ""; - try (BufferedReader br = new BufferedReader(new FileReader(file))) { - br.readLine(); - while ((line = br.readLine()) != null) { - s += line + "\n"; - } - } - return s; - } - - private static String getBootClasspath() { - String current_dir = System.getProperty("user.dir"); - String bootclasspath = current_dir + ANDROID; - return bootclasspath; - } - - private static String getClasspath() { - String current_dir = System.getProperty("user.dir"); - StringBuilder classpath = new StringBuilder(); - for (String library : LIBRARIES) { - classpath.append(current_dir); - classpath.append(library); - classpath.append(":"); - } - classpath.deleteCharAt(classpath.length() - 1); - return classpath.toString(); - } - - private static void checkLibraries() throws InferException { - String current_dir = System.getProperty("user.dir"); - for (String lib_file : LIBRARIES) { - File lib = new File(current_dir + lib_file); - if (!lib.exists()) { - throw new InferException("File " + lib_file + " not found."); - } - } - } - - private static File createResultsDir(TemporaryFolder folder) { - try { - resultsDir = folder.newFolder("infer_out"); - return resultsDir; - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - return null; // unreachable - } - } - - private static void getDotFile() { - File captured = new File(resultsDir, CAPTURED_FOLDER); - if (captured.exists()) { - File f = new File(captured, captured.list()[0]); - dotFile = new File(f, DOT_FILE_NAME); - } else { - dotFile = null; - } - } -} diff --git a/infer/tests/utils/InferStats.java b/infer/tests/utils/InferStats.java deleted file mode 100644 index ceac2a31f..000000000 --- a/infer/tests/utils/InferStats.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 utils; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStreamReader; -import java.io.IOException; -import java.io.Reader; - -@JsonIgnoreProperties(ignoreUnknown=true) -public class InferStats { - - @JsonIgnoreProperties(ignoreUnknown=true) - private static class IntFields { - @JsonProperty(value = "files") - int numFiles; - - @JsonProperty(value = "procedures") - int numProcedures; - - @JsonProperty(value = "lines") - int numLines; - } - - private static class FloatFields { - @JsonProperty(value = "reporting_time") - float reportingTime; - - @JsonProperty(value = "capture_time") - float captureTime; - - @JsonProperty(value = "analysis_time") - float analysisTime; - - @JsonProperty(value = "makefile_generation_time") - float makefileGenerationTime; - } - - @JsonProperty(value = "int") - private IntFields intFields; - - @JsonProperty(value = "float") - private FloatFields floatFields; - - private static InferStats parseInferStatsFromJson(Reader reader) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - InferStats user = mapper.readValue(reader, InferStats.class); - return user; - } - - public static InferStats loadInferStats(Class currentClass, String sourceDir) throws IOException { - BufferedReader reader = - new BufferedReader( - new InputStreamReader( - currentClass.getResourceAsStream(sourceDir + "stats.json"))); - return parseInferStatsFromJson(reader); - } - - public int getNumFiles() { - return intFields.numFiles; - } - - public int getNumProcedures() { - return intFields.numProcedures; - } - - public int getNumLines() { - return intFields.numLines; - } - - public float getReportingTime() { - return floatFields.reportingTime; - } - - public float getCaptureTime() { - return floatFields.captureTime; - } - - public float getAnalysisTime() { - return floatFields.analysisTime; - } - - public float getMakefileGenerationTime() { - return floatFields.makefileGenerationTime; - } - -} diff --git a/infer/tests/utils/Language.java b/infer/tests/utils/Language.java deleted file mode 100644 index 2a8139548..000000000 --- a/infer/tests/utils/Language.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2013 - 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 utils; - -public enum Language { - Java, C, ObjC, CPP, ObjCPP -} diff --git a/infer/tests/utils/TestType.java b/infer/tests/utils/TestType.java deleted file mode 100644 index ac62c9876..000000000 --- a/infer/tests/utils/TestType.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2013 - 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 utils; - -public enum TestType { - END_TO_END, FRONTEND; -} diff --git a/infer/tests/utils/matchers/DotFilesEqual.java b/infer/tests/utils/matchers/DotFilesEqual.java deleted file mode 100644 index c9031650c..000000000 --- a/infer/tests/utils/matchers/DotFilesEqual.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStreamReader; -import java.util.Map; - -public class DotFilesEqual extends BaseMatcher { - - String dotFile; - - public DotFilesEqual(String dotFile) { - this.dotFile = dotFile; - } - - private StringBuilder diffOutput = new StringBuilder(); - private String diffCommand = ""; - - @Override - public boolean matches(Object o) { - File newDotFile = (File) o; - Map env = System.getenv(); - if (env.get("INFER_DOT_REPLACE") != null) { - diffCommand = "cp " + newDotFile.getAbsolutePath() + " " + dotFile; - } else { - diffCommand = "diff -u " + dotFile + " " + newDotFile.getAbsolutePath(); - } - Process diff_process = null; - try { - diff_process = Runtime.getRuntime().exec(diffCommand); - try (BufferedReader inputReader = - new BufferedReader(new InputStreamReader(diff_process.getInputStream())); - BufferedReader errorReader = - new BufferedReader(new InputStreamReader(diff_process.getErrorStream()))) { - - String line = inputReader.readLine(); - while (line != null) { - diffOutput = diffOutput.append(line + "\n"); - line = inputReader.readLine(); - } - String errorLine = errorReader.readLine(); - while (errorLine != null) { - diffOutput = diffOutput.append(errorLine + "\n"); - errorLine = errorReader.readLine(); - } - diff_process.waitFor(); - return "".equals(diffOutput.toString()); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } catch (Exception e) { - e.printStackTrace(); - return false; - } finally { - if (diff_process != null) diff_process.destroy(); - } - } - - @Override - public void describeTo(Description description) { - description.appendText("Dot file equal to " + dotFile); - } - - @Override - public void describeMismatch(Object item, Description description) { - String outputDesc = "The command:\n\n " + diffCommand - + "\n\nfailed with output:\n" + diffOutput.toString() + "\n"; - description.appendText(outputDesc); - } - - public static Matcher dotFileEqualTo(String dotFile) { - return new DotFilesEqual(dotFile); - } - -} diff --git a/infer/tests/utils/matchers/ErrorPattern.java b/infer/tests/utils/matchers/ErrorPattern.java deleted file mode 100644 index ef7884a5c..000000000 --- a/infer/tests/utils/matchers/ErrorPattern.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 utils.matchers; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import utils.InferError; - -public class ErrorPattern { - - private final String errorType; - - private final Path errorFile; - - private final String errorMethod; - - public ErrorPattern(String type, String file, String method) { - errorType = type; - errorFile = Paths.get(file); - errorMethod = method; - } - - String getErrorType() { - return errorType; - } - - Path getErrorFile() { - return errorFile; - } - - String getErrorMethod() { - return errorMethod; - } - - public boolean match(InferError error) { - return error.matchType(errorType) - && error.matchMethod(errorMethod) - && error.matchFile(errorFile); - } - - public static List createPatterns(String type, String file, String[] methods) { - List patterns = new ArrayList<>(); - for (String method : methods) { - patterns.add(new ErrorPattern(type, file, method)); - } - return patterns; - } - - @Override - public String toString() { - return getErrorType() + " in file: " + getErrorFile() + ", method: " + getErrorMethod(); - } - -} diff --git a/infer/tests/utils/matchers/NumberOfFilesAnalyzed.java b/infer/tests/utils/matchers/NumberOfFilesAnalyzed.java deleted file mode 100644 index 8a4df5c6f..000000000 --- a/infer/tests/utils/matchers/NumberOfFilesAnalyzed.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import utils.InferError; -import utils.InferStats; - -public class NumberOfFilesAnalyzed extends BaseMatcher { - - private int expectedNumFiles; - private int actualNumFiles; - - public NumberOfFilesAnalyzed(int expectedNumFiles) { - this.expectedNumFiles = expectedNumFiles; - this.actualNumFiles = -1; - } - - @Override - public boolean matches(Object o) { - InferStats stats = (InferStats) o; - actualNumFiles = stats.getNumFiles(); - return actualNumFiles == expectedNumFiles; - } - - @Override - public void describeTo(Description description) { - description.appendText(expectedNumFiles + " files analyzed by Infer."); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferStats stats = (InferStats) item; - description.appendText("found " + actualNumFiles + " files analyzed by Infer."); - } - - public static Matcher numberOfFilesAnalyzed( - int expectedNumFiles) { - return new NumberOfFilesAnalyzed(expectedNumFiles); - } - -} diff --git a/infer/tests/utils/matchers/NumberOfProceduresAnalyzed.java b/infer/tests/utils/matchers/NumberOfProceduresAnalyzed.java deleted file mode 100644 index 058d513c4..000000000 --- a/infer/tests/utils/matchers/NumberOfProceduresAnalyzed.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import utils.InferError; -import utils.InferStats; - -public class NumberOfProceduresAnalyzed extends BaseMatcher { - - private int expectedNumProcedures; - private int actualNumProcedures; - - public NumberOfProceduresAnalyzed(int expectedNumProcedures) { - this.expectedNumProcedures = expectedNumProcedures; - this.actualNumProcedures = -1; - } - - @Override - public boolean matches(Object o) { - InferStats stats = (InferStats) o; - actualNumProcedures = stats.getNumProcedures(); - return actualNumProcedures == expectedNumProcedures; - } - - @Override - public void describeTo(Description description) { - description.appendText(expectedNumProcedures + " procedures analyzed by Infer."); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferStats stats = (InferStats) item; - description.appendText("found " + actualNumProcedures + " procedures analyzed by Infer."); - } - - public static Matcher numberOfProceduresAnalyzed( - int expectedNumProcedures) { - return new NumberOfProceduresAnalyzed(expectedNumProcedures); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsErrorInMethod.java b/infer/tests/utils/matchers/ResultContainsErrorInMethod.java deleted file mode 100644 index 31ed98296..000000000 --- a/infer/tests/utils/matchers/ResultContainsErrorInMethod.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import java.nio.file.Path; -import java.nio.file.Paths; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsErrorInMethod extends BaseMatcher { - - private String errorType; - private Path errorFile; - private String errorMethod; - - public ResultContainsErrorInMethod(String type, String file, String method) { - this.errorType = type; - this.errorFile = Paths.get(file); - this.errorMethod = method; - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (InferError foundError : results.getErrors()) { - if (foundError.matchType(this.errorType) - && foundError.matchMethod(this.errorMethod) - && foundError.matchFile(this.errorFile)) { - return true; - } - } - return false; - } - - @Override - public void describeTo(Description description) { - description.appendText( - this.errorType + " error in file: " + this.errorFile - + ", method: " + this.errorMethod); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - String resultsString = ""; - for (InferError error : results.getErrors()) { - resultsString = resultsString + "\n\t" + error; - } - description.appendText( - "Found errors: \n" + resultsString - + "\nwith:\n" + results.inferCmdToString()); - } - - public static Matcher contains(String type, String file, String method) { - return new ResultContainsErrorInMethod(type, file, method); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsErrorNoFilename.java b/infer/tests/utils/matchers/ResultContainsErrorNoFilename.java deleted file mode 100644 index 9352c02ed..000000000 --- a/infer/tests/utils/matchers/ResultContainsErrorNoFilename.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsErrorNoFilename extends BaseMatcher { - - private String errorType; - private String errorMethod; - - public ResultContainsErrorNoFilename(String type, String method) { - this.errorType = type; - this.errorMethod = method; - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (InferError foundError : results.getErrors()) { - if (foundError.matchType(this.errorType) - && foundError.matchMethod(this.errorMethod)) { - return true; - } - } - return false; - } - - @Override - public void describeTo(Description description) { - description.appendText( - this.errorType + " error in " + this.errorMethod); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - String resultsString = ""; - for (InferError error : results.getErrors()) { - resultsString = resultsString + "\n\t" + error; - } - description.appendText( - "Found errors: \n" + resultsString - + "\nwith:\n" + results.inferCmdToString()); - } - - public static Matcher contains(String type, String method) { - return new ResultContainsErrorNoFilename(type, method); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsExactly.java b/infer/tests/utils/matchers/ResultContainsExactly.java deleted file mode 100644 index 0dc4ce39a..000000000 --- a/infer/tests/utils/matchers/ResultContainsExactly.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import java.util.ArrayList; -import java.util.List; - -import utils.InferResults; - -public class ResultContainsExactly extends BaseMatcher { - - Matcher containsAll; - Matcher containsOnly; - - private ResultContainsExactly(List patterns) { - containsAll = ResultContainsTheseErrors.contains(patterns); - containsOnly = ResultContainsOnlyTheseErrors.containsOnly(patterns); - } - - @Override - public boolean matches(Object o) { - return containsAll.matches(o) && containsOnly.matches(o); - } - - @Override - public void describeTo(Description description) { - containsAll.describeTo(description); - } - - @Override - public void describeMismatch(Object item, Description description) { - if (!containsAll.matches(item)) { - containsAll.describeMismatch(item, description); - } - if (!containsOnly.matches(item)) { - containsOnly.describeMismatch(item, description); - } - } - - public static Matcher containsExactly(List patterns) { - return new ResultContainsExactly(patterns); - } - - public static Matcher containsExactly( - String type, - String file, - String[] methods) { - ArrayList patterns = new ArrayList<>(); - for (String method : methods) { - patterns.add(new ErrorPattern(type, file, method)); - } - return new ResultContainsExactly(patterns); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsLineNumbers.java b/infer/tests/utils/matchers/ResultContainsLineNumbers.java deleted file mode 100644 index a6df40f55..000000000 --- a/infer/tests/utils/matchers/ResultContainsLineNumbers.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 utils.matchers; - -import com.google.common.base.Optional; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import java.util.Arrays; -import java.util.Vector; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsLineNumbers extends BaseMatcher { - - private int[] lines; - private boolean strict; - private Optional bugType; - - public ResultContainsLineNumbers( - int[] lines, - boolean strict, - Optional bugType) { - this.lines = lines; - this.strict = strict; - this.bugType = bugType; - } - - @Override - public boolean matches(Object o) { - Vector errors = ((InferResults) o).getErrors(); - if (strict && lines.length != errors.size()) { - return false; - } - boolean allContained = true; - for (int line : lines) { - boolean isContained = false; - for (InferError error : errors) { - String bugType = this.bugType.or(error.getErrorType()); - boolean isSameErrType = bugType.equals(error.getErrorType()); - isContained = isContained || (line == error.getErrorLine() && isSameErrType); - } - allContained = allContained && isContained; - } - return allContained; - } - - @Override - public void describeTo(Description description) { - description.appendText("Correct line numbers in the error report."); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - String linesString = Arrays.toString(lines); - String reportedLinesString = Arrays.toString(findLineNumbersInReport(results)); - description.appendText( - "Infer did not report an error in the following lines: " + linesString + - ". \n \t Reported lines are: " + reportedLinesString + - "\n" + results.inferCmdToString()); - } - - public static Matcher containsLines(int[] lines) { - return new ResultContainsLineNumbers(lines, false, Optional.absent()); - } - - public static Matcher containsOnlyLines(int[] lines) { - return new ResultContainsLineNumbers(lines, true, Optional.absent()); - } - - public static Matcher containsLinesOfError(int[] lines, String bugType) { - return new ResultContainsLineNumbers(lines, false, Optional.of(bugType)); - } - - public static Matcher containsOnlyLinesOfError(int[] lines, String bugType) { - return new ResultContainsLineNumbers(lines, true, Optional.of(bugType)); - } - - private int[] findLineNumbersInReport(InferResults results) { - Vector errors = results.getErrors(); - int nErrors = errors.size(); - int[] lines = new int[nErrors]; - for (int i = 0; i < nErrors; i++) { - lines[i] = errors.get(i).getErrorLine(); - } - return lines; - } -} diff --git a/infer/tests/utils/matchers/ResultContainsNoErrorInMethod.java b/infer/tests/utils/matchers/ResultContainsNoErrorInMethod.java deleted file mode 100644 index 050d3a1e6..000000000 --- a/infer/tests/utils/matchers/ResultContainsNoErrorInMethod.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsNoErrorInMethod extends BaseMatcher { - - ErrorPattern pattern; - - public ResultContainsNoErrorInMethod(String type, String file, String method) { - pattern = new ErrorPattern(type, file, method); - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (InferError foundError : results.getErrors()) { - if (pattern.match(foundError)) { - return false; - } - } - return true; - } - - @Override - public void describeTo(Description description) { - description.appendText( - "No " + pattern.getErrorType() + " error in " + pattern.getErrorMethod()); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - description.appendText( - pattern.getErrorType() + " error found in " + - pattern.getErrorMethod() + " in the results of Infer.\n" + - results.inferCmdToString()); - } - - public static Matcher doesNotContain(String type, String file, String method) { - return new ResultContainsNoErrorInMethod(type, file, method); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsNumberOfErrorsInMethod.java b/infer/tests/utils/matchers/ResultContainsNumberOfErrorsInMethod.java deleted file mode 100644 index 480eda851..000000000 --- a/infer/tests/utils/matchers/ResultContainsNumberOfErrorsInMethod.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsNumberOfErrorsInMethod extends BaseMatcher { - - private final ErrorPattern pattern; - private final int numberOfErrors; - int actualNumberErrors; - - public ResultContainsNumberOfErrorsInMethod( - String type, - String file, - String method, - int numberOfErrors) { - this.pattern = new ErrorPattern(type, file, method); - this.numberOfErrors = numberOfErrors; - this.actualNumberErrors = 0; - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (InferError error : results.getErrors()) { - if (pattern.match(error)) { - actualNumberErrors++; - } - } - return (actualNumberErrors == numberOfErrors); - } - - @Override - public void describeTo(Description description) { - description.appendText( - numberOfErrors + " " + pattern.getErrorType() - + " errors in file: " + pattern.getErrorFile() - + ", method: " + pattern.getErrorMethod()); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - description.appendText( - actualNumberErrors + " " + pattern.getErrorType() + - " errors found in " + pattern.getErrorMethod() + " in the results of Infer." + - "\n" + results.inferCmdToString()); - } - - public static Matcher containsNumberOfErrors( - String type, - String file, - String method, - int numberOfErrors) { - return new ResultContainsNumberOfErrorsInMethod(type, file, method, numberOfErrors); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsOnlyTheseErrors.java b/infer/tests/utils/matchers/ResultContainsOnlyTheseErrors.java deleted file mode 100644 index 2d0737e09..000000000 --- a/infer/tests/utils/matchers/ResultContainsOnlyTheseErrors.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import java.util.ArrayList; -import java.util.List; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsOnlyTheseErrors extends BaseMatcher { - - private List patterns; - - public ResultContainsOnlyTheseErrors(List patterns) { - this.patterns = patterns; - } - - private boolean mathTypeAndAnyMethod(InferError e) { - for (ErrorPattern pattern : patterns) { - if (pattern.match(e)) { - return true; - } - } - return false; - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (InferError error : results.getErrors()) { - if (!mathTypeAndAnyMethod(error)) { - return false; - } - } - return true; - } - - @Override - public void describeTo(Description description) { - String errorsString = ""; - for (ErrorPattern pattern : patterns) { - errorsString = - errorsString + "\t" + pattern.toString() + "\n"; - } - description.appendText("Only these errors: \n" + errorsString); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - String unexpectedErrors = ""; - - for (InferError error : results.getErrors()) { - if (!mathTypeAndAnyMethod(error)) { - unexpectedErrors = unexpectedErrors + "\t" + error + "\n"; - } - } - description.appendText( - "Infer reported the following unexpected errors: \n" + - unexpectedErrors + "\n" + results.inferCmdToString()); - } - - public static Matcher containsOnly(String type, String file, String[] methods) { - ArrayList patterns = new ArrayList<>(); - for (String method : methods) { - patterns.add(new ErrorPattern(type, file, method)); - } - return new ResultContainsOnlyTheseErrors(patterns); - } - - public static Matcher containsOnly(List patterns) { - return new ResultContainsOnlyTheseErrors(patterns); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsTheseErrors.java b/infer/tests/utils/matchers/ResultContainsTheseErrors.java deleted file mode 100644 index 5eae2af14..000000000 --- a/infer/tests/utils/matchers/ResultContainsTheseErrors.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import java.util.ArrayList; -import java.util.List; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsTheseErrors extends BaseMatcher { - - private List patterns; - - private ResultContainsTheseErrors(List patterns) { - this.patterns = patterns; - } - - private boolean patternFound(ErrorPattern pattern, InferResults results) { - for (InferError error : results.getErrors()) { - if (pattern.match(error)) { - return true; - } - } - return false; - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (ErrorPattern pattern : patterns) { - if (!patternFound(pattern, results)) { - return false; - } - } - return true; - } - - @Override - public void describeTo(Description description) { - String errorsString = ""; - for (ErrorPattern pattern : patterns) { - errorsString += "\t" + pattern.toString() + "\n"; - } - description.appendText("Expecting these errors: \n" + errorsString); - } - - @Override - public void describeMismatch(Object item, Description description) { - - InferResults results = (InferResults) item; - String expectedErrors = ""; - - for (ErrorPattern pattern : patterns) { - if (!patternFound(pattern, results)) { - expectedErrors += "\t" + pattern.toString() + "\n"; - } - } - description.appendText( - "The following errors were not reported: \n" + expectedErrors + "\n" + "but found: " + - results.toString() + "\n"); - } - - public static Matcher contains(List patterns) { - return new ResultContainsTheseErrors(patterns); - } - - public static Matcher contains(String type, String file, String[] methods) { - ArrayList patterns = new ArrayList<>(); - for (String method : methods) { - patterns.add(new ErrorPattern(type, file, method)); - } - return new ResultContainsTheseErrors(patterns); - } - -} diff --git a/infer/tests/utils/matchers/ResultContainsZeroErrorsInMethod.java b/infer/tests/utils/matchers/ResultContainsZeroErrorsInMethod.java deleted file mode 100644 index 7148f5c94..000000000 --- a/infer/tests/utils/matchers/ResultContainsZeroErrorsInMethod.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 utils.matchers; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -import utils.InferError; -import utils.InferResults; - -public class ResultContainsZeroErrorsInMethod extends BaseMatcher { - - String fileName; - String methodName; - int actualNumberErrors; - - public ResultContainsZeroErrorsInMethod(String fileName, String methodName) { - this.fileName = fileName; - this.methodName = methodName; - } - - @Override - public boolean matches(Object o) { - InferResults results = (InferResults) o; - for (InferError error : results.getErrors()) { - if (fileName.equals(error.getErrorFile()) && - methodName.equals(error.getErrorMethod())) { - actualNumberErrors++; - } - } - return actualNumberErrors == 0; - } - - @Override - public void describeTo(Description description) { - description.appendText(actualNumberErrors + " errors found in method." + methodName); - } - - @Override - public void describeMismatch(Object item, Description description) { - InferResults results = (InferResults) item; - description.appendText( - actualNumberErrors + " errors found in " + methodName + - " in the results of Infer, but expected 0." + "\n" + results.inferCmdToString()); - } - - public static Matcher containsZeroErrors(String fileName, String methodName) { - return new ResultContainsZeroErrorsInMethod(fileName, methodName); - } - -}