diff options
author | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-06-01 16:42:42 +0200 |
---|---|---|
committer | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-06-01 17:26:09 +0200 |
commit | 8ca1cf833adf0ba05d0af8f5d1d70e8962e0efdd (patch) | |
tree | 941078c4fee02fd5defe2628b3cc8dabd57fceaa /tests | |
parent | 24448f1bc0b0746c250b94c5bc7ca5fee5d2ce6d (diff) |
Start implementing buffers (Buffers, SubBuffers, Images 2D and 3D)
It's a big thing. This commit implement the creation of Buffer and
SubBuffers object, with some infrastructure done for Image 2D and 3D
objects.
This part of the spec also comes with a bunch of commands that can be
used to read, write, copy and map buffers or images.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/test_mem.cpp | 163 | ||||
-rw-r--r-- | tests/test_mem.h | 17 | ||||
-rw-r--r-- | tests/tests.c | 2 |
4 files changed, 184 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ea47243..e068a6b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,7 @@ set(OPENCL_TESTS_SOURCE test_device.cpp test_context.cpp test_commandqueue.cpp + test_mem.cpp ) add_executable(tests ${OPENCL_TESTS_SOURCE}) @@ -20,3 +21,4 @@ OPENCL_TEST(tests platform) OPENCL_TEST(tests device) OPENCL_TEST(tests context) OPENCL_TEST(tests commandqueue) +OPENCL_TEST(tests mem) diff --git a/tests/test_mem.cpp b/tests/test_mem.cpp new file mode 100644 index 0000000..6c613b2 --- /dev/null +++ b/tests/test_mem.cpp @@ -0,0 +1,163 @@ +#include "test_mem.h" +#include "CL/cl.h" + +#include <stdio.h> + +START_TEST (test_create_buffer) +{ + cl_context ctx; + cl_mem buf; + cl_int result; + char s[] = "Hello, world !"; + + ctx = clCreateContextFromType(0, CL_DEVICE_TYPE_CPU, 0, 0, &result); + fail_if( + result != CL_SUCCESS, + "unable to create a valid context" + ); + + buf = clCreateBuffer(0, CL_MEM_READ_WRITE, sizeof(s), 0, &result); + fail_if( + result != CL_INVALID_CONTEXT, + "0 is not a valid context" + ); + + buf = clCreateBuffer(ctx, 1337, sizeof(s), 0, &result); + fail_if( + result != CL_INVALID_VALUE, + "1337 is not a valid cl_mem_flags" + ); + + buf = clCreateBuffer(ctx, CL_MEM_USE_HOST_PTR, sizeof(s), 0, &result); + fail_if( + result != CL_INVALID_HOST_PTR, + "host_ptr cannot be NULL if flags is CL_MEM_USE_HOST_PTR" + ); + + buf = clCreateBuffer(ctx, CL_MEM_COPY_HOST_PTR, sizeof(s), 0, &result); + fail_if( + result != CL_INVALID_HOST_PTR, + "host_ptr cannot be NULL if flags is CL_MEM_COPY_HOST_PTR" + ); + + buf = clCreateBuffer(ctx, 0, sizeof(s), s, &result); + fail_if( + result != CL_INVALID_HOST_PTR, + "host_ptr must be NULL if flags is not CL_MEM_{COPY/USE}_HOST_PTR" + ); + + buf = clCreateBuffer(ctx, CL_MEM_USE_HOST_PTR, 0, s, &result); + fail_if( + result != CL_INVALID_BUFFER_SIZE, + "size cannot be 0" + ); + + buf = clCreateBuffer(ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, + sizeof(s), s, &result); + fail_if( + result != CL_SUCCESS, + "cannot create a valid CL_MEM_COPY_HOST_PTR read-write buffer" + ); + + clReleaseMemObject(buf); + clReleaseContext(ctx); +} +END_TEST + +START_TEST (test_create_sub_buffer) +{ + cl_context ctx; + cl_mem buf, subbuf; + cl_int result; + char s[] = "Hello, world !"; + + cl_buffer_region create_info = { // "Hello, [world] !" + .origin = 7, + .size = 5 + }; + + ctx = clCreateContextFromType(0, CL_DEVICE_TYPE_CPU, 0, 0, &result); + fail_if( + result != CL_SUCCESS, + "unable to create a valid context" + ); + + buf = clCreateBuffer(ctx, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, + sizeof(s), s, &result); + fail_if( + result != CL_SUCCESS, + "cannot create a valid CL_MEM_USE_HOST_PTR read-write buffer" + ); + + subbuf = clCreateSubBuffer(0, CL_MEM_WRITE_ONLY, + CL_BUFFER_CREATE_TYPE_REGION, + (void *)&create_info, &result); + fail_if( + result != CL_INVALID_MEM_OBJECT, + "0 is not a valid mem object" + ); + + subbuf = clCreateSubBuffer(buf, CL_MEM_READ_ONLY, + CL_BUFFER_CREATE_TYPE_REGION, + (void *)&create_info, &result); + fail_if( + result != CL_INVALID_VALUE, + "READ_ONLY is not compatible with WRITE_ONLY" + ); + + subbuf = clCreateSubBuffer(buf, CL_MEM_WRITE_ONLY, 1337, (void *)&create_info, + &result); + fail_if( + result != CL_INVALID_VALUE, + "1337 is not a valid buffer_create_type" + ); + + subbuf = clCreateSubBuffer(buf, CL_MEM_WRITE_ONLY, + CL_BUFFER_CREATE_TYPE_REGION, 0, &result); + fail_if( + result != CL_INVALID_VALUE, + "buffer_create_info cannot be NULL" + ); + + create_info.size = 0; + + subbuf = clCreateSubBuffer(buf, CL_MEM_WRITE_ONLY, + CL_BUFFER_CREATE_TYPE_REGION, + (void *)&create_info, &result); + fail_if( + result != CL_INVALID_BUFFER_SIZE, + "create_info.size cannot be 0" + ); + + create_info.size = 5; + + subbuf = clCreateSubBuffer(buf, CL_MEM_WRITE_ONLY, + CL_BUFFER_CREATE_TYPE_REGION, + (void *)&create_info, &result); + fail_if( + result != CL_SUCCESS || subbuf == 0, + "cannot create a valid sub-buffer" + ); + + subbuf = clCreateSubBuffer(subbuf, CL_MEM_WRITE_ONLY, + CL_BUFFER_CREATE_TYPE_REGION, + (void *)&create_info, &result); + fail_if( + result != CL_INVALID_MEM_OBJECT, + "we cannot create a sub-buffer of a sub-buffer" + ); + + clReleaseMemObject(subbuf); + clReleaseMemObject(buf); + clReleaseContext(ctx); +} +END_TEST + +TCase *cl_mem_tcase_create(void) +{ + TCase *tc = NULL; + tc = tcase_create("mem"); + tcase_add_test(tc, test_create_buffer); + tcase_add_test(tc, test_create_sub_buffer); + return tc; +} diff --git a/tests/test_mem.h b/tests/test_mem.h new file mode 100644 index 0000000..866ab84 --- /dev/null +++ b/tests/test_mem.h @@ -0,0 +1,17 @@ +#ifndef __UTEST_MEM__ +#define __UTEST_MEM__ + +#include <check.h> + +#ifdef __cplusplus +extern "C" { +#endif + +TCase *cl_mem_tcase_create(void); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/tests/tests.c b/tests/tests.c index b81ce28..9ae366d 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -2,6 +2,7 @@ #include "test_device.h" #include "test_context.h" #include "test_commandqueue.h" +#include "test_mem.h" #include <stdlib.h> #include <stdio.h> @@ -26,6 +27,7 @@ int main(int argc, char **argv) TESTSUITE(device, "device"); TESTSUITE(context, "context"); TESTSUITE(commandqueue, "commandqueue"); + TESTSUITE(mem, "mem"); if (s == NULL) { printf("test case %s does not exist", argv[1]); |