[babl] tests: Add pthread based concurrency stress test for babl_fish()



commit 539bfd1487015c50f5ab90f4bcc48ee0a2363039
Author: Martin Nordholts <martinn src gnome org>
Date:   Thu Nov 19 19:59:10 2009 +0100

    tests: Add pthread based concurrency stress test for babl_fish()
    
    Add a test that runs a bunch of pthread threads, all trying to use
    babl_fish() at the same time. This test currently fails and it is the
    goal of bug 587675 to make it pass.
    
    The cause of the failure is the static variables in babl-fish-path.c.
    In particular 'current_path' clearly needs to be moved to some
    instance variable.

 tests/.gitignore                |    1 +
 tests/Makefile.am               |    4 +-
 tests/concurrency-stress-test.c |   82 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 1 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index be9ba90..dabfa78 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -6,6 +6,7 @@
 /babl_class_name*
 /babl_fish_path_dhtml*
 /babl_fish_path_fitness*
+/concurrency-stress-test*
 /conversions*
 /float_to_u8
 /formats*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 360906b..5b06374 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,11 +6,13 @@ TESTS =				\
 	sanity			\
 	babl_class_name		\
 	types			\
-	models	
+	models			\
+	concurrency-stress-test 
 
 TESTS_ENVIRONMENT = BABL_PATH=$(top_builddir)/extensions/.libs
 
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
+AM_LDFLAGS  = -pthread
 
 LDADD = $(top_builddir)/babl/libbabl- BABL_API_VERSION@.la \
 	$(MATH_LIB)
diff --git a/tests/concurrency-stress-test.c b/tests/concurrency-stress-test.c
new file mode 100644
index 0000000..20d31b4
--- /dev/null
+++ b/tests/concurrency-stress-test.c
@@ -0,0 +1,82 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2009 Martin Nordholts
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <math.h>
+#include <pthread.h>
+
+#include "babl.h"
+
+
+#define N_THREADS               10
+#define N_ITERATIONS_PER_THREAD 100
+
+
+static void *
+babl_fish_path_stress_test_thread_func (void *not_used)
+{
+  int i;
+
+  for (i = 0; i < N_ITERATIONS_PER_THREAD; i++)
+    {
+      /* Try to get a fish with an as complex conversion path as
+       * possible
+       */
+      Babl *fish = babl_fish ("R'G'B'A u16", "YA double");
+
+      /* Just do something random with the fish */
+      babl_get_name (fish);
+    }
+
+  return NULL;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  pthread_t threads[N_THREADS];
+  int       i;
+
+  babl_init ();
+
+  /* Run a few threads at the same time */
+  for (i = 0; i < N_THREADS; i++)
+    {
+      pthread_create (&threads[i],
+                      NULL, /* attr */
+                      babl_fish_path_stress_test_thread_func,
+                      NULL /* arg */);
+     }
+
+  /* Wait for them all to finish */
+  for (i = 0; i < N_THREADS; i++)
+    {
+      pthread_join (threads[i],
+                    NULL /* thread_return */);
+    }
+
+  babl_exit ();
+
+  /* If we didn't crash we assume we're OK. We might want to add more
+   * asserts in the test later
+   */
+  return 0;
+}



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