Skip to content

Commit

Permalink
rpcdaemon: enable fuzzer build on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
JacekGlen committed Oct 12, 2023
1 parent 661514b commit a33c0eb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ commands:
then
CONAN_CMAKE_ARGS="-DCONAN_PROFILE=<<parameters.conan_profile>>"
fi
if [[ "<<parameters.compiler_id>>" == "clang" ]]
then
TOOLCHAIN_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake"
fi
# if [[ "<<parameters.compiler_id>>" == "clang" ]]
# then
# TOOLCHAIN_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake"
# fi
cmake ../project -DCMAKE_BUILD_TYPE=<<parameters.build_type>> $CONAN_CMAKE_ARGS $TOOLCHAIN_CMAKE_ARGS $BUILD_CMAKE_ARGS
- run:
Expand Down Expand Up @@ -150,6 +150,7 @@ commands:
mkdir -p ~/corpus
mkdir -p ~/crashes
mkdir -p ~/artifacts
for pathname in ../project/third_party/execution-apis/tests/*/*.io; do cp --backup=numbered "$pathname" ~/artifacts; done
./cmd/test/rpcdaemon_fuzzer_test -max_total_time=10 ~/corpus ~/crashes ~/artifacts
jobs:
Expand Down Expand Up @@ -308,13 +309,13 @@ jobs:
linux-clang-fuzzer:
environment:
BUILD_CMAKE_ARGS: -DSILKWORM_FUZZER=ON
ASAN_OPTIONS: alloc_dealloc_mismatch=0 # https://github.com/llvm/llvm-project/issues/59432
UBSAN_OPTIONS: print_stacktrace=1
machine:
image: ubuntu-2204:2023.04.2
resource_class: xlarge
steps:
- checkout_with_submodules
- checkout_with_submodules:
ethereum_tests: false
- build_using_conan:
build_type: Release
compiler_id: clang
Expand Down Expand Up @@ -414,8 +415,7 @@ workflows:
when:
or:
- equal: [ master, <<pipeline.git.branch>> ]
- equal: [ master, <<pipeline.git.branch>> ]
# - matches: { pattern: "^ci\\/.+$", value: <<pipeline.git.branch>> }
- matches: { pattern: "^ci\\/.+$", value: <<pipeline.git.branch>> }
jobs:
- linux-release:
name: linux-gcc-<<pipeline.parameters.gcc_version_min>>-release
Expand Down
4 changes: 2 additions & 2 deletions cmd/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ if(NOT SILKWORM_CORE_ONLY)

# Silkworm RpcDaemon Fuzz Debug Executable
add_executable(rpcdaemon_fuzzer_diagnostics fuzzer_diagnostics.cpp)
target_compile_options(rpcdaemon_fuzzer_diagnostics PRIVATE -fsanitize=address)
target_link_libraries(rpcdaemon_fuzzer_diagnostics PRIVATE silkrpc CLI11::CLI11 -fsanitize=address)
target_compile_options(rpcdaemon_fuzzer_diagnostics PRIVATE -fsanitize=address,undefined)
target_link_libraries(rpcdaemon_fuzzer_diagnostics PRIVATE silkrpc CLI11::CLI11 -fsanitize=address,undefined)
endif()

# Silkworm Sync Tests
Expand Down
32 changes: 32 additions & 0 deletions cmd/test/address_sanitizer_fix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2023 The Silkworm Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// https://github.com/llvm/llvm-project/issues/59432


#ifndef __has_feature
// GCC does not have __has_feature, adding it to avoid compilation errors
#define __has_feature(feature) 0
#endif

#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#ifdef __cplusplus
extern "C"
#endif
const char *__asan_default_options() {
return "alloc_dealloc_mismatch=0";
}
#endif
3 changes: 3 additions & 0 deletions cmd/test/fuzzer_diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
*/


#include <execinfo.h>

#include <cstdlib>
Expand All @@ -23,6 +24,7 @@
#include <CLI/CLI.hpp>

#include <silkworm/silkrpc/test/api_test_database.hpp>
#include "address_sanitizer_fix.hpp"

void print_stack_trace() {
void* trace[16];
Expand Down Expand Up @@ -59,6 +61,7 @@ int main(int argc, char* argv[]) {

app.add_option("input", input_str, "Input string")
->description("Wrap JSON in '' to avoid shell escaping, e.g. '{\"jsonrpc\":\"2.0\",\"id\":1}'")
->default_val(R"({"jsonrpc":"2.0","id":1,"method":"debug_getRawBlock","params":["3"]})")
->required(false);

app.add_option("-f", input_file, "Path to test file or directory")
Expand Down
2 changes: 2 additions & 0 deletions cmd/test/fuzzer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <silkworm/silkrpc/test/api_test_database.hpp>

#include "address_sanitizer_fix.hpp"

using namespace silkworm::rpc::test;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
Expand Down

0 comments on commit a33c0eb

Please sign in to comment.