From b4bd78bb05f7957f7536cca9f7e32b246a8522cb Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 15 Dec 2016 09:04:15 -0800 Subject: [PATCH] [tests] convert utf8 in pwd test to Makefile Reviewed By: jberdine Differential Revision: D4329658 fbshipit-source-id: f9231cc --- .gitignore | 1 + Makefile | 2 +- .../build_systems/build_integration_tests.py | 94 --------------- .../codetoanalyze/utf8_in_pwd/Hello.java | 15 --- .../codetoanalyze/utf8_in_pwd/cmake | 1 - .../codetoanalyze/utf8_in_pwd/gradle | 1 - .../codetoanalyze/utf8_in_pwd/make | 1 - .../utf8_in_pwd_cmake_report.json | 7 -- .../utf8_in_pwd_gradle_report.json | 17 --- .../utf8_in_pwd_javac_report.json | 7 -- .../utf8_in_pwd_make_report.json | 7 -- .../tests/build_systems/utf8_in_pwd/Makefile | 109 ++++++++++++++++++ .../build_systems/utf8_in_pwd/issues.exp | 6 + 13 files changed, 117 insertions(+), 151 deletions(-) delete mode 100644 infer/tests/build_systems/codetoanalyze/utf8_in_pwd/Hello.java delete mode 120000 infer/tests/build_systems/codetoanalyze/utf8_in_pwd/cmake delete mode 120000 infer/tests/build_systems/codetoanalyze/utf8_in_pwd/gradle delete mode 120000 infer/tests/build_systems/codetoanalyze/utf8_in_pwd/make delete mode 100644 infer/tests/build_systems/expected_outputs/utf8_in_pwd_cmake_report.json delete mode 100644 infer/tests/build_systems/expected_outputs/utf8_in_pwd_gradle_report.json delete mode 100644 infer/tests/build_systems/expected_outputs/utf8_in_pwd_javac_report.json delete mode 100644 infer/tests/build_systems/expected_outputs/utf8_in_pwd_make_report.json create mode 100644 infer/tests/build_systems/utf8_in_pwd/Makefile create mode 100644 infer/tests/build_systems/utf8_in_pwd/issues.exp diff --git a/.gitignore b/.gitignore index 571d0c853..2ee2db21c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ duplicates.txt *.ast.biniou /infer/tests/build_systems/codetoanalyze/ndk-build/hello_app/libs/ /infer/tests/build_systems/codetoanalyze/ndk-build/hello_app/obj/ +/infer/tests/build_systems/codetoanalyze/utf8_*n_pwd # generated by oUnit /oUnit-all.cache diff --git a/Makefile b/Makefile index ef7cb2a44..226e88aaf 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif BUILD_SYSTEMS_TESTS = \ assembly ck_analytics ck_imports clang_multiple_files clang_translation clang_unknown_ext \ delete_results_dir fail_on_issue gradle javac linters make project_root_rel reactive \ - utf8_in_procname + utf8_in_procname utf8_in_pwd ifneq ($(ANT),no) BUILD_SYSTEMS_TESTS += ant endif diff --git a/infer/tests/build_systems/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py index 8db324cc0..95e59a70a 100755 --- a/infer/tests/build_systems/build_integration_tests.py +++ b/infer/tests/build_systems/build_integration_tests.py @@ -61,7 +61,6 @@ CODETOANALYZE_DIR = os.path.join(SCRIPT_DIR, 'codetoanalyze') EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs') ALL_TESTS = [ - 'utf8_in_pwd', 'waf', ] @@ -308,105 +307,12 @@ def test(name, class BuildIntegrationTest(unittest.TestCase): - def _test_javac_integration( - self, - enabled=None, - root=os.path.join(ROOT_DIR, 'examples'), - report_fname='javac_report.json'): - test('javac', 'javac', - root, - [{'compile': ['javac', 'Hello.java']}], - enabled=enabled, - report_fname=report_fname) - - def _test_gradle_integration( - self, - enabled=None, - root=os.path.join(ROOT_DIR, 'examples', 'java_hello'), - report_fname='gradle_report.json'): - env = os.environ.copy() - env['PATH'] = '{}:{}'.format( - os.path.join(SCRIPT_DIR, 'mock'), - os.getenv('PATH'), - ) - test('gradle', 'Gradle', - root, - [{'compile': ['gradle', 'build']}], - enabled=enabled, - report_fname=report_fname, - env=env) - - def _test_make_integration( - self, - enabled=None, - root=os.path.join(CODETOANALYZE_DIR, 'make'), - report_fname='make_report.json'): - test('make', 'make', - root, - [{'compile': ['make', 'all']}], - clean_commands=[['make', 'clean']], - enabled=enabled, - report_fname=report_fname) - def test_waf_integration(self): test('waf', 'waf', os.path.join(CODETOANALYZE_DIR, 'make'), [{'compile': ['./waf', 'build']}], clean_commands=[['make', 'clean']]) - def _test_cmake_integration( - self, - enabled=None, - root=os.path.join(CODETOANALYZE_DIR, 'cmake'), - report_fname='cmake_report.json'): - build_root = os.path.join(root, 'build') - if test('cmake', 'CMake', - build_root, - [{'compile': ['cmake', '..']}, - {'compile': ['make', 'clean', 'all']}], - available=lambda: is_tool_available(['cmake', '--version']), - enabled=enabled, - report_fname=report_fname, - # remove build/ directory just in case - preprocess=lambda: shutil.rmtree(build_root, True), - # cmake produces absolute paths using the real path - postprocess=(lambda errors: - make_paths_relative_in_report( - os.path.realpath(root), errors))): - # remove build/ directory - shutil.rmtree(build_root) - - def test_utf8_in_pwd_integration(self): - if not 'utf8_in_pwd' in to_test: - print('\nSkipping utf8_in_pwd integration test') - return - print('\nRunning utf8_in_pwd integration test') - - utf8_in_pwd_path = os.path.join(CODETOANALYZE_DIR, u'utf8_\u03B9n_pwd') - - # copy non-unicode dir to one with unicode in it - shutil.rmtree(utf8_in_pwd_path, True) # remove just in case - shutil.copytree(os.path.join(CODETOANALYZE_DIR, 'utf8_in_pwd'), - utf8_in_pwd_path) - - self._test_cmake_integration( - enabled=True, - root=os.path.join(utf8_in_pwd_path, 'cmake'), - report_fname='utf8_in_pwd_cmake_report.json') - self._test_gradle_integration( - enabled=True, - root=os.path.join(utf8_in_pwd_path, 'gradle'), - report_fname='utf8_in_pwd_gradle_report.json') - self._test_javac_integration( - enabled=True, - root=os.path.join(utf8_in_pwd_path), - report_fname='utf8_in_pwd_javac_report.json') - self._test_make_integration( - enabled=True, - root=os.path.join(utf8_in_pwd_path, 'make'), - report_fname='utf8_in_pwd_make_report.json') - shutil.rmtree(utf8_in_pwd_path, True) # remove copied dir - if __name__ == '__main__': # hackish capturing of the arguments after '--' diff --git a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/Hello.java b/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/Hello.java deleted file mode 100644 index fdb567e99..000000000 --- a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/Hello.java +++ /dev/null @@ -1,15 +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. - */ - -class Hello { - int test() { - String s = null; - return s.length(); - } -} diff --git a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/cmake b/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/cmake deleted file mode 120000 index 8e8a460f7..000000000 --- a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/cmake +++ /dev/null @@ -1 +0,0 @@ -../cmake/ \ No newline at end of file diff --git a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/gradle b/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/gradle deleted file mode 120000 index 5530a6853..000000000 --- a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/gradle +++ /dev/null @@ -1 +0,0 @@ -../../../../../examples/java_hello/ \ No newline at end of file diff --git a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/make b/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/make deleted file mode 120000 index b74302805..000000000 --- a/infer/tests/build_systems/codetoanalyze/utf8_in_pwd/make +++ /dev/null @@ -1 +0,0 @@ -../make/ \ No newline at end of file diff --git a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_cmake_report.json b/infer/tests/build_systems/expected_outputs/utf8_in_pwd_cmake_report.json deleted file mode 100644 index a6ed10eff..000000000 --- a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_cmake_report.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "bug_type": "NULL_DEREFERENCE", - "file": "hello.c", - "procedure": "test" - } -] \ No newline at end of file diff --git a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_gradle_report.json b/infer/tests/build_systems/expected_outputs/utf8_in_pwd_gradle_report.json deleted file mode 100644 index b3f642cea..000000000 --- a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_gradle_report.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "bug_type": "NULL_DEREFERENCE", - "file": "Hello.java", - "procedure": "void Hello.mayCauseNPE()" - }, - { - "bug_type": "RESOURCE_LEAK", - "file": "Hello.java", - "procedure": "void Hello.mayLeakResource()" - }, - { - "bug_type": "RESOURCE_LEAK", - "file": "Hello.java", - "procedure": "void Hello.twoResources()" - } -] \ No newline at end of file diff --git a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_javac_report.json b/infer/tests/build_systems/expected_outputs/utf8_in_pwd_javac_report.json deleted file mode 100644 index 32cd14214..000000000 --- a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_javac_report.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "bug_type": "NULL_DEREFERENCE", - "file": "Hello.java", - "procedure": "int Hello.test()" - } -] \ No newline at end of file diff --git a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_make_report.json b/infer/tests/build_systems/expected_outputs/utf8_in_pwd_make_report.json deleted file mode 100644 index b43a81460..000000000 --- a/infer/tests/build_systems/expected_outputs/utf8_in_pwd_make_report.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "bug_type": "NULL_DEREFERENCE", - "file": "utf8_in_function_names.c", - "procedure": "test_\uc131\uacf5" - } -] \ No newline at end of file diff --git a/infer/tests/build_systems/utf8_in_pwd/Makefile b/infer/tests/build_systems/utf8_in_pwd/Makefile new file mode 100644 index 000000000..992e932d6 --- /dev/null +++ b/infer/tests/build_systems/utf8_in_pwd/Makefile @@ -0,0 +1,109 @@ +# 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. + +# This is mostly a copy-paste-adapt of other integration tests with the twist that the code to +# analyze in placed in a path that contains utf8 characters. This does not provide a 'compile' +# or 'analyze' target. + +TESTS_DIR = ../.. +ROOT_DIR = $(TESTS_DIR)/../.. + +include $(TESTS_DIR)/java.make +include $(ROOT_DIR)/Makefile.config + +UTF8_DIR = $(shell printf '../codetoanalyze/utf8_\u03B9n_pwd') + +CMAKE_DIR = $(UTF8_DIR)/cmake +CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build +CMAKE_ANALYZE_DIR = $(CMAKE_DIR)/_build_infer +CMAKE_SOURCES_DIR = ../codetoanalyze/cmake +CMAKE_SOURCES = $(CMAKE_SOURCES_DIR)/hello.c + +GRADLE_DIR = $(UTF8_DIR)/gradle +GRADLE_SOURCES_DIR = $(ROOT_DIR)/examples/java_hello +GRADLE_SOURCES = $(wildcard $(GRADLE_SOURCES_DIR)/*.java) + +JAVAC_DIR = $(UTF8_DIR)/javac +JAVAC_SOURCES = $(ROOT_DIR)/examples/Hello.java + +MAKE_DIR = $(UTF8_DIR)/make +MAKE_SOURCES_DIR = ../codetoanalyze/make +MAKE_SOURCES = $(wildcard $(MAKE_SOURCES_DIR)/*.c) + +ANALYZER = infer +CLEAN_EXTRA = $(CMAKE_BUILD_DIR) $(CMAKE_ANALYZE_DIR) infer-out-cmake +INFERPRINT_OPTIONS = --issues-tests + +default: print + +$(UTF8_DIR): + $(MKDIR_P) $@ + +$(CMAKE_DIR): $(CMAKE_SOURCES) $(UTF8_DIR) + rsync -aL $(CMAKE_SOURCES_DIR)/ $@/ + touch $@ + +$(GRADLE_DIR): $(GRADLE_SOURCES) $(UTF8_DIR) + rsync -a $(GRADLE_SOURCES_DIR)/ $@/ + touch $@ + +$(JAVAC_DIR): $(JAVAC_SOURCES) $(UTF8_DIR) + $(MKDIR_P) $(JAVAC_DIR) + rsync -a $(JAVAC_SOURCES) $@ + touch $@ + +$(MAKE_DIR): $(MAKE_SOURCES) $(UTF8_DIR) + rsync -a $(MAKE_SOURCES_DIR)/ $@/ + touch $@ + +infer-out-cmake/report.json: $(CMAKE_DIR) $(CMAKE_SOURCES_DIR)/CMakeLists.txt $(CLANG_DEPS) + $(REMOVE_DIR) $(CMAKE_ANALYZE_DIR) && \ + $(MKDIR_P) $(CMAKE_ANALYZE_DIR) && \ + cd $(CMAKE_ANALYZE_DIR) && \ + $(call silent_on_success,\ + $(INFER_BIN) -a compile --project-root $(CMAKE_DIR) --results-dir $(CURDIR)/$(@D) -- cmake ..) + cd $(CMAKE_ANALYZE_DIR) && \ + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) --results-dir $(CURDIR)/$(@D) -- $(MAKE)) + sed -i -e 's#$(abspath $(CMAKE_DIR))/##g' $@ + +infer-out-gradle/report.json: $(JAVA_DEPS) $(GRADLE_DIR) +# mock version of gradle + PATH=$(CURDIR)/../mock:"$$PATH"; \ + cd $(GRADLE_DIR) && \ + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) --results-dir $(CURDIR)/$(@D) -- gradle build) + +infer-out-javac/report.json: $(JAVA_DEPS) $(JAVAC_DIR) + cd $(JAVAC_DIR) && \ + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) --results-dir $(CURDIR)/$(@D) -- \ + javac -cp $(CLASSPATH) $(foreach source,$(JAVAC_SOURCES),$(notdir $(source)))) + +infer-out-make/report.json: $(CLANG_DEPS) $(MAKE_DIR) + cd $(MAKE_DIR) && \ + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) --results-dir $(CURDIR)/$(@D) -- \ + make clean all) + +issues-%.exp.test.noreplace: infer-out-%/report.json $(INFERPRINT_BIN) + $(INFERPRINT_BIN) -q -a $(ANALYZER) $(INFERPRINT_OPTIONS) $@ --from-json-report $< + +issues.exp.test: issues-cmake.exp.test.noreplace issues-gradle.exp.test.noreplace \ + issues-javac.exp.test.noreplace issues-make.exp.test.noreplace + cat $^ > $@ + +.PHONY: print +print: issues.exp.test + +.PHONY: test +test: issues.exp.test + diff -u issues.exp issues.exp.test + +.PHONY: clean +clean: + rm -rf $(UTF8_DIR) issues.exp.test* infer-out-* diff --git a/infer/tests/build_systems/utf8_in_pwd/issues.exp b/infer/tests/build_systems/utf8_in_pwd/issues.exp new file mode 100644 index 000000000..69ed2eeef --- /dev/null +++ b/infer/tests/build_systems/utf8_in_pwd/issues.exp @@ -0,0 +1,6 @@ +hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()] +Hello.java, void Hello.mayCauseNPE(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE(),start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)] +Hello.java, void Hello.mayLeakResource(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource(),start of procedure allocateResource(),return from a call to FileOutputStream Resources.allocateResource(),Taking false branch] +Hello.java, void Hello.twoResources(), 11, RESOURCE_LEAK, [start of procedure twoResources(),exception java.io.IOException,Switch condition is true. Entering switch case,Taking true branch,exception java.io.IOException] +Hello.java, int Hello.test(), 2, NULL_DEREFERENCE, [start of procedure test()] +utf8_in_function_names.c, test_성공, 2, NULL_DEREFERENCE, [start of procedure test_성공()]