[maemo-commits] [maemo-commits] r16262 - in projects/haf/trunk/sapwood: . tests

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Sep 29 14:13:58 EEST 2008
Author: herzi
Date: 2008-09-29 14:13:54 +0300 (Mon, 29 Sep 2008)
New Revision: 16262

Added:
   projects/haf/trunk/sapwood/tests/sapwood-wrapper
Modified:
   projects/haf/trunk/sapwood/ChangeLog
   projects/haf/trunk/sapwood/tests/Makefile.am
   projects/haf/trunk/sapwood/tests/double-free.c
Log:
2008-09-29  Sven Herzberg  <sven at imendio.com>

	Finally be able to reproduce the double free

	* tests/Makefile.am: properly set the compile flags for the testcase
	* tests/double-free.c (pixbuf_proto_get_socket),
	(pixbuf_proto_request), (sapwood_pixmap_get_for_file),
	(pixbuf_proto_unref_pixmap), (false_func), (main): implemented the
	test (with lots of copied and pasted code - needs more cleanup)
	* tests/sapwood-wrapper: added a wrapper script for the testcase
	execution


Modified: projects/haf/trunk/sapwood/ChangeLog
===================================================================
--- projects/haf/trunk/sapwood/ChangeLog	2008-09-29 11:13:48 UTC (rev 16261)
+++ projects/haf/trunk/sapwood/ChangeLog	2008-09-29 11:13:54 UTC (rev 16262)
@@ -1,5 +1,17 @@
 2008-09-29  Sven Herzberg  <sven at imendio.com>
 
+	Finally be able to reproduce the double free
+
+	* tests/Makefile.am: properly set the compile flags for the testcase
+	* tests/double-free.c (pixbuf_proto_get_socket),
+	(pixbuf_proto_request), (sapwood_pixmap_get_for_file),
+	(pixbuf_proto_unref_pixmap), (false_func), (main): implemented the
+	test (with lots of copied and pasted code - needs more cleanup)
+	* tests/sapwood-wrapper: added a wrapper script for the testcase
+	execution
+
+2008-09-29  Sven Herzberg  <sven at imendio.com>
+
 	Respect TESTS_ENVIRONMENT as "make check" usually does
 
 	* Makefile.decl: added TESTS_ENVIRONMENT to the test invocation

Modified: projects/haf/trunk/sapwood/tests/Makefile.am
===================================================================
--- projects/haf/trunk/sapwood/tests/Makefile.am	2008-09-29 11:13:48 UTC (rev 16261)
+++ projects/haf/trunk/sapwood/tests/Makefile.am	2008-09-29 11:13:54 UTC (rev 16262)
@@ -1,7 +1,14 @@
 include $(top_srcdir)/Makefile.decl
 
+AM_CPPFLAGS=-I$(top_srcdir)/protocol $(GTK_CFLAGS)
+LDADD=$(top_builddir)/protocol/libprotocol.la
+
+TESTS_ENVIRONMENT=./sapwood-wrapper
+
 noinst_PROGRAMS = $(TEST_PROGS)
 
 TEST_PROGS+=double-free
 double_free_SOURCES=double-free.c
+double_free_CPPFLAGS=$(AM_CPPFLAGS) $(GIO_CFLAGS) -I$(top_srcdir)/engine
+double_free_LDADD=$(LDADD) $(GIO_LIBS)
 

Modified: projects/haf/trunk/sapwood/tests/double-free.c
===================================================================
--- projects/haf/trunk/sapwood/tests/double-free.c	2008-09-29 11:13:48 UTC (rev 16261)
+++ projects/haf/trunk/sapwood/tests/double-free.c	2008-09-29 11:13:54 UTC (rev 16262)
@@ -23,10 +23,251 @@
  * if advised of the possibility of such damage.
  */
 
