diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index c564a469..b86f799d 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -408,6 +408,9 @@ void setUp(void) cl::pfn_clRetainCommandBufferKHR = ::clRetainCommandBufferKHR; cl::pfn_clReleaseCommandBufferKHR = ::clReleaseCommandBufferKHR; cl::pfn_clGetCommandBufferInfoKHR = ::clGetCommandBufferInfoKHR; + cl::pfn_clCommandCopyImageToBufferKHR = ::clCommandCopyImageToBufferKHR; + cl::pfn_clCommandCopyImageKHR = ::clCommandCopyImageKHR; + cl::pfn_clCommandCopyBufferToImageKHR = ::clCommandCopyBufferToImageKHR; #endif #if defined(cl_khr_semaphore) cl::pfn_clCreateSemaphoreWithPropertiesKHR = ::clCreateSemaphoreWithPropertiesKHR; @@ -489,6 +492,9 @@ void tearDown(void) cl::pfn_clRetainCommandBufferKHR = nullptr; cl::pfn_clReleaseCommandBufferKHR = nullptr; cl::pfn_clGetCommandBufferInfoKHR = nullptr; + cl::pfn_clCommandCopyImageToBufferKHR = nullptr; + cl::pfn_clCommandCopyImageKHR = nullptr; + cl::pfn_clCommandCopyBufferToImageKHR = nullptr; #endif #if defined(cl_khr_semaphore) cl::pfn_clCreateSemaphoreWithPropertiesKHR = nullptr; @@ -3608,6 +3614,145 @@ void testCommandBufferInfoKHRCommandQueues(void) TEST_ASSERT_EQUAL_PTR(make_command_queue(2), command_queues[2]()); #endif } + +static cl_int clcommandCopyImageToBufferKHR_testcommandCopyImageToBuffer(cl_command_buffer_khr command_buffer, cl_command_queue command_queue, cl_mem src_image, +cl_mem dst_buffer, const size_t* src_origin, const size_t* region, size_t dst_offset, cl_uint num_sync_points_in_wait_list, +const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl_mutable_command_khr* mutable_handle, int num_calls) +{ + (void)num_calls; + TEST_ASSERT_EQUAL(command_buffer, commandBufferKhrPool[0]()); + TEST_ASSERT_EQUAL_PTR(command_queue,nullptr); + TEST_ASSERT_EQUAL(src_image, image2DPool[0]()); + TEST_ASSERT_EQUAL(dst_buffer, bufferPool[0]()); + TEST_ASSERT_EQUAL(src_origin[0], 16); + TEST_ASSERT_EQUAL(region[0], 512); + TEST_ASSERT_EQUAL(dst_offset, 10); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); + TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); + TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); + TEST_ASSERT_EQUAL(sync_point_wait_list[2], 3); + TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + if (sync_point != nullptr) + { + *sync_point = 5; + } + + return CL_SUCCESS; +} + +void testCommandCopyImageToBuffer(void) +{ +#if defined(cl_khr_command_buffer) + cl_int ret = CL_INVALID_CONTEXT; + + const std::array origin = {16, 32, 0}; + const std::array region = {512, 512, 0}; + cl::size_type dst_offset = 10; + cl_sync_point_khr sync_point = 0; + const cl::vector sync_points_vec = {1, 2, 3}; + + clCommandCopyImageToBufferKHR_StubWithCallback(clcommandCopyImageToBufferKHR_testcommandCopyImageToBuffer); + ret = commandBufferKhrPool[0].commandCopyImageToBuffer(image2DPool[0], bufferPool[0], origin, region, dst_offset, &sync_points_vec, + &sync_point, nullptr, nullptr); + TEST_ASSERT_EQUAL(ret, CL_SUCCESS); + TEST_ASSERT_EQUAL(5, sync_point); +#endif +} + +static cl_int clCommandCopyImageKHR_testcommandCopyImage(cl_command_buffer_khr command_buffer, cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image, +const size_t* src_origin, const size_t* dst_origin, const size_t* region, cl_uint num_sync_points_in_wait_list, +const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl_mutable_command_khr* mutable_handle, int num_calls) +{ + (void)num_calls; + TEST_ASSERT_EQUAL(command_buffer, commandBufferKhrPool[0]()); + TEST_ASSERT_EQUAL_PTR(command_queue,nullptr); + TEST_ASSERT_EQUAL(src_image, image2DPool[0]()); + TEST_ASSERT_EQUAL(dst_image, image2DPool[1]()); + TEST_ASSERT_EQUAL(src_origin[0], 16); + TEST_ASSERT_EQUAL(dst_origin[0], 16); + TEST_ASSERT_EQUAL(region[0], 512); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); + TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); + TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); + TEST_ASSERT_EQUAL(sync_point_wait_list[2], 3); + TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + if (sync_point != nullptr) + { + *sync_point = 5; + } + + return CL_SUCCESS; +} + +void testCommandCopyImage(void) +{ +#if defined(cl_khr_command_buffer) + cl_int ret = CL_INVALID_CONTEXT; + + const std::array origin = {16, 32, 0}; + const std::array dst_origin = {16, 32, 0}; + const std::array region = {512, 512, 0}; + cl_sync_point_khr sync_point = 0; + const cl::vector sync_points_vec = {1, 2, 3}; + + clCommandCopyImageKHR_StubWithCallback(clCommandCopyImageKHR_testcommandCopyImage); + ret = commandBufferKhrPool[0].commandCopyImage(image2DPool[0], image2DPool[1], origin, dst_origin, region, &sync_points_vec, + &sync_point, nullptr, nullptr); + TEST_ASSERT_EQUAL(ret, CL_SUCCESS); + TEST_ASSERT_EQUAL(5, sync_point); +#endif +} + +static cl_int clCommandCopyBufferToImageKHR_testcommandCopyBufferToImage(cl_command_buffer_khr command_buffer, cl_command_queue command_queue, +cl_mem src_buffer, cl_mem dst_image, size_t src_offset, const size_t* dst_origin, const size_t* region, cl_uint num_sync_points_in_wait_list, +const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl_mutable_command_khr* mutable_handle, int num_calls) +{ + (void)num_calls; + TEST_ASSERT_EQUAL(command_buffer, commandBufferKhrPool[0]()); + TEST_ASSERT_EQUAL_PTR(command_queue,nullptr); + TEST_ASSERT_EQUAL(src_buffer, image2DPool[0]()); + TEST_ASSERT_EQUAL(dst_image, bufferPool[0]()); + TEST_ASSERT_EQUAL(dst_origin[0], 16); + TEST_ASSERT_EQUAL(region[0], 512); + TEST_ASSERT_EQUAL(src_offset, 10); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); + TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); + TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); + TEST_ASSERT_EQUAL(sync_point_wait_list[2], 3); + TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + if (sync_point != nullptr) + { + *sync_point = 5; + } + + return CL_SUCCESS; +} + +void testCommandCopyBufferToImage(void) +{ +#if defined(cl_khr_command_buffer) + cl_int ret = CL_INVALID_CONTEXT; + + const std::array origin = {16, 32, 0}; + const std::array region = {512, 512, 0}; + cl::size_type src_offset = 10; + cl_sync_point_khr sync_point = 0; + const cl::vector sync_points_vec = {1, 2, 3}; + + clCommandCopyBufferToImageKHR_StubWithCallback(clCommandCopyBufferToImageKHR_testcommandCopyBufferToImage); + ret = commandBufferKhrPool[0].commandCopyBufferToImage(bufferPool[0], image2DPool[0], src_offset, origin, region, &sync_points_vec, + &sync_point, nullptr, nullptr); + TEST_ASSERT_EQUAL(ret, CL_SUCCESS); + TEST_ASSERT_EQUAL(5, sync_point); +#endif +} + // Tests for Device::GetInfo static cl_int clGetInfo_testDeviceGetInfoCLDeviceVendorId( cl_device_id device, cl_device_info param_name, size_t param_value_size,