2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/event/async_events_handler.h"
|
|
|
|
#include "opencl/source/event/user_event.h"
|
2020-05-28 20:05:12 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_event.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "test.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
struct CallbackData {
|
|
|
|
static void CL_CALLBACK callback(cl_event event, cl_int status, void *userData) {
|
|
|
|
uint32_t *nestLevel = (uint32_t *)userData;
|
|
|
|
|
|
|
|
if (*nestLevel < 4) {
|
|
|
|
(*nestLevel)++;
|
|
|
|
clSetEventCallback(event, CL_COMPLETE, CallbackData::callback, userData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-25 19:36:04 +08:00
|
|
|
TEST(EventCallbackTest, GivenUserEventWhenAddingCallbackThenNestedCallbacksCanBeCreated) {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
MockEvent<UserEvent> event(nullptr);
|
|
|
|
uint32_t nestLevel = 0;
|
|
|
|
|
|
|
|
event.addCallback(CallbackData::callback, CL_COMPLETE, &nestLevel);
|
|
|
|
event.setStatus(CL_COMPLETE);
|
|
|
|
EXPECT_EQ(4u, nestLevel);
|
|
|
|
}
|
|
|
|
|
2020-02-25 19:36:04 +08:00
|
|
|
TEST(EventCallbackTest, GivenEventWhenAddingCallbackThenNestedCallbacksCanBeCreated) {
|
2020-03-17 19:37:38 +08:00
|
|
|
auto device = std::make_unique<MockClDevice>(MockClDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
|
|
|
MockContext context(device.get());
|
|
|
|
MockCommandQueue queue(&context, context.getDevice(0), nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
MockEvent<Event> event(&queue, CL_COMMAND_MARKER, 0, 0);
|
|
|
|
uint32_t nestLevel = 0;
|
|
|
|
|
|
|
|
event.addCallback(CallbackData::callback, CL_COMPLETE, &nestLevel);
|
|
|
|
event.setStatus(CL_COMPLETE);
|
2020-03-17 19:37:38 +08:00
|
|
|
context.getAsyncEventsHandler().closeThread();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(4u, nestLevel);
|
|
|
|
}
|