summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2012-07-18 17:25:06 +0200
committerAndrea Canciani <ranma42@gmail.com>2012-07-31 16:06:33 +0200
commitca41228a66fe9bbec354cdef034c144ce1619793 (patch)
tree535efb9b0738e153cbd898b42ceb9c908766d6ea
parent77db90242f7b7f12c5792480a10eb3a448e6c55f (diff)
test: Add dynamic-leak-test
Test if loading/unloading pixman leaks data structures. Currently pixman_implementation_t are leaked.
-rw-r--r--.gitignore1
-rw-r--r--configure.ac5
-rw-r--r--test/Makefile.am2
-rw-r--r--test/Makefile.sources1
-rw-r--r--test/dynamic-leak-test.c171
5 files changed, 180 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 08c9834..a839864 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,6 +57,7 @@ test/composite
test/composite-test
test/composite-traps-test
test/convolution-test
+test/dynamic-leak-test
test/fetch-test
test/glyph-test
test/gradient-crash-test
diff --git a/configure.ac b/configure.ac
index 264e99e..1598a30 100644
--- a/configure.ac
+++ b/configure.ac
@@ -858,6 +858,11 @@ if test x$have_setrlimit = xyes && test x$have_sys_time_h = xyes && test x$have_
AC_DEFINE(HAVE_SETRLIMIT, 1, [Whether we have setrlimit()])
fi
+AC_CHECK_LIB(dl, dlsym, have_dlsym=yes, have_dlsym=no)
+if test x$have_dlsym = xyes; then
+ AC_DEFINE(HAVE_DLSYM, 1, [Whether we have dlsym()])
+fi
+
dnl =====================================
dnl Thread local storage
diff --git a/test/Makefile.am b/test/Makefile.am
index aa3f400..6e94323 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -11,3 +11,5 @@ noinst_LTLIBRARIES = libutils.la
noinst_PROGRAMS = $(TESTPROGRAMS) $(BENCHMARKS)
TESTS = $(TESTPROGRAMS)
+
+dynamic_leak_test_LDADD = -ldl
diff --git a/test/Makefile.sources b/test/Makefile.sources
index dd37c43..971837f 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -11,6 +11,7 @@ TESTPROGRAMS = \
scaling-crash-test \
scaling-helpers-test \
gradient-crash-test \
+ dynamic-leak-test \
tls-leak-test \
region-contains-test \
alphamap \
diff --git a/test/dynamic-leak-test.c b/test/dynamic-leak-test.c
new file mode 100644
index 0000000..2133e03
--- /dev/null
+++ b/test/dynamic-leak-test.c
@@ -0,0 +1,171 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "limitmem.h"
+#include "utils.h"
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#elif HAVE_DLSYM
+#include <dlfcn.h>
+#endif
+
+
+#define IMPL_SIZE sizeof (pixman_implementation_t)
+
+#define MAX_SIZE (16 * 1024 * 1024)
+#define MAX_ITERS ((MAX_SIZE + IMPL_SIZE) / IMPL_SIZE)
+
+#define WIDTH 16
+#define HEIGHT 16
+
+static uint32_t *dest;
+
+static
+pixman_image_t * (*dyn_pixman_image_create_bits) (pixman_format_code_t format,
+ int width,
+ int height,
+ uint32_t *bits,
+ int rowstride_bytes);
+
+static
+pixman_image_t * (*dyn_pixman_image_create_solid_fill) (pixman_color_t *color);
+
+static
+pixman_bool_t (*dyn_pixman_image_unref) (pixman_image_t *image);
+
+static
+void (*dyn_pixman_image_composite) (pixman_op_t op,
+ pixman_image_t *src,
+ pixman_image_t *mask,
+ pixman_image_t *dest,
+ int16_t src_x,
+ int16_t src_y,
+ int16_t mask_x,
+ int16_t mask_y,
+ int16_t dest_x,
+ int16_t dest_y,
+ uint16_t width,
+ uint16_t height);
+
+#ifdef _WIN32
+static HMODULE dll;
+
+static int dynamic_load (void)
+{
+ dll = LoadLibrary ("pixman-1.dll");
+
+ if (dll == NULL)
+ {
+ fprintf (stderr, "Dynamic loading of pixman-1.dll failed.\n");
+ return -1;
+ }
+
+ dyn_pixman_image_create_bits = (void *) GetProcAddress (dll, "pixman_image_create_bits");
+ dyn_pixman_image_create_solid_fill = (void *) GetProcAddress (dll, "pixman_image_create_solid_fill");
+ dyn_pixman_image_unref = (void *) GetProcAddress (dll, "pixman_image_unref");
+ dyn_pixman_image_composite = (void *) GetProcAddress (dll, "pixman_image_composite");
+
+ return 0;
+}
+
+static void dynamic_unload (void)
+{
+ FreeLibrary (dll);
+
+ dll = NULL;
+ dyn_pixman_image_create_bits = NULL;
+ dyn_pixman_image_unref = NULL;
+ dyn_pixman_image_composite = NULL;
+}
+
+#elif HAVE_DLSYM
+static void *shared_object;
+
+static int dynamic_load (void)
+{
+ shared_object = dlopen ("../pixman/.libs/libpixman-1.so", RTLD_LAZY);
+ if (shared_object == NULL)
+ shared_object = dlopen ("../pixman/.libs/libpixman-1.dylib", RTLD_LAZY);
+
+ if (shared_object == NULL)
+ {
+ fprintf (stderr, "Dynamic loading of pixman failed.\n");
+ return -1;
+ }
+
+ dyn_pixman_image_create_bits = dlsym (shared_object, "pixman_image_create_bits");
+ dyn_pixman_image_create_solid_fill = dlsym (shared_object, "pixman_image_create_solid_fill");
+ dyn_pixman_image_unref = dlsym (shared_object, "pixman_image_unref");
+ dyn_pixman_image_composite = dlsym (shared_object, "pixman_image_composite");
+
+ return 0;
+}
+
+static void dynamic_unload (void)
+{
+ dlclose (shared_object);
+
+ shared_object = NULL;
+ dyn_pixman_image_create_bits = NULL;
+ dyn_pixman_image_unref = NULL;
+ dyn_pixman_image_composite = NULL;
+}
+
+#else
+static int dynamic_load (void)
+{
+ fprintf (stderr, "Dynamic loading is not supported.\n");
+ return -1;
+}
+
+static void dynamic_unload (void)
+{
+}
+#endif
+
+int
+main (int argc, char **argv)
+{
+ pixman_image_t *dest_img, *src_img;
+ pixman_color_t color;
+ int i, ret = 0;
+
+ if (limitmem (MAX_SIZE))
+ return -1;
+
+ dest = malloc (WIDTH * HEIGHT * 4);
+
+ color.alpha = 45678;
+ color.red = 12345;
+ color.green = 23456;
+ color.blue = 34567;
+
+ for (i = 0; ret == 0 && i < MAX_ITERS; i++)
+ {
+ if (dynamic_load ())
+ {
+ ret = -1;
+ break;
+ }
+
+ dest_img = dyn_pixman_image_create_bits (PIXMAN_a8r8g8b8,
+ WIDTH, HEIGHT,
+ dest,
+ WIDTH * 4);
+ src_img = dyn_pixman_image_create_solid_fill (&color);
+
+ dyn_pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dest_img,
+ 0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
+
+ dyn_pixman_image_unref (src_img);
+ dyn_pixman_image_unref (dest_img);
+
+ dynamic_unload ();
+ }
+
+ free (dest);
+
+ return ret;
+}