Skip to content

Commit f1c90ec

Browse files
authored
ci: run fuzzers (#138)
1 parent 73ba630 commit f1c90ec

File tree

7 files changed

+87
-12
lines changed

7 files changed

+87
-12
lines changed

.circleci/config.yml

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
version: 2.1
22

3+
main_branch_only: &main_branch_only
4+
requires:
5+
- build-bazel
6+
- build-and-test-cmake
7+
- build-and-test-windows-bazel
8+
- build-and-test-windows-cmake
9+
filters:
10+
branches:
11+
only:
12+
- main
13+
314
orbs:
415
codecov: codecov/[email protected]
516

@@ -13,6 +24,27 @@ executors:
1324
- image: "datadog/docker-library:dd-trace-cpp-ci"
1425
resource_class: arm.xlarge
1526

27+
commands:
28+
run_timeout:
29+
description: "Run a command for a specified duration"
30+
parameters:
31+
command:
32+
type: string
33+
duration:
34+
type: string
35+
description:
36+
type: string
37+
steps:
38+
- run:
39+
name: << parameters.description >>
40+
command: |
41+
set +e
42+
timeout << parameters.duration >> << parameters.command >>
43+
# `124` is the exit code timeout returns when the duration is reached
44+
if [[ $? -eq 124 ]]; then
45+
exit 0
46+
fi
47+
1648
jobs:
1749
format:
1850
docker:
@@ -171,6 +203,25 @@ jobs:
171203
- store_artifacts:
172204
path: logs_cpp_parametric_dev.tar.gz
173205

206+
fuzz-testing:
207+
docker:
208+
- image: "datadog/docker-library:dd-trace-cpp-ci"
209+
resource_class: xlarge
210+
environment:
211+
MAKE_JOB_COUNT: 8
212+
steps:
213+
- checkout
214+
- run: bin/with-toolchain llvm cmake . -B .build -DCMAKE_BUILD_TYPE=Debug -DDD_TRACE_BUILD_FUZZERS=1 -DDD_TRACE_ENABLE_SANITIZE=1
215+
- run: cmake --build .build -j ${MAKE_JOB_COUNT} --target dd_trace_cpp-fuzzers
216+
- run_timeout:
217+
description: Run W3C propagation fuzzer
218+
command: ./.build/fuzz/w3c-propagation/w3c-propagation-fuzz
219+
duration: 5m
220+
- run_timeout:
221+
description: Run Base64 fuzzer
222+
command: timeout 5m ./.build/fuzz/base64/base64-fuzz
223+
duration: 5m
224+
174225
workflows:
175226
pull-request:
176227
jobs:
@@ -199,12 +250,6 @@ workflows:
199250
requires:
200251
- build-and-test-cmake
201252
- system-tests:
202-
requires:
203-
- build-bazel
204-
- build-and-test-cmake
205-
- build-and-test-windows-bazel
206-
- build-and-test-windows-cmake
207-
filters:
208-
branches:
209-
only:
210-
- main
253+
<<: *main_branch_only
254+
- fuzz-testing:
255+
<<: *main_branch_only

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ endif ()
3434
# Linking this library requires threads.
3535
find_package(Threads REQUIRED)
3636
include(cmake/deps/curl.cmake)
37+
include(cmake/utils.cmake)
3738

3839
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/src/datadog/version.cpp DD_TRACE_VERSION_CPP_CONTENTS REGEX "#define DD_TRACE_VERSION( |_NUM )")
3940
string(REGEX MATCH "#define DD_TRACE_VERSION \"[^\"]*" DD_TRACE_VERSION ${DD_TRACE_VERSION_CPP_CONTENTS})

cmake/utils.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Function for organizing targets into logical groups.
2+
#
3+
# Description:
4+
# This function add the target to a group of targets. If the group does not exist yet, it will create
5+
# a custom target. The group acts as a meta-target that does not build anything itself but depends on
6+
# other targets.
7+
#
8+
# Parameters:
9+
# TARGET_TO_ADD (string): The name of the target to be added to the group.
10+
# GROUP (string): The name of the group target to which the target will be added.
11+
#
12+
# Usage:
13+
# ADD_TARGET_TO_GROUP(<TARGET_TO_ADD> <GROUP>)
14+
function (ADD_TARGET_TO_GROUP TARGET_TO_ADD GROUP)
15+
if (NOT TARGET ${GROUP})
16+
add_custom_target(${GROUP})
17+
endif ()
18+
19+
message(STATUS "Adding target ${TARGET_TO_ADD} to ${GROUP} group")
20+
add_dependencies(${GROUP} ${TARGET_TO_ADD})
21+
endfunction ()
22+

fuzz/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(base64)
22
add_subdirectory(w3c-propagation)
3+

fuzz/base64/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ add_executable(base64-fuzz main.cpp)
22

33
add_dependencies(base64-fuzz dd_trace_cpp-static)
44
target_link_libraries(base64-fuzz dd_trace_cpp-static)
5+
6+
add_target_to_group(base64-fuzz dd_trace_cpp-fuzzers)

fuzz/w3c-propagation/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ add_executable(w3c-propagation-fuzz fuzz.cpp)
22

33
add_dependencies(w3c-propagation-fuzz dd_trace_cpp-static)
44
target_link_libraries(w3c-propagation-fuzz dd_trace_cpp-static)
5+
6+
add_target_to_group(w3c-propagation-fuzz dd_trace_cpp-fuzzers)

fuzz/w3c-propagation/fuzz.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace {
2020
dd::Tracer& tracer_singleton() {
2121
thread_local auto tracer = []() {
2222
dd::TracerConfig config;
23-
config.defaults.service = "fuzzer";
23+
config.service = "fuzzer";
2424
config.collector = std::make_shared<dd::NullCollector>();
2525

2626
const auto finalized_config = dd::finalize_config(config);
@@ -70,8 +70,10 @@ extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, size_t size) {
7070
for (const char* begin_tracestate = begin_traceparent;
7171
begin_tracestate <= end; ++begin_tracestate) {
7272
MockDictReader reader;
73-
reader.traceparent = dd::range(begin_traceparent, begin_tracestate);
74-
reader.tracestate = dd::range(begin_tracestate, end);
73+
reader.traceparent =
74+
dd::StringView(begin_traceparent, begin_tracestate - begin_traceparent);
75+
reader.tracestate =
76+
dd::StringView(begin_tracestate, end - begin_tracestate);
7577

7678
const auto span = tracer.extract_span(reader);
7779
if (!span) {

0 commit comments

Comments
 (0)