Add support for DEVICE_DETACH and DEVICE_ATTACH sysman events

Change-Id: I2da57ec50a0f3e87499660d37fa248a06f9fdb08
Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma 2020-10-29 15:15:12 +05:30 committed by sys_ocldev
parent 6ab9e9f1e0
commit f4158e10ff
10 changed files with 274 additions and 34 deletions

View File

@ -11,11 +11,12 @@
namespace L0 {
ze_result_t EventsImp::eventRegister(zes_event_type_flags_t events) {
return pOsEvents->eventRegister(events);
}
bool EventsImp::eventListen(zes_event_type_flags_t &pEvent) {
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
return pOsEvents->isResetRequired(pEvent);
}
return false;
return pOsEvents->eventListen(pEvent);
}
void EventsImp::init() {

View File

@ -16,10 +16,7 @@ namespace L0 {
class EventsImp : public Events, NEO::NonCopyableOrMovableClass {
public:
void init() override;
ze_result_t eventRegister(zes_event_type_flags_t events) override {
registeredEvents = events;
return ZE_RESULT_SUCCESS;
}
ze_result_t eventRegister(zes_event_type_flags_t events) override;
bool eventListen(zes_event_type_flags_t &pEvent) override;
OsEvents *pOsEvents = nullptr;
@ -29,7 +26,6 @@ class EventsImp : public Events, NEO::NonCopyableOrMovableClass {
private:
OsSysman *pOsSysman = nullptr;
zes_event_type_flags_t registeredEvents = 0;
};
} // namespace L0

View File

@ -12,6 +12,10 @@
namespace L0 {
const std::string LinuxEventsImp::varFs("/var/lib/libze_intel_gpu/");
const std::string LinuxEventsImp::detachEvent("remove");
const std::string LinuxEventsImp::attachEvent("add");
bool LinuxEventsImp::isResetRequired(zes_event_type_flags_t &pEvent) {
zes_device_state_t pState = {};
if (pLinuxSysmanImp->getSysmanDeviceImp()->deviceGetState(&pState) != ZE_RESULT_SUCCESS) {
@ -24,8 +28,87 @@ bool LinuxEventsImp::isResetRequired(zes_event_type_flags_t &pEvent) {
return false;
}
bool LinuxEventsImp::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
// When device detach uevent is generated, then L0 udev rules will create a file:
// /var/lib/libze_intel_gpu/remove-<ID_PATH_TAG>
// For <ID_PATH_TAG>, check comment in LinuxEventsImp::init()
const std::string deviceDetachFile = detachEvent + "-" + pciIdPathTag;
const std::string deviceDetachFileAbsolutePath = varFs + deviceDetachFile;
uint32_t val = 0;
auto result = pFsAccess->read(deviceDetachFileAbsolutePath, val);
if (result != ZE_RESULT_SUCCESS) {
return false;
}
if (val == 1) {
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
return true;
}
return false;
}
bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
// When device detach uevent is generated, then L0 udev rules will create a file:
// /var/lib/libze_intel_gpu/add-<ID_PATH_TAG>
// For <ID_PATH_TAG>, check comment in LinuxEventsImp::init()
const std::string deviceAttachFile = attachEvent + "-" + pciIdPathTag;
const std::string deviceAttachFileAbsolutePath = varFs + deviceAttachFile;
uint32_t val = 0;
auto result = pFsAccess->read(deviceAttachFileAbsolutePath, val);
if (result != ZE_RESULT_SUCCESS) {
return false;
}
if (val == 1) {
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
return true;
}
return false;
}
bool LinuxEventsImp::eventListen(zes_event_type_flags_t &pEvent) {
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
if (isResetRequired(pEvent)) {
return true;
}
}
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
if (checkDeviceDetachEvent(pEvent)) {
return true;
}
}
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
if (checkDeviceAttachEvent(pEvent)) {
return true;
}
}
return false;
}
ze_result_t LinuxEventsImp::eventRegister(zes_event_type_flags_t events) {
registeredEvents = events;
return ZE_RESULT_SUCCESS;
}
void LinuxEventsImp::init() {
std::string bdfDir;
ze_result_t result = pSysfsAccess->readSymLink("device", bdfDir);
if (ZE_RESULT_SUCCESS != result) {
return;
}
const auto loc = bdfDir.find_last_of('/');
auto bdf = bdfDir.substr(loc + 1);
std::replace(bdf.begin(), bdf.end(), ':', '_');
std::replace(bdf.begin(), bdf.end(), '.', '_');
// ID_PATH_TAG key is received when uevent related to device add/remove is generated.
// Example of ID_PATH_TAG is:
// ID_PATH_TAG=pci-0000_8c_00_0
pciIdPathTag = "pci-" + bdf;
}
LinuxEventsImp::LinuxEventsImp(OsSysman *pOsSysman) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
pFsAccess = &pLinuxSysmanImp->getFsAccess();
init();
}
OsEvents *OsEvents::create(OsSysman *pOsSysman) {

View File

@ -13,13 +13,27 @@ namespace L0 {
class LinuxEventsImp : public OsEvents, NEO::NonCopyableOrMovableClass {
public:
bool isResetRequired(zes_event_type_flags_t &pEvent) override;
bool eventListen(zes_event_type_flags_t &pEvent) override;
ze_result_t eventRegister(zes_event_type_flags_t events) override;
LinuxEventsImp() = default;
LinuxEventsImp(OsSysman *pOsSysman);
~LinuxEventsImp() override = default;
protected:
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
void init();
bool isResetRequired(zes_event_type_flags_t &pEvent);
bool checkDeviceDetachEvent(zes_event_type_flags_t &pEvent);
bool checkDeviceAttachEvent(zes_event_type_flags_t &pEvent);
std::string pciIdPathTag;
private:
FsAccess *pFsAccess = nullptr;
SysfsAccess *pSysfsAccess = nullptr;
static const std::string varFs;
static const std::string detachEvent;
static const std::string attachEvent;
zes_event_type_flags_t registeredEvents = 0;
};
} // namespace L0

View File

@ -15,7 +15,8 @@ namespace L0 {
class OsEvents {
public:
static OsEvents *create(OsSysman *pOsSysman);
virtual bool isResetRequired(zes_event_type_flags_t &pEvent) = 0;
virtual bool eventListen(zes_event_type_flags_t &pEvent) = 0;
virtual ze_result_t eventRegister(zes_event_type_flags_t events) = 0;
virtual ~OsEvents() {}
};

View File

@ -12,7 +12,8 @@ namespace L0 {
class WddmEventsImp : public OsEvents {
public:
bool isResetRequired(zes_event_type_flags_t &pEvent) override;
bool eventListen(zes_event_type_flags_t &pEvent) override;
ze_result_t eventRegister(zes_event_type_flags_t events) override;
WddmEventsImp(OsSysman *pOsSysman);
~WddmEventsImp() = default;
@ -21,10 +22,14 @@ class WddmEventsImp : public OsEvents {
WddmEventsImp &operator=(const WddmEventsImp &obj) = delete;
};
bool WddmEventsImp::isResetRequired(zes_event_type_flags_t &pEvent) {
bool WddmEventsImp::eventListen(zes_event_type_flags_t &pEvent) {
return false;
}
ze_result_t WddmEventsImp::eventRegister(zes_event_type_flags_t events) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
WddmEventsImp::WddmEventsImp(OsSysman *pOsSysman) {
}

View File

@ -9,11 +9,21 @@ ACTION=="change", \
SUBSYSTEM=="drm", \
ENV{RESET_FAILED}=="1", \
ENV{RESET_UNIT}=="gt", \
RUN+="echo 1 > /var/lib/libze_intel_gpu/wedged_file"
RUN+="/bin/sh -c 'echo 1 > /var/lib/libze_intel_gpu/wedged_file'"
ACTION=="unbind", \
SUBSYSTEM=="drm", \
RUN+="echo 0 > /var/lib/libze_intel_gpu/pci_bind_status_file"
RUN+="/bin/sh -c 'echo 0 > /var/lib/libze_intel_gpu/pci_bind_status_file'"
ACTION=="bind", \
SUBSYSTEM=="drm", \
RUN+="echo 1 > /var/lib/libze_intel_gpu/pci_bind_status_file", \
RUN+="echo 0 > /var/lib/libze_intel_gpu/wedged_file"
RUN+="/bin/sh -c 'echo 1 > /var/lib/libze_intel_gpu/pci_bind_status_file'", \
RUN+="/bin/sh -c 'echo 0 > /var/lib/libze_intel_gpu/wedged_file'"
ACTION=="remove", \
SUBSYSTEM=="drm", \
ENV{DEVNAME}=="/dev/dri/card*", \
ENV{ID_PATH_TAG}=="pci-*", \
RUN+="/bin/sh -c 'touch /var/lib/libze_intel_gpu/remove-$env{ID_PATH_TAG}; echo 1 > /var/lib/libze_intel_gpu/remove-$env{ID_PATH_TAG}; rm /var/lib/libze_intel_gpu/add-$env{ID_PATH_TAG};'"
ACTION=="add", \
SUBSYSTEM=="drm", \
ENV{DEVNAME}=="/dev/dri/card*", \
ENV{ID_PATH_TAG}=="pci-*", \
RUN+="/bin/sh -c 'touch /var/lib/libze_intel_gpu/add-$env{ID_PATH_TAG}; echo 1 > /var/lib/libze_intel_gpu/add-$env{ID_PATH_TAG}; rm /var/lib/libze_intel_gpu/remove-$env{ID_PATH_TAG}; echo 0 > /var/lib/libze_intel_gpu/wedged_file;'"

View File

@ -591,6 +591,12 @@ void testSysmanListenEvents(ze_driver_handle_t driver, std::vector<ze_device_han
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
std::cout << "Device " << index << "got reset required event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
std::cout << "Device " << index << "got DEVICE_DETACH event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
std::cout << "Device " << index << "got DEVICE_ATTACH event" << std::endl;
}
}
}
}
@ -722,9 +728,11 @@ int main(int argc, char *argv[]) {
break;
case 'E':
std::for_each(devices.begin(), devices.end(), [&](auto device) {
zesDeviceEventRegister(device, ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED);
zesDeviceEventRegister(device,
ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH | ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH);
});
testSysmanListenEvents(driver, devices, ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED);
testSysmanListenEvents(driver, devices,
ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH | ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH);
break;
default:

View File

@ -13,44 +13,79 @@ namespace L0 {
namespace ult {
const std::string ueventWedgedFile("/var/lib/libze_intel_gpu/wedged_file");
const std::string ueventDetachFile("/var/lib/libze_intel_gpu/remove-pci-0000_03_00_0");
const std::string ueventAttachFile("/var/lib/libze_intel_gpu/add-pci-0000_03_00_0");
const std::string deviceDir("device");
class EventsFsAccess : public FsAccess {};
template <>
struct Mock<EventsFsAccess> : public EventsFsAccess {
ze_result_t getValWedgedFileTrue(const std::string file, uint32_t &val) {
ze_result_t getValReturnValAsOne(const std::string file, uint32_t &val) {
if (file.compare(ueventWedgedFile) == 0) {
val = 1;
} else if (file.compare(ueventDetachFile) == 0) {
val = 1;
} else if (file.compare(ueventAttachFile) == 0) {
val = 1;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValWedgedFileFalse(const std::string file, uint32_t &val) {
ze_result_t getValReturnValAsZero(const std::string file, uint32_t &val) {
if (file.compare(ueventWedgedFile) == 0) {
val = 0;
} else if (file.compare(ueventDetachFile) == 0) {
val = 0;
} else if (file.compare(ueventAttachFile) == 0) {
val = 0;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValWedgedFileNotFound(const std::string file, uint32_t &val) {
ze_result_t getValFileNotFound(const std::string file, uint32_t &val) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t getValWedgedFileInsufficientPermissions(const std::string file, uint32_t &val) {
ze_result_t getValFileInsufficientPermissions(const std::string file, uint32_t &val) {
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
Mock<EventsFsAccess>() = default;
MOCK_METHOD(ze_result_t, read, (const std::string file, std::string &val), (override));
MOCK_METHOD(ze_result_t, read, (const std::string file, uint32_t &val), (override));
MOCK_METHOD(ze_result_t, canWrite, (const std::string file), (override));
};
class EventsSysfsAccess : public SysfsAccess {};
template <>
struct Mock<EventsSysfsAccess> : public EventsSysfsAccess {
MOCK_METHOD(ze_result_t, readSymLink, (const std::string file, std::string &buf), (override));
ze_result_t getValStringSymLinkSuccess(const std::string file, std::string &val) {
if (file.compare(deviceDir) == 0) {
val = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0";
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t getValStringSymLinkFailure(const std::string file, std::string &val) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
Mock<EventsSysfsAccess>() = default;
};
class PublicLinuxEventsImp : public L0::LinuxEventsImp {
public:
PublicLinuxEventsImp(OsSysman *pOsSysman) : LinuxEventsImp(pOsSysman) {}
using LinuxEventsImp::init;
using LinuxEventsImp::pciIdPathTag;
};
} // namespace ult
} // namespace L0

View File

@ -18,15 +18,17 @@ namespace ult {
class SysmanEventsFixture : public SysmanDeviceFixture {
protected:
std::unique_ptr<Mock<EventsFsAccess>> pFsAccess;
FsAccess *pFsAccessOld = nullptr;
FsAccess *pFsAccessOriginal = nullptr;
OsEvents *pOsEventsPrev = nullptr;
L0::EventsImp *pEventsImp;
GlobalOperations *pGlobalOperationsOld = nullptr;
GlobalOperations *pGlobalOperationsOriginal = nullptr;
std::unique_ptr<GlobalOperationsImp> pGlobalOperations;
std::unique_ptr<Mock<EventsSysfsAccess>> pSysfsAccess;
SysfsAccess *pSysfsAccessOriginal = nullptr;
void SetUp() override {
SysmanDeviceFixture::SetUp();
pFsAccessOld = pLinuxSysmanImp->pFsAccess;
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
pFsAccess = std::make_unique<NiceMock<Mock<EventsFsAccess>>>();
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
@ -34,9 +36,16 @@ class SysmanEventsFixture : public SysmanDeviceFixture {
pOsEventsPrev = pEventsImp->pOsEvents;
pEventsImp->pOsEvents = nullptr;
pGlobalOperations = std::make_unique<GlobalOperationsImp>(pLinuxSysmanImp);
pGlobalOperationsOld = pSysmanDeviceImp->pGlobalOperations;
pGlobalOperationsOriginal = pSysmanDeviceImp->pGlobalOperations;
pSysmanDeviceImp->pGlobalOperations = pGlobalOperations.get();
pSysmanDeviceImp->pGlobalOperations->init();
pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess;
pSysfsAccess = std::make_unique<NiceMock<Mock<EventsSysfsAccess>>>();
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<EventsSysfsAccess>::getValStringSymLinkSuccess));
pEventsImp->init();
}
@ -46,8 +55,9 @@ class SysmanEventsFixture : public SysmanDeviceFixture {
}
pEventsImp->pOsEvents = pOsEventsPrev;
pEventsImp = nullptr;
pLinuxSysmanImp->pFsAccess = pFsAccessOld;
pSysmanDeviceImp->pGlobalOperations = pGlobalOperationsOld;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOriginal;
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
pSysmanDeviceImp->pGlobalOperations = pGlobalOperationsOriginal;
SysmanDeviceFixture::TearDown();
}
};
@ -55,7 +65,7 @@ class SysmanEventsFixture : public SysmanDeviceFixture {
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredEventsThenEventListenAPIReturnsAfterReceivingEventWithinTimeout) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValWedgedFileTrue));
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsOne));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
@ -70,7 +80,7 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredE
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredEventsThenEventListenAPIWaitForTimeoutIfEventNotReceived) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValWedgedFileFalse));
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsZero));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
@ -79,7 +89,7 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredE
EXPECT_EQ(0u, numDeviceEvents);
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValWedgedFileNotFound));
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValFileNotFound));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
@ -90,7 +100,7 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredE
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForCurrentlyUnsupportedEventsThenEventListenAPIWaitForTimeoutIfEventNotReceived) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_TEMP_THRESHOLD2));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValWedgedFileTrue));
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsOne));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
@ -101,5 +111,82 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForCurrentlyUnsup
delete[] pDeviceEvents;
}
TEST_F(SysmanEventsFixture, GivenReadSymLinkCallFailsWhenGettingPCIBDFThenEmptyPciIdPathTagReceived) {
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<EventsSysfsAccess>::getValStringSymLinkFailure));
PublicLinuxEventsImp linuxEventImp(pOsSysman);
EXPECT_TRUE(linuxEventImp.pciIdPathTag.empty());
}
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEventsThenEventListenAPIReturnsAfterReceivingEventWithinTimeout) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsOne));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
zes_event_type_flags_t *pDeviceEvents = new zes_event_type_flags_t[1];
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(1u, numDeviceEvents);
EXPECT_EQ(ZES_EVENT_TYPE_FLAG_DEVICE_DETACH, pDeviceEvents[0]);
delete[] phDevices;
delete[] pDeviceEvents;
}
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEventsThenEventListenAPIWaitForTimeoutIfEventNotReceived) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsZero));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
zes_event_type_flags_t *pDeviceEvents = new zes_event_type_flags_t[1];
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValFileNotFound));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
delete[] phDevices;
delete[] pDeviceEvents;
}
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceAttachEventsThenEventListenAPIReturnsAfterReceivingEventWithinTimeout) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsOne));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
zes_event_type_flags_t *pDeviceEvents = new zes_event_type_flags_t[1];
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(1u, numDeviceEvents);
EXPECT_EQ(ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH, pDeviceEvents[0]);
delete[] phDevices;
delete[] pDeviceEvents;
}
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceAttachEventsThenEventListenAPIWaitForTimeoutIfEventNotReceived) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH));
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsZero));
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
phDevices[0] = device->toHandle();
uint32_t numDeviceEvents = 0;
zes_event_type_flags_t *pDeviceEvents = new zes_event_type_flags_t[1];
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValFileNotFound));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
delete[] phDevices;
delete[] pDeviceEvents;
}
} // namespace ult
} // namespace L0