Update sysman events API for bug fixes
Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
parent
39d450bc84
commit
d89b51edd3
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -22,7 +22,7 @@ bool LinuxEventsImp::isResetRequired(zes_event_type_flags_t &pEvent) {
|
|||
return false;
|
||||
}
|
||||
if (pState.reset) {
|
||||
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -40,7 +40,7 @@ bool LinuxEventsImp::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
|
|||
return false;
|
||||
}
|
||||
if (val == 1) {
|
||||
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -58,7 +58,7 @@ bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
|||
return false;
|
||||
}
|
||||
if (val == 1) {
|
||||
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -66,7 +66,7 @@ bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
|||
|
||||
bool LinuxEventsImp::checkIfMemHealthChanged(zes_event_type_flags_t &pEvent) {
|
||||
if (currentMemHealth() != memHealthAtEventRegister) {
|
||||
pEvent = ZES_EVENT_TYPE_FLAG_MEM_HEALTH;
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_MEM_HEALTH;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -75,21 +75,25 @@ bool LinuxEventsImp::checkIfMemHealthChanged(zes_event_type_flags_t &pEvent) {
|
|||
bool LinuxEventsImp::eventListen(zes_event_type_flags_t &pEvent, uint32_t timeout) {
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
||||
if (isResetRequired(pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED); //After receiving event unregister it
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
|
||||
if (checkDeviceDetachEvent(pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_DETACH);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
|
||||
if (checkDeviceAttachEvent(pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
||||
if (checkIfMemHealthChanged(pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +104,7 @@ ze_result_t LinuxEventsImp::eventRegister(zes_event_type_flags_t events) {
|
|||
if (0x7fff < events) {
|
||||
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
|
||||
}
|
||||
registeredEvents = events;
|
||||
registeredEvents |= events;
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
||||
memHealthAtEventRegister = currentMemHealth();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
* Copyright (C) 2019-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -42,6 +42,7 @@ ze_result_t DriverHandleImp::sysmanEventsListen(
|
|||
uint32_t *pNumDeviceEvents,
|
||||
zes_event_type_flags_t *pEvents) {
|
||||
bool gotSysmanEvent = false;
|
||||
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
||||
auto timeToExitLoop = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout);
|
||||
do {
|
||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -133,6 +133,28 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEv
|
|||
delete[] pDeviceEvents;
|
||||
}
|
||||
|
||||
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEventsThenAfterReceivingEventRegisterEventAgainToReceiveEvent) {
|
||||
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]);
|
||||
numDeviceEvents = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
|
||||
EXPECT_EQ(0u, numDeviceEvents);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
|
||||
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 &>(_)))
|
||||
|
@ -192,7 +214,7 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForMemHealthEvent
|
|||
PublicLinuxEventsImp *pLinuxEventsImp = new PublicLinuxEventsImp(pOsSysman);
|
||||
pLinuxEventsImp->eventRegister(ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||
pLinuxEventsImp->memHealthAtEventRegister = ZES_MEM_HEALTH_OK;
|
||||
zes_event_type_flags_t events;
|
||||
zes_event_type_flags_t events = 0;
|
||||
uint32_t timeout = 100u;
|
||||
EXPECT_TRUE(pLinuxEventsImp->eventListen(events, timeout));
|
||||
EXPECT_EQ(events, ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||
|
|
Loading…
Reference in New Issue