[Piglit] [PATCH] cl: Add test for alignment problems

Bruno Jiménez brunojimen at gmail.com
Wed Jun 11 08:17:25 PDT 2014


This test currently give an endless loop when
we try to add the first buffer for second time.
---
 tests/cl.py                         |   1 +
 tests/cl/custom/CMakeLists.cl.txt   |   1 +
 tests/cl/custom/alignment-checker.c | 119 ++++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+)
 create mode 100644 tests/cl/custom/alignment-checker.c

diff --git a/tests/cl.py b/tests/cl.py
index b3382b6..7360e6d 100644
--- a/tests/cl.py
+++ b/tests/cl.py
@@ -44,6 +44,7 @@ profile.tests['Program'] = program
 add_plain_test(custom, 'Run simple kernel', ['cl-custom-run-simple-kernel'])
 add_plain_test(custom, 'Flush after enqueue kernel', ['cl-custom-flush-after-enqueue-kernel'])
 add_plain_test(custom, 'r600 create release buffer bug', ['cl-custom-r600-create-release-buffer-bug'])
+add_plain_test(custom, 'Alignment checker', ['cl-custom-alignment-checker'])
 add_plain_test(custom, 'r600 mapping bug', ['cl-custom-r600-mapping-bug'])
 add_plain_test(custom, 'behavior of read maps', ['cl-custom-behavior-of-read-maps'])
 add_plain_test(custom, 'Buffer flags', ['cl-custom-buffer-flags'])
diff --git a/tests/cl/custom/CMakeLists.cl.txt b/tests/cl/custom/CMakeLists.cl.txt
index 801f4d6..9d3c4ab 100644
--- a/tests/cl/custom/CMakeLists.cl.txt
+++ b/tests/cl/custom/CMakeLists.cl.txt
@@ -3,5 +3,6 @@ piglit_cl_add_custom_test (flush-after-enqueue-kernel flush-after-enqueue-kernel
 piglit_cl_add_custom_test (r600-create-release-buffer-bug r600-create-release-buffer-bug.c)
 piglit_cl_add_custom_test (buffer-flags buffer-flags.c)
 piglit_cl_add_custom_test (use-sub-buffer-in-kernel use-sub-buffer-in-kernel.c)
+piglit_cl_add_custom_test (alignment-checker alignment-checker.c)
 piglit_cl_add_custom_test (r600-mapping-bug r600-mapping-bug.c)
 piglit_cl_add_custom_test (behavior-of-read-maps behavior_of_read_maps.c)
diff --git a/tests/cl/custom/alignment-checker.c b/tests/cl/custom/alignment-checker.c
new file mode 100644
index 0000000..916f45b
--- /dev/null
+++ b/tests/cl/custom/alignment-checker.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2014 Bruno Jiménez
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Bruno Jiménez <brunojimen at gmail.com>
+ *
+ */
+
+#include "piglit-framework-cl-custom.h"
+
+PIGLIT_CL_CUSTOM_TEST_CONFIG_BEGIN
+
+	config.name = "Buffer Alignment Checker";
+	config.run_per_device = true;
+
+PIGLIT_CL_CUSTOM_TEST_CONFIG_END
+
+/* This size is a multiple of the alignment, so the items will be
+ * touching each other, and it is high enough so that when we retry
+ * to add the first buffer it enters an endless loop when trying to
+ * add it before the second one.
+ * This happens because first it tries to add it before the second
+ * buffer and fails (althouh it has enough space), then tries to add
+ * it after the second buffer, and fails again. This process is
+ * endlessly repeated */
+#define ITEM_SIZE 1024 * 8
+
+enum piglit_result
+piglit_cl_test(const int argc,
+			   const char **argv,
+			   const struct piglit_cl_custom_test_config *config,
+			   const struct piglit_cl_custom_test_env *env)
+{
+	unsigned int i;
+	cl_mem buffer0, buffer1;
+	uint32_t local_data0[ITEM_SIZE];
+	uint32_t local_data1[ITEM_SIZE];
+
+	piglit_cl_context context = NULL;
+	cl_command_queue queue;
+
+	context = piglit_cl_create_context(env->platform_id, &env->device_id, 1);
+	buffer0 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, sizeof(local_data0));
+	buffer1 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, sizeof(local_data1));
+
+	queue = context->command_queues[0];
+
+	memset(local_data0, 0x44, sizeof(local_data0));
+	memset(local_data1, 0x55, sizeof(local_data1));
+
+	/* We write buffer0 with known data */
+	piglit_cl_write_whole_buffer(queue, buffer0, local_data0);
+
+	/* We write buffer1 with known data */
+	piglit_cl_write_whole_buffer(queue, buffer1, local_data1);
+
+	/* We read buffer0 and we check if data has spilled from
+	 * buffer1 to it */
+	piglit_cl_read_whole_buffer(queue, buffer0, local_data0);
+	for (i = 0; i < ITEM_SIZE; i++) {
+		if(local_data0[i] != 0x44444444) {
+			return PIGLIT_FAIL;
+		}
+	}
+
+	/* We write again buffer0 with known data */
+	piglit_cl_write_whole_buffer(queue, buffer0, local_data0);
+
+	/* We read buffer1 and we check if data has spilled from
+	 * buffer0 to it */
+	piglit_cl_read_whole_buffer(queue, buffer1, local_data1);
+	for (i = 0; i < ITEM_SIZE; i++) {
+		if(local_data1[i] != 0x55555555) {
+			return PIGLIT_FAIL;
+		}
+	}
+
+	/* We release the first buffer and create it again, so it has
+	 * to be readded to the pool in front of the second one */
+	clReleaseMemObject(buffer0);
+	buffer0 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, sizeof(local_data0));
+	piglit_cl_write_whole_buffer(queue, buffer0, local_data0);
+
+
+	/* We read again both buffers, better safe than sorry! */
+	piglit_cl_read_whole_buffer(queue, buffer0, local_data0);
+	for (i = 0; i < ITEM_SIZE; i++) {
+		if(local_data0[i] != 0x44444444) {
+			return PIGLIT_FAIL;
+		}
+	}
+
+	piglit_cl_read_whole_buffer(queue, buffer1, local_data1);
+	for (i = 0; i < ITEM_SIZE; i++) {
+		if(local_data1[i] != 0x55555555) {
+			return PIGLIT_FAIL;
+		}
+	}
+
+	return PIGLIT_PASS;
+}
-- 
2.0.0



More information about the Piglit mailing list