commit f32c8595d8a8947ad41bded0f8734055dc0c21ab
parent 48d0cb6621c75bea00d8e57539708b1d85302c30
Author: Heikki Lindholm <holin@iki.fi>
Date: Fri, 27 Jun 2008 19:03:38 +0000
add fuzzer tests
Diffstat:
4 files changed, 91 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
@@ -460,6 +460,9 @@ ABI_GSF
echo ""
AC_CHECK_LIB(gsf-1, gsf_init, AC_DEFINE(HAVE_GSF_INIT,1,[gsf_init supported]))
+AC_CHECK_PROG([HAVE_ZZUF],[zzuf], 1, 0)
+AM_CONDITIONAL(HAVE_ZZUF, test 0 != $HAVE_ZZUF)
+
printable=1
AC_MSG_CHECKING([whether to enable printable extractors])
AC_ARG_ENABLE(printable,
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
@@ -9,6 +9,13 @@ AM_CFLAGS = -DELIBDIR=\"$(ELIBDIR)\" -DPLUGIN_PATH="\"${libdir}\"" -DTESTDATADIR
LDADD = \
$(top_builddir)/src/main/libextractor.la
+if HAVE_ZZUF
+fuzz_tests=fuzz_default.sh fuzz_thumbnail.sh
+endif
+
+TESTS_ENVIRONMENT = testdatadir=$(top_srcdir)/test
+TESTS_ENVIRONMENT += bindir=${bindir}
+
check_PROGRAMS = \
trivialtest \
keywordlisttest \
@@ -19,7 +26,7 @@ check_PROGRAMS = \
mt_extracttest1 \
mt_extracttest2
-TESTS = $(check_PROGRAMS)
+TESTS = $(check_PROGRAMS) $(fuzz_tests)
plugintest_SOURCES = \
plugintest.c
diff --git a/src/test/fuzz_default.sh b/src/test/fuzz_default.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+ZZSTARTSEED=0
+ZZSTOPSEED=100
+
+# fallbacks for direct, non-"make check" usage
+if test x"$testdatadir" = x""
+then
+ testdatadir=../../test
+fi
+if test x"$bindir" = x""
+then
+ bindir=`grep "^prefix = " ./Makefile | cut -d ' ' -f 3`
+ bindir="$bindir/bin"
+fi
+
+
+for file in $testdatadir/test*
+do
+ if test -f "$file"
+ then
+ tmpfile=`mktemp`
+ if ! test -f "$tmpfile"
+ then
+ exit 1
+ fi
+ seed=$ZZSTARTSEED
+ while [ $seed -lt $ZZSTOPSEED ]
+ do
+ echo "file $file seed $seed"
+ zzuf -s $seed cat "$file" > "$tmpfile"
+ if ! "$bindir/extract" "$tmpfile" > /dev/null
+ then
+ rm -f "$tmpfile"
+ exit 1
+ fi
+ seed=`expr $seed + 1`
+ done
+ rm -f "$tmpfile"
+ fi
+done
+
diff --git a/src/test/fuzz_thumbnail.sh b/src/test/fuzz_thumbnail.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+ZZSTARTSEED=0
+ZZSTOPSEED=100
+
+# fallbacks for direct, non-"make check" usage
+if test x"$testdatadir" = x""
+then
+ testdatadir=../../test
+fi
+if test x"$bindir" = x""
+then
+ bindir=`grep "^prefix = " ./Makefile | cut -d ' ' -f 3`
+ bindir="$bindir/bin"
+fi
+
+
+for file in $testdatadir/*.bmp $testdatadir/*.png
+do
+ if test -f "$file"
+ then
+ tmpfile=`mktemp`
+ if ! test -f "$tmpfile"
+ then
+ exit 1
+ fi
+ seed=$ZZSTARTSEED
+ while [ $seed -lt $ZZSTOPSEED ]
+ do
+ echo "file $file seed $seed"
+ zzuf -s $seed cat "$file" > "$tmpfile"
+ "$bindir/extract" -n -l libextractor_thumbnail:libextractor_mime "$tmpfile" > /dev/null
+ seed=`expr $seed + 1`
+ done
+ rm -f "$tmpfile"
+ fi
+done
+