On Friday 29 May 2015 05:42:08 Meng Mengmeng wrote: > --- > tests/cl.py | 2 + > tests/cl/api/CMakeLists.cl.txt | 1 + > tests/cl/api/enqueue-read_write-buffer-rect.c | 103 > ++++++++++++++++++++++++++ > 3 files changed, 106 insertions(+) > create mode 100644 tests/cl/api/enqueue-read_write-buffer-rect.c > > diff --git a/tests/cl.py b/tests/cl.py > index c55d3dd..7fce00a 100644 > --- a/tests/cl.py > +++ b/tests/cl.py > @@ -58,6 +58,8 @@ with profile.group_manager(PiglitCLTest, 'api') as g: > g(['cl-api-enqueue-copy-buffer-rect'], 'clEnqueueCopyBufferRect') > g(['cl-api-enqueue-read_write-buffer'], > 'clEnqueueReadBuffer and clEnqueueWriteBuffer') > + g(['cl-api-enqueue-read_write-buffer-rect'], > + 'clEnqueueReadBufferRect and clEnqueueWriteBufferRect') > g(['cl-api-get-mem-object-info'], 'clGetMemObjectInfo') > g(['cl-api-get-image-info'], 'clGetImageInfo') > g(['cl-api-retain_release-mem-object'], > diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt > index 7e78491..e1a25fa 100644 > --- a/tests/cl/api/CMakeLists.cl.txt > +++ b/tests/cl/api/CMakeLists.cl.txt > @@ -21,6 +21,7 @@ piglit_cl_add_api_test (enqueue-copy-buffer > enqueue-copy-buffer.c) > piglit_cl_add_api_test (enqueue-map-buffer enqueue-map-buffer.c) > piglit_cl_add_api_test (enqueue-copy-buffer-rect enqueue-copy-buffer-rect.c) > piglit_cl_add_api_test (enqueue-read_write-buffer > enqueue-read_write-buffer.c) > +piglit_cl_add_api_test (enqueue-read_write-buffer-rect > enqueue-read_write-buffer-rect.c) > piglit_cl_add_api_test (retain_release-mem-object > retain_release-mem-object.c) > piglit_cl_add_api_test (get-mem-object-info get-mem-object-info.c) > piglit_cl_add_api_test (get-image-info get-image-info.c) > diff --git a/tests/cl/api/enqueue-read_write-buffer-rect.c > b/tests/cl/api/enqueue-read_write-buffer-rect.c > new file mode 100644 > index 0000000..3d7f06a > --- /dev/null > +++ b/tests/cl/api/enqueue-read_write-buffer-rect.c > @@ -0,0 +1,103 @@ > +/* > + * Copyright © 2015 Intel Corporation > + * > + * 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: Meng Mengmeng <mengmeng.meng at intel.com> > + * > + */ > + > +#include "piglit-framework-cl-api.h" > +#include "piglit-util-cl.h" > + > + > +PIGLIT_CL_API_TEST_CONFIG_BEGIN > + > + config.name = "clEnqueueReadBufferRect and clEnqueueWriteBufferRect"; > + config.version_min = 11; > + > + config.run_per_platform = true; > + config.create_context = true; > + > +PIGLIT_CL_API_TEST_CONFIG_END > + > +enum piglit_result > +piglit_cl_test(const int argc, > + const char **argv, > + const struct piglit_cl_api_test_config* config, > + const struct piglit_cl_api_test_env* env) > +{ > + > + cl_int i, j, err; > + cl_int k = 0; > + float full_matrix[81], result_matrix[9]; > + const size_t buffer_origin[3] = {3*sizeof(float), 3, 0}; > + const size_t host_origin[3] = {3*sizeof(float), 3, 0}; > + const size_t host_new_origin[3] = {0*sizeof(float), 0, 0}; > + const size_t region[3] = {3*sizeof(float), 3, 1}; > + cl_mem matrix_buffer; > + > + for(i=0; i<81; i++) { > + full_matrix[i] = i*1.0f; > + } > + for(i=0; i<9; i++) { > + result_matrix[i] = 0.0f; > + } > + > + float reference_matrix[9]={30.0f, 31.0f, 32.0f, 39.0f, 40.0f, 41.0f, > 48.0f, 49.0f, 50.0f}; > + > + cl_command_queue queue = env->context->command_queues[0]; > + matrix_buffer = piglit_cl_create_buffer(env->context, > CL_MEM_READ_WRITE , sizeof(full_matrix)); > + err = clEnqueueWriteBufferRect(queue, matrix_buffer, CL_TRUE, > + buffer_origin, host_origin, region, 9*sizeof(float), 0, > + 9*sizeof(float), 0, full_matrix, 0, NULL, NULL); > + if (!piglit_cl_check_error(err, CL_SUCCESS)) { > + fprintf(stderr, > + "Failed (error code: %s): Write a host memory host into > buffer by rectangular region.\n", > + piglit_cl_get_error_name(err)); > + return PIGLIT_FAIL; > + } > + > + > + err = clEnqueueReadBufferRect(queue, matrix_buffer, CL_TRUE, > + buffer_origin, host_new_origin, region, 9*sizeof(float), 0, > + 3*sizeof(float), 0, result_matrix, 0, NULL, NULL); > + if (!piglit_cl_check_error(err, CL_SUCCESS)) { > + fprintf(stderr, > + "Failed (error code: %s): Read a buffer into host > memory by rectangular region.\n", > + piglit_cl_get_error_name(err)); > + return PIGLIT_FAIL; > + } > + > + > + for (i = 0; i < 3; ++i){ > + for (j = 0; j < 3; ++j){ > + if (result_matrix[j+i*3] != reference_matrix[k]){ > + fprintf(stderr, > + "clEnqueueWriteBufferRect and > clEnqueueReadBufferRect: Failed (expected %f, but got %f)\n", > + > reference_matrix[k],result_matrix[j+i*3]); > + return PIGLIT_FAIL; > + } > + else > + k++; > + } > + } > + return PIGLIT_PASS;
As said for v1, usually after checking for correct execution with valid input, piglit cl-api-* programs test for correct behavior and return code with invalid parameters. EdB > +} > _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit