[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7284 - Extractor/src/test
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7284 - Extractor/src/test |
Date: |
Fri, 20 Jun 2008 08:31:56 -0600 (MDT) |
Author: holindho
Date: 2008-06-20 08:31:56 -0600 (Fri, 20 Jun 2008)
New Revision: 7284
Added:
Extractor/src/test/multithreadtest.c
Modified:
Extractor/src/test/Makefile.am
Log:
add multithread testcase
Modified: Extractor/src/test/Makefile.am
===================================================================
--- Extractor/src/test/Makefile.am 2008-06-20 13:33:16 UTC (rev 7283)
+++ Extractor/src/test/Makefile.am 2008-06-20 14:31:56 UTC (rev 7284)
@@ -4,7 +4,7 @@
ELIBDIR = $(libdir)
-AM_CFLAGS = -DELIBDIR=\"$(ELIBDIR)\" -DPLUGIN_PATH="\"${libdir}\""
+AM_CFLAGS = -DELIBDIR=\"$(ELIBDIR)\" -DPLUGIN_PATH="\"${libdir}\""
-DTESTDATADIR="\"$(top_srcdir)/test\""
LDADD = \
$(top_builddir)/src/main/libextractor.la
@@ -13,7 +13,8 @@
trivialtest \
keywordlisttest \
plugintest \
- multiload
+ multiload \
+ multithreadtest
TESTS = $(check_PROGRAMS)
@@ -29,3 +30,8 @@
multiload_SOURCES = \
multiload.c
+multithreadtest_SOURCES = \
+ multithreadtest.c
+multithreadtest_LDFLAGS = \
+ -lpthread
+
Added: Extractor/src/test/multithreadtest.c
===================================================================
--- Extractor/src/test/multithreadtest.c (rev 0)
+++ Extractor/src/test/multithreadtest.c 2008-06-20 14:31:56 UTC (rev
7284)
@@ -0,0 +1,169 @@
+/**
+ * @file test/multithreadtest.c
+ * @brief test extractor plugins from multiple threads simultaneously
+ * @author Heikki Lindholm
+ */
+#include "platform.h"
+#include "extractor.h"
+#include <pthread.h>
+
+struct FileData
+{
+ const char *filename;
+ int use_thumbnailer;
+};
+
+struct TaskData
+{
+ int id;
+ const struct FileData *file;
+};
+
+static int done = 0;
+static int failed = 0;
+
+pthread_mutex_t reference_lock = PTHREAD_MUTEX_INITIALIZER;
+static EXTRACTOR_KeywordList *reference_list;
+
+static int
+compare_keywords_to_ref (EXTRACTOR_KeywordList * list)
+{
+ EXTRACTOR_KeywordList *ptr1, *ptr2;
+ unsigned int cnt;
+ int *match;
+ int i;
+
+ cnt = EXTRACTOR_countKeywords (list);
+
+ pthread_mutex_lock (&reference_lock);
+
+ if (cnt != EXTRACTOR_countKeywords (reference_list))
+ {
+ pthread_mutex_unlock (&reference_lock);
+ return -1;
+ }
+
+ match = alloca (cnt * sizeof (int));
+ memset (match, 0x00, cnt * sizeof (int));
+ ptr1 = list;
+ while (ptr1 != NULL)
+ {
+ int found;
+ found = 0;
+ ptr2 = reference_list;
+ i = 0;
+ while (ptr2 != NULL)
+ {
+ if (ptr2->keywordType == ptr1->keywordType &&
+ strcmp (ptr2->keyword, ptr1->keyword) == 0 && match[i] == 0)
+ {
+ found = 1;
+ match[i] = 1;
+ break;
+ }
+ i++;
+ ptr2 = ptr2->next;
+ }
+ if (found == 0)
+ break;
+ ptr1 = ptr1->next;
+ }
+
+ pthread_mutex_unlock (&reference_lock);
+ for (i = 0; i < cnt; i++)
+ if (match[i] == 0)
+ return -1;
+
+ return 0;
+}
+
+static EXTRACTOR_KeywordList *
+get_keywords_for_file (struct FileData *file)
+{
+ EXTRACTOR_ExtractorList *el;
+ EXTRACTOR_KeywordList *list;
+
+ if (file->use_thumbnailer)
+ {
+ el = EXTRACTOR_addLibrary (NULL, "libextractor_mime");
+ el = EXTRACTOR_loadConfigLibraries (el, "-libextractor_thumbnail");
+ }
+ else
+ {
+ el = EXTRACTOR_loadDefaultLibraries ();
+ }
+ if (el == NULL)
+ {
+ printf ("ERROR: failed to load plugins!\n");
+ return NULL;
+ }
+ list = EXTRACTOR_getKeywords (el, file->filename);
+ /*EXTRACTOR_printKeywords (stderr, list); */
+ EXTRACTOR_removeAll (el);
+
+ return list;
+}
+
+static void *
+test_plugins (void *arg)
+{
+ struct TaskData *td = (struct TaskData *)arg;
+ while (!done)
+ {
+ EXTRACTOR_KeywordList *list;
+
+ list = get_keywords_for_file (td->file);
+
+ if (list == NULL || compare_keywords_to_ref (list) != 0)
+ {
+ printf ("ERROR: thread id %d failed keyword comparison!\n", td->id);
+ failed = 1;
+ }
+ if (list != NULL)
+ EXTRACTOR_freeKeywords (list);
+ }
+ return 0;
+}
+
+static const struct FileData files[] = {
+ { TESTDATADIR "/CatherineCub2.png", 1 },
+ { NULL, 0 }
+};
+
+int
+main (int argc, char *argv[])
+{
+ int num_tasks = 10;
+ pthread_t task_list[num_tasks];
+ struct TaskData td[num_tasks];
+ int ret = 0;
+ int i;
+
+ reference_list = get_keywords_for_file (&files[0]);
+
+ for (i = 0; i < num_tasks; i++)
+ {
+ td[i].id = i;
+ td[i].file = &files[0];
+ ret = pthread_create (&task_list[i], NULL, test_plugins, &td[i]);
+ if (ret != 0)
+ {
+ printf ("ERROR: pthread_create failed for thread %d\n", i);
+ num_tasks = i;
+ done = 1;
+ break;
+ }
+ }
+ if (!done)
+ sleep (20);
+ done = 1;
+ for (i = 0; i < num_tasks; i++)
+ {
+ if (pthread_join (task_list[i], NULL) != 0)
+ printf ("WARNING: pthread_join failed for thread %d\n", i);
+ }
+
+ if (reference_list != NULL)
+ EXTRACTOR_freeKeywords (reference_list);
+ return failed;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7284 - Extractor/src/test,
gnunet <=