gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r7309 - Extractor/src/test


From: gnunet
Subject: [GNUnet-SVN] r7309 - Extractor/src/test
Date: Sun, 22 Jun 2008 23:49:49 -0600 (MDT)

Author: holindho
Date: 2008-06-22 23:49:49 -0600 (Sun, 22 Jun 2008)
New Revision: 7309

Added:
   Extractor/src/test/mt_extracttest1.c
   Extractor/src/test/mt_extracttest2.c
   Extractor/src/test/mt_plugintest1.c
   Extractor/src/test/mt_plugintest2.c
Removed:
   Extractor/src/test/multithreadtest.c
Modified:
   Extractor/src/test/Makefile.am
Log:
more fine-grained multithread tests


Modified: Extractor/src/test/Makefile.am
===================================================================
--- Extractor/src/test/Makefile.am      2008-06-23 00:28:02 UTC (rev 7308)
+++ Extractor/src/test/Makefile.am      2008-06-23 05:49:49 UTC (rev 7309)
@@ -14,7 +14,10 @@
  keywordlisttest \
  plugintest \
  multiload \
- multithreadtest
+ mt_plugintest1 \
+ mt_plugintest2 \
+ mt_extracttest1 \
+ mt_extracttest2
 
 TESTS = $(check_PROGRAMS)
 
@@ -30,8 +33,24 @@
 multiload_SOURCES = \
  multiload.c 
 
-multithreadtest_SOURCES = \
- multithreadtest.c 
-multithreadtest_LDFLAGS = \
+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
+
+

Added: Extractor/src/test/mt_extracttest1.c
===================================================================
--- Extractor/src/test/mt_extracttest1.c                                (rev 0)
+++ Extractor/src/test/mt_extracttest1.c        2008-06-23 05:49:49 UTC (rev 
7309)
@@ -0,0 +1,160 @@
+/**
+ * @file test/mt_extracttest1.c
+ * @brief test keyword extraction from multiple threads simultaneously
+ * @author Heikki Lindholm
+ */
+#include "platform.h"
+#include "extractor.h"
+#include <pthread.h>
+
+struct TaskData
+{
+  int id;
+  const char *filename;
+};
+
+static volatile int done = 0;
+static volatile 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 (const char *filename)
+{
+  EXTRACTOR_ExtractorList *el;
+  EXTRACTOR_KeywordList *list;
+
+  el = EXTRACTOR_loadDefaultLibraries ();
+  if (el == NULL)
+    {
+      printf ("ERROR: failed to load plugins!\n");
+      return NULL;
+    }
+  errno = 0;
+  list = EXTRACTOR_getKeywords (el, filename);
+  if (errno != 0) {
+    printf("ERROR: EXTRACTOR_getKeywords: %s\n", strerror(errno));
+  }
+  /*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->filename);
+
+      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 char *filename = TESTDATADIR "/text2.sxw";
+
+#define TEST_SECS 10
+
+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;
+
+  printf("testing with '%s' for %d seconds\n", filename, TEST_SECS);
+  reference_list = get_keywords_for_file (filename);
+
+    for (i = 0; i < num_tasks; i++)
+      {
+        td[i].id = i;
+        td[i].filename = filename;
+        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 (TEST_SECS);
+    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;
+}

Added: Extractor/src/test/mt_extracttest2.c
===================================================================
--- Extractor/src/test/mt_extracttest2.c                                (rev 0)
+++ Extractor/src/test/mt_extracttest2.c        2008-06-23 05:49:49 UTC (rev 
7309)
@@ -0,0 +1,190 @@
+/**
+ * @file test/mt_extracttest2.c
+ * @brief test keyword extraction from multiple threads simultaneously
+ * with multiple files and use thumbnail extractors as well
+ * @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 volatile int done = 0;
+static volatile 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 (const 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;
+    }
+  errno = 0;
+  list = EXTRACTOR_getKeywords (el, file->filename);
+  if (errno != 0) {
+    printf("ERROR: EXTRACTOR_getKeywords: %s\n", strerror(errno));
+  }
+  /*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 "/test.bmp", 0 },
+  { TESTDATADIR "/test.jpg", 0 },
+  { TESTDATADIR "/test.png", 0 },
+  { TESTDATADIR "/test.sxw", 0 },
+  { TESTDATADIR "/test.bmp", 1 },
+  { TESTDATADIR "/test.png", 1 },
+  { NULL, 0 }
+};
+
+#define TEST_SECS 10
+
+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;
+  int n;
+
+  n = 0;
+  while ((files[n].filename != NULL) && (!failed)) {
+    printf("testing with '%s' for %d seconds\n", files[n].filename, TEST_SECS);
+    reference_list = get_keywords_for_file (&files[n]);
+
+    for (i = 0; i < num_tasks; i++)
+      {
+        td[i].id = i;
+        td[i].file = &files[n];
+        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 (TEST_SECS);
+    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);
+      }
+
+    done = 0;
+    if (reference_list != NULL)
+      EXTRACTOR_freeKeywords (reference_list);
+  
+    n++;
+  }
+
+  return failed;
+}

Added: Extractor/src/test/mt_plugintest1.c
===================================================================
--- Extractor/src/test/mt_plugintest1.c                         (rev 0)
+++ Extractor/src/test/mt_plugintest1.c 2008-06-23 05:49:49 UTC (rev 7309)
@@ -0,0 +1,101 @@
+/**
+ * @file test/mt-plugintest1.c
+ * @brief test extractor plugin load/unload from multiple threads
+ * simultaneously
+ * @author Heikki Lindholm
+ */
+#include "platform.h"
+#include "extractor.h"
+#include <pthread.h>
+
+struct TaskData
+{
+  int id;
+};
+
+static volatile int done = 0;
+static volatile int failed = 0;
+
+static void *
+test_plugins (void *arg)
+{
+  struct TaskData *td = (struct TaskData *) arg;
+  EXTRACTOR_ExtractorList *el;
+  int i;
+
+  while (!done)
+    {
+      /* do some loading and unloading */
+      for (i = 0; i < 10; i++)
+        {
+          el = EXTRACTOR_loadDefaultLibraries ();
+          EXTRACTOR_removeAll (el);
+        }
+
+      /* do some load/unload tests */
+      el = EXTRACTOR_addLibrary (NULL, "libextractor_split");
+      el = EXTRACTOR_addLibrary (el, "libextractor_mime");
+      el = EXTRACTOR_addLibrary (el, "libextractor_filename");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_mime");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_split");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_filename");
+      if (el != NULL)
+        {
+          printf ("add-remove test (1) failed in thread %d!\n", td->id);
+          failed = 1;
+        }
+
+      el = EXTRACTOR_addLibrary (NULL, "libextractor_split");
+      el = EXTRACTOR_addLibrary (el, "libextractor_mime");
+      el = EXTRACTOR_addLibrary (el, "libextractor_filename");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_mime");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_filename");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_split");
+      if (el != NULL)
+        {
+          printf ("add-remove test (2) failed in thread %d!\n", td->id);
+          failed = 1;
+        }
+
+      el = EXTRACTOR_loadConfigLibraries (NULL, "libextractor_filename");
+      el = EXTRACTOR_loadConfigLibraries (el, "-libextractor_split");
+      EXTRACTOR_removeAll (el);
+    }
+  return 0;
+}
+
+#define TEST_SECS 10
+
+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;
+
+  printf("testing for %d seconds\n", TEST_SECS);
+  for (i = 0; i < num_tasks; i++)
+    {
+      td[i].id = i;
+      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 (TEST_SECS);
+  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);
+    }
+
+  return failed;
+}

