Commit 387a8f01 authored by Lev Walkin's avatar Lev Walkin

draft fuzzer infrastructure

parent b5cdc5d2
...@@ -164,7 +164,7 @@ AC_ARG_ENABLE([test-fuzzer], ...@@ -164,7 +164,7 @@ AC_ARG_ENABLE([test-fuzzer],
[enable_test_fuzzer=$enableval], [enable_test_fuzzer=no]) [enable_test_fuzzer=$enableval], [enable_test_fuzzer=no])
AS_IF([test "x$enable_test_fuzzer" != xno], [ AS_IF([test "x$enable_test_fuzzer" != xno], [
AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer], AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],
[LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer"], [LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer -DENABLE_LIBFUZZER"],
[ [
AC_MSG_FAILURE( AC_MSG_FAILURE(
[--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system. [--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system.
......
...@@ -39,6 +39,7 @@ if [ ! "$has_per" ]; then ...@@ -39,6 +39,7 @@ if [ ! "$has_per" ]; then
fi fi
args=$(echo "$source_short" | sed -E -e 's/\.c+$//') args=$(echo "$source_short" | sed -E -e 's/\.c+$//')
source_obj=$(echo "$source_short" | sed -E -e 's/\.c+$/.o/')
OFS=$IFS OFS=$IFS
IFS="." IFS="."
...@@ -57,6 +58,13 @@ touch "${testdir}-FAILED" ...@@ -57,6 +58,13 @@ touch "${testdir}-FAILED"
mkdir -p "${testdir}" mkdir -p "${testdir}"
ln -fns "../${source_full}" "${testdir}" ln -fns "../${source_full}" "${testdir}"
if test "${LIBFUZZER_CFLAGS}" && grep LLVMFuzzer ${source_full} > /dev/null;
then
MAKE_FUZZER=yes
else
MAKE_FUZZER=no
fi
asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1) asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1)
AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}" AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}"
...@@ -69,6 +77,7 @@ COMMON_FLAGS= -I. ...@@ -69,6 +77,7 @@ COMMON_FLAGS= -I.
CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O1 CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O1
CFLAGS += -DSRCDIR=../${srcdir} ${CODECS_FLAGS} CFLAGS += -DSRCDIR=../${srcdir} ${CODECS_FLAGS}
CXXFLAGS = \${CFLAGS} ${CXXFLAGS} CXXFLAGS = \${CFLAGS} ${CXXFLAGS}
LIBFUZZER_CFLAGS = ${LIBFUZZER_CFLAGS}
LDFLAGS = ${LDFLAGS:-} LDFLAGS = ${LDFLAGS:-}
CC ?= ${CC} CC ?= ${CC}
...@@ -90,10 +99,34 @@ compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c ...@@ -90,10 +99,34 @@ compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c
rm -f converter-sample.c rm -f converter-sample.c
@touch compiled-module @touch compiled-module
TARGETS
if [ "${MAKE_FUZZER}" != "yes" ]; then
CHECK_FUZZER=": # No fuzzer defined"
cat <<TARGETS >> "${testdir}/Makefile.targets"
.PHONY check-fuzzer:
check-fuzzer:
TARGETS
else
CHECK_FUZZER="./check-fuzzer -timeout=3 -max_total_time=60 -max-len 512 -detect_leaks=1"
cat <<TARGETS >> "${testdir}/Makefile.targets"
check-fuzzer: \$(OBJS)
rm -f ${source_obj}
\$(CC) \$(CFLAGS) \$(LIBFUZZER_CFLAGS) -c -o ${source_obj} ${source_short}
\$(CC) \$(CFLAGS) \$(LIBFUZZER_CFLAGS) \$(LDFLAGS) -o check-fuzzer \$(OBJS)
rm -f ${source_obj}
TARGETS
fi
cat <<TARGETS >> "${testdir}/Makefile.targets"
check-succeeded: compiled-module check-succeeded: compiled-module
\$(MAKE) check-executable \$(MAKE) check-executable
\$(MAKE) check-fuzzer
@rm -f check-succeeded @rm -f check-succeeded
./check-executable ./check-executable
${CHECK_FUZZER}
@touch check-succeeded @touch check-succeeded
check: check-succeeded check: check-succeeded
...@@ -112,14 +145,18 @@ produce_specific_makefile() { ...@@ -112,14 +145,18 @@ produce_specific_makefile() {
${AUTOGENERATED} ${AUTOGENERATED}
SRCS_C!=find . -name \*.c SRCS_C!=find . -name \*.c
SRCS_CXX!=find . -name \*.cc SRCS_CXX!=find . -name \*.cc
SRCS=\$(SRCS_C) \$(SRCS_CXX)
OBJS=\${SRCS_C:.c=.o} ${SRCS_CXX:.cc=.o} OBJS=\${SRCS_C:.c=.o} ${SRCS_CXX:.cc=.o}
.sinclude <Makefile.targets> .sinclude <Makefile.targets>
OBJECTS OBJECTS
else else
cat <<-OBJECTS > ${make_file} cat <<-OBJECTS > ${make_file}
${AUTOGENERATED} ${AUTOGENERATED}
OBJS =\$(patsubst %.c,%.o,\$(wildcard *.c)) SRCS_C := \$(wildcard *.c)
OBJS+=\$(patsubst %.cc,%.o,\$(wildcard *.cc)) SRCS_CXX := \$(wildcard *.cc)
SRCS = \$(SRCS_C) \$(SRCS_CXX)
OBJS =\$(patsubst %.c,%.o,\$(SRCS_C))
OBJS+=\$(patsubst %.cc,%.o,\$(SRCS_CXX))
-include Makefile.targets -include Makefile.targets
OBJECTS OBJECTS
fi fi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment