[Fix, Sysman] Map uevent to device based on device path

Related-To: LOCI-4307

Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
Bellekallu Rajkiran
2023-04-12 18:30:55 +00:00
committed by Compute-Runtime-Automation
parent 9036a034bd
commit 007f5d70bf
5 changed files with 165 additions and 480 deletions

View File

@@ -246,96 +246,74 @@ bool LinuxEventsUtil::checkIfFabricPortStatusChanged(void *dev, zes_event_type_f
return false;
}
void LinuxEventsUtil::getDevIndexToDevInfoMap(std::vector<zes_event_type_flags_t> &registeredEvents, uint32_t count, zes_device_handle_t *phDevices, std::map<uint32_t, DeviceInfo> &mapOfDevIndexToDevInfo) {
void LinuxEventsUtil::getDevIndexToDevPathMap(std::vector<zes_event_type_flags_t> &registeredEvents, uint32_t count, zes_device_handle_t *phDevices, std::map<uint32_t, std::string> &mapOfDevIndexToDevPath) {
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
auto device = static_cast<SysmanDeviceImp *>(L0::SysmanDevice::fromHandle(phDevices[devIndex]));
registeredEvents[devIndex] = deviceEventsMap[device];
if (!registeredEvents[devIndex]) {
continue;
} else {
auto pDrm = &static_cast<L0::LinuxSysmanImp *>(device->deviceGetOsInterface())->getDrm();
struct stat drmStat = {};
DeviceInfo devInfo = {};
int ret = -1;
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
if ((ret = NEO::SysCalls::fstat(pDrm->getFileDescriptor(), &drmStat)) == 0) {
devInfo.deviceNum = drmStat.st_rdev;
std::string bdf;
auto pSysfsAccess = &static_cast<L0::LinuxSysmanImp *>(device->deviceGetOsInterface())->getSysfsAccess();
if (pSysfsAccess->getRealPath("device", bdf) == ZE_RESULT_SUCCESS) {
// /sys needs to be removed from real path inorder to equate with
// DEVPATH property of uevent.
// Example of real path: /sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0
// Example of DEVPATH: /devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0/i915.iaf.0
const auto loc = bdf.find("/devices");
if (loc == std::string::npos) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
"%s", "Invalid device path\n");
continue;
}
bdf = bdf.substr(loc);
mapOfDevIndexToDevPath.insert({devIndex, bdf});
} else {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
"%s", "Retrieving drm stat failed for fd %d\n", pDrm->getFileDescriptor());
}
if (registeredEvents[devIndex] & ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH) {
std::string bdfDir;
auto pSysfsAccess = &static_cast<L0::LinuxSysmanImp *>(device->deviceGetOsInterface())->getSysfsAccess();
result = pSysfsAccess->getRealPath("device", bdfDir);
if (ZE_RESULT_SUCCESS == result) {
// /sys needs to be removed from real path inorder to equate with
// DEVPATH property of uevent.
// Example of real path: /sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0
// Example of DEVPATH: /devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0/i915.iaf.0
const auto loc = bdfDir.find_first_of('/');
auto bdf = bdfDir.substr(loc + 4);
devInfo.devicePath = bdf;
} else {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
"%s", "Failed to get real path of device\n");
}
}
if ((ret != -1) || (result == ZE_RESULT_SUCCESS)) {
mapOfDevIndexToDevInfo.insert({devIndex, devInfo});
"%s", "Failed to get real path of device\n");
}
}
}
}
bool LinuxEventsUtil::checkDeviceEvents(std::vector<zes_event_type_flags_t> &registeredEvents, std::map<uint32_t, DeviceInfo> mapOfDevIndexToDevInfo, zes_event_type_flags_t *pEvents, void *dev) {
dev_t devnum = pUdevLib->getEventGenerationSourceDevice(dev);
for (auto it = mapOfDevIndexToDevInfo.begin(); it != mapOfDevIndexToDevInfo.end(); it++) {
if ((it->second.deviceNum == devnum) || ((it->second.deviceNum - 127) == devnum)) {
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
if (checkDeviceDetachEvent(pEvents[it->first])) {
return true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
if (checkDeviceAttachEvent(pEvents[it->first])) {
return true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
if (isResetRequired(dev, pEvents[it->first])) {
return true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
if (checkIfMemHealthChanged(dev, pEvents[it->first])) {
return true;
}
}
break;
}
}
bool LinuxEventsUtil::checkDeviceEvents(std::vector<zes_event_type_flags_t> &registeredEvents, std::map<uint32_t, std::string> mapOfDevIndexToDevPath, zes_event_type_flags_t *pEvents, void *dev) {
const char *devicePath = pUdevLib->getEventPropertyValue(dev, "DEVPATH");
bool retVal = false;
if (devicePath != nullptr) {
std::string devPath(devicePath);
// /i915.iaf.* needs to be removed from DEVPATH inorder to equate with
// real path of device.
// Example of real path: /sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0
// Example of DEVPATH: /devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0/i915.iaf.0
const auto loc = devPath.find_last_of('/');
devPath = devPath.substr(0, loc);
for (auto it = mapOfDevIndexToDevInfo.begin(); it != mapOfDevIndexToDevInfo.end(); it++) {
if (it->second.devicePath == devPath) {
if (checkIfFabricPortStatusChanged(dev, pEvents[it->first])) {
return true;
for (auto it = mapOfDevIndexToDevPath.begin(); it != mapOfDevIndexToDevPath.end(); it++) {
if (devPath.find(it->second.c_str()) != std::string::npos) {
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
if (checkDeviceDetachEvent(pEvents[it->first])) {
retVal = true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
if (checkDeviceAttachEvent(pEvents[it->first])) {
retVal = true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
if (isResetRequired(dev, pEvents[it->first])) {
retVal = true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
if (checkIfMemHealthChanged(dev, pEvents[it->first])) {
retVal = true;
}
}
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH) {
if (checkIfFabricPortStatusChanged(dev, pEvents[it->first])) {
retVal = true;
}
}
break;
}
}
}
return false;
return retVal;
}
bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32_t count, std::vector<zes_event_type_flags_t> &registeredEvents, zes_device_handle_t *phDevices, uint64_t timeout) {
@@ -346,7 +324,7 @@ bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32
bool retval = false;
struct pollfd pfd[2];
std::vector<std::string> subsystemList;
std::map<uint32_t, DeviceInfo> mapOfDevIndexToDevInfo = {};
std::map<uint32_t, std::string> mapOfDevIndexToDevPath = {};
if (pUdevLib == nullptr) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
@@ -372,7 +350,7 @@ bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32
auto start = L0::steadyClock::now();
std::chrono::duration<double, std::milli> timeElapsed;
getDevIndexToDevInfoMap(registeredEvents, count, phDevices, mapOfDevIndexToDevInfo);
getDevIndexToDevPathMap(registeredEvents, count, phDevices, mapOfDevIndexToDevPath);
eventsMutex.unlock();
while (NEO::SysCalls::poll(pfd, 2, static_cast<int>(timeout)) > 0) {
bool eventReceived = false;
@@ -382,8 +360,8 @@ bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32
eventsMutex.lock();
uint8_t dummy;
NEO::SysCalls::read(pipeFd[0], &dummy, 1);
mapOfDevIndexToDevInfo.clear();
getDevIndexToDevInfoMap(registeredEvents, count, phDevices, mapOfDevIndexToDevInfo);
mapOfDevIndexToDevPath.clear();
getDevIndexToDevPathMap(registeredEvents, count, phDevices, mapOfDevIndexToDevPath);
eventsMutex.unlock();
} else {
eventReceived = true;
@@ -391,7 +369,7 @@ bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32
}
}
if (mapOfDevIndexToDevInfo.empty()) {
if (mapOfDevIndexToDevPath.empty()) {
break;
}
@@ -424,7 +402,7 @@ bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32
break;
}
retval = checkDeviceEvents(registeredEvents, mapOfDevIndexToDevInfo, pEvents, dev);
retval = checkDeviceEvents(registeredEvents, mapOfDevIndexToDevPath, pEvents, dev);
pUdevLib->dropDeviceReference(dev);
if (retval) {
break;

View File

@@ -12,11 +12,6 @@
namespace L0 {
struct DeviceInfo {
std::string devicePath = {};
dev_t deviceNum = 0;
};
class LinuxEventsImp : public OsEvents, NEO::NonCopyableOrMovableClass {
public:
bool eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
@@ -58,8 +53,8 @@ class LinuxEventsUtil {
static const std::string unbind;
static const std::string bind;
static bool checkRasEventOccured(Ras *rasHandle);
void getDevIndexToDevInfoMap(std::vector<zes_event_type_flags_t> &registeredEvents, uint32_t count, zes_device_handle_t *phDevices, std::map<uint32_t, DeviceInfo> &mapOfDevIndexToDevInfo);
bool checkDeviceEvents(std::vector<zes_event_type_flags_t> &registeredEvents, std::map<uint32_t, DeviceInfo> mapOfDevIndexToDevInfo, zes_event_type_flags_t *pEvents, void *dev);
void getDevIndexToDevPathMap(std::vector<zes_event_type_flags_t> &registeredEvents, uint32_t count, zes_device_handle_t *phDevices, std::map<uint32_t, std::string> &mapOfDevIndexToDevPath);
bool checkDeviceEvents(std::vector<zes_event_type_flags_t> &registeredEvents, std::map<uint32_t, std::string> mapOfDevIndexToDevPath, zes_event_type_flags_t *pEvents, void *dev);
std::once_flag initEventsOnce;
std::mutex eventsMutex;
void init();

View File

@@ -1049,30 +1049,33 @@ void testSysmanReset(ze_device_handle_t &device, bool force) {
void testSysmanListenEvents(ze_driver_handle_t driver, std::vector<ze_device_handle_t> &devices, zes_event_type_flags_t events) {
uint32_t numDeviceEvents = 0;
zes_event_type_flags_t *pEvents = new zes_event_type_flags_t[devices.size()];
uint32_t timeout = 10000u;
uint32_t timeout = 100000u;
uint32_t numDevices = static_cast<uint32_t>(devices.size());
VALIDATECALL(zesDriverEventListen(driver, timeout, numDevices, devices.data(), &numDeviceEvents, pEvents));
if (verbose) {
if (numDeviceEvents) {
for (auto index = 0u; index < devices.size(); index++) {
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
std::cout << "Device " << index << "got reset required event" << std::endl;
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;
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;
std::cout << "Device " << index << " got DEVICE_ATTACH event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS) {
std::cout << "Device " << index << "got RAS UNCORRECTABLE event" << std::endl;
std::cout << "Device " << index << " got RAS UNCORRECTABLE event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) {
std::cout << "Device " << index << "got RAS CORRECTABLE event" << std::endl;
std::cout << "Device " << index << " got RAS CORRECTABLE event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH) {
std::cout << "Device " << index << " got Fabric Health event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
std::cout << "Device " << index << " got memory Health event" << std::endl;
}
}
}
}
@@ -1088,23 +1091,26 @@ void testSysmanListenEventsEx(ze_driver_handle_t driver, std::vector<ze_device_h
if (numDeviceEvents) {
for (auto index = 0u; index < devices.size(); index++) {
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
std::cout << "Device " << index << "got reset required event" << std::endl;
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;
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;
std::cout << "Device " << index << " got DEVICE_ATTACH event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS) {
std::cout << "Device " << index << "got RAS UNCORRECTABLE event" << std::endl;
std::cout << "Device " << index << " got RAS UNCORRECTABLE event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) {
std::cout << "Device " << index << "got RAS CORRECTABLE event" << std::endl;
std::cout << "Device " << index << " got RAS CORRECTABLE event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH) {
std::cout << "Device " << index << " got Fabric Health event" << std::endl;
}
if (pEvents[index] & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
std::cout << "Device " << index << " got memory Health event" << std::endl;
}
}
}
}
@@ -1564,7 +1570,7 @@ int main(int argc, char *argv[]) {
zesDeviceEventRegister(device,
ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH |
ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH | ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS |
ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS | ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH);
ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS | ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH | ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
});
testSysmanListenEvents(driver, devices,
ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH |
@@ -1574,7 +1580,7 @@ int main(int argc, char *argv[]) {
zesDeviceEventRegister(device,
ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH |
ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH | ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS |
ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS | ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH);
ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS | ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH | ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
});
testSysmanListenEventsEx(driver, devices,
ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH |

View File

@@ -169,9 +169,10 @@ struct MockEventsFsAccess : public FsAccess {
struct MockEventsSysfsAccess : public SysfsAccess {
ze_result_t getRealPathResult = ZE_RESULT_SUCCESS;
std::string realPath = "/sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0";
ze_result_t getRealPath(const std::string file, std::string &val) override {
val = "/sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0";
val = realPath;
return getRealPathResult;
}
@@ -203,6 +204,7 @@ class EventsUdevLibMock : public UdevLib {
EventsUdevLibMock() = default;
std::string eventPropertyValueTypeResult = "PORT_CHANGE";
std::string eventPropertyValueDevPathResult = "/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0/i915.iaf.0";
std::string getEventPropertyValueResult = "1";
const char *getEventPropertyValue(void *dev, const char *key) override {
if (strcmp(key, "TYPE") == 0) {
@@ -212,9 +214,14 @@ class EventsUdevLibMock : public UdevLib {
return nullptr;
}
} else if (strcmp(key, "DEVPATH") == 0) {
if (eventPropertyValueDevPathResult.empty()) {
return nullptr;
}
return eventPropertyValueDevPathResult.c_str();
} else if (getEventPropertyValueResult.empty()) {
return nullptr;
}
return "1";
return getEventPropertyValueResult.c_str();
}
ADDMETHOD_NOBASE(registerEventsFromSubsystemAndGetFd, int, 0, (std::vector<std::string> & subsystemList));

View File

@@ -16,7 +16,6 @@ namespace L0 {
namespace ult {
constexpr uint32_t mockHandleCount = 2u;
constexpr int drmDeviceFd = 0;
constexpr int mockReadPipeFd = 8;
constexpr int mockWritePipeFd = 9;
class SysmanEventsFixture : public SysmanDeviceFixture {
@@ -54,7 +53,7 @@ class SysmanEventsFixture : public SysmanDeviceFixture {
pEventsImp = static_cast<L0::EventsImp *>(pSysmanDeviceImp->pEvents);
// Assign pUdevLib library handle to LinuxEventImp object, so that udev library handle methods could be mocked
pLinuxSysmanImp->pUdevLib = new UdevLibMock();
pLinuxSysmanImp->pUdevLib = new EventsUdevLibMock();
pLinuxEventsImp = new PublicLinuxEventsImp(pOsSysman);
pEventsImp->pOsEvents = pLinuxEventsImp;
pPmuInterface = std::make_unique<MockPmuInterfaceImpForEvents>(pLinuxSysmanImp);
@@ -121,17 +120,11 @@ TEST_F(SysmanEventsFixture, GivenValidSysmanHandleWhenEventsAreClearedThenDevice
}
return 1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -166,19 +159,13 @@ TEST_F(SysmanEventsFixture, GivenPollSystemCallReturnsFailureWhenlisteningForRes
pollFd[i].revents = POLLIN;
}
}
return 1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
return -1;
});
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -217,21 +204,12 @@ TEST_F(SysmanEventsFixture, GivenPipeSystemCallReturnsFailureWhenlisteningForRes
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -274,21 +252,12 @@ TEST_F(SysmanEventsFixture, GivenPollSystemCallReturnsOnAllFdsWhenlisteningForRe
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -333,21 +302,12 @@ TEST_F(SysmanEventsFixture, GivenPollSystemCallReturnsOnPipeFdWhenlisteningForRe
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -411,17 +371,11 @@ TEST_F(SysmanEventsFixture, GivenNoEventsAreRegisteredWhenListeningForEventsThen
VariableBackup<decltype(SysCalls::sysCallsPoll)> mockPoll(&SysCalls::sysCallsPoll, [](struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) -> int {
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -498,7 +452,7 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForCurrentlyUnsup
}
TEST_F(SysmanEventsFixture,
GivenValidDeviceHandleAndListeningForEventsWhenEventGenerationSourceDeviceIsNotDrmAndAuxiliaryThenEventListenReturnFalse) {
GivenValidDeviceHandleAndListeningForEventsWhenEventGeneratedDevicePathIsNullThenEventListenReturnsAfterTimeout) {
VariableBackup<FirmwareUtil *> backupFwUtil(&pLinuxSysmanImp->pFwUtilInterface);
auto pMockFwInterface = new MockEventsFwInterface;
pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface;
@@ -516,21 +470,13 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->eventPropertyValueDevPathResult.clear();
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -570,17 +516,11 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -615,21 +555,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleAndListeningEventsWhenNullEven
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->getEventTypeResult = nullptr;
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -672,19 +603,11 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
pUdevLibLocal->allocateDeviceToReceiveDataResult = nullptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 10;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -727,21 +650,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredE
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -767,62 +681,6 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForResetRequiredE
delete pMockFwInterface;
}
TEST_F(SysmanEventsFixture, GivenFstatSystemCallFailsWhenListeningForResetRequiredEventsThenEventListenAPIReturnsAfterTimeout) {
VariableBackup<FirmwareUtil *> backupFwUtil(&pLinuxSysmanImp->pFwUtilInterface);
auto pMockFwInterface = new MockEventsFwInterface;
pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface;
VariableBackup<decltype(SysCalls::sysCallsPipe)> mockPipe(&SysCalls::sysCallsPipe, [](int pipeFd[2]) -> int {
pipeFd[0] = mockReadPipeFd;
pipeFd[1] = mockWritePipeFd;
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsPoll)> mockPoll(&SysCalls::sysCallsPoll, [](struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) -> int {
for (uint64_t i = 0; i < numberOfFds; i++) {
if (pollFd[i].fd == mockFd) {
pollFd[i].revents = POLLIN;
}
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
return -1;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
GlobalOsSysmanDriver = static_cast<L0::OsSysmanDriver *>(pPublicLinuxSysmanDriverImp);
VariableBackup<L0::UdevLib *> udevBackup(&pPublicLinuxSysmanDriverImp->pUdevLib);
pPublicLinuxSysmanDriverImp->pUdevLib = pUdevLibLocal;
// Step 4: Call APIs for validation
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED));
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(), 1u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
// Step 5: Cleanup
delete[] phDevices;
delete[] pDeviceEvents;
L0::osSysmanDriverDestructor();
delete pMockFwInterface;
}
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenEventRegisterIsCalledThenSuccessIsReturned) {
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -882,76 +740,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForFabricHealthEv
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 12345;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 12218;
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
GlobalOsSysmanDriver = static_cast<L0::OsSysmanDriver *>(pPublicLinuxSysmanDriverImp);
VariableBackup<L0::UdevLib *> udevBackup(&pPublicLinuxSysmanDriverImp->pUdevLib);
pPublicLinuxSysmanDriverImp->pUdevLib = pUdevLibLocal;
// Step 4: Call APIs for validation
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH));
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(), 1u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(1u, numDeviceEvents);
EXPECT_EQ(ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH, pDeviceEvents[0]);
// Step 5: Cleanup
delete[] phDevices;
delete[] pDeviceEvents;
L0::osSysmanDriverDestructor();
delete pMockFwInterface;
}
TEST_F(SysmanEventsFixture, GivenFstatSystemCallFailsWhenListeningForFabricHealthEventsThenEventListenAPIReturnsAfterTimeout) {
VariableBackup<FirmwareUtil *> backupFwUtil(&pLinuxSysmanImp->pFwUtilInterface);
auto pMockFwInterface = new MockEventsFwInterface;
pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface;
VariableBackup<decltype(SysCalls::sysCallsPipe)> mockPipe(&SysCalls::sysCallsPipe, [](int pipeFd[2]) -> int {
pipeFd[0] = mockReadPipeFd;
pipeFd[1] = mockWritePipeFd;
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsPoll)> mockPoll(&SysCalls::sysCallsPoll, [](struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) -> int {
for (uint64_t i = 0; i < numberOfFds; i++) {
if (pollFd[i].fd == mockFd) {
pollFd[i].revents = POLLIN;
}
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
return -1;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -995,13 +789,6 @@ TEST_F(SysmanEventsFixture, GivenImproperDevPathForUeventWhenListeningForFabricH
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
@@ -1052,13 +839,6 @@ TEST_F(SysmanEventsFixture, GivenInvalidEventTypeWhenListeningForFabricHealthEve
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
@@ -1109,13 +889,6 @@ TEST_F(SysmanEventsFixture, GivenRealPathSystemCallFailsWhenListeningForFabricHe
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
pSysfsAccess->getRealPathResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
@@ -1149,6 +922,57 @@ TEST_F(SysmanEventsFixture, GivenRealPathSystemCallFailsWhenListeningForFabricHe
delete pMockFwInterface;
}
TEST_F(SysmanEventsFixture, GivenRealPathSystemCallReturnsInvalidDeviceWhenListeningForFabricHealthEventsThenEventListenAPIReturnsAfterTimeout) {
VariableBackup<FirmwareUtil *> backupFwUtil(&pLinuxSysmanImp->pFwUtilInterface);
auto pMockFwInterface = new MockEventsFwInterface;
pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface;
VariableBackup<decltype(SysCalls::sysCallsPipe)> mockPipe(&SysCalls::sysCallsPipe, [](int pipeFd[2]) -> int {
pipeFd[0] = mockReadPipeFd;
pipeFd[1] = mockWritePipeFd;
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsPoll)> mockPoll(&SysCalls::sysCallsPoll, [](struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) -> int {
for (uint64_t i = 0; i < numberOfFds; i++) {
if (pollFd[i].fd == mockFd) {
pollFd[i].revents = POLLIN;
}
}
return 1;
});
pSysfsAccess->realPath = "Invalid";
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 20;
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
GlobalOsSysmanDriver = static_cast<L0::OsSysmanDriver *>(pPublicLinuxSysmanDriverImp);
VariableBackup<L0::UdevLib *> udevBackup(&pPublicLinuxSysmanDriverImp->pUdevLib);
pPublicLinuxSysmanDriverImp->pUdevLib = pUdevLibLocal;
// Step 4: Call APIs for validation
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH));
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(), 1u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
EXPECT_EQ(0u, numDeviceEvents);
// Step 5: Cleanup
delete[] phDevices;
delete[] pDeviceEvents;
L0::osSysmanDriverDestructor();
delete pMockFwInterface;
}
TEST_F(SysmanEventsFixture, GivenEventPropertyForTypeKeyIsNullPtrWhenListeningForFabricHealthEventsThenEventListenAPIReturnsAfterTimeout) {
VariableBackup<FirmwareUtil *> backupFwUtil(&pLinuxSysmanImp->pFwUtilInterface);
auto pMockFwInterface = new MockEventsFwInterface;
@@ -1167,13 +991,6 @@ TEST_F(SysmanEventsFixture, GivenEventPropertyForTypeKeyIsNullPtrWhenListeningFo
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
@@ -1224,13 +1041,6 @@ TEST_F(SysmanEventsFixture, GivenEventPropertyForTypeKeyInvalidWhenListeningForF
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new EventsUdevLibMock();
@@ -1327,20 +1137,12 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "0";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1385,22 +1187,13 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventTypeResult = "add"; // In order to receive RESET_REQUIRED event type must be "change"
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -1444,21 +1237,13 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = nullptr;
pUdevLibLocal->getEventPropertyValueResult.clear();
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -1502,13 +1287,6 @@ HWTEST2_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 4: Call APIs for validation
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED));
@@ -1541,21 +1319,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEv
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->getEventTypeResult = "remove";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1596,21 +1365,12 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->getEventTypeResult = "change"; // ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH will be received only if EventType is "remove"
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1649,21 +1409,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceAttachEv
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->getEventTypeResult = "add";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1704,21 +1455,12 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->getEventTypeResult = "change"; // ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH will be received only if EventType is "add"
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1757,21 +1499,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceAttachEv
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
pUdevLibLocal->getEventTypeResult = "add";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1811,21 +1544,12 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForMemHealthEvent
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "1";
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -1865,20 +1589,12 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = "0"; // getEventPropertyValue must return 1 in order to assure that MEM_HEALTH event is there
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
@@ -1918,22 +1634,13 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventTypeResult = "add"; // In order to receive MEM_HEALTH event type must be "change"
pUdevLibLocal->getEventPropertyValueResult = "1"; // getEventPropertyValue must return 1 in order to assure that MEM_HEALTH event is there
pUdevLibLocal->getEventTypeResult = "add"; // In order to receive MEM_HEALTH event type must be "change"
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
@@ -1972,21 +1679,13 @@ TEST_F(SysmanEventsFixture,
}
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return drmDeviceFd;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsFstat)> mockFstat(&NEO::SysCalls::sysCallsFstat, [](int fd, struct stat *buf) -> int {
buf->st_rdev = 0;
return 0;
});
// Step 1: Initialize a mocked udev lib object for this test case
auto pUdevLibLocal = new UdevLibMock();
auto pUdevLibLocal = new EventsUdevLibMock();
int a = 0;
void *ptr = &a; // Initialize a void pointer with dummy data
pUdevLibLocal->allocateDeviceToReceiveDataResult = ptr;
pUdevLibLocal->getEventGenerationSourceDeviceResult = 0;
pUdevLibLocal->getEventPropertyValueResult = nullptr; // getEventPropertyValue must return 1 in order to assure that MEM_HEALTH event is there
pUdevLibLocal->getEventPropertyValueResult.clear(); // getEventPropertyValue must return 1 in order to assure that MEM_HEALTH event is there
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);