Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[In-Progress] Kicking off fuzz testing with libfuzzer #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.1
jobs:
lint:
docker:
- image: redislabsmodules/llvm-toolset:latest
- image: silkeh/clang:12
steps:
- checkout
- run:
Expand All @@ -14,12 +14,12 @@ jobs:

sanitize:
docker:
- image: redislabsmodules/llvm-toolset:latest
- image: silkeh/clang:12
steps:
- checkout
- run:
name: Install CMAKE
command: 'apt install -y cmake'
command: 'apt install -y cmake --fix-missing'
- run:
name: Pull Submodules
command: git submodule update --init --recursive
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option(BUILD_BENCHMARK "Build benchmark" ON)
option(BUILD_TESTS "Build tests" ON)
OPTION(ENABLE_CODECOVERAGE "Enable code coverage testing support" OFF)
OPTION(ENABLE_PROFILE "Enable code profiling support" OFF)
option(ENABLE_FUZZER "Enable fuzz testing" OFF)
option(BUILD_EXAMPLES "Build examples" ON)

# --- Build properties ---
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ifndef CMAKE_TEST_OPTIONS
CMAKE_TEST_OPTIONS=\
-DBUILD_SHARED=ON \
-DBUILD_STATIC=ON \
-DENABLE_FUZZER=ON \
-DBUILD_TESTS=ON \
-DENABLE_CODECOVERAGE=ON \
-DBUILD_BENCHMARK=OFF \
Expand Down
15 changes: 15 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ add_executable(td_test td_test.c minunit.h)
target_link_libraries(td_test tdigest m)
enable_testing()
add_test(td_test td_test)


# --- Fuzz testing ---
if (ENABLE_FUZZER)
message(STATUS "Forcing compiler to be clang given we're using libfuzz.")
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang)
add_executable(td_fuzz test_fuzzer.cc)
target_compile_options(td_fuzz PRIVATE $<$<C_COMPILER_ID:Clang>:-g -O1
-fsanitize=fuzzer>)

target_link_libraries(td_fuzz
PRIVATE $<$<C_COMPILER_ID:Clang>:-fsanitize=fuzzer> tdigest)
add_test(td_fuzz td_fuzz)
endif()
10 changes: 10 additions & 0 deletions tests/test_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test_fuzzer.cc
#include <stdint.h>
#include <stddef.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size > 0 && data[0] == 'H')
if (size > 1 && data[1] == 'I')
if (size > 2 && data[2] == '!')
__builtin_trap();
return 0;
}