8000 Feat: fuzz tests by waldgange · Pull Request #763 · bloomberg/blazingmq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feat: fuzz tests #763

8000
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

Merged
merged 11 commits into from
Jun 26, 2025
Merged

Feat: fuzz tests #763

merged 11 commits into from
Jun 26, 2025

Conversation

waldgange
Copy link
Collaborator
@waldgange waldgange commented May 28, 2025

This PR inroduces a new job to sanitizers workflow. The job builds Fuzz-tests and their dependencies instrumented with address sanitizer. This job is launched in parallel with other sanitizers after a PR is approved. The fuzz tests sources reside in src/standalones/s_bmqfuzz. Three tests are added so far:

  • s_bmqfuzz_eval.cpp targets BloombergLP::bmqeval::SimpleEvaluator::compile
  • s_bmqfuzz_parseutil.cpp targets BloombergLP::mqbcmd::ParseUtil::parse
  • s_bmqfuzz_bmqt_uri.cpp targets BloombergLP::bmqt::UriParser::parse

There is also a script for building them locally bin/build-fuzz.sh

Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2700 of commit caff4b7 has completed with FAILURE

Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2702 of commit 927b21f has completed with FAILURE

Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2712 of commit c89f0a2 has completed with FAILURE

Comment on lines 63 to 75
CMAKE_OPTIONS=(\
-DBDE_BUILD_TARGET_64=ON \
-DBDE_BUILD_TARGET_SAFE=ON \
-DBDE_BUILD_TARGET_CPP20=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_LIBDIR="lib" \
-DCMAKE_INSTALL_PREFIX="${DIR_INSTALL}" \
-DCMAKE_MODULE_PATH="${DIR_THIRDPARTY}/bde-tools/cmake;${DIR_THIRDPARTY}/bde-tools/BdeBuildSystem" \
-DCMAKE_PREFIX_PATH="${DIR_INSTALL}" \
-DCMAKE_TOOLCHAIN_FILE="${DIR_THIRDPARTY}/bde-tools/BdeBuildSystem/toolchains/linux/clang-default.cmake" \
-DCMAKE_CXX_FLAGS="-fsanitize=fuzzer-no-link" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DINSTALL_TARGETS=fuzztests)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should start moving these configs into CMakePresets.json, so we can manage all the commonalities between these build modes.

Can this be replaced with a preset called fuzz-tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a preset for non-parametrized flags


file(GLOB sources "*fuzzer.cpp")
foreach (source ${sources})
string(REGEX MATCH "\/([A-Za-z_]+)\.cpp$" _ ${source})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why regex match if we glob all the .cpp files in the directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified this

target_bmq_default_compiler_flags(${targetName})
target_include_directories(${targetName} PRIVATE ${fuzz-tests_INCLUDE_DIRS})
target_link_libraries(${targetName} PRIVATE ${fuzz-tests_PCDEPS})
target_link_options(${targetName} PRIVATE "-fsanitize=fuzzer")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we set sanitizer flags in the toolchain file, we may want to provide one based off of the one we'd be using from https://github.com/bloomberg/bde-tools/tree/main/cmake/toolchains/linux

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 15 to 30
foreach (source ${sources})
string(REGEX MATCH "\/([A-Za-z_]+)\.cpp$" _ ${source})
set(targetName ${CMAKE_MATCH_1})
add_executable(${targetName} ${source})

target_bmq_default_compiler_flags(${targetName})
target_include_directories(${targetName} PRIVATE ${fuzz-tests_INCLUDE_DIRS})
target_link_libraries(${targetName} PRIVATE ${fuzz-tests_PCDEPS})
target_link_options(${targetName} PRIVATE "-fsanitize=fuzzer")

set_target_properties(${targetName}
PROPERTIES OUTPUT_NAME ${targetName})

# Add the current tutorial to the 'fuzztests' rule
add_dependencies("fuzztests" ${targetName})
endforeach()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a nontrivial enough bit of CMake that it should be put in a function and documented

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CMakeLists.txt Outdated
Comment on lines 199 to 204
if (installIT)
set(BMQ_TARGET_BMQ_NEEDED YES)
set(BMQ_TARGET_MQB_NEEDED YES)
set(BMQ_TARGET_BMQBRKR_NEEDED YES)
set(BMQ_TARGET_BMQTOOL_NEEDED YES)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this IT install rules related to fuzz testing? Can we have a separate PR for it if not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. It's not related directly to the fuzz tests

Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
@waldgange waldgange marked this pull request as ready for review June 11, 2025 13:29
@waldgange waldgange requested a review from a team as a code owner June 11, 2025 13:29
Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2735 of commit db59087 has completed with FAILURE

Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
@waldgange waldgange requested a review from hallfox June 11, 2025 17:20
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2739 of commit 9fb98f6 has completed with FAILURE

