Add uuid support using inband information

Added chipset specific uuid retrieving functionality
This is used by zeDeviceGetProperties


Related-To: LOCI-2636

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2021-11-26 09:40:06 +00:00
committed by Compute-Runtime-Automation
parent cf70a57efb
commit 06be26fd1e
22 changed files with 1202 additions and 10 deletions

View File

@@ -22,6 +22,8 @@
#include "CL/cl.h" #include "CL/cl.h"
static_assert(NEO::HwInfoConfig::uuidSize == ZE_MAX_DEVICE_UUID_SIZE);
struct _ze_device_handle_t {}; struct _ze_device_handle_t {};
namespace NEO { namespace NEO {
class Device; class Device;

View File

@@ -10,6 +10,7 @@
#include "shared/source/built_ins/sip.h" #include "shared/source/built_ins/sip.h"
#include "shared/source/command_container/implicit_scaling.h" #include "shared/source/command_container/implicit_scaling.h"
#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h"
#include "shared/source/device/device_info.h" #include "shared/source/device/device_info.h"
#include "shared/source/device/sub_device.h" #include "shared/source/device/sub_device.h"
#include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/execution_environment.h"
@@ -465,12 +466,18 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties)
pDeviceProperties->flags = 0u; pDeviceProperties->flags = 0u;
uint32_t rootDeviceIndex = this->neoDevice->getRootDeviceIndex(); std::array<uint8_t, NEO::HwInfoConfig::uuidSize> deviceUuid;
if (this->neoDevice->getUuid(deviceUuid)) {
std::copy_n(std::begin(deviceUuid), ZE_MAX_DEVICE_UUID_SIZE, std::begin(pDeviceProperties->uuid.id));
} else {
memset(pDeviceProperties->uuid.id, 0, ZE_MAX_DEVICE_UUID_SIZE); uint32_t rootDeviceIndex = this->neoDevice->getRootDeviceIndex();
memcpy_s(pDeviceProperties->uuid.id, sizeof(uint32_t), &pDeviceProperties->vendorId, sizeof(pDeviceProperties->vendorId));
memcpy_s(pDeviceProperties->uuid.id + sizeof(uint32_t), sizeof(uint32_t), &pDeviceProperties->deviceId, sizeof(pDeviceProperties->deviceId)); memset(pDeviceProperties->uuid.id, 0, ZE_MAX_DEVICE_UUID_SIZE);
memcpy_s(pDeviceProperties->uuid.id + (2 * sizeof(uint32_t)), sizeof(uint32_t), &rootDeviceIndex, sizeof(rootDeviceIndex)); memcpy_s(pDeviceProperties->uuid.id, sizeof(uint32_t), &deviceInfo.vendorId, sizeof(deviceInfo.vendorId));
memcpy_s(pDeviceProperties->uuid.id + sizeof(uint32_t), sizeof(uint32_t), &hardwareInfo.platform.usDeviceID, sizeof(hardwareInfo.platform.usDeviceID));
memcpy_s(pDeviceProperties->uuid.id + (2 * sizeof(uint32_t)), sizeof(uint32_t), &rootDeviceIndex, sizeof(rootDeviceIndex));
}
pDeviceProperties->subdeviceId = isSubdevice ? static_cast<NEO::SubDevice *>(neoDevice)->getSubDeviceIndex() : 0; pDeviceProperties->subdeviceId = isSubdevice ? static_cast<NEO::SubDevice *>(neoDevice)->getSubDeviceIndex() : 0;

View File

@@ -0,0 +1,12 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(UNIX)
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_device_uuid.cpp
)
endif()

View File

