Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Add tests for errors in buffer copy and map
Browse files Browse the repository at this point in the history
Also fix CL_MEM_COPY_OVERLAP error detection in function
clEnqueueCopyBuffer() of the OpenCL stub.

Issue #33
  • Loading branch information
nunofachada committed Jun 12, 2019
1 parent 1463d78 commit fa7ecbe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/lib/ocl_stub/ocl_enqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,22 @@ clEnqueueCopyBuffer(cl_command_queue command_queue, cl_mem src_buffer,
const cl_event * event_wait_list, cl_event * event) {

/* Error check. */
if (command_queue == NULL) {
/* Not testing if events in wait list belong to this context. */
if (command_queue == NULL)
return CL_INVALID_COMMAND_QUEUE;
} else if ((src_buffer == NULL) || (dst_buffer == NULL)) {
if ((src_buffer == NULL) || (dst_buffer == NULL))
return CL_INVALID_MEM_OBJECT;
} else if ((src_buffer->context != command_queue->context)
|| (dst_buffer->context != command_queue->context)) {
if ((src_buffer->context != command_queue->context)
|| (dst_buffer->context != command_queue->context))
return CL_INVALID_CONTEXT;
/* Not testing if events in wait list belong to this context. */
} else if ((src_offset + size > src_buffer->size)
|| (dst_offset + size > dst_buffer->size)) {
return CL_INVALID_VALUE;
} else if (src_buffer == dst_buffer) {
/* For now just don't allow copies within the same buffer,
* although OCL allows it if they don't overlap. */
if ((src_offset + size > src_buffer->size)
|| (dst_offset + size > dst_buffer->size))
return CL_INVALID_VALUE;
}
if ((src_buffer == dst_buffer)
&& ((src_offset == dst_offset)
|| ((src_offset < dst_offset) && (src_offset + size > dst_offset))
|| ((dst_offset < src_offset) && (dst_offset + size > src_offset))))
return CL_MEM_COPY_OVERLAP;

/* These are ignored. */
(void)(num_events_in_wait_list);
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/test_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ static void copy_test() {
for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
g_assert_cmpuint(h1[i], ==, h2[i]);

/* Do an invalid copy, check if error is thrown. */
ccl_buffer_enqueue_copy(
b1, b1, q, 0, 0, buf_size, NULL, &err);
g_assert_error(err, CCL_OCL_ERROR, CL_MEM_COPY_OVERLAP);
g_clear_error(&err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

Expand Down Expand Up @@ -432,6 +438,12 @@ static void map_unmap_test() {
(CCLMemObj *) b, q, h_out, NULL, &err);
g_assert_no_error(err);

/* Do an invalid map, check if error is thrown. */
ccl_buffer_enqueue_map(
b, q, CL_TRUE, CL_MAP_READ, buf_size, buf_size, NULL, NULL, &err);
g_assert_error(err, CCL_OCL_ERROR, CL_INVALID_VALUE);
g_clear_error(&err);

/* Confirm that memory allocated by wrappers has not yet been freed. */
g_assert(!ccl_wrapper_memcheck());

Expand Down

0 comments on commit fa7ecbe

Please sign in to comment.