Added: Extractor/src/test/mt_plugintest2.c
===================================================================
--- Extractor/src/test/mt_plugintest2.c                         (rev 0)
+++ Extractor/src/test/mt_plugintest2.c 2008-06-23 05:49:49 UTC (rev 7309)
@@ -0,0 +1,78 @@
+/**
+ * @file test/mt-plugintest1.c
+ * @brief test extractor plugin load/unload from multiple threads
+ * simultaneously - thumbnailer plugins test
+ * @author Heikki Lindholm
+ */
+#include "platform.h"
+#include "extractor.h"
+#include <pthread.h>
+
+struct TaskData
+{
+  int id;
+};
+
+static volatile int done = 0;
+static volatile int failed = 0;
+
+static void *
+test_plugins (void *arg)
+{
+  struct TaskData *td = (struct TaskData *) arg;
+  EXTRACTOR_ExtractorList *el;
+  int i;
+
+  while (!done)
+    {
+      /* do some load/unload tests */
+      el = EXTRACTOR_addLibrary (NULL, "libextractor_thumbnailgtk");
+      el = EXTRACTOR_addLibrary (el, "libextractor_thumbnailqt");
+      el = EXTRACTOR_addLibrary (el, "libextractor_thumbnailffmpeg");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_thumbnailffmpeg");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_thumbnailqt");
+      el = EXTRACTOR_removeLibrary (el, "libextractor_thumbnailgtk");
+      if (el != NULL)
+        {
+          printf ("add-remove test failed in thread %d!\n", td->id);
+          failed = 1;
+        }
+    }
+  return 0;
+}
+
+#define TEST_SECS 10
+
+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;
+
+  printf("testing for %d seconds\n", TEST_SECS);
+  for (i = 0; i < num_tasks; i++)
+    {
+      td[i].id = i;
+      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 (TEST_SECS);
+  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);
+    }
+
+  return failed;
+}

Deleted: Extractor/src/test/multithreadtest.c
===================================================================
--- Extractor/src/test/multithreadtest.c        2008-06-23 00:28:02 UTC (rev 
7308)
+++ Extractor/src/test/multithreadtest.c        2008-06-23 05:49:49 UTC (rev 
7309)
@@ -1,189 +0,0 @@
-/**
- * @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 volatile int done = 0;
-static volatile 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 (const 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;
-    }
-  errno = 0;
-  list = EXTRACTOR_getKeywords (el, file->filename);
-  if (errno != 0) {
-    printf("ERROR: EXTRACTOR_getKeywords: %s\n", strerror(errno));
-  }
-  /*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 "/test.bmp", 0 },
-  { TESTDATADIR "/test.jpg", 0 },
-  { TESTDATADIR "/test.png", 0 },
-  { TESTDATADIR "/test.sxw", 0 },
-  { TESTDATADIR "/test.bmp", 1 },
-  { TESTDATADIR "/test.png", 1 },
-  { NULL, 0 }
-};
-
-#define TEST_SECS 10
-
-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;
-  int n;
-
-  n = 0;
-  while ((files[n].filename != NULL) && (!failed)) {
-    printf("testing with '%s' for %d seconds\n", files[n].filename, TEST_SECS);
-    reference_list = get_keywords_for_file (&files[n]);
-
-    for (i = 0; i < num_tasks; i++)
-      {
-        td[i].id = i;
-        td[i].file = &files[n];
-        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 (TEST_SECS);
-    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);
-      }
-
-    done = 0;
-    if (reference_list != NULL)
-      EXTRACTOR_freeKeywords (reference_list);
-  
-    n++;
-  }
-
-  return failed;
-}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]