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

draft fuzzer infrastructure

parent b5cdc5d2
......@@ -164,7 +164,7 @@ AC_ARG_ENABLE([test-fuzzer],
[enable_test_fuzzer=$enableval], [enable_test_fuzzer=no])
AS_IF([test "x$enable_test_fuzzer" != xno], [
AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],
[LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer"],
[LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer -DENABLE_LIBFUZZER"],
[
AC_MSG_FAILURE(
[--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system.
......
......@@ -39,6 +39,7 @@ if [ ! "$has_per" ]; then
fi
args=$(echo "$source_short" | sed -E -e 's/\.c+$//')
source_obj=$(echo "$source_short" | sed -E -e 's/\.c+$/.o/')
OFS=$IFS
IFS="."
......@@ -57,6 +58,13 @@ touch "${testdir}-FAILED"
mkdir -p "${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)
AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}"
......@@ -69,6 +77,7 @@ COMMON_FLAGS= -I.
CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O1
CFLAGS += -DSRCDIR=../${srcdir} ${CODECS_FLAGS}
CXXFLAGS = \${CFLAGS} ${CXXFLAGS}
LIBFUZZER_CFLAGS = ${LIBFUZZER_CFLAGS}
LDFLAGS = ${LDFLAGS:-}
CC ?= ${CC}
......@@ -90,10 +99,34 @@ compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c
rm -f converter-sample.c
@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
\$(MAKE) check-executable
\$(MAKE) check-fuzzer
@rm -f check-succeeded
./check-executable
${CHECK_FUZZER}
@touch check-succeeded
check: check-succeeded
......@@ -112,14 +145,18 @@ produce_specific_makefile() {
${AUTOGENERATED}
SRCS_C!=find . -name \*.c
SRCS_CXX!=find . -name \*.cc
SRCS=\$(SRCS_C) \$(SRCS_CXX)
OBJS=\${SRCS_C:.c=.o} ${SRCS_CXX:.cc=.o}
.sinclude <Makefile.targets>
OBJECTS
else
cat <<-OBJECTS > ${make_file}
${AUTOGENERATED}
OBJS =\$(patsubst %.c,%.o,\$(wildcard *.c))
OBJS+=\$(patsubst %.cc,%.o,\$(wildcard *.cc))
SRCS_C := \$(wildcard *.c)
SRCS_CXX := \$(wildcard *.cc)
SRCS = \$(SRCS_C) \$(SRCS_CXX)
OBJS =\$(patsubst %.c,%.o,\$(SRCS_C))
OBJS+=\$(patsubst %.cc,%.o,\$(SRCS_CXX))
-include Makefile.targets
OBJECTS
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