From c613820a985d0305926b01933bd8cf35db1b4346 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 7 Sep 2016 09:11:38 -0700 Subject: [PATCH] Convert c tests to the new testing format Reviewed By: jberdine, sblackshear Differential Revision: D3827953 fbshipit-source-id: 53a47df --- .buckconfig | 3 - Makefile | 5 +- infer/tests/BUCK | 1 - infer/tests/codetoanalyze/Makefile.clang | 25 ++++++ infer/tests/codetoanalyze/c/errors/BUCK | 28 ------- infer/tests/codetoanalyze/c/errors/Makefile | 42 ++++------ .../c/errors/arithmetic/Makefile | 1 - .../c/errors/assertions/Makefile | 1 - .../c/errors/assertions/assert_example.c | 1 + .../c/errors/attributes/Makefile | 12 --- .../c/errors/custom_error/Makefile | 1 - .../c/errors/dangling_deref/Makefile | 12 --- .../c/errors/enumeration/other_enum.c | 1 + .../c/errors/initialization/Makefile | 1 - infer/tests/codetoanalyze/c/errors/issues.exp | 82 +++++++++++++++++++ .../codetoanalyze/c/errors/lists/Makefile | 12 --- .../codetoanalyze/c/errors/lists/lists.c | 2 +- .../c/errors/local_vars/Makefile | 1 - .../c/errors/memory_leaks/Makefile | 1 - .../c/errors/null_dereference/Makefile | 1 - .../null_pointer_dereference.c | 2 +- .../c/errors/offsetof_expr/offsetof_expr.c | 1 + .../c/errors/resource_leaks/Makefile | 1 - .../c/errors/vaarg_expr/vaarg_expr.c | 1 + .../c/frontend/assertions/assert_example.c | 2 +- .../c/frontend/enumeration/other_enum.c | 4 +- .../c/frontend/enumeration/other_enum.c.dot | 8 +- .../c/frontend/offsetof_expr/offsetof_expr.c | 2 +- .../offsetof_expr/offsetof_expr.c.dot | 4 +- .../c/frontend/vaarg_expr/vaarg_expr.c | 2 +- .../c/frontend/vaarg_expr/vaarg_expr.c.dot | 4 +- infer/tests/codetoanalyze/cpp/errors/Makefile | 21 +---- infer/tests/endtoend/BUCK | 11 --- .../tests/endtoend/c/infer/AngelismTest.java | 62 -------------- .../c/infer/ArrayOfStructsAbductionTest.java | 62 -------------- .../c/infer/ArrayOutOfBoundsTest.java | 56 ------------- .../endtoend/c/infer/AsmAngelismTest.java | 52 ------------ .../c/infer/AssertKeepBranchTest.java | 57 ------------- infer/tests/endtoend/c/infer/AssertTest.java | 58 ------------- .../c/infer/AssertionFailureTest.java | 58 ------------- infer/tests/endtoend/c/infer/BUCK | 16 ---- .../c/infer/CompoundLiteralExprTest.java | 54 ------------ .../endtoend/c/infer/CustomErrorTest.java | 55 ------------- .../c/infer/DanglingDereferenceTest.java | 64 --------------- .../endtoend/c/infer/DivideByZeroTest.java | 53 ------------ infer/tests/endtoend/c/infer/EnumTest.java | 62 -------------- .../endtoend/c/infer/InitListExprTest.java | 54 ------------ infer/tests/endtoend/c/infer/ListsTest.java | 56 ------------- .../tests/endtoend/c/infer/LocalVarsTest.java | 49 ----------- .../endtoend/c/infer/MemoryLeakTest.java | 59 ------------- .../NullDereferenceShortCircuitTest.java | 58 ------------- .../endtoend/c/infer/NullDereferenceTest.java | 75 ----------------- .../c/infer/NullDereferenceTest2.java | 73 ----------------- .../c/infer/NullDereferenceTest3.java | 58 ------------- .../endtoend/c/infer/OffsetOfExprTest.java | 59 ------------- .../endtoend/c/infer/ResourceLeakTest.java | 55 ------------- .../tests/endtoend/c/infer/SentinelTest.java | 52 ------------ .../endtoend/c/infer/UnsafeMallocTest.java | 62 -------------- .../c/infer/UnsignedIsNonnegativeTest.java | 51 ------------ .../tests/endtoend/c/infer/VAArgExprTest.java | 59 ------------- 60 files changed, 150 insertions(+), 1675 deletions(-) create mode 100644 infer/tests/codetoanalyze/Makefile.clang delete mode 100644 infer/tests/codetoanalyze/c/errors/BUCK delete mode 120000 infer/tests/codetoanalyze/c/errors/arithmetic/Makefile delete mode 120000 infer/tests/codetoanalyze/c/errors/assertions/Makefile create mode 120000 infer/tests/codetoanalyze/c/errors/assertions/assert_example.c delete mode 100644 infer/tests/codetoanalyze/c/errors/attributes/Makefile delete mode 120000 infer/tests/codetoanalyze/c/errors/custom_error/Makefile delete mode 100644 infer/tests/codetoanalyze/c/errors/dangling_deref/Makefile create mode 120000 infer/tests/codetoanalyze/c/errors/enumeration/other_enum.c delete mode 120000 infer/tests/codetoanalyze/c/errors/initialization/Makefile create mode 100644 infer/tests/codetoanalyze/c/errors/issues.exp delete mode 100644 infer/tests/codetoanalyze/c/errors/lists/Makefile delete mode 120000 infer/tests/codetoanalyze/c/errors/local_vars/Makefile delete mode 120000 infer/tests/codetoanalyze/c/errors/memory_leaks/Makefile delete mode 120000 infer/tests/codetoanalyze/c/errors/null_dereference/Makefile create mode 120000 infer/tests/codetoanalyze/c/errors/offsetof_expr/offsetof_expr.c delete mode 120000 infer/tests/codetoanalyze/c/errors/resource_leaks/Makefile create mode 120000 infer/tests/codetoanalyze/c/errors/vaarg_expr/vaarg_expr.c delete mode 100644 infer/tests/endtoend/c/infer/AngelismTest.java delete mode 100644 infer/tests/endtoend/c/infer/ArrayOfStructsAbductionTest.java delete mode 100644 infer/tests/endtoend/c/infer/ArrayOutOfBoundsTest.java delete mode 100644 infer/tests/endtoend/c/infer/AsmAngelismTest.java delete mode 100644 infer/tests/endtoend/c/infer/AssertKeepBranchTest.java delete mode 100644 infer/tests/endtoend/c/infer/AssertTest.java delete mode 100644 infer/tests/endtoend/c/infer/AssertionFailureTest.java delete mode 100644 infer/tests/endtoend/c/infer/BUCK delete mode 100644 infer/tests/endtoend/c/infer/CompoundLiteralExprTest.java delete mode 100644 infer/tests/endtoend/c/infer/CustomErrorTest.java delete mode 100644 infer/tests/endtoend/c/infer/DanglingDereferenceTest.java delete mode 100644 infer/tests/endtoend/c/infer/DivideByZeroTest.java delete mode 100644 infer/tests/endtoend/c/infer/EnumTest.java delete mode 100644 infer/tests/endtoend/c/infer/InitListExprTest.java delete mode 100644 infer/tests/endtoend/c/infer/ListsTest.java delete mode 100644 infer/tests/endtoend/c/infer/LocalVarsTest.java delete mode 100644 infer/tests/endtoend/c/infer/MemoryLeakTest.java delete mode 100644 infer/tests/endtoend/c/infer/NullDereferenceShortCircuitTest.java delete mode 100644 infer/tests/endtoend/c/infer/NullDereferenceTest.java delete mode 100644 infer/tests/endtoend/c/infer/NullDereferenceTest2.java delete mode 100644 infer/tests/endtoend/c/infer/NullDereferenceTest3.java delete mode 100644 infer/tests/endtoend/c/infer/OffsetOfExprTest.java delete mode 100644 infer/tests/endtoend/c/infer/ResourceLeakTest.java delete mode 100644 infer/tests/endtoend/c/infer/SentinelTest.java delete mode 100644 infer/tests/endtoend/c/infer/UnsafeMallocTest.java delete mode 100644 infer/tests/endtoend/c/infer/UnsignedIsNonnegativeTest.java delete mode 100644 infer/tests/endtoend/c/infer/VAArgExprTest.java diff --git a/.buckconfig b/.buckconfig index df24b7af3..b8259b76f 100644 --- a/.buckconfig +++ b/.buckconfig @@ -3,9 +3,6 @@ endtoend_test_objc = //infer/tests/endtoend:objc_endtoend_tests frontend_test_objc = //infer/tests/frontend:objc_frontend_tests - endtoend_test_java = //infer/tests/endtoend:java_endtoend_tests - endtoend_test_c = //infer/tests/endtoend:edgc_endtoend_tests - integration_tests = //infer/tests:integration_tests objc = //infer/tests:objc_tests c = //infer/tests:c_tests diff --git a/Makefile b/Makefile index c8d579c87..6947d64dc 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ DIRECT_TESTS= TARGETS_TO_TEST= ifeq ($(BUILD_C_ANALYZERS),yes) TARGETS_TO_TEST += c cpp -DIRECT_TESTS += cpp_infer_test +DIRECT_TESTS += c_infer_test cpp_infer_test endif ifeq ($(BUILD_JAVA_ANALYZERS),yes) TARGETS_TO_TEST += java @@ -98,6 +98,9 @@ endif ocaml_unit_test: test_this_build $(TEST_BUILD_DIR)/unit/inferunit.byte +c_infer_test: + make -C ./infer/tests/codetoanalyze/c/errors test + cpp_infer_test: make -C ./infer/tests/codetoanalyze/cpp/errors test diff --git a/infer/tests/BUCK b/infer/tests/BUCK index e0b2ccf0c..22ccee2f8 100644 --- a/infer/tests/BUCK +++ b/infer/tests/BUCK @@ -1,7 +1,6 @@ java_test( name='c_tests', deps=[ - '//infer/tests/endtoend:c_endtoend_tests', '//infer/tests/frontend:c_frontend_tests', ], ) diff --git a/infer/tests/codetoanalyze/Makefile.clang b/infer/tests/codetoanalyze/Makefile.clang new file mode 100644 index 000000000..bf6803c16 --- /dev/null +++ b/infer/tests/codetoanalyze/Makefile.clang @@ -0,0 +1,25 @@ +# 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. + +ROOT_DIR = ../../../../.. +include $(ROOT_DIR)/Makefile.config + +ANALYZER = infer + +default: compile + +print: analyze + $(INFERPRINT_BIN) -q -a $(ANALYZER) --issues-tests issues.exp.test + LC_ALL=C sort -t, -k1,1 -k2,2 -k3n,3 -o issues.exp.test issues.exp.test + +test: analyze print + make clean + diff -u issues.exp issues.exp.test + rm issues.exp.test + +clean: + rm -rf *.o infer-out duplicates.txt diff --git a/infer/tests/codetoanalyze/c/errors/BUCK b/infer/tests/codetoanalyze/c/errors/BUCK deleted file mode 100644 index 901c8a3dd..000000000 --- a/infer/tests/codetoanalyze/c/errors/BUCK +++ /dev/null @@ -1,28 +0,0 @@ -sources = glob(['**/*.c']) -sources += glob(['**/Makefile']) - -out = 'out' - -clean_cmd = ' '.join(['rm', '-rf', out]) -env_cmd = ' '.join(['export', 'INFER_REPORT_CUSTOM_ERROR=1']) -infer_cmd = ' '.join([ - 'infer', - '--no-progress-bar', - '--no-filtering', - '-o', 'out', - '--testing_mode', - '--', - 'make' -]) -copy_cmd = ' '.join(['cp', out + '/report.csv', '$OUT']) -command = ' && '.join([clean_cmd, env_cmd, infer_cmd, copy_cmd]) - -genrule( - name = 'analyze', - srcs = sources, - out = 'report.csv', - cmd = command, - visibility = [ - 'PUBLIC', - ], -) diff --git a/infer/tests/codetoanalyze/c/errors/Makefile b/infer/tests/codetoanalyze/c/errors/Makefile index 5987f4b87..903f50f24 100644 --- a/infer/tests/codetoanalyze/c/errors/Makefile +++ b/infer/tests/codetoanalyze/c/errors/Makefile @@ -1,27 +1,21 @@ +# 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. -all: - make -C arithmetic - make -C assertions - make -C attributes - make -C custom_error - make -C initialization - make -C local_vars - make -C null_dereference - make -C resource_leaks - make -C memory_leaks - make -C lists - make -C dangling_deref +include ../../Makefile.clang -clean: - make -C arithmetic clean - make -C assertions clean - make -C custom_error clean - make -C attributes clean - make -C initialization clean - make -C local_vars clean - make -C null_dereference clean - make -C resource_leaks clean - make -C memory_leaks - make -C lists - make -C dangling_deref +OPTIONS = -c +FILES = \ + */*.c \ + +compile: + clang $(OPTIONS) $(FILES) + +analyze: + INFER_REPORT_CUSTOM_ERROR=1 \ + $(INFER_BIN) -a $(ANALYZER) --check-duplicate-symbols --developer-mode -- clang $(OPTIONS) $(FILES) >/dev/null 2>duplicates.txt + grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 diff --git a/infer/tests/codetoanalyze/c/errors/arithmetic/Makefile b/infer/tests/codetoanalyze/c/errors/arithmetic/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/arithmetic/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/assertions/Makefile b/infer/tests/codetoanalyze/c/errors/assertions/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/assertions/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/assertions/assert_example.c b/infer/tests/codetoanalyze/c/errors/assertions/assert_example.c new file mode 120000 index 000000000..a5102a199 --- /dev/null +++ b/infer/tests/codetoanalyze/c/errors/assertions/assert_example.c @@ -0,0 +1 @@ +../../frontend/assertions/assert_example.c \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/attributes/Makefile b/infer/tests/codetoanalyze/c/errors/attributes/Makefile deleted file mode 100644 index ec67ebe4f..000000000 --- a/infer/tests/codetoanalyze/c/errors/attributes/Makefile +++ /dev/null @@ -1,12 +0,0 @@ - -SOURCES = $(shell ls *.c) -OBJECTS = $(SOURCES:.c=.o) - -all: clean $(OBJECTS) - echo $(OBJECTS) - -.c.o: - ${CC} -c $< - -clean: - rm -rf $(OBJECTS) diff --git a/infer/tests/codetoanalyze/c/errors/custom_error/Makefile b/infer/tests/codetoanalyze/c/errors/custom_error/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/custom_error/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/dangling_deref/Makefile b/infer/tests/codetoanalyze/c/errors/dangling_deref/Makefile deleted file mode 100644 index ec67ebe4f..000000000 --- a/infer/tests/codetoanalyze/c/errors/dangling_deref/Makefile +++ /dev/null @@ -1,12 +0,0 @@ - -SOURCES = $(shell ls *.c) -OBJECTS = $(SOURCES:.c=.o) - -all: clean $(OBJECTS) - echo $(OBJECTS) - -.c.o: - ${CC} -c $< - -clean: - rm -rf $(OBJECTS) diff --git a/infer/tests/codetoanalyze/c/errors/enumeration/other_enum.c b/infer/tests/codetoanalyze/c/errors/enumeration/other_enum.c new file mode 120000 index 000000000..680562041 --- /dev/null +++ b/infer/tests/codetoanalyze/c/errors/enumeration/other_enum.c @@ -0,0 +1 @@ +../../frontend/enumeration/other_enum.c \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/initialization/Makefile b/infer/tests/codetoanalyze/c/errors/initialization/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/initialization/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/issues.exp b/infer/tests/codetoanalyze/c/errors/issues.exp new file mode 100644 index 000000000..52847e3fa --- /dev/null +++ b/infer/tests/codetoanalyze/c/errors/issues.exp @@ -0,0 +1,82 @@ +arithmetic/array_out_of_bounds.c, bound_error, 2, ARRAY_OUT_OF_BOUNDS_L1 +arithmetic/array_out_of_bounds.c, bound_error_nested, 2, ARRAY_OUT_OF_BOUNDS_L1 +arithmetic/divide_by_zero.c, arith_divide_by_zero, 3, DIVIDE_BY_ZERO +arithmetic/unsigned_values.c, signed_array, 3, DIVIDE_BY_ZERO +arithmetic/unsigned_values.c, signed_field, 3, DIVIDE_BY_ZERO +arithmetic/unsigned_values.c, signed_int, 3, DIVIDE_BY_ZERO +arithmetic/unsigned_values.c, signed_int_ptr, 3, DIVIDE_BY_ZERO +assertions/assertion_example.c, report_div0_and_no_npe, 2, DIVIDE_BY_ZERO +assertions/assertion_failure.c, assertion_failure_with_heap, 7, ASSERTION_FAILURE +assertions/assertion_failure.c, assignemt_before_check, 3, ASSERTION_FAILURE +assertions/assertion_failure.c, failure_on_both_branches, 6, ASSERTION_FAILURE +assertions/assertion_failure.c, should_report_assertion_failure, 3, ASSERTION_FAILURE +assertions/assertion_failure.c, simple_assertion_failure, 3, ASSERTION_FAILURE +attributes/sentinel.c, truncated_call, 5, PREMATURE_NIL_TERMINATION_ARGUMENT +custom_error/custom.c, paf, 3, UNEXPECTED_NEGATIVE_EXPONENT +custom_error/custom.c, pouf, 3, UNEXPECTED_NEGATIVE_EXPONENT +dangling_deref/dpd.c, dpd, 3, DANGLING_POINTER_DEREFERENCE +dangling_deref/dpd.c, dpd, 3, RETURN_VALUE_IGNORED +dangling_deref/dpd.c, intraprocdpd, 3, DANGLING_POINTER_DEREFERENCE +dangling_deref/dpd.c, nodpd, 2, RETURN_VALUE_IGNORED +dangling_deref/dpd.c, nodpd1, 3, NULL_DEREFERENCE +dangling_deref/dpd.c, nodpd1, 3, RETURN_VALUE_IGNORED +enumeration/other_enum.c, other_enum_test, 4, DIVIDE_BY_ZERO +initialization/compound_literal.c, divide_by_zero, 0, DIVIDE_BY_ZERO +initialization/initlistexpr.c, init_divide_by_zero, 2, Assert_failure +initialization/initlistexpr.c, init_divide_by_zero, 2, DIVIDE_BY_ZERO +lists/lists.c, lists_main, 2, DIVIDE_BY_ZERO +local_vars/local_vars.c, m1, 6, DIVIDE_BY_ZERO +local_vars/local_vars.c, m2, 9, DIVIDE_BY_ZERO +local_vars/local_vars.c, mm, 6, DIVIDE_BY_ZERO +local_vars/local_vars.c, t, 8, DIVIDE_BY_ZERO +memory_leaks/test.c, common_realloc_leak, 3, MEMORY_LEAK +memory_leaks/test.c, conditional_last_instruction, 2, MEMORY_LEAK +memory_leaks/test.c, simple_leak, 2, MEMORY_LEAK +memory_leaks/test.c, uses_allocator, 3, MEMORY_LEAK +null_dereference/angelism.c, bake, 2, NULL_DEREFERENCE +null_dereference/angelism.c, call_by_ref_actual_already_in_footprint_bad, 1, NULL_DEREFERENCE +null_dereference/angelism.c, struct_value_by_ref_callee_write_no_skip, 3, NULL_DEREFERENCE +null_dereference/angelism.c, struct_value_by_ref_callee_write_skip, 4, NULL_DEREFERENCE +null_dereference/angelism.c, struct_value_by_ref_ptr_write, 4, NULL_DEREFERENCE +null_dereference/angelism.c, struct_value_from_pointer_skip_bad, 3, NULL_DEREFERENCE +null_dereference/angelism.c, struct_value_skip_null_deref, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_clearerr, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_feof, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_ferror, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fgetc, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fgetpos, 5, NULL_DEREFERENCE +null_dereference/getc.c, crash_fgets, 5, NULL_DEREFERENCE +null_dereference/getc.c, crash_fileno, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fprintf, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fputc, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fputs, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fseeks, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_fsetpos, 5, NULL_DEREFERENCE +null_dereference/getc.c, crash_ftell, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_getc, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_putc, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_rewind, 4, NULL_DEREFERENCE +null_dereference/getc.c, crash_ungetc, 5, NULL_DEREFERENCE +null_dereference/getc.c, crash_vfprintf, 5, NULL_DEREFERENCE +null_dereference/malloc_no_null_check.c, test_malloc, 2, NULL_DEREFERENCE +null_dereference/memcpy-test.c, testError1, 3, NULL_DEREFERENCE +null_dereference/memcpy-test.c, testError2, 5, NULL_DEREFERENCE +null_dereference/memcpy-test.c, testError3, 4, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, basic_null_dereference, 2, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, function_call_can_return_null_pointer, 3, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, no_check_for_null_after_malloc, 3, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, no_check_for_null_after_realloc, 9, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, null_passed_as_argument, 1, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, null_pointer_interproc, 2, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, null_pointer_with_function_pointer, 4, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, potentially_null_pointer_passed_as_argument, 3, NULL_DEREFERENCE +null_dereference/null_pointer_dereference.c, simple_null_pointer, 2, NULL_DEREFERENCE +null_dereference/short.c, f_error, 2, NULL_DEREFERENCE +null_dereference/short.c, g_error, 2, NULL_DEREFERENCE +null_dereference/short.c, l_error, 2, NULL_DEREFERENCE +offsetof_expr/offsetof_expr.c, test_offsetof_expr, 3, DIVIDE_BY_ZERO +offsetof_expr/offsetof_expr.c, test_offsetof_expr, 5, DIVIDE_BY_ZERO +resource_leaks/leak.c, fileNotClosed, 5, RESOURCE_LEAK +resource_leaks/leak.c, socketNotClosed, 5, RESOURCE_LEAK +vaarg_expr/vaarg_expr.c, vaarg_foo, 6, DIVIDE_BY_ZERO +vaarg_expr/vaarg_expr.c, vaarg_foo, 8, DIVIDE_BY_ZERO diff --git a/infer/tests/codetoanalyze/c/errors/lists/Makefile b/infer/tests/codetoanalyze/c/errors/lists/Makefile deleted file mode 100644 index ec67ebe4f..000000000 --- a/infer/tests/codetoanalyze/c/errors/lists/Makefile +++ /dev/null @@ -1,12 +0,0 @@ - -SOURCES = $(shell ls *.c) -OBJECTS = $(SOURCES:.c=.o) - -all: clean $(OBJECTS) - echo $(OBJECTS) - -.c.o: - ${CC} -c $< - -clean: - rm -rf $(OBJECTS) diff --git a/infer/tests/codetoanalyze/c/errors/lists/lists.c b/infer/tests/codetoanalyze/c/errors/lists/lists.c index 19ba2622a..207192826 100644 --- a/infer/tests/codetoanalyze/c/errors/lists/lists.c +++ b/infer/tests/codetoanalyze/c/errors/lists/lists.c @@ -23,7 +23,7 @@ int add2(struct l2* l) { } /* Divide by zero error shows that we get a spec for add2 */ -int main() { +int lists_main() { int res = add2(0); return 5 / res; } diff --git a/infer/tests/codetoanalyze/c/errors/local_vars/Makefile b/infer/tests/codetoanalyze/c/errors/local_vars/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/local_vars/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/memory_leaks/Makefile b/infer/tests/codetoanalyze/c/errors/memory_leaks/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/memory_leaks/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/null_dereference/Makefile b/infer/tests/codetoanalyze/c/errors/null_dereference/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/null_dereference/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c b/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c index 76aab269c..ae03284a8 100644 --- a/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c +++ b/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c @@ -40,7 +40,7 @@ int negation_in_conditional() { return *x; // this never happens } -int* foo() { return 0; } +static int* foo() { return 0; } void null_pointer_with_function_pointer() { int* (*fp)(); diff --git a/infer/tests/codetoanalyze/c/errors/offsetof_expr/offsetof_expr.c b/infer/tests/codetoanalyze/c/errors/offsetof_expr/offsetof_expr.c new file mode 120000 index 000000000..69ce7e767 --- /dev/null +++ b/infer/tests/codetoanalyze/c/errors/offsetof_expr/offsetof_expr.c @@ -0,0 +1 @@ +../../frontend/offsetof_expr/offsetof_expr.c \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/resource_leaks/Makefile b/infer/tests/codetoanalyze/c/errors/resource_leaks/Makefile deleted file mode 120000 index 67091171e..000000000 --- a/infer/tests/codetoanalyze/c/errors/resource_leaks/Makefile +++ /dev/null @@ -1 +0,0 @@ -../generic.mk \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/errors/vaarg_expr/vaarg_expr.c b/infer/tests/codetoanalyze/c/errors/vaarg_expr/vaarg_expr.c new file mode 120000 index 000000000..e5ac2839e --- /dev/null +++ b/infer/tests/codetoanalyze/c/errors/vaarg_expr/vaarg_expr.c @@ -0,0 +1 @@ +../../frontend/vaarg_expr/vaarg_expr.c \ No newline at end of file diff --git a/infer/tests/codetoanalyze/c/frontend/assertions/assert_example.c b/infer/tests/codetoanalyze/c/frontend/assertions/assert_example.c index e3a8a250e..8bdc89d52 100644 --- a/infer/tests/codetoanalyze/c/frontend/assertions/assert_example.c +++ b/infer/tests/codetoanalyze/c/frontend/assertions/assert_example.c @@ -13,7 +13,7 @@ struct MyPoint { int x; }; -int test(struct MyPoint* activeq) { +int test_assert(struct MyPoint* activeq) { assert(activeq != 0); return activeq->x; } diff --git a/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c b/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c index f1bc9426a..588fe6402 100644 --- a/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c +++ b/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c @@ -9,7 +9,7 @@ enum Foo { A, B, C = 10, D, E = 1, F, G = F + C }; -int main() { +int other_enum_main() { enum Foo foo_a = A; enum Foo foo_b = B; enum Foo foo_c = C; @@ -19,7 +19,7 @@ int main() { enum Foo foo_g = G; } -int test() { +int other_enum_test() { enum Foo foo_g = G; enum Foo foo_a = A; if (foo_g == 12) diff --git a/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c.dot b/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c.dot index 8bb1346df..7909422e5 100644 --- a/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c.dot @@ -37,10 +37,10 @@ digraph iCFG { 12 -> 13 ; -11 [label="11: Exit test \n " color=yellow style=filled] +11 [label="11: Exit other_enum_test \n " color=yellow style=filled] -10 [label="10: Start test\nFormals: \nLocals: foo_a:int foo_g:int \n DECLARE_LOCALS(&return,&foo_a,&foo_g); [line 22]\n " color=yellow style=filled] +10 [label="10: Start other_enum_test\nFormals: \nLocals: foo_a:int foo_g:int \n DECLARE_LOCALS(&return,&foo_a,&foo_g); [line 22]\n " color=yellow style=filled] 10 -> 20 ; @@ -72,10 +72,10 @@ digraph iCFG { 3 -> 2 ; -2 [label="2: Exit main \n " color=yellow style=filled] +2 [label="2: Exit other_enum_main \n " color=yellow style=filled] -1 [label="1: Start main\nFormals: \nLocals: foo_g:int foo_f:int foo_e:int foo_d:int foo_c:int foo_b:int foo_a:int \n DECLARE_LOCALS(&return,&foo_g,&foo_f,&foo_e,&foo_d,&foo_c,&foo_b,&foo_a); [line 12]\n " color=yellow style=filled] +1 [label="1: Start other_enum_main\nFormals: \nLocals: foo_g:int foo_f:int foo_e:int foo_d:int foo_c:int foo_b:int foo_a:int \n DECLARE_LOCALS(&return,&foo_g,&foo_f,&foo_e,&foo_d,&foo_c,&foo_b,&foo_a); [line 12]\n " color=yellow style=filled] 1 -> 9 ; diff --git a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c index 6d4b26437..be735f008 100644 --- a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c +++ b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c @@ -15,7 +15,7 @@ struct address { int v3; }; -int test() { +int test_offsetof_expr() { int i = offsetof(struct address, v2); if (i == 9) { return 9 / 0; diff --git a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot index 0241d7949..53ec05717 100644 --- a/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c.dot @@ -33,10 +33,10 @@ digraph iCFG { 3 -> 4 ; -2 [label="2: Exit test \n " color=yellow style=filled] +2 [label="2: Exit test_offsetof_expr \n " color=yellow style=filled] -1 [label="1: Start test\nFormals: \nLocals: i:int \n DECLARE_LOCALS(&return,&i); [line 18]\n " color=yellow style=filled] +1 [label="1: Start test_offsetof_expr\nFormals: \nLocals: i:int \n DECLARE_LOCALS(&return,&i); [line 18]\n " color=yellow style=filled] 1 -> 10 ; diff --git a/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c b/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c index 20c1614ed..23f0cd570 100644 --- a/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c +++ b/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c @@ -9,7 +9,7 @@ #include -int foo(int x, ...) { +int vaarg_foo(int x, ...) { va_list valist; va_start(valist, x); int i = va_arg(valist, int); diff --git a/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c.dot b/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c.dot index 43858886b..0fb075f6a 100644 --- a/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c.dot @@ -41,10 +41,10 @@ digraph iCFG { 3 -> 2 ; -2 [label="2: Exit foo \n " color=yellow style=filled] +2 [label="2: Exit vaarg_foo \n " color=yellow style=filled] -1 [label="1: Start foo\nFormals: x:int \nLocals: val:int i:int valist:void [1] \n DECLARE_LOCALS(&return,&val,&i,&valist); [line 12]\n " color=yellow style=filled] +1 [label="1: Start vaarg_foo\nFormals: x:int \nLocals: val:int i:int valist:void [1] \n DECLARE_LOCALS(&return,&val,&i,&valist); [line 12]\n " color=yellow style=filled] 1 -> 12 ; diff --git a/infer/tests/codetoanalyze/cpp/errors/Makefile b/infer/tests/codetoanalyze/cpp/errors/Makefile index be7c92e84..001fe7048 100644 --- a/infer/tests/codetoanalyze/cpp/errors/Makefile +++ b/infer/tests/codetoanalyze/cpp/errors/Makefile @@ -5,24 +5,10 @@ # 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. -ROOT_DIR = ../../../../.. -include $(ROOT_DIR)/Makefile.config +include ../../Makefile.clang OPTIONS = -x c++ -std=c++11 -isystem$(CLANG_INCLUDES)/c++/v1/ -c -default: compile - -print: analyze - $(INFERPRINT_BIN) -q -a $(ANALYZER) --issues-tests issues.exp.test - LC_ALL=C sort -o issues.exp.test issues.exp.test - -test: analyze print - make clean - diff -u issues.exp issues.exp.test - rm issues.exp.test - -ANALYZER = infer - FILES = \ attributes/*.cpp \ conditional/*.cpp \ @@ -52,7 +38,4 @@ compile: analyze: $(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets cpp --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) >/dev/null 2>duplicates.txt - grep "DUPLICATE_SYMBOLS" duplicates.txt; true - -clean: - rm -rf *.o infer-out duplicates.txt + grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 diff --git a/infer/tests/endtoend/BUCK b/infer/tests/endtoend/BUCK index 1ef22792f..5b00eb71e 100644 --- a/infer/tests/endtoend/BUCK +++ b/infer/tests/endtoend/BUCK @@ -11,17 +11,6 @@ tests_dependencies = [ '//infer/tests/codetoanalyze/java/infer:infer', ] -# ############### C endtoend tests ######################## -java_test( - name='c_endtoend_tests', - deps=[ - '//infer/tests/endtoend/c/infer:infer', - ], - visibility=[ - 'PUBLIC', - ], -) - # ############### ObjC endtoend tests ######################## java_test( name='objc_endtoend_tests', diff --git a/infer/tests/endtoend/c/infer/AngelismTest.java b/infer/tests/endtoend/c/infer/AngelismTest.java deleted file mode 100644 index c249bf8b8..000000000 --- a/infer/tests/endtoend/c/infer/AngelismTest.java +++ /dev/null @@ -1,62 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class AngelismTest { - - public static final String SOURCE_FILE = - "null_dereference/angelism.c"; - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - AngelismTest.class, - SOURCE_FILE); - } - - @Test - public void angelismNPETest() throws InterruptedException, IOException, InferException { - String[] procedures = { - "bake", - "call_by_ref_actual_already_in_footprint_bad", - "struct_value_by_ref_ptr_write", - "struct_value_by_ref_callee_write_no_skip", - "struct_value_by_ref_callee_write_skip", - "struct_value_skip_null_deref", - "struct_value_from_pointer_skip_bad" - }; - assertThat( - "Results should contain null pointer dereference error", - inferResults, - containsExactly( - NULL_DEREFERENCE, - SOURCE_FILE, - procedures - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/ArrayOfStructsAbductionTest.java b/infer/tests/endtoend/c/infer/ArrayOfStructsAbductionTest.java deleted file mode 100644 index f7860ddba..000000000 --- a/infer/tests/endtoend/c/infer/ArrayOfStructsAbductionTest.java +++ /dev/null @@ -1,62 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -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 ArrayOfStructsAbductionTest { - - public static final String source_file = - "infer/tests/codetoanalyze/c/errors/initialization/abduce_structured_types.c"; - - private static ImmutableList inferCmd; - - public static final String BAD_FOOTPRINT = "Bad_footprint"; - - @ClassRule - public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - ImmutableList extraOptions = - new ImmutableList.Builder() - .add("--developer-mode") - .build(); - inferCmd = InferRunner.createCInferCommand(folder, source_file, extraOptions); - } - - @Test - public void whenInferRunsOnAssertExampleThenNPENotFound() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferC(inferCmd); - String[] no_procedures = {}; - - assertThat("Results should not contain a bad footprint error", - inferResults, - containsExactly(BAD_FOOTPRINT, - source_file, - no_procedures)); - } - -} diff --git a/infer/tests/endtoend/c/infer/ArrayOutOfBoundsTest.java b/infer/tests/endtoend/c/infer/ArrayOutOfBoundsTest.java deleted file mode 100644 index 0c514e343..000000000 --- a/infer/tests/endtoend/c/infer/ArrayOutOfBoundsTest.java +++ /dev/null @@ -1,56 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class ArrayOutOfBoundsTest { - - public static final String SOURCE_FILE = - "arithmetic/array_out_of_bounds.c"; - - public static final String ARRAY_OUT_OF_BOUNDS_L1 = - "ARRAY_OUT_OF_BOUNDS_L1"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - ArrayOutOfBoundsTest.class, - SOURCE_FILE - ); - } - - @Test - public void whenInferRunsOnBoundErrorThenArrayOutOfBoundsIsFound() - throws InterruptedException, IOException, InferException { - String[] procedures = {"bound_error", "bound_error_nested"}; - assertThat( - "Results should contain array bound errors", - inferResults, - containsExactly( - ARRAY_OUT_OF_BOUNDS_L1, - SOURCE_FILE, - procedures - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/AsmAngelismTest.java b/infer/tests/endtoend/c/infer/AsmAngelismTest.java deleted file mode 100644 index 9d36d3a6a..000000000 --- a/infer/tests/endtoend/c/infer/AsmAngelismTest.java +++ /dev/null @@ -1,52 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class AsmAngelismTest { - - public static final String SOURCE_FILE = "null_dereference/asm_angelism.c"; - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - AsmAngelismTest.class, - SOURCE_FILE); - } - - @Test - public void angelismNPETest() throws InterruptedException, IOException, InferException { - String[] procedures = {}; - assertThat( - "Results should not contain null pointer dereference error", - inferResults, - containsExactly( - NULL_DEREFERENCE, - SOURCE_FILE, - procedures - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/AssertKeepBranchTest.java b/infer/tests/endtoend/c/infer/AssertKeepBranchTest.java deleted file mode 100644 index 98fabfac5..000000000 --- a/infer/tests/endtoend/c/infer/AssertKeepBranchTest.java +++ /dev/null @@ -1,57 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import com.google.common.collect.ImmutableList; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class AssertKeepBranchTest { - - public static final String source_file = "assertions/assertion_example.c"; - - private static ImmutableList inferCmd; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(AssertKeepBranchTest.class, source_file); - } - - @Test - public void whenRunsOnAssertionExampleThenDiv0AndNoNPEIsFound() - throws InterruptedException, IOException, InferException { - String[] methods = { - "report_div0_and_no_npe", - }; - assertThat( - "Results should contain " + DIVIDE_BY_ZERO, - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - source_file, - methods - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/AssertTest.java b/infer/tests/endtoend/c/infer/AssertTest.java deleted file mode 100644 index 985addc86..000000000 --- a/infer/tests/endtoend/c/infer/AssertTest.java +++ /dev/null @@ -1,58 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain; - -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 AssertTest { - - public static final String source_file = - "infer/tests/codetoanalyze/c/frontend/assertions/assert_example.c"; - - private static ImmutableList inferCmd; - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - @ClassRule - public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferCmd = InferRunner.createCInferCommand(folder, source_file); - } - - @Test - public void whenInferRunsOnAssertExampleThenNPENotFound() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferC(inferCmd); - assertThat( - "Results should not contain a null dereference error", - inferResults, - doesNotContain( - NULL_DEREFERENCE, - source_file, - "test")); - } - -} diff --git a/infer/tests/endtoend/c/infer/AssertionFailureTest.java b/infer/tests/endtoend/c/infer/AssertionFailureTest.java deleted file mode 100644 index 25b6aa16e..000000000 --- a/infer/tests/endtoend/c/infer/AssertionFailureTest.java +++ /dev/null @@ -1,58 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class AssertionFailureTest { - - public static final String SOURCE_FILE = - "assertions/assertion_failure.c"; - - public static final String ASSERTION_FAILURE = "ASSERTION_FAILURE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(AssertionFailureTest.class, SOURCE_FILE); - } - - @Test - public void whenRunsOnAssertionFailureThenAssertionFailureIsFound() - throws InterruptedException, IOException, InferException { - String[] methods = { - "simple_assertion_failure", - "should_report_assertion_failure", - "assertion_failure_with_heap", - "assignemt_before_check", - "failure_on_both_branches", - }; - assertThat( - "Results should contain " + ASSERTION_FAILURE, - inferResults, - containsExactly( - ASSERTION_FAILURE, - SOURCE_FILE, - methods - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/BUCK b/infer/tests/endtoend/c/infer/BUCK deleted file mode 100644 index a1874be7e..000000000 --- a/infer/tests/endtoend/c/infer/BUCK +++ /dev/null @@ -1,16 +0,0 @@ -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/c/errors:analyze', - ], - visibility=[ - 'PUBLIC', - ], -) diff --git a/infer/tests/endtoend/c/infer/CompoundLiteralExprTest.java b/infer/tests/endtoend/c/infer/CompoundLiteralExprTest.java deleted file mode 100644 index 574bdebbd..000000000 --- a/infer/tests/endtoend/c/infer/CompoundLiteralExprTest.java +++ /dev/null @@ -1,54 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class CompoundLiteralExprTest { - - public static final String SOURCE_FILE = - "initialization/compound_literal.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void loadResults() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(CompoundLiteralExprTest.class, SOURCE_FILE); - } - - @Test - public void whenInferRunsThenDivideByZeroIsFound() - throws InterruptedException, IOException, InferException { - String[] methods = { - "divide_by_zero" - }; - assertThat( - "Results should contain " + DIVIDE_BY_ZERO, - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - SOURCE_FILE, - methods - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/CustomErrorTest.java b/infer/tests/endtoend/c/infer/CustomErrorTest.java deleted file mode 100644 index a80f85908..000000000 --- a/infer/tests/endtoend/c/infer/CustomErrorTest.java +++ /dev/null @@ -1,55 +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 endtoend.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class CustomErrorTest { - - public static final String SOURCE_FILE = - "custom_error/custom.c"; - - public static final String CUSTOM_ERROR = "UNEXPECTED_NEGATIVE_EXPONENT"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(CustomErrorTest.class, SOURCE_FILE); - } - - @Test - public void whenRunsOnAssertionFailureThenAssertionFailureIsFound() - throws InterruptedException, IOException, InferException { - String[] methods = { - "paf", - "pouf", - }; - assertThat( - "Results should contain " + CUSTOM_ERROR, - inferResults, - containsExactly( - CUSTOM_ERROR, - SOURCE_FILE, - methods - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/DanglingDereferenceTest.java b/infer/tests/endtoend/c/infer/DanglingDereferenceTest.java deleted file mode 100644 index 6cf7fc68b..000000000 --- a/infer/tests/endtoend/c/infer/DanglingDereferenceTest.java +++ /dev/null @@ -1,64 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; -import static utils.matchers.ResultContainsErrorInMethod.contains; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class DanglingDereferenceTest { - - public static final String SOURCE_FILE = - "dangling_deref/dpd.c"; - - public static final String DANGLING_POINTER_DEREFERENCE = "DANGLING_POINTER_DEREFERENCE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - DanglingDereferenceTest.class, - SOURCE_FILE); - } - - - @Test - public void DanglingDereferenceTest1() throws InterruptedException, IOException, InferException { - assertThat( - "Results should contain dangling pointer dereference error", - inferResults, - contains( - DANGLING_POINTER_DEREFERENCE, - SOURCE_FILE, - "dpd")); - } - - @Test - public void DanglingDereferenceTest2() throws InterruptedException, IOException, InferException { - assertThat( - "Results should contain dangling pointer dereference error", - inferResults, - contains( - DANGLING_POINTER_DEREFERENCE, - SOURCE_FILE, - "intraprocdpd")); - } - - - -} diff --git a/infer/tests/endtoend/c/infer/DivideByZeroTest.java b/infer/tests/endtoend/c/infer/DivideByZeroTest.java deleted file mode 100644 index cea2779d1..000000000 --- a/infer/tests/endtoend/c/infer/DivideByZeroTest.java +++ /dev/null @@ -1,53 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class DivideByZeroTest { - - public static final String SOURCE_FILE = - "arithmetic/divide_by_zero.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(DivideByZeroTest.class, SOURCE_FILE); - } - - @Test - public void whenInferRunsOnDivideByZeroThenDivideByZeroIsFound() - throws InterruptedException, IOException, InferException { - String[] procedures = {"arith_divide_by_zero"}; - assertThat( - "Results should contain divide by zero error", - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - SOURCE_FILE, - procedures - ) - ); - } - - -} diff --git a/infer/tests/endtoend/c/infer/EnumTest.java b/infer/tests/endtoend/c/infer/EnumTest.java deleted file mode 100644 index b800de930..000000000 --- a/infer/tests/endtoend/c/infer/EnumTest.java +++ /dev/null @@ -1,62 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -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 EnumTest { - - public static final String SOURCE_FILE = - "infer/tests/codetoanalyze/c/frontend/enumeration/other_enum.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - private static ImmutableList inferCmd; - - @ClassRule - public static DebuggableTemporaryFolder folder = - new DebuggableTemporaryFolder(); - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferCmd = InferRunner.createCInferCommand(folder, SOURCE_FILE); - } - - @Test - public void whenInferRunsOnDivideByZeroThenDivideByZeroIsFound() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferC(inferCmd); - String[] procedures = {"test"}; - assertThat( - "Results should contain divide by zero error", - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - SOURCE_FILE, - procedures - ) - ); - } - - -} diff --git a/infer/tests/endtoend/c/infer/InitListExprTest.java b/infer/tests/endtoend/c/infer/InitListExprTest.java deleted file mode 100644 index 204d9a820..000000000 --- a/infer/tests/endtoend/c/infer/InitListExprTest.java +++ /dev/null @@ -1,54 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class InitListExprTest { - - public static final String SOURCE_FILE = - "initialization/initlistexpr.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void loadResults() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(InitListExprTest.class, SOURCE_FILE); - } - - @Test - public void whenInferRunsOnInitListExprThenDivideByZeroIsFound() - throws InterruptedException, IOException, InferException { - String[] methods = { - "init_divide_by_zero" - }; - assertThat( - "Results should contain " + DIVIDE_BY_ZERO, - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - SOURCE_FILE, - methods - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/ListsTest.java b/infer/tests/endtoend/c/infer/ListsTest.java deleted file mode 100644 index e6054cca5..000000000 --- a/infer/tests/endtoend/c/infer/ListsTest.java +++ /dev/null @@ -1,56 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class ListsTest { - - public static final String SOURCE_FILE = "lists/lists.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(DivideByZeroTest.class, SOURCE_FILE); - } - - @Test - public void whenInferRunsOnDivideByZeroThenDivideByZeroIsFound() - throws InterruptedException, IOException, InferException { - String[] procedures = - { "main", - // TODO: fix me! - // "call_all" - }; - assertThat( - "Results should contain divide by zero error", - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - SOURCE_FILE, - procedures - ) - ); - } - - -} diff --git a/infer/tests/endtoend/c/infer/LocalVarsTest.java b/infer/tests/endtoend/c/infer/LocalVarsTest.java deleted file mode 100644 index 67190c53c..000000000 --- a/infer/tests/endtoend/c/infer/LocalVarsTest.java +++ /dev/null @@ -1,49 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class LocalVarsTest { - - public static final String local_vars_file = - "local_vars/local_vars.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(LocalVarsTest.class, local_vars_file); - } - - @Test - public void whenInferRunsOnLocalVarsThenOnlyTheExpectedErrorsAreFound() - throws InterruptedException, IOException, InferException { - String[] expectedProcedures = {"m1", "m2", "mm", "t"}; - assertThat( - "No unexpected errors should be found", inferResults, - containsExactly( - DIVIDE_BY_ZERO, - local_vars_file, - expectedProcedures)); - } - -} diff --git a/infer/tests/endtoend/c/infer/MemoryLeakTest.java b/infer/tests/endtoend/c/infer/MemoryLeakTest.java deleted file mode 100644 index 6841b8d65..000000000 --- a/infer/tests/endtoend/c/infer/MemoryLeakTest.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 endtoend.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class MemoryLeakTest { - - public static final String SOURCE_FILE = "memory_leaks/test.c"; - - public static final String MEMORY_LEAK = "MEMORY_LEAK"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - MemoryLeakTest.class, - SOURCE_FILE); - } - - @Test - public void memoryLeakTest() throws InterruptedException, IOException, InferException { - String[] procedures = { - "simple_leak", - "uses_allocator", - "common_realloc_leak", - "conditional_last_instruction", - }; - assertThat( - "Results should contain the expected memory leak errors", - inferResults, - containsExactly( - MEMORY_LEAK, - SOURCE_FILE, - procedures - ) - ); - } - - - -} diff --git a/infer/tests/endtoend/c/infer/NullDereferenceShortCircuitTest.java b/infer/tests/endtoend/c/infer/NullDereferenceShortCircuitTest.java deleted file mode 100644 index 12b344803..000000000 --- a/infer/tests/endtoend/c/infer/NullDereferenceShortCircuitTest.java +++ /dev/null @@ -1,58 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class NullDereferenceShortCircuitTest { - - public static final String SOURCE_FILE = - "null_dereference/short.c"; - - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - NullDereferenceShortCircuitTest.class, - SOURCE_FILE); - } - - @Test - public void nullDereferenceTest() throws InterruptedException, IOException, InferException { - String[] procedures = { - "f_error", - "g_error", - "l_error" - }; - System.out.println(inferResults.toString()); - assertThat( - "Results should contain null pointer dereference error", - inferResults, - containsExactly( - NULL_DEREFERENCE, - SOURCE_FILE, - procedures - ) - ); - } -} diff --git a/infer/tests/endtoend/c/infer/NullDereferenceTest.java b/infer/tests/endtoend/c/infer/NullDereferenceTest.java deleted file mode 100644 index 6f625c833..000000000 --- a/infer/tests/endtoend/c/infer/NullDereferenceTest.java +++ /dev/null @@ -1,75 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; -import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class NullDereferenceTest { - - public static final String SOURCE_FILE = - "null_dereference/null_pointer_dereference.c"; - - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - NullDereferenceTest.class, - SOURCE_FILE); - } - - @Test - public void nullDereferenceTest() throws InterruptedException, IOException, InferException { - String[] procedures = { - "basic_null_dereference", - "simple_null_pointer", - "null_pointer_interproc", - "null_pointer_with_function_pointer", - "no_check_for_null_after_malloc", - "no_check_for_null_after_realloc", - "potentially_null_pointer_passed_as_argument", - "null_passed_as_argument", - "function_call_can_return_null_pointer", - }; - assertThat( - "Results should contain null pointer dereference error", - inferResults, - containsExactly( - NULL_DEREFERENCE, - SOURCE_FILE, - procedures - ) - ); - } - - @Test - public void whenInferRunsOnSimpleNpe_interprocThenCorrectLineIsReported() - throws InterruptedException, IOException, InferException { - int[] lines = {20, 32, 49, 60, 66, 79, 88, 93, 122}; - assertThat( - "Results should contain null pointer dereference error", - inferResults, - containsOnlyLines(lines)); - } - -} diff --git a/infer/tests/endtoend/c/infer/NullDereferenceTest2.java b/infer/tests/endtoend/c/infer/NullDereferenceTest2.java deleted file mode 100644 index 3fd9abd9d..000000000 --- a/infer/tests/endtoend/c/infer/NullDereferenceTest2.java +++ /dev/null @@ -1,73 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class NullDereferenceTest2 { - - public static final String SOURCE_FILE = - "null_dereference/getc.c"; - - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - NullDereferenceTest2.class, - SOURCE_FILE); - } - - @Test - public void nullDereferenceTest() throws InterruptedException, IOException, InferException { - String[] procedures = { - "crash_getc", - "crash_fgetc", - "crash_ungetc", - "crash_fputs", - "crash_fputc", - "crash_putc", - "crash_fseeks", - "crash_ftell", - "crash_fgets", - "crash_rewind", - "crash_fileno", - "crash_clearerr", - "crash_ferror", - "crash_feof", - "crash_fprintf", - "crash_vfprintf", - "crash_fgetpos", - "crash_fsetpos", - }; - System.out.println(inferResults.toString()); - assertThat( - "Results should contain null pointer dereference error", - inferResults, - containsExactly( - NULL_DEREFERENCE, - SOURCE_FILE, - procedures - ) - ); - } -} diff --git a/infer/tests/endtoend/c/infer/NullDereferenceTest3.java b/infer/tests/endtoend/c/infer/NullDereferenceTest3.java deleted file mode 100644 index f816daa26..000000000 --- a/infer/tests/endtoend/c/infer/NullDereferenceTest3.java +++ /dev/null @@ -1,58 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class NullDereferenceTest3 { - - public static final String SOURCE_FILE = - "null_dereference/memcpy-test.c"; - - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - NullDereferenceTest3.class, - SOURCE_FILE); - } - - @Test - public void nullDereferenceTest() throws InterruptedException, IOException, InferException { - String[] procedures = { - "testError1", - "testError2", - "testError3", - }; - assertThat( - "Results should contain null pointer dereference error", - inferResults, - containsExactly( - NULL_DEREFERENCE, - SOURCE_FILE, - procedures - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/OffsetOfExprTest.java b/infer/tests/endtoend/c/infer/OffsetOfExprTest.java deleted file mode 100644 index 1f3d5ffef..000000000 --- a/infer/tests/endtoend/c/infer/OffsetOfExprTest.java +++ /dev/null @@ -1,59 +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.c; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines; - -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 OffsetOfExprTest { - - public static final String FILE = - "infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c"; - - private static ImmutableList inferCmd; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - @ClassRule - public static DebuggableTemporaryFolder folder = - new DebuggableTemporaryFolder(); - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferCmd = InferRunner.createCInferCommand( - folder, - FILE); - - } - - @Test - public void matchErrors() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferObjC(inferCmd); - assertThat( - "Results should contain the correct " + DIVIDE_BY_ZERO, - inferResults, - containsOnlyLines(new int[]{21, 23})); - } - -} diff --git a/infer/tests/endtoend/c/infer/ResourceLeakTest.java b/infer/tests/endtoend/c/infer/ResourceLeakTest.java deleted file mode 100644 index 78784cf94..000000000 --- a/infer/tests/endtoend/c/infer/ResourceLeakTest.java +++ /dev/null @@ -1,55 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class ResourceLeakTest { - - public static final String SOURCE_FILE = - "resource_leaks/leak.c"; - - public static final String RESOURCE_LEAK = "RESOURCE_LEAK"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(ResourceLeakTest.class, SOURCE_FILE); - } - - @Test - public void mathErrors() - throws InterruptedException, IOException, InferException { - String[] functions = { - "fileNotClosed", - "socketNotClosed" - }; - assertThat( - "Results should contain " + RESOURCE_LEAK, - inferResults, - containsExactly( - RESOURCE_LEAK, - SOURCE_FILE, - functions - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/SentinelTest.java b/infer/tests/endtoend/c/infer/SentinelTest.java deleted file mode 100644 index d6a40f4c6..000000000 --- a/infer/tests/endtoend/c/infer/SentinelTest.java +++ /dev/null @@ -1,52 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class SentinelTest { - - public static final String SOURCE_FILE = - "attributes/sentinel.c"; - - public static final String PREMATURE_NIL_TERMINATION_ARGUMENT = - "PREMATURE_NIL_TERMINATION_ARGUMENT"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults( - SentinelTest.class, - SOURCE_FILE); - } - - @Test - public void whenInferRunsOnThenPNTAisFound() - throws InterruptedException, IOException, InferException { - String[] expectedPNTAProcedures = {"truncated_call"}; - - assertThat( - "Only PNTA should be found", inferResults, - containsExactly( - PREMATURE_NIL_TERMINATION_ARGUMENT, - SOURCE_FILE, - expectedPNTAProcedures)); - } -} diff --git a/infer/tests/endtoend/c/infer/UnsafeMallocTest.java b/infer/tests/endtoend/c/infer/UnsafeMallocTest.java deleted file mode 100644 index 619dff134..000000000 --- a/infer/tests/endtoend/c/infer/UnsafeMallocTest.java +++ /dev/null @@ -1,62 +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.c.infer; - -import com.google.common.collect.ImmutableList; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain; - -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 UnsafeMallocTest { - - public static final String SOURCE_FILE = - "infer/tests/codetoanalyze/c/errors/null_dereference/malloc_no_null_check.c"; - - public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; - private static ImmutableList inferCommand; - - @ClassRule - public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferCommand = InferRunner.createCInferCommand( - folder, - SOURCE_FILE, - ImmutableList.of("--unsafe-malloc")); - } - - @Test - public void unsafeMallocTest() throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferC(inferCommand); - - assertThat( - "Results should not contain null pointer dereference error", - inferResults, - doesNotContain( - NULL_DEREFERENCE, - SOURCE_FILE, - "test_malloc" - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/UnsignedIsNonnegativeTest.java b/infer/tests/endtoend/c/infer/UnsignedIsNonnegativeTest.java deleted file mode 100644 index a7a85960e..000000000 --- a/infer/tests/endtoend/c/infer/UnsignedIsNonnegativeTest.java +++ /dev/null @@ -1,51 +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.c.infer; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsExactly.containsExactly; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import utils.InferException; -import utils.InferResults; - -public class UnsignedIsNonnegativeTest { - - public static final String SOURCE_FILE = "arithmetic/unsigned_values.c"; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - private static InferResults inferResults; - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferResults = InferResults.loadCInferResults(DivideByZeroTest.class, SOURCE_FILE); - } - - @Test - public void whenInferRunsOnDivideByZeroThenDivideByZeroIsFound() - throws InterruptedException, IOException, InferException { - String[] procedures = {"signed_int", "signed_int_ptr", "signed_field", "signed_array"}; - assertThat( - "Results should contain divide by zero error", - inferResults, - containsExactly( - DIVIDE_BY_ZERO, - SOURCE_FILE, - procedures - ) - ); - } - -} diff --git a/infer/tests/endtoend/c/infer/VAArgExprTest.java b/infer/tests/endtoend/c/infer/VAArgExprTest.java deleted file mode 100644 index aaf259412..000000000 --- a/infer/tests/endtoend/c/infer/VAArgExprTest.java +++ /dev/null @@ -1,59 +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.c; - -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines; - -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 VAArgExprTest { - - public static final String FILE = - "infer/tests/codetoanalyze/c/frontend/vaarg_expr/vaarg_expr.c"; - - private static ImmutableList inferCmd; - - public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; - - @ClassRule - public static DebuggableTemporaryFolder folder = - new DebuggableTemporaryFolder(); - - @BeforeClass - public static void runInfer() throws InterruptedException, IOException { - inferCmd = InferRunner.createCInferCommand( - folder, - FILE); - - } - - @Test - public void matchErrors() - throws InterruptedException, IOException, InferException { - InferResults inferResults = InferRunner.runInferObjC(inferCmd); - assertThat( - "Results should contain the correct " + DIVIDE_BY_ZERO, - inferResults, - containsOnlyLines(new int[]{18, 20})); - } - -}