+#include <config.h>
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <gio/gio.h>
+#include <gtk/gtktestutils.h>
+#include "sapwood-pixmap.h"
+#include "sapwood-proto.h"
+
+#undef SAPWOOD_PIXMAP_ERROR
+#define SAPWOOD_PIXMAP_ERROR 0
+#define SAPWOOD_PIXMAP_ERROR_FAILED 0
+#define SAPWOOD_SERVER "sapwood-server"
+
+struct _SapwoodPixmap {
+  guint32    id;
+  gint       width;
+  gint       height;
+  GdkPixmap *pixmap[3][3];
+  GdkBitmap *pixmask[3][3];
+};
+
+/* FIXME: refactor this out into a libproto-client.la library for the engine
+ * and the test cases */
+static int
+pixbuf_proto_get_socket (GError **err)
+{
+  struct sockaddr_un  sun;
+  const char         *sock_path;
+  int                 fd;
+
+  fd = socket (PF_LOCAL, SOCK_STREAM, 0);
+  if (fd < 0)
+    {
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "socket: %s", strerror (errno));
+      return -1;
+    }
+
+  sock_path = sapwood_socket_path_get_default ();
+
+  memset (&sun, '\0', sizeof(sun));
+  sun.sun_family = AF_LOCAL;
+#ifdef HAVE_ABSTRACT_SOCKETS
+  strcpy (&sun.sun_path[1], sock_path);
+#else
+  strcpy (&sun.sun_path[0], sock_path);
+#endif
+  if (connect (fd, (struct sockaddr *)&sun, sizeof (sun)) < 0)
+    {
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "Failed to connect to sapwood server using `%s': %s\n\n"
+		   "\t`%s' MUST be started before applications",
+		   sock_path, strerror (errno),
+		   SAPWOOD_SERVER);
+      close (fd);
+      return -1;
+    }
+
+  return fd;
+}
+
+static gboolean
+pixbuf_proto_request (const char *req,
+                      ssize_t     reqlen,
+                      char       *rep,
+                      ssize_t     replen,
+                      GError    **err)
+{
+  static int fd = -1;
+  ssize_t    n;
+
+  if (fd == -1)
+    {
+      fd = pixbuf_proto_get_socket (err);
+      if (fd == -1)
+	return FALSE;
+    }
+
+  n = write (fd, req, reqlen);
+  if (n < 0)
+    {
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "write: %s", g_strerror (errno));
+      return FALSE;
+    }
+  else if (n != reqlen)
+    {
+      /* FIXME */
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "wrote %d of %d bytes", n, reqlen);
+      return FALSE;
+    }
+
+  if (!rep)
+    return TRUE;
+
+  n = read (fd, rep, replen);
+  if (n < 0)
+    {
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "read: %s", g_strerror (errno));
+      return FALSE;
+    }
+  else if (n != replen)
+    {
+      /* FIXME */
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "read %d, expected %d bytes", n, replen);
+      return FALSE;
+    }
+  else if (n != replen)
+    {
+      /* FIXME */
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "read %d, expected %d bytes", n, replen);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+SapwoodPixmap *
+sapwood_pixmap_get_for_file (const char *filename,
+                             int         border_left,
+                             int         border_right,
+                             int         border_top,
+                             int         border_bottom,
+                             GError    **err)
+{
+  SapwoodPixmap     *self;
+  char               buf[ sizeof(PixbufOpenRequest) + PATH_MAX + 1 ] = {0};
+  PixbufOpenRequest *req = (PixbufOpenRequest *) buf;
+  PixbufOpenResponse rep;
+  int                flen;
+
+  /* marshal request */
+  flen = g_strlcpy (req->filename, filename, PATH_MAX);
+  if (flen > PATH_MAX)
+    {
+      g_set_error (err, SAPWOOD_PIXMAP_ERROR, SAPWOOD_PIXMAP_ERROR_FAILED,
+		   "%s: filename too long", filename);
+      return NULL;
+    }
+
+  req->base.op       = PIXBUF_OP_OPEN;
+  req->base.length   = sizeof(*req) + flen + 1;
+  req->border_left   = border_left;
+  req->border_right  = border_right;
+  req->border_top    = border_top;
+  req->border_bottom = border_bottom;
+
+  if (!pixbuf_proto_request ((char*)req,  req->base.length,
+			     (char*)&rep, sizeof(rep), err))
+    return NULL;
+
+  /* unmarshal response */
+  self = g_new0 (SapwoodPixmap, 1);
+  self->id     = rep.id;
+  self->width  = rep.width;
+  self->height = rep.height;
+
+  return self;
+}
+
+static void
+pixbuf_proto_unref_pixmap (guint32 id)
+{
+  PixbufCloseRequest  req;
+  GError             *err = NULL;
+
+  req.base.op     = PIXBUF_OP_CLOSE;
+  req.base.length = sizeof(PixbufCloseRequest);
+  req.id          = id;
+  if (!pixbuf_proto_request ((char*)&req, req.base.length, NULL, 0, &err))
+    {
+      g_warning ("close(0x%x): %s", id, err->message);
+      g_error_free (err);
+      return;
+    }
+}
+
+static gboolean
+false_func (void)
+{
+  GFile* top_srcdir = g_file_new_for_commandline_arg (g_getenv ("top_srcdir"));
+  GFile* image = g_file_resolve_relative_path (top_srcdir, "demos/images/gradient.png");
+  SapwoodPixmap* pixmap;
+  gchar* path;
+  GError* error = NULL;
+
+  path = g_file_get_path (image);
+  pixmap = sapwood_pixmap_get_for_file (path, 0, 0, 0, 0, &error);
+  g_free (path);
+
+  if (!pixmap)
+    {
+      g_warning ("Error creating pixmap: %s",
+                 error->message);
+      g_clear_error (&error);
+    }
+  else
+    {
+      pixbuf_proto_unref_pixmap (pixmap->id);
+      g_free (pixmap);
+    }
+
+  g_object_unref (image);
+  g_object_unref (top_srcdir);
+  return FALSE;
+}
+
 int
 main (int   argc,
       char**argv)
 {
+  GMainLoop* loop;
+  GError* error = NULL;
+  int fd;
+
+  g_type_init ();
+
+  /* gtester disables this if it doesn't find xvfb */
+  g_setenv ("DISPLAY", ":0.0", TRUE);
+
+  gdk_init (&argc, &argv);
+
+  fd = pixbuf_proto_get_socket (&error);
+  if (fd == -1)
+    {
+      g_warning ("%s", error->message);
+      g_clear_error (&error);
+      return 1;
+    }
+
+  loop = g_main_loop_new (NULL, FALSE);
+  g_timeout_add_full (G_PRIORITY_LOW, 100,
+                      (GSourceFunc)false_func, loop,
+                      (GDestroyNotify)g_main_loop_quit);
+  g_main_loop_run (loop);
+  g_main_loop_unref (loop);
+  close (fd);
   return 0;
 }
 