@@ -0,0 +1,137 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/device/root_device.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "gtest/gtest.h"
namespace L0 {
namespace ult {
struct TestDeviceUuid : public ::testing::Test {
void SetUp() override {}
void TearDown() override {}
};
HWTEST2_F(TestDeviceUuid, GivenCorrectTelemetryNodesAreAvailableWhenRetrievingDeviceAndSubDevicePropertiesThenCorrectUuidIsReceived, IsXEHP) {
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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(&NEO::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(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::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", "0xfdc76195"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0xFEEDBEADDEABDEEF;
memcpy(buf, &data, sizeof(data));
return sizeof(data);
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
DebugManagerStateRestore restore;
DebugManager.flags.CreateMultipleSubDevices.set(2);
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
DrmMockResources *drmMock = nullptr;
auto executionEnvironment = new NEO::ExecutionEnvironment();
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
auto osInterface = new OSInterface();
drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
std::vector<std::string> pciPaths = {
"0000:3a:00.0"};
drmMock->setPciPath(pciPaths[0].c_str());
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
uint64_t expectedVal = 0xFEEDBEADDEABDEEF;
ze_device_properties_t deviceProps;
deviceProps = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
EXPECT_EQ(ZE_RESULT_SUCCESS, device->getProperties(&deviceProps));
EXPECT_TRUE(0 == std::memcmp(deviceProps.uuid.id, &expectedVal, sizeof(expectedVal)));
uint32_t subdeviceCount = neoDevice->getNumGenericSubDevices();
std::vector<ze_device_handle_t> subdevices;
subdevices.resize(subdeviceCount);
device->getSubDevices(&subdeviceCount, subdevices.data());
uint8_t expectedUuid[16] = {0};
std::memcpy(expectedUuid, &expectedVal, sizeof(uint64_t));
expectedUuid[15] = 1;
EXPECT_EQ(ZE_RESULT_SUCCESS, static_cast<Device *>(subdevices[0])->getProperties(&deviceProps));
EXPECT_TRUE(0 == std::memcmp(deviceProps.uuid.id, expectedUuid, sizeof(expectedUuid)));
expectedUuid[15] = 2;
EXPECT_EQ(ZE_RESULT_SUCCESS, static_cast<Device *>(subdevices[1])->getProperties(&deviceProps));
EXPECT_TRUE(0 == std::memcmp(deviceProps.uuid.id, expectedUuid, sizeof(expectedUuid)));
}
} // namespace ult
} // namespace L0

View File

@@ -267,6 +267,10 @@ bool Device::createDeviceImpl() {
} }
createBindlessHeapsHelper(); createBindlessHeapsHelper();
if (!isEngineInstanced()) {
auto hardwareInfo = getRootDeviceEnvironment().getMutableHardwareInfo();
uuid.isValid = HwInfoConfig::get(hardwareInfo->platform.eProductFamily)->getUuid(this, uuid.id);
}
return true; return true;
} }
@@ -637,4 +641,12 @@ void Device::finalizeRayTracing() {
} }
OSTime *Device::getOSTime() const { return getRootDeviceEnvironment().osTime.get(); }; OSTime *Device::getOSTime() const { return getRootDeviceEnvironment().osTime.get(); };
bool Device::getUuid(std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) {
if (this->uuid.isValid) {
uuid = this->uuid.id;
}
return this->uuid.isValid;
}
} // namespace NEO } // namespace NEO

View File

@@ -16,6 +16,7 @@
#include "shared/source/helpers/engine_control.h" #include "shared/source/helpers/engine_control.h"
#include "shared/source/helpers/engine_node_helper.h" #include "shared/source/helpers/engine_node_helper.h"
#include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/hw_info.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/performance_counters.h" #include "shared/source/os_interface/performance_counters.h"
#include "shared/source/program/sync_buffer_handler.h" #include "shared/source/program/sync_buffer_handler.h"
@@ -129,6 +130,7 @@ class Device : public ReferenceTrackedObject<Device> {
uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const; uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const;
const std::vector<SubDevice *> getSubDevices() const { return subdevices; } const std::vector<SubDevice *> getSubDevices() const { return subdevices; }
bool getUuid(std::array<uint8_t, HwInfoConfig::uuidSize> &uuid);
protected: protected:
Device() = delete; Device() = delete;
@@ -190,6 +192,10 @@ class Device : public ReferenceTrackedObject<Device> {
GraphicsAllocation *rtMemoryBackedBuffer = nullptr; GraphicsAllocation *rtMemoryBackedBuffer = nullptr;
std::vector<GraphicsAllocation *> rtDispatchGlobals; std::vector<GraphicsAllocation *> rtDispatchGlobals;
struct {
bool isValid = false;
std::array<uint8_t, HwInfoConfig::uuidSize> id;
} uuid;
}; };
inline EngineControl &Device::getDefaultEngine() { inline EngineControl &Device::getDefaultEngine() {

View File

@@ -28,6 +28,7 @@ class HwInfoConfig {
static HwInfoConfig *get(PRODUCT_FAMILY product) { static HwInfoConfig *get(PRODUCT_FAMILY product) {
return hwInfoConfigFactory[product]; return hwInfoConfigFactory[product];
} }
static constexpr uint32_t uuidSize = 16u;
int configureHwInfoWddm(const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, OSInterface *osIface); int configureHwInfoWddm(const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, OSInterface *osIface);
int configureHwInfoDrm(const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, OSInterface *osIface); int configureHwInfoDrm(const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, OSInterface *osIface);
virtual int configureHardwareCustom(HardwareInfo *hwInfo, OSInterface *osIface) = 0; virtual int configureHardwareCustom(HardwareInfo *hwInfo, OSInterface *osIface) = 0;
@@ -80,6 +81,7 @@ class HwInfoConfig {
virtual bool isBlitterForImagesSupported() const = 0; virtual bool isBlitterForImagesSupported() const = 0;
virtual bool isTile64With3DSurfaceOnBCSSupported(const HardwareInfo &hwInfo) const = 0; virtual bool isTile64With3DSurfaceOnBCSSupported(const HardwareInfo &hwInfo) const = 0;
virtual uint32_t computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const = 0; virtual uint32_t computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const = 0;
virtual bool getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const = 0;
protected: protected:
virtual LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const = 0; virtual LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const = 0;
@@ -145,6 +147,7 @@ class HwInfoConfigHw : public HwInfoConfig {
bool isBlitterForImagesSupported() const override; bool isBlitterForImagesSupported() const override;
bool isTile64With3DSurfaceOnBCSSupported(const HardwareInfo &hwInfo) const override; bool isTile64With3DSurfaceOnBCSSupported(const HardwareInfo &hwInfo) const override;
uint32_t computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const override; uint32_t computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const override;
bool getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const override;
protected: protected:
HwInfoConfigHw() = default; HwInfoConfigHw() = default;

View File

@@ -276,4 +276,9 @@ template <PRODUCT_FAMILY gfxProduct>
uint32_t HwInfoConfigHw<gfxProduct>::computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const { uint32_t HwInfoConfigHw<gfxProduct>::computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const {
return hwInfo.gtSystemInfo.MaxSubSlicesSupported; return hwInfo.gtSystemInfo.MaxSubSlicesSupported;
} }
template <PRODUCT_FAMILY gfxProduct>
bool HwInfoConfigHw<gfxProduct>::getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const {
return false;
}
} // namespace NEO } // namespace NEO

View File

@@ -82,11 +82,14 @@ set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h ${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h
${CMAKE_CURRENT_SOURCE_DIR}/system_info.h ${CMAKE_CURRENT_SOURCE_DIR}/system_info.h
${CMAKE_CURRENT_SOURCE_DIR}/system_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/system_info.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pmt_util.h
${CMAKE_CURRENT_SOURCE_DIR}/pmt_util.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/system_info_extended.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/system_info_extended.cpp
) )
if(SUPPORT_XEHP_AND_LATER) if(SUPPORT_XEHP_AND_LATER)
list(APPEND NEO_CORE_OS_INTERFACE_LINUX list(APPEND NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_xehp_and_later.inl ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_xehp_and_later.inl
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_uuid_xehp_and_later.inl
) )
endif() endif()

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
namespace UuidUtil {
static inline bool UuidGetRootPciPath(Drm *pDrm, std::string &rootPciPath);
static inline bool UuidReadFromTelem(std::string_view telemDir, std::array<char, PmtUtil::guidStringSize> &guidString,
const uint64_t offset, const uint8_t deviceIndex, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid);
} // namespace UuidUtil
template <>
bool HwInfoConfigHw<gfxProduct>::getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const {
UNRECOVERABLE_IF(device == nullptr);
if (device->getRootDeviceEnvironment().osInterface == nullptr) {
return false;
}
auto pDrm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<Drm>();
std::string rootPciPath;
if (!UuidUtil::UuidGetRootPciPath(pDrm, rootPciPath)) {
return false;
}
std::map<uint32_t, std::string> telemPciPath;
PmtUtil::getTelemNodesInPciPath(rootPciPath, telemPciPath);
// number of telem nodes must be same as subdevice count + 1(root device)
if (telemPciPath.size() < device->getRootDevice()->getNumSubDevices() + 1) {
return false;
}
auto deviceIndex = device->isSubDevice() ? static_cast<SubDevice *>(device)->getSubDeviceIndex() + 1 : 0;
auto iterator = telemPciPath.begin();
// use the root node
std::string telemDir = iterator->second;
std::array<char, PmtUtil::guidStringSize> guidString;
if (!PmtUtil::readGuid(telemDir, guidString)) {
return false;
}
uint64_t offset = ULONG_MAX;
if (!PmtUtil::readOffset(telemDir, offset)) {
return false;
}
return UuidUtil::UuidReadFromTelem(telemDir, guidString, offset, deviceIndex, uuid);
}
namespace UuidUtil {
bool UuidGetRootPciPath(Drm *pDrm, std::string &rootPciPath) {
auto pciLinkPath = NEO::getPciLinkPath(pDrm->getFileDescriptor());
// pciLinkPath = "../../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/drm/renderD128/",
// then root path = "/pci0000:37/0000:37:01.0"
if (pciLinkPath == std::nullopt) {
return false;
}
auto startPos = pciLinkPath->find("/pci");
auto endPos = pciLinkPath->find("/", startPos + 1);
endPos = pciLinkPath->find("/", endPos + 1);
rootPciPath = pciLinkPath->substr(startPos, endPos - startPos);
return true;
}
bool UuidReadFromTelem(std::string_view telemDir, std::array<char, PmtUtil::guidStringSize> &guidString, const uint64_t offset,
const uint8_t deviceIndex, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) {
auto pos = guidUuidOffsetMap.find(guidString.data());
if (pos != guidUuidOffsetMap.end()) {
uuid.fill(0);
ssize_t bytesRead = PmtUtil::readTelem(telemDir.data(), pos->second.second, pos->second.first + offset, uuid.data());
if (bytesRead == pos->second.second) {
uuid[15] = deviceIndex;
return true;
}
}
return false;
}
} // namespace UuidUtil

View File

@@ -13,7 +13,7 @@
#include <unistd.h> #include <unistd.h>
namespace NEO { namespace NEO {
std::optional<std::string> getPciPath(int deviceFd) { std::optional<std::string> getPciLinkPath(int deviceFd) {
char path[256] = {0}; char path[256] = {0};
size_t pathlen = 256; size_t pathlen = 256;
@@ -33,9 +33,17 @@ std::optional<std::string> getPciPath(int deviceFd) {
return std::nullopt; return std::nullopt;
} }
std::string_view devicePathView(devicePath, static_cast<size_t>(readLinkSize)); return std::string(devicePath, static_cast<size_t>(readLinkSize));
devicePathView = devicePathView.substr(devicePathView.find("/drm/render") - 12u, 12u); }
return std::string(devicePathView); std::optional<std::string> getPciPath(int deviceFd) {
auto deviceLinkPath = NEO::getPciLinkPath(deviceFd);
if (deviceLinkPath == std::nullopt) {
return std::nullopt;
}
return deviceLinkPath->substr(deviceLinkPath->find("/drm/render") - 12u, 12u);
} }
} // namespace NEO } // namespace NEO

View File

@@ -13,5 +13,6 @@
namespace NEO { namespace NEO {
std::optional<std::string> getPciPath(int deviceFd); std::optional<std::string> getPciPath(int deviceFd);
std::optional<std::string> getPciLinkPath(int deviceFd);
} } // namespace NEO

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/pmt_util.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/source/utilities/directory.h"
#include <climits>
#include <algorithm>
#include <cstring>
#include <fcntl.h>
#include <map>
#include <sstream>
#include <string_view>
namespace NEO {
void PmtUtil::getTelemNodesInPciPath(std::string_view rootPciPath, std::map<uint32_t, std::string> &telemPciPath) {
// if bdf = 0000:3a:00.0
// link = "../../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/drm/renderD128/",
// then root path = "/pci0000:37/0000:37:01.0"
auto telemNodeList = Directory::getFiles("/sys/class/intel_pmt");
std::string_view telemDirString("/sys/class/intel_pmt/telem");
telemPciPath.clear();
// Get the telem nodes under the same root pci path
for (auto &telemNode : telemNodeList) {
char symlink[256] = {'\0'};
std::size_t pos = telemNode.find(telemDirString);
if (pos != std::string::npos) {
pos += telemDirString.length();
int len = SysCalls::readlink(telemNode.c_str(), symlink, sizeof(symlink) - 1);
if (len != -1) {
symlink[len] = '\0';
std::string_view symlinkString(symlink);
if (symlinkString.find(rootPciPath.data()) != std::string::npos) {
int index = std::stoi(telemNode.substr(pos));
telemPciPath[index] = telemNode;
}
}
}
}
}
bool PmtUtil::readGuid(std::string_view telemDir, std::array<char, PmtUtil::guidStringSize> &guidString) {
std::ostringstream guidFilename;
guidFilename << telemDir << "/guid";
int fd = SysCalls::open(guidFilename.str().c_str(), O_RDONLY);
if (fd <= 0) {
return false;
}
guidString.fill('\0');
ssize_t bytesRead = SysCalls::pread(fd, guidString.data(), guidString.size() - 1, 0);
SysCalls::close(fd);
if (bytesRead <= 0) {
return false;
}
std::replace(guidString.begin(), guidString.end(), '\n', '\0');
return true;
}
bool PmtUtil::readOffset(std::string_view telemDir, uint64_t &offset) {
std::ostringstream offsetFilename;
offsetFilename << telemDir << "/offset";
int fd = SysCalls::open(offsetFilename.str().c_str(), O_RDONLY);
if (fd <= 0) {
return false;
}
offset = ULONG_MAX;
std::array<char, 16> offsetString = {'\0'};
ssize_t bytesRead = SysCalls::pread(fd, offsetString.data(), offsetString.size() - 1, 0);
if (bytesRead > 0) {
std::replace(offsetString.begin(), offsetString.end(), '\n', '\0');
offset = std::strtoul(offsetString.data(), nullptr, 10);
}
SysCalls::close(fd);
if (offset == ULONG_MAX) {
return false;
}
return true;
}
ssize_t PmtUtil::readTelem(std::string_view telemDir, const std::size_t count, const uint64_t offset, void *data) {
if (data == nullptr) {
return 0;
}
ssize_t bytesRead = 0;
std::ostringstream telemFilename;
telemFilename << telemDir << "/telem";
int fd = SysCalls::open(telemFilename.str().c_str(), O_RDONLY);
if (fd > 0) {
bytesRead = SysCalls::pread(fd, data, count, offset);
SysCalls::close(fd);
}
return bytesRead;
}
} // namespace NEO

View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include <map>
#include <string>
namespace NEO {
class PmtUtil {
public:
static constexpr uint32_t guidStringSize = 16u;
static void getTelemNodesInPciPath(std::string_view rootPciPath, std::map<uint32_t, std::string> &telemPciPath);
static bool readGuid(std::string_view telemDir, std::array<char, PmtUtil::guidStringSize> &guidString);
static bool readOffset(std::string_view telemDir, uint64_t &offset);
static ssize_t readTelem(std::string_view telemDir, const std::size_t size, const uint64_t offset, void *data);
};
} // namespace NEO

View File

@@ -5,16 +5,26 @@
* *
*/ */
#include "shared/source/device/sub_device.h"
#include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/hw_info.h"
#include "shared/source/kernel/kernel_properties.h" #include "shared/source/kernel/kernel_properties.h"
#include "shared/source/os_interface/hw_info_config.h" #include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/hw_info_config.inl" #include "shared/source/os_interface/hw_info_config.inl"
#include "shared/source/os_interface/hw_info_config_xehp_and_later.inl" #include "shared/source/os_interface/hw_info_config_xehp_and_later.inl"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/pci_path.h"
#include "shared/source/os_interface/linux/pmt_util.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/source/utilities/directory.h"
namespace NEO { namespace NEO {
constexpr static auto gfxProduct = IGFX_XE_HP_SDV; constexpr static auto gfxProduct = IGFX_XE_HP_SDV;
const std::map<std::string, std::pair<uint32_t, uint32_t>> guidUuidOffsetMap = {
//add new values for guid in the form of {"guid", {offset, size}} for each platform
{"0xfdc76195", {64u, 8u}}};
#include "shared/source/os_interface/linux/hw_info_config_uuid_xehp_and_later.inl"
#include "shared/source/xe_hp_core/os_agnostic_hw_info_config_xe_hp_core.inl" #include "shared/source/xe_hp_core/os_agnostic_hw_info_config_xe_hp_core.inl"
template <> template <>

View File

@@ -5,6 +5,7 @@
* *
*/ */
#include "shared/source/device/sub_device.h"
#include "shared/source/helpers/constants.h" #include "shared/source/helpers/constants.h"
#include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/hw_info.h"
#include "shared/source/kernel/kernel_properties.h" #include "shared/source/kernel/kernel_properties.h"
@@ -12,10 +13,19 @@
#include "shared/source/os_interface/hw_info_config.inl" #include "shared/source/os_interface/hw_info_config.inl"
#include "shared/source/os_interface/hw_info_config_dg2_and_later.inl" #include "shared/source/os_interface/hw_info_config_dg2_and_later.inl"
#include "shared/source/os_interface/hw_info_config_xehp_and_later.inl" #include "shared/source/os_interface/hw_info_config_xehp_and_later.inl"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/pci_path.h"
#include "shared/source/os_interface/linux/pmt_util.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/source/utilities/directory.h"
namespace NEO { namespace NEO {
constexpr static auto gfxProduct = IGFX_PVC; constexpr static auto gfxProduct = IGFX_PVC;
const std::map<std::string, std::pair<uint32_t, uint32_t>> guidUuidOffsetMap = {
//add new values for guid in the form of {"guid", {offset, size}} for each platform
{"0x0", {0x0, 0}}};
#include "shared/source/os_interface/linux/hw_info_config_uuid_xehp_and_later.inl"
#include "shared/source/xe_hpc_core/os_agnostic_hw_info_config_pvc.inl" #include "shared/source/xe_hpc_core/os_agnostic_hw_info_config_pvc.inl"
template <> template <>

View File

@@ -25,6 +25,26 @@ std::vector<std::string> Directory::getFiles(const std::string &path) {
files.push_back("./test_files/linux/devices/device/drm/card1"); files.push_back("./test_files/linux/devices/device/drm/card1");
return files; return files;
} }
if (path == "/sys/class/intel_pmt") {
return {
"/sys/class/intel_pmt/crashlog1",
"/sys/class/intel_pmt/crashlog2",
"/sys/class/intel_pmt/crashlog3",
"/sys/class/intel_pmt/crashlog4",
"/sys/class/intel_pmt/telem2",
"/sys/class/intel_pmt/telem1",
"/sys/class/intel_pmt/telem10",
"/sys/class/intel_pmt/telem11",
"/sys/class/intel_pmt/telem12",
"/sys/class/intel_pmt/telem3",
"/sys/class/intel_pmt/telem5",
"/sys/class/intel_pmt/telem4",
"/sys/class/intel_pmt/telem6",
"/sys/class/intel_pmt/telem8",
"/sys/class/intel_pmt/telem7",
"/sys/class/intel_pmt/telem9",
};
}
return files; return files;
} }
}; // namespace NEO }; // namespace NEO

View File

@@ -266,4 +266,9 @@ uint32_t HwInfoConfigHw<IGFX_UNKNOWN>::computeMaxNeededSubSliceSpace(const Hardw
return hwInfo.gtSystemInfo.MaxSubSlicesSupported; return hwInfo.gtSystemInfo.MaxSubSlicesSupported;
} }
template <>
bool HwInfoConfigHw<IGFX_UNKNOWN>::getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const {
return false;
}
} //namespace NEO } //namespace NEO

View File

@@ -44,6 +44,10 @@ uint32_t mmapFuncCalled = 0u;
uint32_t munmapFuncCalled = 0u; uint32_t munmapFuncCalled = 0u;
bool isInvalidAILTest = false; bool isInvalidAILTest = false;
int (*sysCallsOpen)(const char *pathname, int flags) = nullptr;
ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset) = nullptr;
int (*sysCallsReadlink)(const char *path, char *buf, size_t bufsize) = nullptr;
int close(int fileDescriptor) { int close(int fileDescriptor) {
closeFuncCalled++; closeFuncCalled++;
closeFuncArgPassed = fileDescriptor; closeFuncArgPassed = fileDescriptor;
@@ -51,6 +55,11 @@ int close(int fileDescriptor) {
} }
int open(const char *file, int flags) { int open(const char *file, int flags) {
if (sysCallsOpen != nullptr) {
return sysCallsOpen(file, flags);
}
if (strcmp(file, "/dev/dri/by-path/pci-0000:invalid-render") == 0) { if (strcmp(file, "/dev/dri/by-path/pci-0000:invalid-render") == 0) {
return 0; return 0;
} }
@@ -110,6 +119,11 @@ int access(const char *pathName, int mode) {
} }
int readlink(const char *path, char *buf, size_t bufsize) { int readlink(const char *path, char *buf, size_t bufsize) {
if (sysCallsReadlink != nullptr) {
return sysCallsReadlink(path, buf, bufsize);
}
if (isInvalidAILTest) { if (isInvalidAILTest) {
return -1; return -1;
} }
@@ -150,6 +164,9 @@ int fstat(int fd, struct stat *buf) {
} }
ssize_t pread(int fd, void *buf, size_t count, off_t offset) { ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
if (sysCallsPread != nullptr) {
return sysCallsPread(fd, buf, count, offset);
}
preadFuncCalled++; preadFuncCalled++;
return 0; return 0;
} }

View File

@@ -0,0 +1,18 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include <iostream>
namespace NEO {
namespace SysCalls {
extern int (*sysCallsOpen)(const char *pathname, int flags);
extern ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset);
extern int (*sysCallsReadlink)(const char *path, char *buf, size_t bufsize);
} // namespace SysCalls
} // namespace NEO

View File

@@ -8,6 +8,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_uuid_tests.cpp
) )
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX}) set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX})

