Skip to content

Commit

Permalink
[fuzz] add support to build fuzzing targets (openthread#2014)
Browse files Browse the repository at this point in the history
This enables adding OpenThread to OSS-Fuzz.
  • Loading branch information
jwhui authored Jul 20, 2017
1 parent 3c981ea commit 791dd24
Show file tree
Hide file tree
Showing 5 changed files with 488 additions and 6 deletions.
25 changes: 25 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,29 @@ NL_ENABLE_OPTIMIZATION([yes])

AM_CONDITIONAL([OPENTHREAD_BUILD_OPTIMIZED], [test "${nl_cv_build_optimized}" = "yes"])

# Fuzz Targets

AC_MSG_CHECKING([whether to build fuzz targets])
AC_ARG_ENABLE(fuzz-targets,
[AS_HELP_STRING([--enable-fuzz-targets],[Enable building of fuzz targets @<:@default=no@:>@.])],
[
case "${enableval}" in
no|yes)
enable_fuzz_targets=${enableval}
;;
*)
AC_MSG_ERROR([Invalid value ${enableval} for --enable-fuzz-targets])
;;
esac
],
[enable_fuzz_targets=no])
AC_MSG_RESULT(${enable_fuzz_targets})

AM_CONDITIONAL([OPENTHREAD_ENABLE_FUZZ_TARGETS], [test "${enable_fuzz_targets}" = "yes"])

# Address Sanitizer

AC_MSG_CHECKING([whether to build with Address Sanitizer support])
Expand Down Expand Up @@ -1376,6 +1399,7 @@ tools/harness-automation/Makefile
tools/harness-thci/Makefile
tools/spi-hdlc-adapter/Makefile
tests/Makefile
tests/fuzz/Makefile
tests/scripts/Makefile
tests/scripts/thread-cert/Makefile
tests/unit/Makefile
Expand Down Expand Up @@ -1413,6 +1437,7 @@ AC_MSG_NOTICE([
Lcov : ${LCOV:--}
Genhtml : ${GENHTML:--}
Build tests : ${nl_cv_build_tests}
Build fuzz targets : ${enable_fuzz_targets}
Build tools : ${build_tools}
OpenThread tests : ${with_tests}
Prefix : ${prefix}
Expand Down
21 changes: 15 additions & 6 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,33 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
DIST_SUBDIRS = \
unit \
scripts \
fuzz \
$(NULL)

# Always build (e.g. for 'make all') these subdirectories.

if OPENTHREAD_EXAMPLES_POSIX
if OPENTHREAD_ENABLE_CLI
SUBDIRS = \
unit \
scripts \
$(NULL)
endif
endif

# Always pretty (e.g. for 'make pretty') these subdirectories.

PRETTY_SUBDIRS = \
fuzz \
unit \
$(NULL)

if OPENTHREAD_EXAMPLES_POSIX
if OPENTHREAD_ENABLE_CLI
SUBDIRS += \
unit \
scripts \
$(NULL)
endif
endif

if OPENTHREAD_ENABLE_FUZZ_TARGETS
SUBDIRS += fuzz
endif

if OPENTHREAD_BUILD_TESTS
if OPENTHREAD_BUILD_COVERAGE
Expand Down
49 changes: 49 additions & 0 deletions tests/fuzz/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright (c) 2017, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

include $(abs_top_nlbuild_autotools_dir)/automake/pre.am

bin_PROGRAMS = \
radio-receive-done-fuzzer \
$(NULL)

AM_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src/core \
$(NULL)

COMMON_LDADD = \
$(top_builddir)/src/core/libopenthread-ftd.a \
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
$(LIB_FUZZING_ENGINE) \
$(NULL)

radio_receive_done_fuzzer_LDADD = $(COMMON_LDADD)
radio_receive_done_fuzzer_SOURCES = radio_receive_done.cpp fuzzer_platform.c

include $(abs_top_nlbuild_autotools_dir)/automake/post.am
Loading

0 comments on commit 791dd24

Please sign in to comment.