forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add unit tests for review status config files
They break right now, but should test the expected behaviour.
- Loading branch information
Showing
18 changed files
with
686 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
OBJS = $(SRCS:.cpp=.o) | ||
|
||
CXXFLAGS = -Wno-all -Wno-extra -std=c++11 | ||
|
||
SRCS = call_and_message.cpp \ | ||
divide_zero.cpp \ | ||
divide_zero_duplicate.cpp \ | ||
file_to_be_skipped.cpp \ | ||
new_delete.cpp \ | ||
null_dereference.cpp \ | ||
stack_address_escape.cpp \ | ||
skip_header.cpp \ | ||
path_begin1.cpp \ | ||
path_begin2.cpp \ | ||
statistical_checkers.cpp | ||
|
||
.cpp.o: | ||
$(CXX) $(CXXFLAGS) -c $< -o $@ | ||
|
||
all: $(OBJS) space path_begin_var1 path_begin_var2 | ||
|
||
space: | ||
$(CXX) -c has\ a\ space.cpp -Wno-all -Wno-extra | ||
|
||
path_begin_var1: | ||
$(CXX) -c -DVAR=1 path_begin.cpp -Wno-all -Wno-extra | ||
|
||
path_begin_var2: | ||
$(CXX) -c -DVAR=2 path_begin.cpp -Wno-all -Wno-extra | ||
|
||
clean: | ||
rm -rf *.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// core.CallAndMessage (C, C++, ObjC) | ||
// Check for logical errors for function calls and Objective-C message | ||
// expressions (e.g., uninitialized arguments, null function pointers). | ||
|
||
struct S { | ||
int x; | ||
}; | ||
|
||
void f(struct S s); | ||
|
||
void test1() { | ||
struct S s; | ||
// insert_suppress_here | ||
f(s); // warn: passed-by-value arg contain uninitialized data | ||
} | ||
|
||
void test2() { | ||
void (*foo)(void); | ||
foo(); // warn: function pointer is uninitialized | ||
} | ||
|
||
void test3() { | ||
void (*foo)(void); | ||
foo = 0; | ||
foo(); // warn: function pointer is null | ||
} | ||
|
||
class C { | ||
public: | ||
void f(); | ||
}; | ||
|
||
void test4() { | ||
C *pc; | ||
pc->f(); // warn: object pointer is uninitialized | ||
} | ||
|
||
void test5() { | ||
C *pc = 0; | ||
pc->f(); // warn: object pointer is null <- non breaking space here save the file in latin1 (ISO-8895-1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// core.DivideZero (C, C++, ObjC) | ||
// Check for division by zero. | ||
|
||
void test1(int z) { | ||
if (z == 0) | ||
int x = 1 / z; // warn | ||
} | ||
|
||
void test2() { | ||
int x = 1; | ||
// insert_suppress_here | ||
int y = x % 0; // warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// core.DivideZero (C, C++, ObjC) | ||
// Check for division by zero. | ||
|
||
void test1(int z) { | ||
if (z == 0) | ||
int x = 1 / z; // warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// This file is to be included in a skip list file. | ||
|
||
void skipped_test(int z) { | ||
if (z == 0) | ||
int x = 1 / z; // warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// core.NullDereference (C, C++, ObjC) | ||
// Check for dereferences of null pointers. | ||
|
||
int main() | ||
{ | ||
int *p = 0; | ||
return *p + 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// cplusplus.NewDelete (C++) | ||
// Check for double-free, use-after-free and offset problems involving C++ | ||
// delete. | ||
|
||
void f(int *p); | ||
|
||
void testUseMiddleArgAfterDelete(int *p) { | ||
delete p; | ||
f(p); // warn: use after free | ||
} | ||
|
||
class SomeClass { | ||
public: | ||
void f(); | ||
}; | ||
|
||
void test1() { | ||
SomeClass *c = new SomeClass; | ||
delete c; | ||
c->f(); // warn: use after free | ||
} | ||
|
||
void test2() { | ||
int *p = (int *)__builtin_alloca(sizeof(int)); | ||
delete p; // warn: deleting memory allocated by alloca | ||
} | ||
|
||
void test3() { | ||
int *p = new int; | ||
delete p; | ||
delete p; // warn: attempt to free released ° | ||
} | ||
|
||
void test4() { | ||
int i; | ||
delete &i; // warn: delete address of local | ||
} | ||
|
||
void test() { | ||
int *p = new int[1]; | ||
delete[] (++p); | ||
// warn: argument to 'delete[]' is offset by 4 bytes | ||
// from the start of memory allocated by 'new[]' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// core.NullDereference (C, C++, ObjC) | ||
// Check for dereferences of null pointers. | ||
|
||
void test1(int *p) { | ||
if (p) | ||
return; | ||
|
||
int x = p[0]; // warn | ||
} | ||
|
||
void test2(int *p) { | ||
if (!p) | ||
*p = 0; // warn | ||
} | ||
|
||
class C { | ||
public: | ||
int x; | ||
}; | ||
|
||
void test3() { | ||
C *pc = 0; | ||
int k = pc->x; // warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
|
||
int div_zero2(int z, int w) { | ||
|
||
if (z == 0){ | ||
int x = 1 / z; // warn | ||
return x; | ||
} | ||
|
||
if (w==0){ | ||
z=0; | ||
int x = 1 / z; // warn | ||
return x; | ||
} | ||
|
||
} | ||
|
||
int f(int x){ | ||
return div_zero2(0, x); | ||
} | ||
|
||
int g(int x){ | ||
return div_zero2(x, 0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
#include "path_end.h" | ||
|
||
int f(int x){ | ||
if(x == 0){ | ||
x = div_zero(x); | ||
return x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
#include "path_end.h" | ||
|
||
int g(int y){ | ||
return div_zero(y); | ||
} | ||
|
||
int test(int z){ | ||
if(z == 0){ | ||
return g(z); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
int div_zero(int z) { | ||
if (z == 0){ | ||
int x = 1 / z; // warn | ||
return x; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "cpp", | ||
"clean_cmd": "make clean", | ||
"build_cmd": "make" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
int null_div(int z) { | ||
int x = z / 0; // warn | ||
return x; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
#include "skip.h" | ||
|
||
int test() { | ||
int x = null_div(42); | ||
return x; | ||
} | ||
|
||
int test1(int i) { | ||
int y = i / 0; // warn | ||
return y; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ------------------------------------------------------------------------- | ||
// Part of the CodeChecker project, under the Apache License v2.0 with | ||
// LLVM Exceptions. See LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// ------------------------------------------------------------------------- | ||
|
||
// core.StackAddressEscape (C) | ||
// Check that addresses of stack memory do not escape the function. | ||
|
||
char const *p; | ||
|
||
void test1() { | ||
char const str[] = "string"; | ||
p = str; // warn | ||
} | ||
|
||
void* test2() { | ||
return __builtin_alloca(12); // warn | ||
} | ||
|
||
void test3() { | ||
static int *x; | ||
int y; | ||
x = &y; // warn | ||
} |
Oops, something went wrong.