[gegl/gsoc2009-gpu] Add a new set of automated tests for GeglTile's COW



commit 63d567ababed31046aadadba9f6798a703396fb8
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Thu Jul 23 13:24:25 2009 +0800

    Add a new set of automated tests for GeglTile's COW
    
    Add two programs that test GeglTile's expected copy-on-write behavior.
    The first program, test-gegl-tile-cow, tests for copy-on-write semantics
    (i.e. pointers to data should be the same after tile duplication, pointers
    to data should be allocated memory only after a write operation). While
    the second program, test-gegl-tile-cow-consistency, tests for tile
    GPU data/data synchronization during (and after) duplication.

 tests/Makefile.am                      |    4 +-
 tests/test-gegl-tile-cow-consistency.c |   87 ++++++++++++++++++++++++++++++
 tests/test-gegl-tile-cow.c             |   90 ++++++++++++++++++++++++++++++++
 3 files changed, 180 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 64cc094..0a39d35 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,7 +19,9 @@ TESTS = \
 	test-gegl-tile-lock-mode-write-then-read \
 	test-gegl-tile-lock-mode-write-then-gpu-read \
 	test-gegl-tile-lock-mode-gpu-write-then-read \
-	test-gegl-tile-lock-mode-gpu-write-then-gpu-read
+	test-gegl-tile-lock-mode-gpu-write-then-gpu-read \
+	test-gegl-tile-cow \
+	test-gegl-tile-cow-consistency
 noinst_PROGRAMS = $(TESTS)
 
 # Common CPPFLAGS
diff --git a/tests/test-gegl-tile-cow-consistency.c b/tests/test-gegl-tile-cow-consistency.c
new file mode 100644
index 0000000..53f6ee8
--- /dev/null
+++ b/tests/test-gegl-tile-cow-consistency.c
@@ -0,0 +1,87 @@
+/* This file is part of GEGL.
+ *
+ * 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 GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2009 Jerson Michael Perpetua <jersonperpetua gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-gpu-texture.h"
+
+#include "../../gegl/buffer/gegl-tile.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  gint      retval = SUCCESS;
+
+  GeglTile *tile;
+  GeglTile *tile2;
+
+  gfloat   *gpu_components;
+
+  gegl_init (&argc, &argv);
+
+  tile = gegl_tile_new (50, 50, babl_format ("RGBA float"));
+
+  /* clear tile data (not GPU data) and leave the tile unsynchronized */
+  gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
+  memset (gegl_tile_get_data (tile), 0x00, sizeof (gfloat) * 4 * 50 * 50);
+  gegl_tile_unlock (tile);
+
+  tile2 = gegl_tile_dup (tile);
+
+    {
+      gint cnt;
+
+      /* we don't need to lock the tile here if no other threads are/will be
+       * accessing the tile, gegl_tile_dup() should have synchronized the
+       * tile data and GPU data automatically for us
+       */
+      gfloat *components  = (gpointer) gegl_tile_get_data (tile2);
+
+      gpu_components = g_new (gfloat, 4 * 50 * 50);
+      gegl_gpu_texture_get (gegl_tile_get_gpu_data (tile2),
+                            NULL,
+                            gpu_components,
+                            babl_format ("RGBA float"));
+
+      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+        if (components[cnt] != gpu_components[cnt])
+          {
+            g_printerr ("Test on gegl_tile_dup() GPU data/data consistency "
+                        "failed. Aborting.\n");
+
+            retval = FAILURE;
+            goto abort;
+          }
+
+abort:
+      g_free (gpu_components);
+    }
+
+  g_object_unref (tile2);
+  g_object_unref (tile);
+
+  gegl_exit ();
+
+  return retval;
+}
diff --git a/tests/test-gegl-tile-cow.c b/tests/test-gegl-tile-cow.c
new file mode 100644
index 0000000..7cf8427
--- /dev/null
+++ b/tests/test-gegl-tile-cow.c
@@ -0,0 +1,90 @@
+/* This file is part of GEGL.
+ *
+ * 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 GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2009 Jerson Michael Perpetua <jersonperpetua gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-gpu-texture.h"
+
+#include "../../gegl/buffer/gegl-tile.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  gint      retval = SUCCESS;
+
+  GeglTile *tile;
+  GeglTile *tile2;
+
+  gegl_init (&argc, &argv);
+
+  tile  = gegl_tile_new (50, 50, babl_format ("RGBA float"));
+  tile2 = gegl_tile_dup (tile);
+
+  if (gegl_tile_get_data (tile) != gegl_tile_get_data (tile2))
+    {
+      g_printerr ("Test on tile data equality after tile duplication failed. "
+                  "Aborting\n");
+
+      retval = FAILURE;
+      goto abort;
+    }
+
+  if (gegl_tile_get_gpu_data (tile) != gegl_tile_get_gpu_data (tile2))
+    {
+      g_printerr ("Test on tile GPU data equality after tile duplication "
+                  "failed. Aborting\n");
+
+      retval = FAILURE;
+      goto abort;
+    }
+
+  gegl_tile_lock   (tile2, GEGL_TILE_LOCK_WRITE);
+  gegl_tile_unlock (tile2);
+
+  if (gegl_tile_get_data (tile) == gegl_tile_get_data (tile2))
+    {
+      g_printerr ("Test on tile data inequality after uncloning failed. "
+                  "Aborting\n");
+
+      retval = FAILURE;
+      goto abort;
+    }
+
+  if (gegl_tile_get_gpu_data (tile) == gegl_tile_get_gpu_data (tile2))
+    {
+      g_printerr ("Test on tile GPU data inequality after uncloning failed. "
+                  "Aborting\n");
+
+      retval = FAILURE;
+      goto abort;
+    }
+
+abort:
+  g_object_unref (tile2);
+  g_object_unref (tile);
+
+  gegl_exit ();
+
+  return retval;
+}



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