diff options
author | Junyan He <junyan.he@linux.intel.com> | 2013-11-07 16:44:46 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2013-11-07 17:38:09 +0800 |
commit | bab11d647ca9a856fe158fe906ea1b5cdf62b15d (patch) | |
tree | 857efee350970b2851978ce88a5da3f204a77f63 /utests | |
parent | 79270b1bec2d85e86eab077c397bf05cbc4922a8 (diff) |
Add the test case for sub buffer check
Signed-off-by: Junyan He <junyan.he@linux.intel.com>
Reviewed-by: Homer Hsing <homer.xing@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests')
-rw-r--r-- | utests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | utests/sub_buffer.cpp | 135 |
2 files changed, 136 insertions, 0 deletions
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index 2be0c360..c87cba8e 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -132,6 +132,7 @@ set (utests_sources builtin_pow.cpp builtin_exp.cpp builtin_convert_sat.cpp + sub_buffer.cpp runtime_createcontext.cpp runtime_null_kernel_arg.cpp runtime_event.cpp diff --git a/utests/sub_buffer.cpp b/utests/sub_buffer.cpp new file mode 100644 index 00000000..f65e8ff3 --- /dev/null +++ b/utests/sub_buffer.cpp @@ -0,0 +1,135 @@ +#include "utest_helper.hpp" + +void sub_bufffer_check(void) +{ + cl_int error; + cl_ulong max_alloc_size; + cl_uint address_align; + cl_mem main_buf; + cl_mem sub_buf; + char *main_buf_content; + char sub_buf_content[32]; + + error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(max_alloc_size), &max_alloc_size, NULL); + OCL_ASSERT(error == CL_SUCCESS); + error = clGetDeviceInfo(device, CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof(address_align ), &address_align, NULL ); + OCL_ASSERT(error == CL_SUCCESS); + + main_buf_content = (char *)malloc(sizeof(char) * max_alloc_size); + + for (cl_ulong i = 0; i < max_alloc_size; i++) { + main_buf_content[i] = rand() & 63; + } + + main_buf = clCreateBuffer(ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, max_alloc_size, main_buf_content, &error); + OCL_ASSERT(error == CL_SUCCESS); + + /* Test read sub buffer. */ + for (cl_ulong sz = 64; sz < max_alloc_size; sz*=4) { + for (cl_ulong off = 0; off < max_alloc_size; off += 1234) { + cl_buffer_region region; + region.origin = off; + region.size = sz; + + sub_buf = clCreateSubBuffer(main_buf, 0, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &error ); + + /* invalid size, should be failed. */ + if(off + sz > max_alloc_size) { + OCL_ASSERT(error != CL_SUCCESS); + continue; + } + /* invalid align, should be failed. */ + if(off & (address_align-1)) { + OCL_ASSERT(error != CL_SUCCESS); + continue; + } + + OCL_ASSERT(error == CL_SUCCESS); + + error = clEnqueueReadBuffer(queue, sub_buf, CL_TRUE, 0, 32, (void *)sub_buf_content, 0, NULL, NULL); + OCL_ASSERT(error == CL_SUCCESS); + +#if 0 + printf("\nRead ########### Src buffer: \n"); + for (int i = 0; i < 32; ++i) + printf(" %2.2u", main_buf_content[off + i]); + + printf("\nRead ########### dst buffer: \n"); + for (int i = 0; i < 32; ++i) + printf(" %2.2u", sub_buf_content[i]); + printf("\n"); +#endif + for (int i = 0; i < 32; ++i) { + + if (main_buf_content[off + i] != sub_buf_content[i]) { + printf ("different index is %d\n", i); + OCL_ASSERT(0); + } + } + + } + } + + + for (cl_ulong sz = 64; sz < max_alloc_size; sz*=4) { + for (cl_ulong off = 0; off < max_alloc_size; off += 1234) { + cl_buffer_region region; + region.origin = off; + region.size = sz; + + sub_buf = clCreateSubBuffer(main_buf, 0, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &error ); + + /* invalid size, should be failed. */ + if(off + sz > max_alloc_size) { + OCL_ASSERT(error != CL_SUCCESS); + continue; + } + /* invalid align, should be failed. */ + if(off & (address_align-1)) { + OCL_ASSERT(error != CL_SUCCESS); + continue; + } + + OCL_ASSERT(error == CL_SUCCESS); + + for (int i = 0; i < 32; i++) { + sub_buf_content[i] = rand() & 63; + } + + error = clEnqueueWriteBuffer(queue, main_buf, CL_TRUE, off, 32, sub_buf_content, 0, NULL, NULL); + OCL_ASSERT(error == CL_SUCCESS); + + void * mapped_ptr = clEnqueueMapBuffer(queue, sub_buf, CL_TRUE, (cl_map_flags)( CL_MAP_READ | CL_MAP_WRITE ), + 0, 32, 0, NULL, NULL, &error ); + OCL_ASSERT(error == CL_SUCCESS); + +#if 0 + printf("\nMap ########### Src buffer: \n"); + for (int i = 0; i < 32; ++i) + printf(" %2.2u", sub_buf_content[i]); + + printf("\nMap ########### dst buffer: \n"); + for (int i = 0; i < 32; ++i) + printf(" %2.2u", ((char *)mapped_ptr)[i]); + printf("\n"); +#endif + for (int i = 0; i < 32; i++) { + + if (((char *)mapped_ptr)[i] != sub_buf_content[i]) { + printf ("different index is %d\n", i); + OCL_ASSERT(0); + } + } + + error = clEnqueueUnmapMemObject(queue, sub_buf, mapped_ptr, 0, NULL, NULL ); + OCL_ASSERT(error == CL_SUCCESS); + + clReleaseMemObject(sub_buf); + } + } + + + free(main_buf_content); +} + +MAKE_UTEST_FROM_FUNCTION(sub_bufffer_check); |