---
 tests/cl.py                        |  1 +
 tests/cl/custom/CMakeLists.cl.txt  |  1 +
 tests/cl/custom/r600-mapping-bug.c | 95 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+)
 create mode 100644 tests/cl/custom/r600-mapping-bug.c

diff --git a/tests/cl.py b/tests/cl.py
index a954337..e41d115 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, 'r600 mapping bug', ['cl-custom-r600-mapping-bug'])
 add_plain_test(custom, 'Buffer flags', ['cl-custom-buffer-flags'])
 
 # API
diff --git a/tests/cl/custom/CMakeLists.cl.txt 
b/tests/cl/custom/CMakeLists.cl.txt
index 1843e19..c4ebc00 100644
--- a/tests/cl/custom/CMakeLists.cl.txt
+++ b/tests/cl/custom/CMakeLists.cl.txt
@@ -3,3 +3,4 @@ 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 (r600-mapping-bug r600-mapping-bug.c)
diff --git a/tests/cl/custom/r600-mapping-bug.c 
b/tests/cl/custom/r600-mapping-bug.c
new file mode 100644
index 0000000..0f9dc27
--- /dev/null
+++ b/tests/cl/custom/r600-mapping-bug.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <brunoji...@gmail.com>
+ *
+ */
+
+#include "piglit-framework-cl-custom.h"
+
+PIGLIT_CL_CUSTOM_TEST_CONFIG_BEGIN
+
+       config.name = "Mapping Bug Checker (Pool Relocation)";
+       config.run_per_device = true;
+
+PIGLIT_CL_CUSTOM_TEST_CONFIG_END
+
+#define BUFFER_ELEMENTS 1024
+
+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_int err;
+       cl_mem buffer0, buffer1;
+       uint32_t local_data0[BUFFER_ELEMENTS];
+
+       uint32_t *map0, *map1;
+
+       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));
+
+       /* NOTE: buffer1 *MUST* be big enough to force the buffer pool to get
+        * relocated. With current mesa code, 16 * 1024 dw is enough. */
+       buffer1 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE,
+                               16 * sizeof(local_data0));
+       queue = context->command_queues[0];
+
+       map0 = clEnqueueMapBuffer(queue, buffer0, CL_TRUE, CL_MAP_WRITE,
+                               0, sizeof(local_data0), 0, NULL, NULL, &err);
+       if (err != CL_SUCCESS)
+               return PIGLIT_FAIL;
+
+       map1 = clEnqueueMapBuffer(queue, buffer1, CL_TRUE, CL_MAP_WRITE,
+                               0, 16 * sizeof(local_data0), 0, NULL, NULL, 
&err);
+       if (err != CL_SUCCESS)
+               return PIGLIT_FAIL;
+
+       /* If we have hit the bug, now the map for buffer0 would point to a
+        * place in the GPU memory where buffer0 *WAS* before the pool got
+        * relocated. So writing to it means to write to somewhere random.
+        * if we read the contents of buffer0 afterwards, we should read
+        * garbage. */
+
+       memset(map0, 0x55, sizeof(local_data0));
+
+       clEnqueueUnmapMemObject(queue, buffer0, map0, 0, NULL, NULL);
+       clEnqueueUnmapMemObject(queue, buffer1, map1, 0, NULL, NULL);
+
+       /* We read buffer0 and we check if it is all garbage, or
+        * all 0x55 */
+       piglit_cl_read_whole_buffer(queue, buffer0, local_data0);
+       for (i = 0; i < BUFFER_ELEMENTS; i++) {
+               if(local_data0[i] != 0x55555555) {
+                       return PIGLIT_FAIL;
+               }
+       }
+
+       return PIGLIT_PASS;
+}
-- 
1.9.3

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to