Revert "Add support for serial number property"

This reverts commit ba461e565e.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2022-10-09 06:25:33 +02:00
committed by Compute-Runtime-Automation
parent 1c73031a9b
commit 668f988e61
13 changed files with 45 additions and 454 deletions

View File

@ -9,10 +9,8 @@
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/string.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/tools/source/sysman/sysman_const.h"
namespace L0 {
@ -74,10 +72,7 @@ void GlobalOperationsImp::init() {
pOsGlobalOperations->getModelName(sysmanProperties.modelName);
pOsGlobalOperations->getBrandName(sysmanProperties.brandName);
pOsGlobalOperations->getBoardNumber(sysmanProperties.boardNumber);
memset(sysmanProperties.serialNumber, 0, ZES_STRING_PROPERTY_SIZE);
if (!pOsGlobalOperations->getSerialNumber(sysmanProperties.serialNumber)) {
memcpy_s(sysmanProperties.serialNumber, ZES_STRING_PROPERTY_SIZE, unknown.c_str(), unknown.length() + 1);
}
pOsGlobalOperations->getSerialNumber(sysmanProperties.serialNumber);
}
void GlobalOperationsImp::initGlobalOperations() {
std::call_once(initGlobalOpOnce, [this]() {

View File

@ -8,7 +8,6 @@
#include "level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/linux/pci_path.h"
#include "level_zero/core/source/device/device_imp.h"
#include "level_zero/tools/source/sysman/global_operations/global_operations_imp.h"
@ -42,56 +41,8 @@ static const std::map<int, zes_engine_type_flags_t> engineMap = {
{3, ZES_ENGINE_TYPE_FLAG_MEDIA},
{4, ZES_ENGINE_TYPE_FLAG_COMPUTE}};
bool LinuxGlobalOperationsImp::readSerialNumber(std::string_view telemDir, std::array<char, NEO::PmtUtil::guidStringSize> &guidString, const uint64_t offset, char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) {
std::map<std::string, uint64_t> keyOffsetMap;
if (ZE_RESULT_SUCCESS == PlatformMonitoringTech::getKeyOffsetMap(guidString.data(), keyOffsetMap)) {
auto ppinOffset = keyOffsetMap.find("PPIN");
if (ppinOffset != keyOffsetMap.end()) {
uint64_t value;
ssize_t bytesRead = NEO::PmtUtil::readTelem(telemDir.data(), sizeof(uint64_t), ppinOffset->second + offset, &value);
if (bytesRead == sizeof(uint64_t)) {
std::ostringstream serialNumberString;
serialNumberString << std::hex << std::showbase << value;
memcpy_s(serialNumber, ZES_STRING_PROPERTY_SIZE, serialNumberString.str().c_str(), serialNumberString.str().size());
return true;
}
}
}
return false;
}
bool LinuxGlobalOperationsImp::getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) {
auto pDrm = &pLinuxSysmanImp->getDrm();
std::optional<std::string> rootPath = NEO::getPciRootPath(pDrm->getFileDescriptor());
if (!rootPath.has_value()) {
return false;
}
std::map<uint32_t, std::string> telemPciPath;
NEO::PmtUtil::getTelemNodesInPciPath(rootPath.value(), telemPciPath);
if (telemPciPath.size() < pDevice->getNEODevice()->getNumSubDevices() + 1) {
return false;
}
auto iterator = telemPciPath.begin();
std::string telemDir = iterator->second;
std::array<char, NEO::PmtUtil::guidStringSize> guidString;
if (!NEO::PmtUtil::readGuid(telemDir, guidString)) {
return false;
}
uint64_t offset = ULONG_MAX;
if (!NEO::PmtUtil::readOffset(telemDir, offset)) {
return false;
}
if (!LinuxGlobalOperationsImp::readSerialNumber(telemDir, guidString, offset, serialNumber)) {
return false;
}
return true;
void LinuxGlobalOperationsImp::getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) {
std::strncpy(serialNumber, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
}
Device *LinuxGlobalOperationsImp::getDevice() {

View File

@ -6,8 +6,6 @@
*/
#pragma once
#include "shared/source/os_interface/linux/pmt_util.h"
#include "level_zero/tools/source/sysman/global_operations/os_global_operations.h"
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h"
@ -17,7 +15,7 @@ struct Device;
class LinuxGlobalOperationsImp : public OsGlobalOperations, NEO::NonCopyableOrMovableClass {
public:
bool getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) override;
void getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) override;
void getBoardNumber(char (&boardNumber)[ZES_STRING_PROPERTY_SIZE]) override;
void getBrandName(char (&brandName)[ZES_STRING_PROPERTY_SIZE]) override;
void getModelName(char (&modelName)[ZES_STRING_PROPERTY_SIZE]) override;
@ -54,7 +52,6 @@ class LinuxGlobalOperationsImp : public OsGlobalOperations, NEO::NonCopyableOrMo
static const std::string srcVersionFile;
static const std::string agamaVersionFile;
static const std::string ueventWedgedFile;
static bool readSerialNumber(std::string_view telemDir, std::array<char, NEO::PmtUtil::guidStringSize> &guidString, const uint64_t offset, char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]);
std::string devicePciBdf = "";
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
uint32_t rootDeviceIndex = 0u;

View File

@ -18,7 +18,7 @@ namespace L0 {
class OsGlobalOperations {
public:
virtual bool getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) = 0;
virtual void getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) = 0;
virtual void getBoardNumber(char (&boardNumber)[ZES_STRING_PROPERTY_SIZE]) = 0;
virtual void getBrandName(char (&brandName)[ZES_STRING_PROPERTY_SIZE]) = 0;
virtual void getModelName(char (&modelName)[ZES_STRING_PROPERTY_SIZE]) = 0;

View File

@ -13,8 +13,7 @@ Device *WddmGlobalOperationsImp::getDevice() {
return pDevice;
}
bool WddmGlobalOperationsImp::getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) {
return false;
void WddmGlobalOperationsImp::getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) {
}
void WddmGlobalOperationsImp::getBoardNumber(char (&boardNumber)[ZES_STRING_PROPERTY_SIZE]) {

View File

@ -16,7 +16,7 @@ namespace L0 {
class KmdSysManager;
class WddmGlobalOperationsImp : public OsGlobalOperations, NEO::NonCopyableOrMovableClass {
public:
bool getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) override;
void getSerialNumber(char (&serialNumber)[ZES_STRING_PROPERTY_SIZE]) override;
void getBoardNumber(char (&boardNumber)[ZES_STRING_PROPERTY_SIZE]) override;
void getBrandName(char (&brandName)[ZES_STRING_PROPERTY_SIZE]) override;
void getModelName(char (&modelName)[ZES_STRING_PROPERTY_SIZE]) override;

View File

@ -146,7 +146,7 @@ static std::string modifyPathOnLevel(std::string realPciPath, uint8_t nLevel) {
}
return realPciPath;
}
std::string LinuxSysmanImp::getPciRootPortDirectoryPath(std::string realPciPath) {
std::string getPciRootPortDirectoryPath(std::string realPciPath) {
// the rootport is always the first pci folder after the pcie slot.
// +-[0000:89]-+-00.0
// | +-00.1

View File

@ -56,7 +56,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
ze_device_handle_t getCoreDeviceHandle() override;
SysmanDeviceImp *getSysmanDeviceImp();
std::string getPciCardBusDirectoryPath(std::string realPciPath);
static std::string getPciRootPortDirectoryPath(std::string realPciPath);
void releasePmtObject();
ze_result_t createPmtHandles();
void createFwUtilInterface();

View File

@ -153,7 +153,7 @@ ze_result_t PlatformMonitoringTech::init(FsAccess *pFsAccess, const std::string
"Telemetry sysfs entry not available %s\n", guidPath.c_str());
return result;
}
result = PlatformMonitoringTech::getKeyOffsetMap(guid, keyOffsetMap);
result = getKeyOffsetMap(guid, keyOffsetMap);
if (ZE_RESULT_SUCCESS != result) {
// We didnt have any entry for this guid in guidToKeyOffsetMap
return result;

View File

@ -31,12 +31,12 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass {
static void create(const std::vector<ze_device_handle_t> &deviceHandles,
FsAccess *pFsAccess, std::string &gpuUpstreamPortPath,
std::map<uint32_t, L0::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject);
static ze_result_t getKeyOffsetMap(std::string guid, std::map<std::string, uint64_t> &keyOffsetMap);
protected:
static uint32_t rootDeviceTelemNodeIndex;
std::string telemetryDeviceEntry{};
std::map<std::string, uint64_t> keyOffsetMap;
ze_result_t getKeyOffsetMap(std::string guid, std::map<std::string, uint64_t> &keyOffsetMap);
ze_result_t init(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, PRODUCT_FAMILY productFamily);
static void doInitPmtObject(FsAccess *pFsAccess, uint32_t subdeviceId, PlatformMonitoringTech *pPmt, const std::string &gpuUpstreamPortPath,
std::map<uint32_t, L0::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject, PRODUCT_FAMILY productFamily);

View File

@ -239,6 +239,36 @@ const std::map<std::string, std::map<std::string, uint64_t>> guidToKeyOffsetMap
{"VF1_HBM2_WRITE", 348},
{"VF1_HBM3_READ", 360},
{"VF1_HBM3_WRITE", 364}}},
{"0x41fe79a5", // For PVC root device
{{"PPIN", 152}}}};
{"0xb15a0edd", // For PVC device
{{"HBM0MaxDeviceTemperature", 28},
{"HBM1MaxDeviceTemperature", 36},
{"TileMinTemperature", 40},
{"TileMaxTemperature", 44},
{"GTMinTemperature", 48},
{"GTMaxTemperature", 52},
{"VF0_VFID", 88},
{"VF0_HBM0_READ", 92},
{"VF0_HBM0_WRITE", 96},
{"VF0_HBM1_READ", 104},
{"VF0_HBM1_WRITE", 108},
{"VF0_TIMESTAMP_L", 168},
{"VF0_TIMESTAMP_H", 172},
{"VF1_VFID", 176},
{"VF1_HBM0_READ", 180},
{"VF1_HBM0_WRITE", 184},
{"VF1_HBM1_READ", 192},
{"VF1_HBM1_WRITE", 196},
{"VF1_TIMESTAMP_L", 256},
{"VF1_TIMESTAMP_H", 260},
{"HBM2MaxDeviceTemperature", 300},
{"HBM3MaxDeviceTemperature", 308},
{"VF0_HBM2_READ", 312},
{"VF0_HBM2_WRITE", 316},
{"VF0_HBM3_READ", 328},
{"VF0_HBM3_WRITE", 332},
{"VF1_HBM2_READ", 344},
{"VF1_HBM2_WRITE", 348},
{"VF1_HBM3_READ", 360},
{"VF1_HBM3_WRITE", 364}}}};
} // namespace L0

View File

@ -48,7 +48,7 @@ const std::string driverVersion("5.0.0-37-generic SMP mod_unload");
const std::string srcVersion("5.0.0-37");
const std::string ueventWedgedFile("/var/lib/libze_intel_gpu/wedged_file");
const std::string mockFunctionResetPath("/MOCK_FUNCTION_LEVEL_RESET_PATH");
const std::string mockDeviceDir("devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0");
const std::string mockDeviceDir("/MOCK_DEVICE_DIR");
const std::string mockDeviceName("/MOCK_DEVICE_NAME");
struct GlobalOperationsEngineHandleContext : public EngineHandleContext {

View File

@ -6,8 +6,6 @@
*/
#include "shared/test/common/helpers/ult_hw_config.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
@ -180,63 +178,8 @@ class SysmanGlobalOperationsIntegratedFixture : public SysmanGlobalOperationsFix
}
};
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhenCallingzesGlobalOperationsGetPropertiesThenVerifyValidPropertiesAreReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
{"/sys/class/intel_pmt/telem1", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
std::vector<std::string> supportedFiles = {
"/sys/class/intel_pmt/telem1/guid",
"/sys/class/intel_pmt/telem1/offset",
"/sys/class/intel_pmt/telem1/telem",
};
auto itr = std::find(supportedFiles.begin(), supportedFiles.end(), std::string(pathname));
if (itr != supportedFiles.end()) {
// skipping "0"
return static_cast<int>(std::distance(supportedFiles.begin(), itr)) + 1;
}
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::vector<std::pair<std::string, std::string>> supportedFiles = {
{"/sys/class/intel_pmt/telem1/guid", "0x41fe79a5\n"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
if ((--fd >= 0) && (fd < static_cast<int>(supportedFiles.size()))) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0x3e8c9dfe1c2e4d5c;
memcpy(buf, &data, sizeof(data));
return count;
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return count;
}
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhenCallingzetGlobalOperationsGetPropertiesThenVerifyzetGlobalOperationsGetPropertiesCallSucceeds) {
zes_device_properties_t properties;
const std::string expectedSerialNumber("0x3e8c9dfe1c2e4d5c");
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
@ -245,331 +188,8 @@ TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhenCallingzesGlobal
EXPECT_TRUE(0 == vendorIntel.compare(properties.brandName));
EXPECT_TRUE(0 == driverVersion.compare(properties.driverVersion));
EXPECT_TRUE(0 == expectedModelName.compare(properties.modelName));
EXPECT_TRUE(0 == expectedSerialNumber.compare(properties.serialNumber));
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
EXPECT_TRUE(0 == vendorIntel.compare(properties.vendorName));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndReadTelemOffsetFailsWhenCallingzesGlobalOperationsGetPropertiesThenInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
{"/sys/class/intel_pmt/telem1", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
std::vector<std::string> supportedFiles = {
"/sys/class/intel_pmt/telem1/guid",
"/sys/class/intel_pmt/telem1/offset",
"/sys/class/intel_pmt/telem1/telem",
};
auto itr = std::find(supportedFiles.begin(), supportedFiles.end(), std::string(pathname));
if (itr != supportedFiles.end()) {
if (std::string(pathname) == "/sys/class/intel_pmt/telem1/offset") {
return 0;
}
return static_cast<int>(std::distance(supportedFiles.begin(), itr)) + 1;
}
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::vector<std::pair<std::string, std::string>> supportedFiles = {
{"/sys/class/intel_pmt/telem1/guid", "0x41fe79a5\n"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
if ((--fd >= 0) && (fd < static_cast<int>(supportedFiles.size()))) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0x3e8c9dfe1c2e4d5c;
memcpy(buf, &data, sizeof(data));
return count;
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return count;
}
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndInvalidGuidWhenCallingzesGlobalOperationsGetPropertiesThenInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
{"/sys/class/intel_pmt/telem1", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
std::vector<std::string> supportedFiles = {
"/sys/class/intel_pmt/telem1/guid",
"/sys/class/intel_pmt/telem1/offset",
"/sys/class/intel_pmt/telem1/telem",
};
auto itr = std::find(supportedFiles.begin(), supportedFiles.end(), std::string(pathname));
if (itr != supportedFiles.end()) {
return static_cast<int>(std::distance(supportedFiles.begin(), itr)) + 1;
}
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::vector<std::pair<std::string, std::string>> supportedFiles = {
{"/sys/class/intel_pmt/telem1/guid", "Invalidguid\n"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
if ((--fd >= 0) && (fd < static_cast<int>(supportedFiles.size()))) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0x3e8c9dfe1c2e4d5c;
memcpy(buf, &data, sizeof(data));
return count;
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return count;
}
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndPpinOffsetIsAbsentWhenCallingzesGlobalOperationsGetPropertiesThenInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
{"/sys/class/intel_pmt/telem1", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
std::vector<std::string> supportedFiles = {
"/sys/class/intel_pmt/telem1/guid",
"/sys/class/intel_pmt/telem1/offset",
"/sys/class/intel_pmt/telem1/telem",
};
auto itr = std::find(supportedFiles.begin(), supportedFiles.end(), std::string(pathname));
if (itr != supportedFiles.end()) {
return static_cast<int>(std::distance(supportedFiles.begin(), itr)) + 1;
}
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::vector<std::pair<std::string, std::string>> supportedFiles = {
{"/sys/class/intel_pmt/telem1/guid", "0xb15a0edd\n"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
if ((--fd >= 0) && (fd < static_cast<int>(supportedFiles.size()))) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0x3e8c9dfe1c2e4d5c;
memcpy(buf, &data, sizeof(data));
return count;
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return count;
}
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndReadPpinInfoFailsWhenCallingzesGlobalOperationsGetPropertiesThenInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
{"/sys/class/intel_pmt/telem1", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
std::vector<std::string> supportedFiles = {
"/sys/class/intel_pmt/telem1/guid",
"/sys/class/intel_pmt/telem1/offset",
"/sys/class/intel_pmt/telem1/telem",
};
auto itr = std::find(supportedFiles.begin(), supportedFiles.end(), std::string(pathname));
if (itr != supportedFiles.end()) {
return static_cast<int>(std::distance(supportedFiles.begin(), itr)) + 1;
}
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::vector<std::pair<std::string, std::string>> supportedFiles = {
{"/sys/class/intel_pmt/telem1/guid", "0x41fe79a5\n"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
if ((--fd >= 0) && (fd < static_cast<int>(supportedFiles.size()))) {
if (supportedFiles[fd].first == "/sys/class/intel_pmt/telem1/telem") {
return 0;
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return count;
}
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndOpenSysCallFailsWhenCallingzesGlobalOperationsGetPropertiesThenInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
{"/sys/class/intel_pmt/telem1", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return 0;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndTelemNodeReadLinkFailsWhenCallingzesGlobalOperationsGetPropertiesThenVerifyInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
std::map<std::string, std::string> fileNameLinkMap = {
{"/sys/dev/char/226:128", "../../devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8a:00.0/drm/renderD128"},
};
auto it = fileNameLinkMap.find(std::string(path));
if (it != fileNameLinkMap.end()) {
std::memcpy(buf, it->second.c_str(), it->second.size());
return static_cast<int>(it->second.size());
}
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleAndReadLinkFailsWhenCallingzesGlobalOperationsGetPropertiesThenVerifyInvalidSerialNumberIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
return -1;
});
auto pDrmMock = std::make_unique<DrmMock>((const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
auto pOriginalDrm = pLinuxSysmanImp->pDrm;
pLinuxSysmanImp->pDrm = pDrmMock.get();
zes_device_properties_t properties;
ze_result_t result = zesDeviceGetProperties(device, &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_TRUE(0 == unknown.compare(properties.serialNumber));
pLinuxSysmanImp->pDrm = pOriginalDrm;
}
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhenCallingzesDeviceGetPropertiesForCheckingDriverVersionWhenAgmaFileIsAbsentThenVerifyzesDeviceGetPropertiesCallSucceeds) {