Convert c tests to the new testing format

Reviewed By: jberdine, sblackshear

Differential Revision: D3827953

fbshipit-source-id: 53a47df
master
Cristiano Calcagno 8 years ago committed by Facebook Github Bot 9
parent e18381ab67
commit c613820a98

@ -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

@ -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

@ -1,7 +1,6 @@
java_test(
name='c_tests',
deps=[
'//infer/tests/endtoend:c_endtoend_tests',
'//infer/tests/frontend:c_frontend_tests',
],
)

@ -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

@ -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',
],
)

@ -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

@ -0,0 +1 @@
../../frontend/assertions/assert_example.c

@ -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)

@ -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)

@ -0,0 +1 @@
../../frontend/enumeration/other_enum.c

@ -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

@ -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)

@ -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;
}

@ -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)();

@ -0,0 +1 @@
../../frontend/offsetof_expr/offsetof_expr.c

@ -0,0 +1 @@
../../frontend/vaarg_expr/vaarg_expr.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;
}

@ -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)

@ -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 ;

@ -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;

@ -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 ;

@ -9,7 +9,7 @@
#include <stdarg.h>
int foo(int x, ...) {
int vaarg_foo(int x, ...) {
va_list valist;
va_start(valist, x);
int i = va_arg(valist, int);

@ -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 ;

@ -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

@ -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',

@ -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
)
);
}
}

@ -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<String> 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<String> extraOptions =
new ImmutableList.Builder<String>()
.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));
}
}

@ -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
)
);
}
}

@ -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
)
);
}
}

@ -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<String> 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
)
);
}
}

@ -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<String> 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"));
}
}

@ -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
)
);
}
}

@ -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',
],
)

@ -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
)
);
}
}

@ -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
)
);
}
}

@ -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"));
}
}

@ -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
)
);
}
}

@ -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<String> 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
)
);
}
}

@ -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
)
);
}
}

@ -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
)
);
}
}

@ -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));
}
}

@ -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
)
);
}
}

@ -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
)
);
}
}

@ -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));
}
}

@ -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
)
);
}
}

@ -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
)
);
}
}

@ -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<String> 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}));
}
}

@ -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
)
);
}
}

@ -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));
}
}

@ -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<String> inferCommand;
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCommand = InferRunner.createCInferCommand(
folder,
SOURCE_FILE,
ImmutableList.<String>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"
)
);
}
}

@ -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
)
);
}
}

@ -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<String> 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}));
}
}
Loading…
Cancel
Save