Skip to content

Commit fa13e1b

Browse files
author
MarcoFalke
committed
build: Add option --enable-danger-fuzz-link-all
1 parent 44444ba commit fa13e1b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

.fuzzbuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ setup:
77
- sudo apt-get update
88
- sudo apt-get install -y autoconf bsdmainutils clang git libboost-all-dev libboost-program-options-dev libc++1 libc++abi1 libc++abi-dev libc++-dev libclang1 libclang-dev libdb5.3++ libevent-dev libllvm-ocaml-dev libomp5 libomp-dev libprotobuf-dev libqt5core5a libqt5dbus5 libqt5gui5 libssl-dev libtool llvm llvm-dev llvm-runtime pkg-config protobuf-compiler qttools5-dev qttools5-dev-tools software-properties-common
99
- ./autogen.sh
10-
- CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined
10+
- CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined --enable-danger-fuzz-link-all
1111
- make
1212
- git clone https://github.com/bitcoin-core/qa-assets
1313
auto_targets:

configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ AC_ARG_ENABLE([fuzz],
167167
[enable_fuzz=$enableval],
168168
[enable_fuzz=no])
169169

170+
AC_ARG_ENABLE([danger_fuzz_link_all],
171+
AS_HELP_STRING([--enable-danger-fuzz-link-all],
172+
[Danger! Modifies source code. Needs git and gnu sed installed. Link each fuzz target (default no).]),
173+
[enable_danger_fuzz_link_all=$enableval],
174+
[enable_danger_fuzz_link_all=no])
175+
170176
AC_ARG_WITH([qrencode],
171177
[AS_HELP_STRING([--with-qrencode],
172178
[enable QR code support (default is yes if qt is enabled and libqrencode is found)])],
@@ -1612,6 +1618,7 @@ AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
16121618
AM_CONDITIONAL([USE_BDB], [test "x$use_bdb" = "xyes"])
16131619
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
16141620
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
1621+
AM_CONDITIONAL([ENABLE_FUZZ_LINK_ALL],[test x$enable_danger_fuzz_link_all = xyes])
16151622
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
16161623
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
16171624
AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])

src/Makefile.test.include

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ endif
1010

1111
TEST_SRCDIR = test
1212
TEST_BINARY=test/test_bitcoin$(EXEEXT)
13+
FUZZ_BINARY=test/fuzz/fuzz$(EXEEXT)
1314

1415
JSON_TEST_FILES = \
1516
test/data/script_tests.json \
@@ -320,6 +321,11 @@ if EMBEDDED_UNIVALUE
320321
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check
321322
endif
322323

324+
if ENABLE_FUZZ_LINK_ALL
325+
all-local: $(FUZZ_BINARY)
326+
bash ./test/fuzz/danger_link_all.sh
327+
endif
328+
323329
%.cpp.test: %.cpp
324330
@echo Running tests: `cat $< | grep -E "(BOOST_FIXTURE_TEST_SUITE\\(|BOOST_AUTO_TEST_SUITE\\()" | cut -d '(' -f 2 | cut -d ',' -f 1 | cut -d ')' -f 1` from $<
325331
$(AM_V_at)$(TEST_BINARY) --catch_system_errors=no -l test_suite -t "`cat $< | grep -E "(BOOST_FIXTURE_TEST_SUITE\\(|BOOST_AUTO_TEST_SUITE\\()" | cut -d '(' -f 2 | cut -d ',' -f 1 | cut -d ')' -f 1`" -- DEBUG_LOG_OUT > $<.log 2>&1 || (cat $<.log && false)

src/test/fuzz/danger_link_all.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
export LC_ALL=C.UTF-8
7+
8+
set -e
9+
10+
ROOT_DIR="$(git rev-parse --show-toplevel)"
11+
12+
# Run only once (break make recursion)
13+
if [ -d "${ROOT_DIR}/lock_fuzz_link_all" ]; then
14+
exit
15+
fi
16+
mkdir "${ROOT_DIR}/lock_fuzz_link_all"
17+
18+
echo "Linking each fuzz target separately."
19+
for FUZZING_HARNESS in $(PRINT_ALL_FUZZ_TARGETS_AND_ABORT=1 "${ROOT_DIR}/src/test/fuzz/fuzz" | sort -u); do
20+
echo "Building src/test/fuzz/${FUZZING_HARNESS} ..."
21+
git checkout -- "${ROOT_DIR}/src/test/fuzz/fuzz.cpp"
22+
sed -i "s/std::getenv(\"FUZZ\")/\"${FUZZING_HARNESS}\"/g" "${ROOT_DIR}/src/test/fuzz/fuzz.cpp"
23+
make
24+
mv "${ROOT_DIR}/src/test/fuzz/fuzz" "${ROOT_DIR}/src/test/fuzz/${FUZZING_HARNESS}"
25+
done
26+
git checkout -- "${ROOT_DIR}/src/test/fuzz/fuzz.cpp"
27+
rmdir "${ROOT_DIR}/lock_fuzz_link_all"
28+
echo "Successfully built all fuzz targets."

0 commit comments

Comments
 (0)