View File

@@ -0,0 +1,698 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/device/root_device.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/linux/pmt_util.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
#include "test.h"
namespace NEO {
struct MultipleDeviceUuidTest : public ::testing::Test {
void SetUp() override {
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
std::vector<std::string> pciPaths = {
"0000:3a:00.0",
"0000:9b:00.0"};
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<Device>(deviceFactory->rootDevices[i]));
auto execEnv = deviceFactory->rootDevices[i]->getExecutionEnvironment();
auto rootEnv = execEnv->rootDeviceEnvironments[i].get();
rootEnv->osInterface.reset(new OSInterface);
auto drmMock = new DrmMockResources(*execEnv->rootDeviceEnvironments[i]);
execEnv->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
drmMock->setPciPath(pciPaths[i % pciPaths.size()].c_str());
}
}
void TearDown() override {
for (auto &device : devices) {
device.release();
}
}
DebugManagerStateRestore restorer;
std::unique_ptr<UltDeviceFactory> deviceFactory;
const uint32_t numRootDevices = 2u;
const uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<Device>> devices;
};
} // namespace NEO
using namespace NEO;
HWTEST2_F(MultipleDeviceUuidTest, whenRetrievingDeviceUuidThenCorrectUuidIsReceived, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/crashlog1", "../../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-4.4.auto/intel_pmt/crashlog1/"},
{"/sys/class/intel_pmt/crashlog2", "../../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-4.4.auto/intel_pmt/crashlog2/"},
{"/sys/class/intel_pmt/crashlog3", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-4.8.auto/intel_pmt/crashlog3/"},
{"/sys/class/intel_pmt/crashlog4", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-4.8.auto/intel_pmt/crashlog4/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem10", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-2.6.auto/intel_pmt/telem10/"},
{"/sys/class/intel_pmt/telem11", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-2.6.auto/intel_pmt/telem11/"},
{"/sys/class/intel_pmt/telem12", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-2.6.auto/intel_pmt/telem12/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
{"/sys/class/intel_pmt/telem4", "./../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-2.2.auto/intel_pmt/telem4/"},
{"/sys/class/intel_pmt/telem6", "./../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-2.2.auto/intel_pmt/telem6/"},
{"/sys/class/intel_pmt/telem5", "./../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-2.2.auto/intel_pmt/telem5/"},
{"/sys/class/intel_pmt/telem8", "./../devices/pci0000:98/0000:98:01.0/0000:99:00.0/0000:9a:02.0/0000:9d:00.1/intel-dvsec-2.5.auto/intel_pmt/telem8/"},
{"/sys/class/intel_pmt/telem7", "./../devices/pci0000:98/0000:98:01.0/0000:99:00.0/0000:9a:02.0/0000:9d:00.1/intel-dvsec-2.5.auto/intel_pmt/telem7/"},
{"/sys/class/intel_pmt/telem9", "./../devices/pci0000:98/0000:98:01.0/0000:99:00.0/0000:9a:02.0/0000:9d:00.1/intel-dvsec-2.5.auto/intel_pmt/telem9/"},
};
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(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", "0xfdc76195\n"},
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0xFEEDBEADDEABDEEF;
memcpy(buf, &data, sizeof(data));
return sizeof(data);
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
uint64_t expectedVal = 0xFEEDBEADDEABDEEF;
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {};
std::memcpy(expectedUuid, &expectedVal, sizeof(expectedVal));
EXPECT_EQ(true, HwInfoConfig::get(productFamily)->getUuid(devices[0].get(), uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {0};
std::memcpy(expectedUuid, &expectedVal, sizeof(expectedVal));
expectedUuid[15] = i + 1;
EXPECT_EQ(true, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
}
}
HWTEST2_F(MultipleDeviceUuidTest, whenRetrievingDeviceUuidThenCorrectUuidIsReceived, IsPVC) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/crashlog1", "../../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-4.4.auto/intel_pmt/crashlog1/"},
{"/sys/class/intel_pmt/crashlog2", "../../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-4.4.auto/intel_pmt/crashlog2/"},
{"/sys/class/intel_pmt/crashlog3", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-4.8.auto/intel_pmt/crashlog3/"},
{"/sys/class/intel_pmt/crashlog4", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-4.8.auto/intel_pmt/crashlog4/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem10", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-2.6.auto/intel_pmt/telem10/"},
{"/sys/class/intel_pmt/telem11", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-2.6.auto/intel_pmt/telem11/"},
{"/sys/class/intel_pmt/telem12", "../../devices/pci0000:e8/0000:e8:03.1/intel-dvsec-2.6.auto/intel_pmt/telem12/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
{"/sys/class/intel_pmt/telem4", "./../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-2.2.auto/intel_pmt/telem4/"},
{"/sys/class/intel_pmt/telem6", "./../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-2.2.auto/intel_pmt/telem6/"},
{"/sys/class/intel_pmt/telem5", "./../devices/pci0000:6a/0000:6a:03.1/intel-dvsec-2.2.auto/intel_pmt/telem5/"},
{"/sys/class/intel_pmt/telem8", "./../devices/pci0000:98/0000:98:01.0/0000:99:00.0/0000:9a:02.0/0000:9d:00.1/intel-dvsec-2.5.auto/intel_pmt/telem8/"},
{"/sys/class/intel_pmt/telem7", "./../devices/pci0000:98/0000:98:01.0/0000:99:00.0/0000:9a:02.0/0000:9d:00.1/intel-dvsec-2.5.auto/intel_pmt/telem7/"},
{"/sys/class/intel_pmt/telem9", "./../devices/pci0000:98/0000:98:01.0/0000:99:00.0/0000:9a:02.0/0000:9d:00.1/intel-dvsec-2.5.auto/intel_pmt/telem9/"},
};
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(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 {
const std::string unSetGuid("0x0");
const uint32_t unSetBytesRead = 0;
std::vector<std::pair<std::string, std::string>> supportedFiles = {
{"/sys/class/intel_pmt/telem1/guid", unSetGuid},
{"/sys/class/intel_pmt/telem1/offset", "0"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0xFEEDBEADDEABDEEF;
memcpy(buf, &data, sizeof(data));
if (unSetGuid == "0x0") {
return unSetBytesRead;
} else {
return sizeof(data);
}
}
if (supportedFiles[fd].second == "dummy1") {
uint64_t data = 0xABCDEFFEDCBA;
memcpy(buf, &data, sizeof(data));
if (unSetGuid == "0x0") {
return unSetBytesRead;
} else {
return sizeof(data);
}
return sizeof(data);
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
uint64_t expectedVal = 0xFEEDBEADDEABDEEF;
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {};
std::memcpy(expectedUuid, &expectedVal, sizeof(expectedVal));
EXPECT_EQ(true, HwInfoConfig::get(productFamily)->getUuid(devices[0].get(), uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {0};
std::memcpy(expectedUuid, &expectedVal, sizeof(expectedVal));
expectedUuid[15] = i + 1;
EXPECT_EQ(true, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
}
}
HWTEST2_F(MultipleDeviceUuidTest, givenTelemDirectoriesAreLessThanExpectedWhenRetrievingUuidForSubDeviceThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
};
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(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
return -1;
});
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
}
}
HWTEST2_F(MultipleDeviceUuidTest, GivenMissingGuidWhenRetrievingUuidForSubDeviceThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
std::vector<std::string> supportedFiles = {
"/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/offset", "0"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
if (supportedFiles[fd].second == "dummy") {
uint64_t data = 0xFEEDBEADDEABDEEF;
memcpy(buf, &data, sizeof(data));
return sizeof(data);
}
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
}
}
HWTEST2_F(MultipleDeviceUuidTest, GivenIncorrectGuidWhenRetrievingUuidForSubDeviceThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(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 {
return -1;
});
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
}
}
HWTEST2_F(MultipleDeviceUuidTest, GivenMissingOffsetWhenRetrievingUuidForSubDeviceThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(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/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", "0xfdc76195"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
}
}
HWTEST2_F(MultipleDeviceUuidTest, GivenIncorrectOffsetWhenRetrievingUuidForSubDeviceThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(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", "0xfdc76195"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
uint32_t subDeviceCount = numSubDevices;
std::vector<SubDevice *> subDevices(subDeviceCount);
subDevices = devices[0]->getSubDevices();
for (auto i = 0u; i < subDeviceCount; i++) {
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(subDevices[i], uuid));
}
}
HWTEST2_F(MultipleDeviceUuidTest, GivenMissingTelemNodeWhenRetrievingUuidThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(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",
};
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", "0xfdc76195"},
{"/sys/class/intel_pmt/telem1/offset", "0"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(devices[0].get(), uuid));
}
HWTEST2_F(MultipleDeviceUuidTest, GivenIncorrectTelemNodeWhenRetrievingUuidThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(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", "0xfdc76195"},
{"/sys/class/intel_pmt/telem1/offset", "0"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(devices[0].get(), uuid));
}
HWTEST2_F(MultipleDeviceUuidTest, GivenIncorrectGuidValueWhenRetrievingUuidThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&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:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/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(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", "0xabcddcba"},
{"/sys/class/intel_pmt/telem1/offset", "0"},
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
};
fd -= 1;
if ((fd) < static_cast<int>(supportedFiles.size())) {
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
return supportedFiles[fd].second.size();
}
return -1;
});
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(devices[0].get(), uuid));
}
HWTEST2_F(MultipleDeviceUuidTest, GivenDeviceLinkIsNotAvailableWhenRetrievingUuidForRootDeviceThenFailureIsReturned, IsXEHP) {
VariableBackup<decltype(SysCalls::sysCallsReadlink)> mockReadLink(&SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
return -1;
});
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return 0;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
return -1;
});
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, HwInfoConfig::get(productFamily)->getUuid(devices[0].get(), uuid));
}
TEST(PmtUtilTest, givenDataPtrIsNullWhenPmtUtilReadTelemIsCalledThenVerifyZeroIsReturned) {
VariableBackup<decltype(SysCalls::sysCallsOpen)> mockOpen(&SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
return 1;
});
VariableBackup<decltype(SysCalls::sysCallsPread)> mockPread(&SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
return 16;
});
EXPECT_TRUE(0 == PmtUtil::readTelem("dummy", 16, 0, nullptr));
}