From e977de564c56ad92da4809ee8008e1e5234fe764 Mon Sep 17 00:00:00 2001 From: Aravind Gopalakrishnan Date: Mon, 22 Mar 2021 23:09:42 -0700 Subject: [PATCH] Add L0 event ULTs (2) Signed-off-by: Aravind Gopalakrishnan --- level_zero/core/source/event/event.cpp | 5 +- .../unit_tests/sources/event/test_event.cpp | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index 4b9fb1a280..6f3271e547 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -47,10 +47,7 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, uint32_t numDevices, if (this->devices.empty()) { ze_device_handle_t hDevice; uint32_t count = 1; - ze_result_t result = driver->getDevice(&count, &hDevice); - if (result) { - return result; - } + driver->getDevice(&count, &hDevice); this->devices.push_back(Device::fromHandle(hDevice)); rootDeviceIndices.push_back(this->devices[0]->getNEODevice()->getRootDeviceIndex()); maxRootDeviceIndex = rootDeviceIndices[0]; diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index 4d86c9d585..a11e8bfa45 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -5,12 +5,15 @@ * */ +#include "opencl/test/unit_test/mocks/mock_csr.h" #include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/mocks/mock_memory_operations_handler.h" #include "test.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" +#include "level_zero/core/test/unit_tests/mocks/mock_device.h" #include "level_zero/core/test/unit_tests/mocks/mock_event.h" namespace L0 { @@ -122,6 +125,18 @@ TEST_F(EventPoolCreate, givenCloseIpcHandleCalledReturnsNotSupported) { EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); } +TEST_F(EventPoolCreate, GivenAtLeastOneValidDeviceHandleWhenCreatingEventPoolThenEventPoolCreated) { + ze_event_pool_desc_t eventPoolDesc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, + nullptr, + ZE_EVENT_POOL_FLAG_HOST_VISIBLE, + 1}; + + ze_device_handle_t devices[] = {nullptr, device->toHandle()}; + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 2, devices, &eventPoolDesc)); + ASSERT_NE(nullptr, eventPool); +} + TEST_F(EventCreate, givenAnEventCreatedThenTheEventHasTheDeviceCommandStreamReceiverSet) { ze_event_pool_desc_t eventPoolDesc = { ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, @@ -219,6 +234,46 @@ TEST_F(EventSynchronizeTest, givenCallToEventHostSynchronizeWithTimeoutNonZeroAn EXPECT_EQ(ZE_RESULT_SUCCESS, result); } +using EventAubCsrTest = Test; + +HWTEST_F(EventAubCsrTest, givenCallToEventHostSynchronizeWithAubModeCsrReturnsSuccess) { + std::unique_ptr> driverHandle; + NEO::MockDevice *neoDevice = nullptr; + L0::Device *device = nullptr; + + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique>(); + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + int32_t tag; + auto aubCsr = new MockCsrAub(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()); + neoDevice->resetCommandStreamReceiver(aubCsr); + + std::unique_ptr eventPool = nullptr; + std::unique_ptr event; + + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.count = 1; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; + + ze_event_desc_t eventDesc = {}; + eventDesc.index = 0; + eventDesc.signal = 0; + eventDesc.wait = 0; + + eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); + ASSERT_NE(nullptr, eventPool); + event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); + ASSERT_NE(nullptr, event); + + ze_result_t result = event->hostSynchronize(10); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); +} + struct EventCreateAllocationResidencyTest : public ::testing::Test { void SetUp() override { neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get());