diff --git a/test_conformance/events/main.cpp b/test_conformance/events/main.cpp index 74682f99..ab91f0e3 100644 --- a/test_conformance/events/main.cpp +++ b/test_conformance/events/main.cpp @@ -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); diff --git a/test_conformance/events/procs.h b/test_conformance/events/procs.h index 97309db3..d840714e 100644 --- a/test_conformance/events/procs.h +++ b/test_conformance/events/procs.h @@ -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); diff --git a/test_conformance/events/test_callbacks.cpp b/test_conformance/events/test_callbacks.cpp index 04481dec..78a2ae4a 100644 --- a/test_conformance/events/test_callbacks.cpp +++ b/test_conformance/events/test_callbacks.cpp @@ -21,6 +21,8 @@ #if !defined(_MSC_VER) #include #endif // !_MSC_VER +#include +#include extern const char *IGetStatusString(cl_int status); @@ -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(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) { @@ -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; +}