Added: projects/haf/trunk/sapwood/tests/sapwood-wrapper
===================================================================
--- projects/haf/trunk/sapwood/tests/sapwood-wrapper	2008-09-29 11:13:48 UTC (rev 16261)
+++ projects/haf/trunk/sapwood/tests/sapwood-wrapper	2008-09-29 11:13:54 UTC (rev 16262)
@@ -0,0 +1,17 @@
+#!/bin/bash
+export GTK_PATH=/home/herzi/Hacking/Maemo/prefix/lib/gtk-2.0
+export GTK2_RC_FILES=/home/herzi/Hacking/Maemo/prefix/share/themes/devel/gtk-2.0/gtkrc
+export SAPWOOD_SERVER_DEBUG=1
+
+if test $# -eq 0; then
+        echo "Usage: $0 <command> [args]" >&2
+        return 1
+fi
+
+DISPLAY=:0 ../server/sapwood-server &
+
+export $(grep ^top_srcdir Makefile | sed 's/ = /=/')
+sleep 1
+$@ || echo "$@: return value: $?"
+
+kill %- # %- : last job started : http://tldp.org/LDP/abs/html/x8885.html#JOBIDTABLE


Property changes on: projects/haf/trunk/sapwood/tests/sapwood-wrapper
___________________________________________________________________
Name: svn:executable
   + *


More information about the maemo-commits mailing list