Co-authored-by: Taylor Foxhall <lxmachina@gmail.com>
Signed-off-by: Anton Pryakhin <antonpryakhin@gmail.com>
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2749 of commit d7eb932 has completed with FAILURE

Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2754 of commit e11b880 has completed with FAILURE

if [ "${FUZZER}" == "on" ]; then
export FUZZER_FLAG="fuzzer-no-link"
else
export CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/usr/include;/usr/include/clang/${LLVM_VERSION}/include"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in the else branch?

Copy link
Collaborator Author
@waldgange waldgange Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default standard library include paths contain libstdc++ headers. We don't want to change it for fuzz-tests. I didn't want to brake anything for the old workflows, so I desided to leave it in the else branch. However this doesn't look like correct include paths for libc++. We set this path properly later in the toolchain:

string(CONCAT TOOLCHAIN_CXX_FLAGS
"${TOOLCHAIN_CXX_FLAGS} "
"-stdlib=libc++ "
"-I${LIBCXX_BUILD_PATH}/include/c++/v1 "
)

So I've got rid of this branch at all and added a flag that removes default include paths for non-fuzz case


if [[ -z "${2}" || ("${2}" != "on" && "${2}" != "off") ]]; then
echo 'Error: Wrong fuzzer argument. It can be either "on" or "off"' >&2
echo ' (Usage: build_sanitizer.sh <sanitizer-name> <fuzzer>)' >&2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a section to the comment block at the top with a usage example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"-stdlib=libc++ "
"-I${LIBCXX_BUILD_PATH}/include/c++/v1 "
)
if(DEFINED ENV{LIBCXX_BUILD_PATH})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what build configuration are we using libc++? Just when fuzzers are disabled? I think we should be consistent about which standard library we use. It seems like we'd lose some instrumentation coverage if we don't custom build LLVM here. My understanding is we have this kind of matrix:

Sanitizer Fuzz? std choice
ASAN no libc++ instrumented
MSAN no libc++ instrumented
TSAN no libc++ instrumented
UBSAN no libc++ instrumented
ASAN yes libstd++

That makes me kind of think that the fuzz test builds are kind of exceptional and should probably have their own build rules

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. But these two workflows also have a lot in common - all dependencies, except the standard library, instumented with sanitizers. So it's very convenient to reuse this toolchain. Do we really want another toolchain for that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's fair

add_custom_target("fuzztests")

find_package(BdeBuildSystem REQUIRED)
bbs_read_metadata(PACKAGE fuzz-tests)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid BDE package name, but BDE also doesn't really define a clear way for organizing a separate package with dedicated test executables. I'm going to recommend we invent the following conventions:

  1. Fuzz tests should have the suffix .fuzz.cpp
  2. This specific package of fuzz tests should live in src/standalones/s_bmqfuzz

(maybe we can consult with them on what their opinions about this would be?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked BDE team about fuzz tests. They build them in a slightly different way. They put each fuzz test to the test driver of the corresponding component. Here is an example. However they didn't integrate neither with BFuzz nor with oss-fuzz. They run their fuzz tests locally instead. What do you think? Should we do the same with our tests?

add_dependencies("fuzztests" ${targetName})
endfunction()

file(GLOB sources "*fuzzer.cpp")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should get this list from ${fuzz-tests_SOURCE_FILES}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

waldgange and others added 2 commits June 20, 2025 19:51
Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
Co-authored-by: Taylor Foxhall <lxmachina@gmail.com>
Signed-off-by: Anton Pryakhin <antonpryakhin@gmail.com>
@waldgange waldgange requested a review from hallfox June 20, 2025 17:18
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2779 of commit 402061a has completed with FAILURE

Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
Copy link
@bmq-oss-ci bmq-oss-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build 2780 of commit 67d8867 has completed with FAILURE

@waldgange waldgange merged commit 4285ece into bloomberg:main Jun 26, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0