From 093c12c5d90bc3df4aa4ce55912c005a10f070da Mon Sep 17 00:00:00 2001 From: Junyan He Date: Wed, 26 Mar 2014 18:28:02 +0800 Subject: [PATCH] Add one tests case specific for unaligned buffer copy. Signed-off-by: Junyan He Reviewed-by: Zhigang Gong --- utests/CMakeLists.txt | 1 + utests/enqueue_copy_buf.cpp | 4 +- utests/enqueue_copy_buf_unaligned.cpp | 118 ++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 utests/enqueue_copy_buf_unaligned.cpp diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index 49bcf62..9ca9c8b 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -171,6 +171,7 @@ set (utests_sources load_program_from_bin.cpp profiling_exec.cpp enqueue_copy_buf.cpp + enqueue_copy_buf_unaligned.cpp utest_assert.cpp utest.cpp utest_file_map.cpp diff --git a/utests/enqueue_copy_buf.cpp b/utests/enqueue_copy_buf.cpp index 969eaa8..b647b7e 100644 --- a/utests/enqueue_copy_buf.cpp +++ b/utests/enqueue_copy_buf.cpp @@ -1,6 +1,6 @@ #include "utest_helper.hpp" -void test_copy_buf(size_t sz, size_t src_off, size_t dst_off, size_t cb) +static void test_copy_buf(size_t sz, size_t src_off, size_t dst_off, size_t cb) { unsigned int i; OCL_MAP_BUFFER(0); @@ -56,7 +56,7 @@ void enqueue_copy_buf(void) OCL_CREATE_BUFFER(buf[0], 0, sz * sizeof(char), NULL); OCL_CREATE_BUFFER(buf[1], 0, sz * sizeof(char), NULL); - for (i=0; i sz || dst_off + cb > sz) { + /* Expect Error. */ + OCL_ASSERT(clEnqueueCopyBuffer(queue, buf[0], buf[1], + src_off, dst_off, cb*sizeof(char), 0, NULL, NULL)); + return; + } + + OCL_ASSERT(!clEnqueueCopyBuffer(queue, buf[0], buf[1], + src_off, dst_off, cb*sizeof(char), 0, NULL, NULL)); + + OCL_MAP_BUFFER(0); + OCL_MAP_BUFFER(1); + +#if 0 + printf ("@@@@@@@@@ cb is %d\n", cb); + printf ("@@@@@@@@@ src_off is %d\n", src_off); + printf ("@@@@@@@@@ dst_off is %d\n", dst_off); + printf("\n########### Src buffer: \n"); + for (i = 0; i < sz; ++i) + printf(" %2.2u", ((unsigned char*)buf_data[0])[i]); + + printf("\n########### dst buffer: \n"); + for (i = 0; i < sz; ++i) + printf(" %2.2u", ((unsigned char*)buf_data[1])[i]); +#endif + + // Check results + for (i = 0; i < cb; ++i) { + if (((char*)buf_data[0])[i +src_off] != ((char*)buf_data[1])[i + dst_off]) { + printf ("different index is %d\n", i); + OCL_ASSERT(0); + } + } + + for (i = 0; i < dst_off; ++i) { + if (((char*)buf_data[1])[i] != 64) { + printf ("wrong write, different index is %d\n", i); + OCL_ASSERT(0); + } + } + + for (i = dst_off + cb; i < sz; ++i) { + if (((char*)buf_data[1])[i] != 64) { + printf ("wrong write, different index is %d\n", i); + OCL_ASSERT(0); + } + } + + OCL_UNMAP_BUFFER(0); + OCL_UNMAP_BUFFER(1); + +} + +void enqueue_copy_buf_unaligned(void) +{ + size_t i; + size_t j; + const size_t sz = 1024; + int offset = 0; + + OCL_CREATE_BUFFER(buf[0], 0, sz * sizeof(char), NULL); + OCL_CREATE_BUFFER(buf[1], 0, sz * sizeof(char), NULL); + +#if 1 + /* Test the same offset cases. */ + for (i=0; i