mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-31 12:11:31 +08:00
fix(sysman): The Correct Device Name is returned during Sysman Init
Added some sysman and nl_api tests to increase the code coverage Related-To: NEO-15786 Signed-off-by: Pratik Bari <pratik.bari@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
bb0f62896f
commit
70fe9c5df0
@@ -28,6 +28,7 @@ static constexpr std::string_view nlSocketDisableSeqCheckRoutine = "nl_socket_di
|
||||
static constexpr std::string_view nlSocketFreeRoutine = "nl_socket_free";
|
||||
static constexpr std::string_view nlSocketModifyCbRoutine = "nl_socket_modify_cb";
|
||||
static constexpr std::string_view nlaDataRoutine = "nla_data";
|
||||
static constexpr std::string_view nlaGetStringRoutine = "nla_get_string";
|
||||
static constexpr std::string_view nlaGetU32Routine = "nla_get_u32";
|
||||
static constexpr std::string_view nlaGetU64Routine = "nla_get_u64";
|
||||
static constexpr std::string_view nlaGetU8Routine = "nla_get_u8";
|
||||
@@ -74,6 +75,7 @@ bool NlApi::loadEntryPoints() {
|
||||
ok = ok && getSymbolAddr(nlSocketFreeRoutine, nlSocketFreeEntry);
|
||||
ok = ok && getSymbolAddr(nlSocketModifyCbRoutine, nlSocketModifyCbEntry);
|
||||
ok = ok && getSymbolAddr(nlaDataRoutine, nlaDataEntry);
|
||||
ok = ok && getSymbolAddr(nlaGetStringRoutine, nlaGetStringEntry);
|
||||
ok = ok && getSymbolAddr(nlaGetU32Routine, nlaGetU32Entry);
|
||||
ok = ok && getSymbolAddr(nlaGetU64Routine, nlaGetU64Entry);
|
||||
ok = ok && getSymbolAddr(nlaGetU8Routine, nlaGetU8Entry);
|
||||
@@ -169,6 +171,11 @@ void *NlApi::nlaData(const struct nlattr *attr) {
|
||||
return (*nlaDataEntry)(attr);
|
||||
}
|
||||
|
||||
char *NlApi::nlaGetString(const struct nlattr *attr) {
|
||||
UNRECOVERABLE_IF(nullptr == nlaGetStringEntry);
|
||||
return (*nlaGetStringEntry)(attr);
|
||||
}
|
||||
|
||||
uint32_t NlApi::nlaGetU32(const struct nlattr *attr) {
|
||||
UNRECOVERABLE_IF(nullptr == nlaGetU32Entry);
|
||||
return (*nlaGetU32Entry)(attr);
|
||||
|
||||
@@ -38,6 +38,7 @@ typedef void (*pNlSocketDisableSeqCheck)(struct nl_sock *);
|
||||
typedef void (*pNlSocketFree)(struct nl_sock *);
|
||||
typedef int (*pNlSocketModifyCb)(struct nl_sock *, enum nl_cb_type, enum nl_cb_kind, nl_recvmsg_msg_cb_t, void *);
|
||||
typedef void *(*pNlaData)(const struct nlattr *);
|
||||
typedef char *(*pNlaGetString)(const struct nlattr *);
|
||||
typedef uint32_t (*pNlaGetU32)(const struct nlattr *);
|
||||
typedef uint64_t (*pNlaGetU64)(const struct nlattr *);
|
||||
typedef uint8_t (*pNlaGetU8)(const struct nlattr *);
|
||||
@@ -74,6 +75,7 @@ class NlApi : public NEO::NonCopyableAndNonMovableClass {
|
||||
MOCKABLE_VIRTUAL void nlSocketFree(struct nl_sock *sock);
|
||||
MOCKABLE_VIRTUAL int nlSocketModifyCb(struct nl_sock *sock, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t cb, void *arg);
|
||||
MOCKABLE_VIRTUAL void *nlaData(const struct nlattr *attr);
|
||||
MOCKABLE_VIRTUAL char *nlaGetString(const struct nlattr *attr);
|
||||
MOCKABLE_VIRTUAL uint32_t nlaGetU32(const struct nlattr *attr);
|
||||
MOCKABLE_VIRTUAL uint64_t nlaGetU64(const struct nlattr *attr);
|
||||
MOCKABLE_VIRTUAL uint8_t nlaGetU8(const struct nlattr *attr);
|
||||
@@ -121,6 +123,7 @@ class NlApi : public NEO::NonCopyableAndNonMovableClass {
|
||||
pNlSocketFree nlSocketFreeEntry = nullptr;
|
||||
pNlSocketModifyCb nlSocketModifyCbEntry = nullptr;
|
||||
pNlaData nlaDataEntry = nullptr;
|
||||
pNlaGetString nlaGetStringEntry = nullptr;
|
||||
pNlaGetU32 nlaGetU32Entry = nullptr;
|
||||
pNlaGetU64 nlaGetU64Entry = nullptr;
|
||||
pNlaGetU8 nlaGetU8Entry = nullptr;
|
||||
|
||||
@@ -553,5 +553,9 @@ bool SysFsAccessInterface::isRootUser() {
|
||||
return FsAccessInterface::isRootUser();
|
||||
}
|
||||
|
||||
std::string SysFsAccessInterface::getDeviceDirName() {
|
||||
return getDirName(dirname);
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
|
||||
@@ -128,6 +128,7 @@ class SysFsAccessInterface : protected FsAccessInterface {
|
||||
MOCKABLE_VIRTUAL bool isMyDeviceFile(const std::string dev);
|
||||
bool directoryExists(const std::string path) override;
|
||||
bool isRootUser() override;
|
||||
std::string getDeviceDirName();
|
||||
|
||||
protected:
|
||||
SysFsAccessInterface();
|
||||
|
||||
@@ -67,6 +67,7 @@ ze_result_t LinuxSysmanImp::init() {
|
||||
pProcfsAccess = pSysmanKmdInterface->getProcFsAccess();
|
||||
pSysfsAccess = pSysmanKmdInterface->getSysFsAccess();
|
||||
|
||||
deviceName = pFsAccess->getBaseName(pSysfsAccess->getDeviceDirName());
|
||||
auto sysmanHwDeviceId = getSysmanHwDeviceIdInstance();
|
||||
int myDeviceFd = sysmanHwDeviceId.getFileDescriptor();
|
||||
rootPath = NEO::getPciRootPath(myDeviceFd).value_or("");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2020-2024 Intel Corporation
|
||||
# Copyright (C) 2020-2025 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -13,7 +13,7 @@ if(UNIX)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_nl_dll.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_nl_dll.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_iaf_nl_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_nl_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mock_nl_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_iaf_nl_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_nl_api.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_iaf_nl_api.h
|
||||
@@ -26,3 +26,5 @@ if(UNIX)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
add_subdirectories()
|
||||
|
||||
@@ -272,7 +272,7 @@ int MockNlApi::genlHandleMsg(struct nl_msg *msg, void *arg) {
|
||||
}
|
||||
|
||||
delete head;
|
||||
delete info.attrs;
|
||||
delete[] info.attrs;
|
||||
if (succeeded) {
|
||||
return NLE_SUCCESS;
|
||||
} else {
|
||||
@@ -332,6 +332,11 @@ void *MockNlApi::nlaData(const struct nlattr *attr) {
|
||||
return pAttr->nested;
|
||||
}
|
||||
|
||||
char *MockNlApi::nlaGetString(const struct nlattr *attr) {
|
||||
static const char *mockString = "mockString";
|
||||
return const_cast<char *>(mockString);
|
||||
}
|
||||
|
||||
uint32_t MockNlApi::nlaGetU32(const struct nlattr *attr) {
|
||||
const MyNlattr *pAttr = reinterpret_cast<const MyNlattr *>(attr);
|
||||
return pAttr->content & 0xFFFFFFFFUL;
|
||||
|
||||
@@ -56,6 +56,10 @@ class MockNlApi : public L0::Sysman::NlApi {
|
||||
std::vector<bool> mockLoadEntryPointsReturnValue{};
|
||||
std::vector<bool> isMockGenlRegisterFamilyRepeatedCall{};
|
||||
bool isRepeated = false;
|
||||
bool readSingleError = false;
|
||||
bool isErrorCounterAvailable = false;
|
||||
bool queryErrorList = false;
|
||||
bool isErrorAvailable = false;
|
||||
|
||||
int genlUnregisterFamily(struct genl_ops *ops) override;
|
||||
int genlHandleMsg(struct nl_msg *msg, void *arg) override;
|
||||
@@ -64,6 +68,7 @@ class MockNlApi : public L0::Sysman::NlApi {
|
||||
void *genlmsgPut(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version) override;
|
||||
int nlRecvmsgsDefault(struct nl_sock *sock) override;
|
||||
void *nlaData(const struct nlattr *attr) override;
|
||||
char *nlaGetString(const struct nlattr *attr) override;
|
||||
uint32_t nlaGetU32(const struct nlattr *attr) override;
|
||||
uint64_t nlaGetU64(const struct nlattr *attr) override;
|
||||
uint8_t nlaGetU8(const struct nlattr *attr) override;
|
||||
|
||||
@@ -27,6 +27,7 @@ struct nlattr MockNlDll::mockNlattr;
|
||||
struct nlattr MockNlDll::mockNextNlattr;
|
||||
struct genl_ops MockNlDll::mockGenlOps;
|
||||
nl_recvmsg_msg_cb_t MockNlDll::mockCb = mockCallback;
|
||||
const std::string MockNlDll::mockStr = "mockString";
|
||||
|
||||
extern "C" {
|
||||
int mockGenlConnect(struct nl_sock *sock) {
|
||||
@@ -118,6 +119,11 @@ uint32_t mockNlaGetU32(const struct nlattr *attr) {
|
||||
return MockNlDll::mockU32Val;
|
||||
}
|
||||
|
||||
char *mockNlaGetString(const struct nlattr *attr) {
|
||||
EXPECT_EQ(&MockNlDll::mockNlattr, attr);
|
||||
return const_cast<char *>(MockNlDll::mockStr.c_str());
|
||||
}
|
||||
|
||||
uint64_t mockNlaGetU64(const struct nlattr *attr) {
|
||||
EXPECT_EQ(&MockNlDll::mockNlattr, attr);
|
||||
return MockNlDll::mockU64Val;
|
||||
@@ -239,6 +245,7 @@ MockNlDll::MockNlDll() {
|
||||
funcMap["nl_socket_modify_cb"] = reinterpret_cast<void *>(&mockNlSocketModifyCb);
|
||||
funcMap["nla_data"] = reinterpret_cast<void *>(&mockNlaData);
|
||||
funcMap["nla_get_u32"] = reinterpret_cast<void *>(&mockNlaGetU32);
|
||||
funcMap["nla_get_string"] = reinterpret_cast<void *>(&mockNlaGetString);
|
||||
funcMap["nla_get_u64"] = reinterpret_cast<void *>(&mockNlaGetU64);
|
||||
funcMap["nla_get_u8"] = reinterpret_cast<void *>(&mockNlaGetU8);
|
||||
funcMap["nla_is_nested"] = reinterpret_cast<void *>(&mockNlaIsNested);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
* Copyright (C) 2020-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -41,6 +41,7 @@ class MockNlDll : public NEO::OsLibrary {
|
||||
static struct nlattr mockNextNlattr;
|
||||
static struct genl_ops mockGenlOps;
|
||||
static nl_recvmsg_msg_cb_t mockCb;
|
||||
static const std::string mockStr;
|
||||
|
||||
constexpr static int mockFamilyId = 0x2020;
|
||||
constexpr static char mockFamilyName[] = "TestName";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2024 Intel Corporation
|
||||
* Copyright (C) 2020-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -61,6 +61,7 @@ TEST_F(SysmanNlApiFixture, GivenNlApiWhenMissingDllEntryPointThenVerifyLoadEntry
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nl_socket_modify_cb"));
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nla_data"));
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nla_get_u32"));
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nla_get_string"));
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nla_get_u64"));
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nla_get_u8"));
|
||||
EXPECT_FALSE(testLoadEntryPointsWithMissingFunction("nla_is_nested"));
|
||||
@@ -142,6 +143,10 @@ TEST_F(SysmanNlApiFixture, GivenNlApiWhenCompleteMockNlDllThenVerifyNlaDataRetur
|
||||
EXPECT_NE(nullptr, testNlApi.nlaData(&MockNlDll::mockNlattr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanNlApiFixture, GivenNlApiWhenCompleteMockNlDllThenVerifyNlaGetStringReturnsValue) {
|
||||
EXPECT_STREQ(const_cast<char *>(MockNlDll::mockStr.c_str()), testNlApi.nlaGetString(&MockNlDll::mockNlattr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanNlApiFixture, GivenNlApiWhenCompleteMockNlDllThenVerifyNlaGetU32ReturnsValue) {
|
||||
EXPECT_EQ(MockNlDll::mockU32Val, testNlApi.nlaGetU32(&MockNlDll::mockNlattr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user