diff --git a/.circleci/config.yml b/.circleci/config.yml index 6d1e489..c4b2ce9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ version: 2.1 jobs: lint: docker: - - image: redislabsmodules/llvm-toolset:latest + - image: silkeh/clang:12 steps: - checkout - run: @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c24767..264271b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 --- diff --git a/Makefile b/Makefile index db8f06a..3bc9cf0 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5163a06..a24686c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 $<$:-g -O1 + -fsanitize=fuzzer>) + + target_link_libraries(td_fuzz + PRIVATE $<$:-fsanitize=fuzzer> tdigest) + add_test(td_fuzz td_fuzz) +endif() diff --git a/tests/test_fuzzer.cc b/tests/test_fuzzer.cc new file mode 100644 index 0000000..8b83386 --- /dev/null +++ b/tests/test_fuzzer.cc @@ -0,0 +1,10 @@ +// Test_fuzzer.cc +#include +#include +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; +} \ No newline at end of file