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



commit af029075d2e69ecc500ccab691cc4b199f53ff78
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Thu Jul 16 08:26:02 2009 +0800

    Add a new set of automated tests for GeglTile's new lock modes
    
    * Consistency test for GPU writes through GPU reads
    * Consistency test for GPU writes through normal reads
    * Consistency test for normal writes through GPU reads
    * Consistency test for normal writes through normal reads

 tests/Makefile.am                                  |    6 +-
 ...t-gegl-tile-lock-mode-gpu-write-then-gpu-read.c |  101 ++++++++++++++++++++
 .../test-gegl-tile-lock-mode-gpu-write-then-read.c |   97 +++++++++++++++++++
 .../test-gegl-tile-lock-mode-write-then-gpu-read.c |  100 +++++++++++++++++++
 tests/test-gegl-tile-lock-mode-write-then-read.c   |   96 +++++++++++++++++++
 5 files changed, 399 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2abac64..64cc094 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,7 +15,11 @@ TESTS = \
 	test-gegl-gpu-texture-set-subrect \
 	test-gegl-gpu-texture-copy \
 	test-gegl-gpu-texture-copy-subrect \
-	test-gegl-gpu-texture-dup
+	test-gegl-gpu-texture-dup \
+	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
 noinst_PROGRAMS = $(TESTS)
 
 # Common CPPFLAGS
