Skip to content

Commit 2ca632e

Browse files
author
MarcoFalke
committed
test: Build fuzz targets into seperate executables
1 parent fab4bed commit 2ca632e

File tree

7 files changed

+507
-221
lines changed

7 files changed

+507
-221
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev libprotobuf-dev"
9898
DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1"
9999
GOAL="install"
100-
BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports --enable-debug CXXFLAGS=\"-g0 -O2\""
100+
BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-fuzz --enable-glibc-back-compat --enable-reduce-exports --enable-debug CXXFLAGS=\"-g0 -O2\""
101101
102102
- stage: test
103103
name: 'x86_64 Linux [GOAL: install] [xenial] [no depends, only system libs, sanitizers: thread (TSan), no wallet]'

configure.ac

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
102102

103103
AC_ARG_VAR(PYTHONPATH, Augments the default search path for python module files)
104104

105-
# Enable wallet
106105
AC_ARG_ENABLE([wallet],
107106
[AS_HELP_STRING([--disable-wallet],
108107
[disable wallet (enabled by default)])],
@@ -147,6 +146,11 @@ AC_ARG_ENABLE([extended-functional-tests],
147146
[use_extended_functional_tests=$enableval],
148147
[use_extended_functional_tests=no])
149148

149+
AC_ARG_ENABLE([fuzz],
150+
AS_HELP_STRING([--enable-fuzz],[enable building of fuzz targets (default no)]),
151+
[enable_fuzz=$enableval],
152+
[enable_fuzz=no])
153+
150154
AC_ARG_WITH([qrencode],
151155
[AS_HELP_STRING([--with-qrencode],
152156
[enable QR code support (default is yes if qt is enabled and libqrencode is found)])],
@@ -1394,6 +1398,7 @@ AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
13941398
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
13951399
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
13961400
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
1401+
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
13971402
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
13981403
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
13991404
AM_CONDITIONAL([ENABLE_BIP70],[test x$enable_bip70 = xyes])
@@ -1536,6 +1541,9 @@ if test x$bitcoin_enable_qt != xno; then
15361541
fi
15371542
echo " with zmq = $use_zmq"
15381543
echo " with test = $use_tests"
1544+
if test x$use_tests != xno; then
1545+
echo " with fuzz = $enable_fuzz"
1546+
fi
15391547
echo " with bench = $use_bench"
15401548
echo " with upnp = $use_upnp"
15411549
echo " use asm = $use_asm"

doc/fuzzing.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Fuzz-testing Bitcoin Core
22
==========================
33

4-
A special test harness `test_bitcoin_fuzzy` is provided to provide an easy
5-
entry point for fuzzers and the like. In this document we'll describe how to
6-
use it with AFL and libFuzzer.
4+
A special test harness in `src/test/fuzz/` is provided for each fuzz target to
5+
provide an easy entry point for fuzzers and the like. In this document we'll
6+
describe how to use it with AFL and libFuzzer.
77

88
## AFL
99

@@ -23,10 +23,10 @@ export AFLPATH=$PWD
2323
To build Bitcoin Core using AFL instrumentation (this assumes that the
2424
`AFLPATH` was set as above):
2525
```
26-
./configure --disable-ccache --disable-shared --enable-tests CC=${AFLPATH}/afl-gcc CXX=${AFLPATH}/afl-g++
26+
./configure --disable-ccache --disable-shared --enable-tests --enable-fuzz CC=${AFLPATH}/afl-gcc CXX=${AFLPATH}/afl-g++
2727
export AFL_HARDEN=1
2828
cd src/
29-
make test/test_bitcoin_fuzzy
29+
make
3030
```
3131
We disable ccache because we don't want to pollute the ccache with instrumented
3232
objects, and similarly don't want to use non-instrumented cached objects linked
@@ -35,7 +35,7 @@ in.
3535
The fuzzing can be sped up significantly (~200x) by using `afl-clang-fast` and
3636
`afl-clang-fast++` in place of `afl-gcc` and `afl-g++` when compiling. When
3737
compiling using `afl-clang-fast`/`afl-clang-fast++` the resulting
38-
`test_bitcoin_fuzzy` binary will be instrumented in such a way that the AFL
38+
binary will be instrumented in such a way that the AFL
3939
features "persistent mode" and "deferred forkserver" can be used. See
4040
https://github.com/mcarpenter/afl/tree/master/llvm_mode for details.
4141

@@ -63,7 +63,7 @@ Extract these (or other starting inputs) into the `inputs` directory before star
6363

6464
To start the actual fuzzing use:
6565
```
66-
$AFLPATH/afl-fuzz -i ${AFLIN} -o ${AFLOUT} -m52 -- test/test_bitcoin_fuzzy
66+
$AFLPATH/afl-fuzz -i ${AFLIN} -o ${AFLOUT} -m52 -- test/fuzz/fuzz_target_foo
6767
```
6868

6969
You may have to change a few kernel parameters to test optimally - `afl-fuzz`
@@ -77,7 +77,7 @@ found in the `compiler-rt` runtime libraries package).
7777
To build the `test/test_bitcoin_fuzzy` executable run
7878

7979
```
80-
./configure --disable-ccache --with-sanitizers=fuzzer,address CC=clang CXX=clang++
80+
./configure --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address CC=clang CXX=clang++
8181
make
8282
```
8383

0 commit comments

Comments
 (0)