Reviewed By: jberdine, sblackshear Differential Revision: D3827953 fbshipit-source-id: 53a47dfmaster
parent
e18381ab67
commit
c613820a98
@ -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
|
||||
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -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 +0,0 @@
|
||||
../generic.mk
|
@ -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
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -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)
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -0,0 +1 @@
|
||||
../../frontend/offsetof_expr/offsetof_expr.c
|
@ -1 +0,0 @@
|
||||
../generic.mk
|
@ -0,0 +1 @@
|
||||
../../frontend/vaarg_expr/vaarg_expr.c
|
@ -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…
Reference in new issue