libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit b3fd152712e62176669bc0e4446094445d75ca66
parent ce23e2d6602379a9cdbb665afbde7168107ab87b
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 20 Dec 2009 20:51:54 +0000

starting work on testcases

Diffstat:
MTODO | 10++++------
Msrc/main/Makefile.am | 59++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/main/extractor.c | 43+++++++++++++++++++++++++++++++++++++------
Rsrc/test/fuzz_default.sh -> src/main/fuzz_default.sh | 0
Asrc/main/fuzz_thumbnail.sh | 39+++++++++++++++++++++++++++++++++++++++
Asrc/main/test_plugin_load_multi.c | 38++++++++++++++++++++++++++++++++++++++
Asrc/main/test_plugin_loading.c | 40++++++++++++++++++++++++++++++++++++++++
Asrc/main/test_trivial.c | 35+++++++++++++++++++++++++++++++++++
Msrc/test/Makefile.am | 2+-
Dsrc/test/fuzz_thumbnail.sh | 39---------------------------------------
Dsrc/test/multiload.c | 37-------------------------------------
Dsrc/test/plugintest.c | 78------------------------------------------------------------------------------
Dsrc/test/trivialtest.c | 32--------------------------------
13 files changed, 252 insertions(+), 200 deletions(-)

diff --git a/TODO b/TODO @@ -1,15 +1,13 @@ * ffmpeg needs make 3.81: add configure check for it Core: -* check for symbolic links, do not load same plugin twice! - (happens right now for installations with multiple - available thumbnailers) +* port test cases * support "hash" plugins as *optional* plugins (need a way to indicate that they should not be used "by default") -* use "-" in config not to append plugin, but to remove one! -* document -* port test cases +* support "footer" plugins that need the end of the file, + and not the beginning +* document the new APIs * document special options; we have: - force-kill: plugin process committs suicide after each file - oop-only: plugin is never run in-process diff --git a/src/main/Makefile.am b/src/main/Makefile.am @@ -38,7 +38,7 @@ libextractor_la_LIBADD = \ EXTRA_DIST = \ iconv.c -libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" $(AM_CPPFLAGS) +libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" -DPLUGININSTDIR=\"${plugindir}\" $(AM_CPPFLAGS) libextractor_la_SOURCES = \ extractor.c \ @@ -52,3 +52,60 @@ extract_SOURCES = \ getopt1.c + + +ELIBDIR = $(libdir) + +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 = \ + test_trivial \ + test_plugin_loading \ + test_plugin_load_multi + +nocheck = \ + mt_plugintest1 \ + mt_plugintest2 \ + mt_extracttest1 \ + mt_extracttest2 + +TESTS = $(check_PROGRAMS) $(fuzz_tests) + +test_trivial_SOURCES = \ + test_trivial.c + +test_plugin_loading_SOURCES = \ + test_plugin_loading.c + +test_plugin_load_multi_SOURCES = \ + test_plugin_load_multi.c + +mt_plugintest1_SOURCES = \ + mt_plugintest1.c +mt_plugintest1_LDFLAGS = \ + -lpthread + +mt_plugintest2_SOURCES = \ + mt_plugintest2.c +mt_plugintest2_LDFLAGS = \ + -lpthread + +mt_extracttest1_SOURCES = \ + mt_extracttest1.c +mt_extracttest1_LDFLAGS = \ + -lpthread + +mt_extracttest2_SOURCES = \ + mt_extracttest2.c +mt_extracttest2_LDFLAGS = \ + -lpthread + + diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -349,15 +349,38 @@ append_to_dir (const char *path, { char *ret; +#ifdef MINGW + if (fname[0] == '\\') + fname++; +#else + if (fname[0] == '/') + fname++; +#endif ret = malloc (strlen (path) + strlen(fname) + 2); - sprintf (ret, + #ifdef MINGW - "%s\%s", + if (path[strlen(path)-1] == '\\') + sprintf (ret, + "%s%s", + path, + fname); + else + sprintf (ret, + "%s\%s", + path, + fname); #else + if (path[strlen(path)-1] == '/') + sprintf (ret, + "%s%s", + path, + fname); + else + sprintf (ret, "%s/%s", -#endif path, fname); +#endif return ret; } @@ -406,12 +429,15 @@ get_installation_paths (PathProcessor pp, #endif if (prefix == NULL) prefix = get_path_from_PATH(); + pp (pp_cls, PLUGININSTDIR); if (prefix == NULL) return; if (prefix != NULL) { path = append_to_dir (prefix, PLUGINDIR); - pp (pp_cls, path); + if (0 != strcmp (path, + PLUGININSTDIR)) + pp (pp_cls, path); free (path); free (prefix); return; @@ -458,7 +484,7 @@ find_plugin_in_path (void *cls, continue; /* only load '.so' and '.dll' */ sym_name = strstr (ent->d_name, "_"); if (sym_name == NULL) - continue; + continue; sym_name++; sym = strdup (sym_name); dot = strstr (sym, "."); @@ -751,7 +777,12 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList * prev, libname = find_plugin (library); if (libname == NULL) - return prev; + { + fprintf (stderr, + "Could not load `%s'\n", + library); + return prev; + } result = calloc (1, sizeof (struct EXTRACTOR_PluginList)); result->next = prev; result->short_libname = strdup (library); diff --git a/src/test/fuzz_default.sh b/src/main/fuzz_default.sh diff --git a/src/main/fuzz_thumbnail.sh b/src/main/fuzz_thumbnail.sh @@ -0,0 +1,39 @@ +#!/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/*.gif $testdatadir/*.png $testdatadir/*.ppm +do + if test -f "$file" + then + tmpfile=`mktemp extractortmp.XXXXXX` || exit 1 + seed=$ZZSTARTSEED + trap "echo $tmpfile caused SIGSEGV ; exit 1" SEGV + while [ $seed -lt $ZZSTOPSEED ] + do +# echo "file $file seed $seed" + zzuf -c -s $seed cat "$file" > "$tmpfile" + if ! "$bindir/extract" -n -l thumbnailffmpeg:thumbnailqt:thumbnailgtk "$tmpfile" > /dev/null + then + echo "$tmpfile caused error exit" + exit 1 + fi + seed=`expr $seed + 1` + done + rm -f "$tmpfile" + fi +done + diff --git a/src/main/test_plugin_load_multi.c b/src/main/test_plugin_load_multi.c @@ -0,0 +1,38 @@ +/** + * @file main/test_plugin_load_multi.c + * @brief testcase for libextractor plugin loading that loads the same + * plugins multiple times! + * @author Christian Grothoff + */ + +#include "platform.h" +#include "extractor.h" + +static int +testLoadPlugins () +{ + struct EXTRACTOR_PluginList *el1; + struct EXTRACTOR_PluginList *el2; + + el1 = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); + el2 = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); + if ((el1 == NULL) || (el2 == NULL)) + { + fprintf (stderr, + "Failed to load default plugins!\n"); + return 1; + } + EXTRACTOR_plugin_remove_all (el1); + EXTRACTOR_plugin_remove_all (el2); + return 0; +} + +int +main (int argc, char *argv[]) +{ + int ret = 0; + + ret += testLoadPlugins (); + ret += testLoadPlugins (); + return ret; +} diff --git a/src/main/test_plugin_loading.c b/src/main/test_plugin_loading.c @@ -0,0 +1,40 @@ +/** + * @file main/test_plugin_loading.c + * @brief testcase for dynamic loading and unloading of plugins + */ +#include "platform.h" +#include "extractor.h" + +int +main (int argc, char *argv[]) +{ + struct EXTRACTOR_PluginList *arg; + + /* do some load/unload tests */ + arg = EXTRACTOR_plugin_add (NULL, "mime", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); + arg = EXTRACTOR_plugin_add (arg, "png", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); + arg = EXTRACTOR_plugin_add (arg, "zip", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); + arg = EXTRACTOR_plugin_remove (arg, "mime"); + arg = EXTRACTOR_plugin_remove (arg, "zip"); + arg = EXTRACTOR_plugin_remove (arg, "png"); + if (arg != NULL) + { + fprintf (stderr, + "add-remove test failed!\n"); + return -1; + } + + arg = EXTRACTOR_plugin_add (NULL, "mime", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); + arg = EXTRACTOR_plugin_add (arg, "png", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); + arg = EXTRACTOR_plugin_add (arg, "zip", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); + arg = EXTRACTOR_plugin_remove (arg, "zip"); + arg = EXTRACTOR_plugin_remove (arg, "mime"); + arg = EXTRACTOR_plugin_remove (arg, "png"); + if (arg != NULL) + { + fprintf (stderr, + "add-remove test failed!\n"); + return -1; + } + return 0; +} diff --git a/src/main/test_trivial.c b/src/main/test_trivial.c @@ -0,0 +1,35 @@ +/** + * @file main/test_trivial.c + * @brief trivial testcase for libextractor plugin loading + * @author Christian Grothoff + */ +#include "platform.h" +#include "extractor.h" + +static int +testLoadPlugins (enum EXTRACTOR_Options policy) +{ + struct EXTRACTOR_PluginList *pl; + + pl = EXTRACTOR_plugin_add_defaults (policy); + if (pl == NULL) + { + fprintf (stderr, + "Failed to load default plugins!\n"); + return 1; + } + EXTRACTOR_plugin_remove_all (pl); + return 0; +} + +int +main (int argc, char *argv[]) +{ + int ret = 0; + + ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY); + ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY); + ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY); + ret += testLoadPlugins (EXTRACTOR_OPTION_OUT_OF_PROCESS_NO_RESTART); + return ret; +} diff --git a/src/test/Makefile.am b/src/test/Makefile.am @@ -10,7 +10,7 @@ LDADD = \ $(top_builddir)/src/main/libextractor.la if HAVE_ZZUF -fuzz_tests=fuzz_default.sh fuzz_thumbnail.sh + fuzz_tests=fuzz_default.sh fuzz_thumbnail.sh endif TESTS_ENVIRONMENT = testdatadir=$(top_srcdir)/test diff --git a/src/test/fuzz_thumbnail.sh b/src/test/fuzz_thumbnail.sh @@ -1,39 +0,0 @@ -#!/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/*.gif $testdatadir/*.png $testdatadir/*.ppm -do - if test -f "$file" - then - tmpfile=`mktemp extractortmp.XXXXXX` || exit 1 - seed=$ZZSTARTSEED - trap "echo $tmpfile caused SIGSEGV ; exit 1" SEGV - while [ $seed -lt $ZZSTOPSEED ] - do -# echo "file $file seed $seed" - zzuf -c -s $seed cat "$file" > "$tmpfile" - if ! "$bindir/extract" -n -l libextractor_thumbnail:libextractor_mime "$tmpfile" > /dev/null - then - echo "$tmpfile caused error exit" - exit 1 - fi - seed=`expr $seed + 1` - done - rm -f "$tmpfile" - fi -done - diff --git a/src/test/multiload.c b/src/test/multiload.c @@ -1,37 +0,0 @@ -/** - * @file test/multiload.c - * @brief testcase for libextractor plugin loading that loads the same - * plugins multiple times! - * @author Christian Grothoff - */ - -#include "platform.h" -#include "extractor.h" - -static int -testLoadPlugins () -{ - EXTRACTOR_ExtractorList *el1; - EXTRACTOR_ExtractorList *el2; - - el1 = EXTRACTOR_loadDefaultLibraries (); - el2 = EXTRACTOR_loadDefaultLibraries (); - if ((el1 == NULL) || (el2 == NULL)) - { - printf ("Failed to load default plugins!\n"); - return 1; - } - EXTRACTOR_removeAll (el1); - EXTRACTOR_removeAll (el2); - return 0; -} - -int -main (int argc, char *argv[]) -{ - int ret = 0; - - ret += testLoadPlugins (); - ret += testLoadPlugins (); - return ret; -} diff --git a/src/test/plugintest.c b/src/test/plugintest.c @@ -1,78 +0,0 @@ -/** - * @file test/plugintest.c - * @brief testcase for dynamic loading and unloading of plugins - */ -#include "platform.h" -#include "extractor.h" - -int -main (int argc, char *argv[]) -{ - int i; - EXTRACTOR_ExtractorList *arg; - EXTRACTOR_KeywordList *list; - EXTRACTOR_KeywordList *list1; - - /* do some loading and unloading */ - for (i = 0; i < 10; i++) - { - arg = EXTRACTOR_loadDefaultLibraries (); - EXTRACTOR_removeAll (arg); - } - - /* do some load/unload tests */ - arg = EXTRACTOR_addLibrary (NULL, "libextractor_split"); - arg = EXTRACTOR_addLibrary (arg, "libextractor_mime"); - arg = EXTRACTOR_addLibrary (arg, "libextractor_filename"); - arg = EXTRACTOR_removeLibrary (arg, "libextractor_mime"); - arg = EXTRACTOR_removeLibrary (arg, "libextractor_split"); - arg = EXTRACTOR_removeLibrary (arg, "libextractor_filename"); - if (arg != NULL) - { - printf ("add-remove test failed!\n"); - return -1; - } - - arg = EXTRACTOR_addLibrary (NULL, "libextractor_split"); - arg = EXTRACTOR_addLibrary (arg, "libextractor_mime"); - arg = EXTRACTOR_addLibrary (arg, "libextractor_filename"); - arg = EXTRACTOR_removeLibrary (arg, "libextractor_mime"); - arg = EXTRACTOR_removeLibrary (arg, "libextractor_filename"); - arg = EXTRACTOR_removeLibrary (arg, "libextractor_split"); - if (arg != NULL) - { - printf ("add-remove test failed!\n"); - return -1; - } - - arg = EXTRACTOR_loadConfigLibraries (NULL, "libextractor_filename"); - arg = EXTRACTOR_loadConfigLibraries (arg, "-libextractor_split"); - list = EXTRACTOR_getKeywords (arg, "/etc/resolv.conf"); - if (4 != EXTRACTOR_countKeywords (list)) - { - printf ("Invalid number of keywords (4 != %d)\n", - EXTRACTOR_countKeywords (list)); - return -1; - } - i = 0; - list1 = list; - while (list1 != NULL) - { - if ((strcmp (list1->keyword, "resolv") == 0) || - (strcmp (list1->keyword, "conf") == 0) || - (strcmp (list1->keyword, "resolv.conf") == 0)) - i++; - list1 = list1->next; - } - if (i != 3) - { - printf ("Wrong keyword extracted.\n"); - EXTRACTOR_printKeywords (stderr, list); - return -1; - } - - EXTRACTOR_removeAll (arg); - EXTRACTOR_freeKeywords (list); - - return 0; -} diff --git a/src/test/trivialtest.c b/src/test/trivialtest.c @@ -1,32 +0,0 @@ -/** - * @file test/trivialtest.c - * @brief trivial testcase for libextractor plugin loading - * @author Christian Grothoff - */ -#include "platform.h" -#include "extractor.h" - -static int -testLoadPlugins () -{ - EXTRACTOR_ExtractorList *el; - - el = EXTRACTOR_loadDefaultLibraries (); - if (el == NULL) - { - printf ("Failed to load default plugins!\n"); - return 1; - } - EXTRACTOR_removeAll (el); - return 0; -} - -int -main (int argc, char *argv[]) -{ - int ret = 0; - - ret += testLoadPlugins (); - ret += testLoadPlugins (); - return ret; -}