diff --git a/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c b/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c
new file mode 100644
index 0000000..6af888d
--- /dev/null
+++ b/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c
@@ -0,0 +1,101 @@
+/* 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;
+  gfloat   *components;
+
+  gegl_init (&argc, &argv);
+
+  tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
+  components = g_new (gfloat, 4 * 50 * 50);
+
+    {
+      gint    cnt;
+      gfloat *tile_components = g_new (gfloat, 4 * 50 * 50);
+
+      memset (tile->data, 0, 4 * 50 * 50);
+      gegl_gpu_texture_clear (tile->gpu_data, NULL);
+
+      /* initialize tile to a random image */
+      for (cnt = 0; cnt < 1000; cnt++)
+        {
+          gint x = g_random_int_range (0, 50);
+          gint y = g_random_int_range (0, 50);
+
+          gfloat *pixel = &components[(y * 4 * 50) + (x * 4)];
+
+          pixel[0] = g_random_double ();
+          pixel[1] = g_random_double ();
+          pixel[2] = g_random_double ();
+          pixel[3] = 1.0;
+        }
+
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_GPU_WRITE);
+
+      gegl_gpu_texture_set (gegl_tile_get_gpu_data (tile),
+                            NULL,
+                            components,
+                            babl_format ("RGBA float"));
+
+      gegl_tile_unlock (tile);
+
+      /* check contents of tile for consistency with previous write */
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_GPU_READ);
+
+      gegl_gpu_texture_get (gegl_tile_get_gpu_data (tile),
+                            NULL,
+                            tile_components,
+                            babl_format ("RGBA float"));
+
+      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+        if (tile_components[cnt] != components[cnt])
+          {
+            g_printerr ("Tile GPU texture inconsistent with original GPU "
+                        "texture. Aborting.\n");
+
+            retval = FAILURE;
+            break;
+          }
+
+      gegl_tile_unlock (tile);
+    }
+
+  g_free (components);
+  g_object_unref (tile);
+
+  gegl_exit ();
+
+  return retval;
+}
diff --git a/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c b/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c
new file mode 100644
index 0000000..98d6a56
--- /dev/null
+++ b/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c
@@ -0,0 +1,97 @@
+/* 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;
+  gfloat   *components;
+
+  gegl_init (&argc, &argv);
+
+  tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
+  components = g_new (gfloat, 4 * 50 * 50);
+
+    {
+      gint    cnt;
+      gfloat *tile_components;
+
+      memset (tile->data, 0, 4 * 50 * 50);
+      gegl_gpu_texture_clear (tile->gpu_data, NULL);
+
+      /* initialize tile to a random image */
+      for (cnt = 0; cnt < 1000; cnt++)
+        {
+          gint x = g_random_int_range (0, 50);
+          gint y = g_random_int_range (0, 50);
+
+          gfloat *pixel = &components[(y * 4 * 50) + (x * 4)];
+
+          pixel[0] = g_random_double ();
+          pixel[1] = g_random_double ();
+          pixel[2] = g_random_double ();
+          pixel[3] = 1.0;
+        }
+
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_GPU_WRITE);
+
+      gegl_gpu_texture_set (gegl_tile_get_gpu_data (tile),
+                            NULL,
+                            components,
+                            babl_format ("RGBA float"));
+
+      gegl_tile_unlock (tile);
+
+      /* check contents of tile for consistency with previous write */
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_READ);
+      tile_components = (gpointer) gegl_tile_get_data (tile);
+
+      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+        if (tile_components[cnt] != components[cnt])
+          {
+            g_printerr ("Tile data inconsistent with original GPU texture. "
+                        "Aborting.\n");
+
+            retval = FAILURE;
+            break;
+          }
+
+      gegl_tile_unlock (tile);
+    }
+
+  g_free (components);
+  g_object_unref (tile);
+
+  gegl_exit ();
+
+  return retval;
+}
diff --git a/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c b/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c
new file mode 100644
index 0000000..577b280
--- /dev/null
+++ b/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c
@@ -0,0 +1,100 @@
+/* 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;
+  gfloat   *components;
+
+  gegl_init (&argc, &argv);
+
+  tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
+  components = g_new (gfloat, 4 * 50 * 50);
+
+    {
+      gint    cnt;
+      gfloat *tile_components = g_new (gfloat, 4 * 50 * 50);
+
+      memset (tile->data, 0, 4 * 50 * 50);
+      gegl_gpu_texture_clear (tile->gpu_data, NULL);
+
+      /* initialize tile to a random image */
+      for (cnt = 0; cnt < 1000; cnt++)
+        {
+          gint x = g_random_int_range (0, 50);
+          gint y = g_random_int_range (0, 50);
+
+          gfloat *pixel = &components[(y * 4 * 50) + (x * 4)];
+
+          pixel[0] = g_random_double ();
+          pixel[1] = g_random_double ();
+          pixel[2] = g_random_double ();
+          pixel[3] = 1.0;
+        }
+
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
+
+      memcpy (gegl_tile_get_data (tile),
+              components,
+              sizeof (gfloat) * 4 * 50 * 50);
+
+      gegl_tile_unlock (tile);
+
+      /* check contents of tile for consistency with previous write */
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_GPU_READ);
+
+      gegl_gpu_texture_get (gegl_tile_get_gpu_data (tile),
+                            NULL,
+                            tile_components,
+                            babl_format ("RGBA float"));
+
+      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+        if (tile_components[cnt] != components[cnt])
+          {
+            g_printerr ("Tile GPU texture inconsistent with original image "
+                        "data. Aborting.\n");
+
+            retval = FAILURE;
+            break;
+          }
+
+      gegl_tile_unlock (tile);
+    }
+
+  g_free (components);
+  g_object_unref (tile);
+
+  gegl_exit ();
+
+  return retval;
+}
diff --git a/tests/test-gegl-tile-lock-mode-write-then-read.c b/tests/test-gegl-tile-lock-mode-write-then-read.c
new file mode 100644
index 0000000..7006563
--- /dev/null
+++ b/tests/test-gegl-tile-lock-mode-write-then-read.c
@@ -0,0 +1,96 @@
+/* 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;
+  gfloat   *components;
+
+  gegl_init (&argc, &argv);
+
+  tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
+  components = g_new (gfloat, 4 * 50 * 50);
+
+    {
+      gint    cnt;
+      gfloat *tile_components;
+
+      memset (tile->data, 0, 4 * 50 * 50);
+      gegl_gpu_texture_clear (tile->gpu_data, NULL);
+
+      /* initialize tile to a random image */
+      for (cnt = 0; cnt < 1000; cnt++)
+        {
+          gint x = g_random_int_range (0, 50);
+          gint y = g_random_int_range (0, 50);
+
+          gfloat *pixel = &components[(y * 4 * 50) + (x * 4)];
+
+          pixel[0] = g_random_double ();
+          pixel[1] = g_random_double ();
+          pixel[2] = g_random_double ();
+          pixel[3] = 1.0;
+        }
+
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
+
+      memcpy (gegl_tile_get_data (tile),
+              components,
+              sizeof (gfloat) * 4 * 50 * 50);
+
+      gegl_tile_unlock (tile);
+
+      /* check contents of tile for consistency with previous write */
+      gegl_tile_lock (tile, GEGL_TILE_LOCK_READ);
+      tile_components = (gpointer) gegl_tile_get_data (tile);
+
+      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+        if (tile_components[cnt] != components[cnt])
+          {
+            g_printerr ("Tile data inconsistent with original image data. "
+                        "Aborting.\n");
+
+            retval = FAILURE;
+            break;
+          }
+
+      gegl_tile_unlock (tile);
+    }
+
+  g_free (components);
+  g_object_unref (tile);
+
+  gegl_exit ();
+
+  return retval;
+}



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