Skip to content

Commit fa09244

Browse files
committed
Add fuzz tests for the explore_me example
1 parent 1d192fc commit fa09244

File tree

6 files changed

+177
-1
lines changed

6 files changed

+177
-1
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/external)
1414
enable_testing()
1515
include(googletest)
1616

17+
find_package(cifuzz NO_SYSTEM_ENVIRONMENT_PATH)
18+
enable_fuzz_testing()
19+
1720
add_subdirectory(src/explore_me)
18-
add_subdirectory(src/automotive)
21+
add_subdirectory(src/automotive)

CMakeUserPresets.json

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"version": 3,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 20,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "cifuzz (Coverage)",
11+
"displayName": "cifuzz (Coverage)",
12+
"binaryDir": "${sourceDir}/.cifuzz-build/replayer/gcov",
13+
"cacheVariables": {
14+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
15+
"CIFUZZ_ENGINE": "replayer",
16+
"CIFUZZ_SANITIZERS": "gcov",
17+
"CIFUZZ_TESTING": {
18+
"type": "BOOL",
19+
"value": "ON"
20+
},
21+
"CMAKE_BUILD_RPATH_USE_ORIGIN": {
22+
"type": "BOOL",
23+
"value": "ON"
24+
}
25+
}
26+
},
27+
{
28+
"name": "cifuzz (Fuzzing)",
29+
"displayName": "cifuzz (Fuzzing)",
30+
"binaryDir": "${sourceDir}/.cifuzz-build/libfuzzer/address+undefined",
31+
"cacheVariables": {
32+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
33+
"CIFUZZ_ENGINE": "libfuzzer",
34+
"CIFUZZ_SANITIZERS": "address;undefined",
35+
"CIFUZZ_TESTING": {
36+
"type": "BOOL",
37+
"value": "ON"
38+
},
39+
"CMAKE_BUILD_RPATH_USE_ORIGIN": {
40+
"type": "BOOL",
41+
"value": "ON"
42+
}
43+
},
44+
"environment": {
45+
"CC": "clang",
46+
"CXX": "clang++"
47+
}
48+
},
49+
{
50+
"name": "cifuzz (Regression Test)",
51+
"displayName": "cifuzz (Regression Test)",
52+
"binaryDir": "${sourceDir}/.cifuzz-build/replayer/address+undefined",
53+
"cacheVariables": {
54+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
55+
"CIFUZZ_ENGINE": "replayer",
56+
"CIFUZZ_SANITIZERS": "address;undefined",
57+
"CIFUZZ_TESTING": {
58+
"type": "BOOL",
59+
"value": "ON"
60+
},
61+
"CMAKE_BUILD_RPATH_USE_ORIGIN": {
62+
"type": "BOOL",
63+
"value": "ON"
64+
}
65+
}
66+
}
67+
],
68+
"buildPresets": [
69+
{
70+
"name": "cifuzz (Coverage)",
71+
"displayName": "cifuzz (Coverage)",
72+
"configurePreset": "cifuzz (Coverage)",
73+
"configuration": "RelWithDebInfo"
74+
},
75+
{
76+
"name": "cifuzz (Fuzzing)",
77+
"displayName": "cifuzz (Fuzzing)",
78+
"configurePreset": "cifuzz (Fuzzing)",
79+
"configuration": "RelWithDebInfo"
80+
},
81+
{
82+
"name": "cifuzz (Regression Test)",
83+
"displayName": "cifuzz (Regression Test)",
84+
"configurePreset": "cifuzz (Regression Test)",
85+
"configuration": "RelWithDebInfo"
86+
}
87+
],
88+
"testPresets": [
89+
{
90+
"name": "cifuzz (Regression Test)",
91+
"displayName": "cifuzz (Regression Test)",
92+
"configurePreset": "cifuzz (Regression Test)",
93+
"filter": {
94+
"include": {
95+
"label": "^cifuzz_regression_test$"
96+
}
97+
}
98+
}
99+
]
100+
}

cifuzz.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Configuration for a CI Fuzz project
2+
## Generated on 2023-06-06
3+
4+
## The build system used to build this project. If not set, cifuzz tries
5+
## to detect the build system automatically.
6+
## Valid values: "bazel", "cmake", "maven", "gradle", "other".
7+
#build-system: cmake
8+
9+
## If the build system type is "other", this command is used by
10+
## `cifuzz run` to build the fuzz test.
11+
#build-command: "make my_fuzz_test"
12+
13+
## Directories containing sample inputs for the code under test.
14+
## See https://llvm.org/docs/LibFuzzer.html#corpus
15+
#seed-corpus-dirs:
16+
# - path/to/seed-corpus
17+
18+
## A file containing input language keywords or other interesting byte
19+
## sequences.
20+
## See https://llvm.org/docs/LibFuzzer.html#dictionaries
21+
#dict: path/to/dictionary.dct
22+
23+
## Command-line arguments to pass to libFuzzer.
24+
## See https://llvm.org/docs/LibFuzzer.html#options
25+
engine-args:
26+
- -use_value_profile=1
27+
28+
## Maximum time to run fuzz tests. The default is to run indefinitely.
29+
#timeout: 30m
30+
31+
## By default, fuzz tests are executed in a sandbox to prevent accidental
32+
## damage to the system. Set to false to run fuzz tests unsandboxed.
33+
## Only supported on Linux.
34+
#use-sandbox: false
35+
36+
## Set to true to print output of the `cifuzz run` command as JSON.
37+
#print-json: true
38+
39+
## Set to true to disable desktop notifications
40+
#no-notifications: true
41+
42+
## Set URL of the CI App
43+
#server: https://app.code-intelligence.com
44+
45+
## Set the project name on the CI App
46+
#project: my-project-1a2b3c4d

src/explore_me/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ foreach(TestType IN ITEMS
3434
)
3535

3636
add_test(explore_me.${TestType} ${TestType}_test)
37+
38+
add_fuzz_test(${TestType}_fuzz_test
39+
${TestType}_test.cpp
40+
)
41+
42+
target_link_libraries(${TestType}_fuzz_test
43+
explore_me
44+
${GTEST_BOTH_LIBRARIES}
45+
)
3746
endforeach(TestType )

src/explore_me/complex_checks_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ TEST(ExploreComplexChecksTests, DeveloperTest) {
1111
TEST(ExploreComplexChecksTests, MaintainerTest) {
1212
EXPECT_NO_THROW(ExploreComplexChecks(20, -10, "Maintainer"));
1313
}
14+
15+
FUZZ_TEST(const uint8_t *data, size_t size) {
16+
FuzzedDataProvider fdp(data, size);
17+
long a = fdp.ConsumeIntegral<long>();
18+
long b = fdp.ConsumeIntegral<long>();
19+
std::string c = fdp.ConsumeRemainingBytesAsString();
20+
21+
ExploreComplexChecks(a, b, c);
22+
}

src/explore_me/simple_checks_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ TEST(ExploreSimpleChecksTests, DeveloperTest) {
1111
TEST(ExploreSimpleChecksTests, MaintainerTest) {
1212
EXPECT_NO_THROW(ExploreSimpleChecks(20, -10, "Maintainer"));
1313
}
14+
15+
FUZZ_TEST(const uint8_t *data, size_t size) {
16+
FuzzedDataProvider fdp(data, size);
17+
int a = fdp.ConsumeIntegral<int>();
18+
int b = fdp.ConsumeIntegral<int>();
19+
std::string c = fdp.ConsumeRemainingBytesAsString();
20+
21+
ExploreSimpleChecks(a, b, c);
22+
}

0 commit comments

Comments
 (0)