Skip to content

Commit

Permalink
Added two tests not calling event calback upon error status (#2028)
Browse files Browse the repository at this point in the history
#1900 
Tested on POCL, callback is not called.
  • Loading branch information
kamil-goras-mobica committed Aug 20, 2024
1 parent 746544a commit 6cbe8ca
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test_conformance/events/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ test_definition test_list[] = {
ADD_TEST(callbacks),
ADD_TEST(callbacks_simultaneous),
ADD_TEST(userevents_multithreaded),
ADD_TEST(callback_on_error_simple),
ADD_TEST(callback_on_error_enqueue_command)
};

const int test_num = ARRAY_SIZE(test_list);
Expand Down
8 changes: 8 additions & 0 deletions test_conformance/events/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,11 @@ extern int test_userevents_multithreaded(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_callback_on_error_simple(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_callback_on_error_enqueue_command(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
84 changes: 84 additions & 0 deletions test_conformance/events/test_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#if !defined(_MSC_VER)
#include <unistd.h>
#endif // !_MSC_VER
#include <chrono>
#include <thread>

extern const char *IGetStatusString(cl_int status);

Expand Down Expand Up @@ -71,6 +73,15 @@ void CL_CALLBACK single_event_callback_function_flags(cl_event event,
sCallbackTriggered_flag[pdata->index] = true;
}

void CL_CALLBACK combuf_event_callback_function(cl_event event,
cl_int commandStatus,
void *userData)
{
bool *pdata = static_cast<bool *>(userData);
log_info("\tEvent callback triggered\n");
*pdata = true;
}

int test_callback_event_single(cl_device_id device, cl_context context,
cl_command_queue queue, Action *actionToTest)
{
Expand Down Expand Up @@ -372,3 +383,76 @@ int test_callbacks_simultaneous(cl_device_id deviceID, cl_context context,
if (actionEvents) delete[] actionEvents;
return -1;
}

int test_callback_on_error_simple(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
cl_int error = CL_SUCCESS;
clEventWrapper user_event = clCreateUserEvent(context, &error);
test_error(error, "clCreateUserEvent failed");

bool confirmation = false;
error = clSetEventCallback(user_event, CL_COMPLETE,
combuf_event_callback_function, &confirmation);
test_error(error, "clSetEventCallback failed");

error = clSetUserEventStatus(user_event, CL_INVALID_VALUE);
test_error(error, "clSetUserEventStatus failed");

// Wait for callback
std::this_thread::sleep_for(std::chrono::milliseconds(500));

if (!confirmation)
{
log_error("callback not called upon error status different than "
"CL_SUCCESS\n");
return TEST_FAIL;
}

return CL_SUCCESS;
}

int test_callback_on_error_enqueue_command(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements)
{
cl_int error = CL_SUCCESS;
bool confirmation = false;

clEventWrapper user_event = clCreateUserEvent(context, &error);
test_error(error, "clCreateUserEvent failed");
clEventWrapper fill_event;

const cl_int pattern_pri = 0xA;
clMemWrapper in_mem =
clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(cl_int) * num_elements,
nullptr, &error);
test_error(error, "clCreateBuffer failed");

error = clEnqueueFillBuffer(queue, in_mem, &pattern_pri, sizeof(cl_int), 0,
num_elements * sizeof(cl_int), 1, &user_event,
&fill_event);
test_error(error, "clEnqueueFillBuffer failed");

error = clSetEventCallback(fill_event, CL_COMPLETE,
combuf_event_callback_function, &confirmation);
test_error(error, "clSetEventCallback failed");

error = clSetUserEventStatus(user_event, CL_INVALID_VALUE);
test_error(error, "clSetUserEventStatus failed");

error = clFinish(queue);

// Wait for callback
std::this_thread::sleep_for(std::chrono::milliseconds(500));

if (!confirmation)
{
log_error("callback not called upon error status different than "
"CL_SUCCESS\n");
return TEST_FAIL;
}

return CL_SUCCESS;
}

0 comments on commit 6cbe8ca

Please sign in to comment.