Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UT for EnqueueMapBuffer #259

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/test_openclhpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4517,4 +4517,41 @@ void testgetObjectInfo() {
TEST_ASSERT_EQUAL(type, CL_GL_OBJECT_BUFFER);
TEST_ASSERT_EQUAL(bufobj, 0);
}
static void *clEnqueueMapBuffer_testenqueueMapBuffer(
cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map,
cl_map_flags map_flags, size_t offset, size_t size,
cl_uint num_events_in_wait_list, const cl_event *event_wait_list,
cl_event *event, cl_int *errcode_ret, int num_calls) {
(void)command_queue;
TEST_ASSERT_EQUAL_PTR(make_mem(0), buffer);
TEST_ASSERT_EQUAL(CL_TRUE, blocking_map);
TEST_ASSERT_EQUAL(CL_MAP_WRITE, map_flags);
TEST_ASSERT_EQUAL(0, offset);
TEST_ASSERT_EQUAL(sizeof(int) * 1024, size);
TEST_ASSERT_EQUAL(0, num_events_in_wait_list);
TEST_ASSERT_EQUAL_PTR(nullptr, event_wait_list);
TEST_ASSERT_NOT_NULL(event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event pointer is an optional output, so if the pointer is non-NULL then we should be writing a value to it (e.g. make_event(N), and checking that the expected value was written in the calling function.

See, for example:

TEST_ASSERT_NOT_EQUAL(nullptr, errcode_ret);
TEST_ASSERT_EQUAL(0, num_calls);
return make_mem(0);
}
void testenqueueMapBuffer() {
cl_bool blocking = CL_TRUE;
cl_map_flags flags = CL_MAP_WRITE;
cl::size_type offset = 0;
cl::size_type size = sizeof(int) * 1024;
cl::Event event_data(make_event(0), false);
cl::Event *event = &event_data;
const cl::vector<cl::Event> *events = nullptr;
cl_int *err = nullptr;
void *ret = nullptr;

clEnqueueMapBuffer_StubWithCallback(
clEnqueueMapBuffer_testenqueueMapBuffer);
ret = enqueueMapBuffer(bufferPool[0], blocking, flags, offset, size, events,
event, err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a very strong opinion about this, but it would require less code to pass in some of these values directly vs. assigning them to a variable first.

Suggested change
ret = enqueueMapBuffer(bufferPool[0], blocking, flags, offset, size, events,
event, err);
ret = enqueueMapBuffer(bufferPool[0], CL_TRUE, CL_MAP_WRITE, 0, sizeof(int) * 1024, events,
event, err);


TEST_ASSERT_EQUAL_PTR(make_mem(0), ret);
event_data() = nullptr;
}
} // extern "C"