diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index 3d84b7f443..be5447fe64 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -61,7 +61,7 @@ if(BUILD_WITH_L0) endif() if(UNIX) - # Xml Package + # Xml Library find_package(LibXml2) if(PC_LIBXML_FOUND) include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR}) @@ -69,15 +69,6 @@ if(BUILD_WITH_L0) else() message(STATUS "LibXml2 Library headers not available. Building without.") endif() - # Netlink and Generic Netlink - find_path(LIBGENL_INCLUDE_DIR netlink/genl/genl.h PATH_SUFFIXES libnl3) - if(LIBGENL_INCLUDE_DIR) - message(STATUS "LibGenl headers directory: ${LIBGENL_INCLUDE_DIR}") - include_directories(SYSTEM ${LIBGENL_INCLUDE_DIR}) - set(LIBGENL_FOUND TRUE) - else() - message(STATUS "LibGenl headers not available. Building without") - endif() endif() if(UNIX) diff --git a/level_zero/tools/source/sysman/linux/nl_api/CMakeLists.txt b/level_zero/tools/source/sysman/linux/nl_api/CMakeLists.txt deleted file mode 100644 index 75f26f0c8f..0000000000 --- a/level_zero/tools/source/sysman/linux/nl_api/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (C) 2020 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -if(LIBGENL_FOUND) - set(L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API - ${CMAKE_CURRENT_SOURCE_DIR}/nl_api.h - ${CMAKE_CURRENT_SOURCE_DIR}/nl_api.cpp - ) -endif() - -if(UNIX) - target_sources(${L0_STATIC_LIB_NAME} - PRIVATE - ${L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API} - ) -endif() - -# Make our source files visible to parent -set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API ${L0_SRCS_TOOLS_SYSMAN_LINUX_NL_API}) diff --git a/level_zero/tools/source/sysman/linux/nl_api/nl_api.cpp b/level_zero/tools/source/sysman/linux/nl_api/nl_api.cpp deleted file mode 100644 index 9f067256e5..0000000000 --- a/level_zero/tools/source/sysman/linux/nl_api/nl_api.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (C) 2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "nl_api.h" - -namespace L0 { - -static const std::string libgenlFile = "libnl-genl-3.so.200"; -static const std::string genlConnectRoutine = "genl_connect"; -static const std::string genlCtrlResolveRoutine = "genl_ctrl_resolve"; -static const std::string genlHandleMsgRoutine = "genl_handle_msg"; -static const std::string genlmsgPutRoutine = "genlmsg_put"; -static const std::string genlOpsResolveRoutine = "genl_ops_resolve"; -static const std::string genlRegisterFamilyRoutine = "genl_register_family"; -static const std::string genlUnregisterFamilyRoutine = "genl_unregister_family"; -static const std::string nlaDataRoutine = "nla_data"; -static const std::string nlaGetU32Routine = "nla_get_u32"; -static const std::string nlaGetU64Routine = "nla_get_u64"; -static const std::string nlaGetU8Routine = "nla_get_u8"; -static const std::string nlaIsNestedRoutine = "nla_is_nested"; -static const std::string nlaLenRoutine = "nla_len"; -static const std::string nlaNextRoutine = "nla_next"; -static const std::string nlaOkRoutine = "nla_ok"; -static const std::string nlaPutU16Routine = "nla_put_u16"; -static const std::string nlaPutU32Routine = "nla_put_u32"; -static const std::string nlaPutU64Routine = "nla_put_u64"; -static const std::string nlaPutU8Routine = "nla_put_u8"; -static const std::string nlaTypeRoutine = "nla_type"; -static const std::string nlmsgAllocRoutine = "nlmsg_alloc"; -static const std::string nlmsgHdrRoutine = "nlmsg_hdr"; -static const std::string nlmsgAttrdataRoutine = "nlmsg_attrdata"; -static const std::string nlmsgAttrlenRoutine = "nlmsg_attrlen"; -static const std::string nlmsgFreeRoutine = "nlmsg_free"; -static const std::string nlRecvmsgsDefaultRoutine = "nl_recvmsgs_default"; -static const std::string nlSendAutoRoutine = "nl_send_auto"; -static const std::string nlSocketAllocRoutine = "nl_socket_alloc"; -static const std::string nlSocketDisableSeqCheckRoutine = "nl_socket_disable_seq_check"; -static const std::string nlSocketFreeRoutine = "nl_socket_free"; -static const std::string nlSocketModifyCbRoutine = "nl_socket_modify_cb"; - -template -bool NlApi::getProcAddr(NEO::OsLibrary *lh, const std::string name, T &proc) { - proc = reinterpret_cast(lh->getProcAddress(name)); - return nullptr != proc; -} - -bool NlApi::loadEntryPoints() { - bool ok = true; - ok = ok && getProcAddr(genlLibraryHandle, genlConnectRoutine, genlConnectEntry); - ok = ok && getProcAddr(genlLibraryHandle, genlCtrlResolveRoutine, genlCtrlResolveEntry); - ok = ok && getProcAddr(genlLibraryHandle, genlHandleMsgRoutine, genlHandleMsgEntry); - ok = ok && getProcAddr(genlLibraryHandle, genlmsgPutRoutine, genlmsgPutEntry); - ok = ok && getProcAddr(genlLibraryHandle, genlOpsResolveRoutine, genlOpsResolveEntry); - ok = ok && getProcAddr(genlLibraryHandle, genlRegisterFamilyRoutine, genlRegisterFamilyEntry); - ok = ok && getProcAddr(genlLibraryHandle, genlUnregisterFamilyRoutine, genlUnregisterFamilyEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlaDataRoutine, nlaDataEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlaGetU32Routine, nlaGetU32Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaGetU64Routine, nlaGetU64Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaGetU8Routine, nlaGetU8Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaIsNestedRoutine, nlaIsNestedEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlaLenRoutine, nlaLenEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlaNextRoutine, nlaNextEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlaOkRoutine, nlaOkEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlaPutU16Routine, nlaPutU16Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaPutU32Routine, nlaPutU32Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaPutU64Routine, nlaPutU64Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaPutU8Routine, nlaPutU8Entry); - ok = ok && getProcAddr(genlLibraryHandle, nlaTypeRoutine, nlaTypeEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlmsgAllocRoutine, nlmsgAllocEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlmsgHdrRoutine, nlmsgHdrEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlmsgAttrdataRoutine, nlmsgAttrdataEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlmsgAttrlenRoutine, nlmsgAttrlenEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlmsgFreeRoutine, nlmsgFreeEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlRecvmsgsDefaultRoutine, nlRecvmsgsDefaultEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlSendAutoRoutine, nlSendAutoEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlSocketAllocRoutine, nlSocketAllocEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlSocketDisableSeqCheckRoutine, nlSocketDisableSeqCheckEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlSocketFreeRoutine, nlSocketFreeEntry); - ok = ok && getProcAddr(genlLibraryHandle, nlSocketModifyCbRoutine, nlSocketModifyCbEntry); - - return ok; -} - -int NlApi::genlConnect(struct nl_sock *sock) { - UNRECOVERABLE_IF(nullptr == genlConnectEntry); - return (*genlConnectEntry)(sock); -} - -int NlApi::genlCtrlResolve(struct nl_sock *sock, const char *name) { - UNRECOVERABLE_IF(nullptr == genlCtrlResolveEntry); - return (*genlCtrlResolveEntry)(sock, name); -} - -int NlApi::genlHandleMsg(struct nl_msg *msg, void *arg) { - UNRECOVERABLE_IF(nullptr == genlHandleMsgEntry); - return (*genlHandleMsgEntry)(msg, arg); -} - -void *NlApi::genlmsgPut(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version) { - UNRECOVERABLE_IF(nullptr == genlmsgPutEntry); - return (*genlmsgPutEntry)(msg, port, seq, family, hdrlen, flags, cmd, version); -} - -int NlApi::genlOpsResolve(struct nl_sock *sock, struct genl_ops *ops) { - UNRECOVERABLE_IF(nullptr == genlOpsResolveEntry); - return (*genlOpsResolveEntry)(sock, ops); -} - -int NlApi::genlRegisterFamily(struct genl_ops *ops) { - UNRECOVERABLE_IF(nullptr == genlRegisterFamilyEntry); - return (*genlRegisterFamilyEntry)(ops); -} - -int NlApi::genlUnregisterFamily(struct genl_ops *ops) { - UNRECOVERABLE_IF(nullptr == genlUnregisterFamilyEntry); - return (*genlUnregisterFamilyEntry)(ops); -} - -void *NlApi::nlaData(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaDataEntry); - return (*nlaDataEntry)(attr); -} - -uint32_t NlApi::nlaGetU32(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaGetU32Entry); - return (*nlaGetU32Entry)(attr); -} - -uint64_t NlApi::nlaGetU64(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaGetU64Entry); - return (*nlaGetU64Entry)(attr); -} - -uint8_t NlApi::nlaGetU8(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaGetU8Entry); - return (*nlaGetU8Entry)(attr); -} - -int NlApi::nlaIsNested(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaIsNestedEntry); - return (*nlaIsNestedEntry)(attr); -} - -int NlApi::nlaLen(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaLenEntry); - return (*nlaLenEntry)(attr); -} - -struct nlattr *NlApi::nlaNext(const struct nlattr *attr, int *remaining) { - UNRECOVERABLE_IF(nullptr == nlaNextEntry); - return (*nlaNextEntry)(attr, remaining); -} - -int NlApi::nlaOk(const struct nlattr *attr, int remaining) { - UNRECOVERABLE_IF(nullptr == nlaOkEntry); - return (*nlaOkEntry)(attr, remaining); -} - -int NlApi::nlaPutU16(struct nl_msg *msg, int id, uint16_t data) { - UNRECOVERABLE_IF(nullptr == nlaPutU16Entry); - return (*nlaPutU16Entry)(msg, id, data); -} - -int NlApi::nlaPutU32(struct nl_msg *msg, int id, uint32_t data) { - UNRECOVERABLE_IF(nullptr == nlaPutU32Entry); - return (*nlaPutU32Entry)(msg, id, data); -} - -int NlApi::nlaPutU64(struct nl_msg *msg, int id, uint64_t data) { - UNRECOVERABLE_IF(nullptr == nlaPutU64Entry); - return (*nlaPutU64Entry)(msg, id, data); -} - -int NlApi::nlaPutU8(struct nl_msg *msg, int id, uint8_t data) { - UNRECOVERABLE_IF(nullptr == nlaPutU8Entry); - return (*nlaPutU8Entry)(msg, id, data); -} - -int NlApi::nlaType(const struct nlattr *attr) { - UNRECOVERABLE_IF(nullptr == nlaTypeEntry); - return (*nlaTypeEntry)(attr); -} - -struct nl_msg *NlApi::nlmsgAlloc() { - UNRECOVERABLE_IF(nullptr == nlmsgAllocEntry); - return (*nlmsgAllocEntry)(); -} - -struct nlmsghdr *NlApi::nlmsgHdr(struct nl_msg *msg) { - UNRECOVERABLE_IF(nullptr == nlmsgHdrEntry); - return (*nlmsgHdrEntry)(msg); -} - -struct nlattr *NlApi::nlmsgAttrdata(const struct nlmsghdr *hdr, int attr) { - UNRECOVERABLE_IF(nullptr == nlmsgAttrdataEntry); - return (*nlmsgAttrdataEntry)(hdr, attr); -} - -int NlApi::nlmsgAttrlen(const struct nlmsghdr *hdr, int attr) { - UNRECOVERABLE_IF(nullptr == nlmsgAttrlenEntry); - return (*nlmsgAttrlenEntry)(hdr, attr); -} - -void NlApi::nlmsgFree(struct nl_msg *msg) { - UNRECOVERABLE_IF(nullptr == nlmsgFreeEntry); - (*nlmsgFreeEntry)(msg); - return; -} - -int NlApi::nlRecvmsgsDefault(struct nl_sock *sock) { - UNRECOVERABLE_IF(nullptr == nlRecvmsgsDefaultEntry); - return (*nlRecvmsgsDefaultEntry)(sock); -} - -int NlApi::nlSendAuto(struct nl_sock *sock, struct nl_msg *msg) { - UNRECOVERABLE_IF(nullptr == nlSendAutoEntry); - return (*nlSendAutoEntry)(sock, msg); -} - -struct nl_sock *NlApi::nlSocketAlloc() { - UNRECOVERABLE_IF(nullptr == nlSocketAllocEntry); - return (*nlSocketAllocEntry)(); -} - -void NlApi::nlSocketDisableSeqCheck(struct nl_sock *sock) { - UNRECOVERABLE_IF(nullptr == nlSocketDisableSeqCheckEntry); - (*nlSocketDisableSeqCheckEntry)(sock); - return; -} - -void NlApi::nlSocketFree(struct nl_sock *sock) { - UNRECOVERABLE_IF(nullptr == nlSocketFreeEntry); - (*nlSocketFreeEntry)(sock); - return; -} - -int NlApi::nlSocketModifyCb(struct nl_sock *sock, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t cb, void *arg) { - UNRECOVERABLE_IF(nullptr == nlSocketModifyCbEntry); - return (*nlSocketModifyCbEntry)(sock, type, kind, cb, arg); -} - -NlApi *NlApi::create() { - NlApi *pNlApi = new NlApi; - UNRECOVERABLE_IF(nullptr == pNlApi); - - pNlApi->genlLibraryHandle = NEO::OsLibrary::load(libgenlFile); - if (nullptr == pNlApi->genlLibraryHandle) { - delete pNlApi; - return nullptr; - } - if (!pNlApi->loadEntryPoints()) { - delete pNlApi; - return nullptr; - } - return pNlApi; -} - -NlApi::~NlApi() { - if (nullptr != genlLibraryHandle) { - delete genlLibraryHandle; - genlLibraryHandle = nullptr; - } -} -} // namespace L0 diff --git a/level_zero/tools/source/sysman/linux/nl_api/nl_api.h b/level_zero/tools/source/sysman/linux/nl_api/nl_api.h deleted file mode 100644 index 83683388e6..0000000000 --- a/level_zero/tools/source/sysman/linux/nl_api/nl_api.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "shared/source/helpers/non_copyable_or_moveable.h" - -#include "level_zero/core/source/device/device.h" - -#include -#include -#include -#include -#include -#include -#include - -namespace L0 { - -typedef int (*pGenlConnect)(struct nl_sock *); -typedef int (*pGenlCtrlResolve)(struct nl_sock *, const char *); -typedef int (*pGenlHandleMsg)(struct nl_msg *, void *); -typedef void *(*pGenlmsgPut)(struct nl_msg *, uint32_t, uint32_t, int, int, int, uint8_t, uint8_t); -typedef int (*pGenlOpsResolve)(struct nl_sock *, struct genl_ops *); -typedef int (*pGenlRegisterFamily)(struct genl_ops *); -typedef int (*pGenlUnregisterFamily)(struct genl_ops *); -typedef void *(*pNlaData)(const struct nlattr *nla); -typedef uint32_t (*pNlaGetU32)(const struct nlattr *); -typedef uint64_t (*pNlaGetU64)(const struct nlattr *); -typedef uint8_t (*pNlaGetU8)(const struct nlattr *); -typedef int (*pNlaIsNested)(const struct nlattr *); -typedef int (*pNlaLen)(const struct nlattr *); -typedef struct nlattr *(*pNlaNext)(const struct nlattr *, int *); -typedef int (*pNlaOk)(const struct nlattr *, int); -typedef int (*pNlaPutU16)(struct nl_msg *, int, uint16_t); -typedef int (*pNlaPutU32)(struct nl_msg *, int, uint32_t); -typedef int (*pNlaPutU64)(struct nl_msg *, int, uint64_t); -typedef int (*pNlaPutU8)(struct nl_msg *, int, uint8_t); -typedef int (*pNlaType)(const struct nlattr *); -typedef struct nl_msg *(*pNlmsgAlloc)(); -typedef void (*pNlmsgFree)(struct nl_msg *); -typedef int (*pNlRecvmsgsDefault)(struct nl_sock *); -typedef int (*pNlSendAuto)(struct nl_sock *, struct nl_msg *); -typedef struct nl_sock *(*pNlSocketAlloc)(); -typedef void (*pNlSocketDisableSeqCheck)(struct nl_sock *); -typedef struct nlattr *(*pNlmsgAttrdata)(const struct nlmsghdr *, int); -typedef struct nlmsghdr *(*pNlmsgHdr)(struct nl_msg *); -typedef int (*pNlmsgAttrlen)(const struct nlmsghdr *, int); -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 *); - -class NlApi : public NEO::NonCopyableOrMovableClass { - public: - int genlConnect(struct nl_sock *sock); - int genlCtrlResolve(struct nl_sock *sock, const char *name); - int genlHandleMsg(struct nl_msg *msg, void *arg); - void *genlmsgPut(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version); - int genlOpsResolve(struct nl_sock *sock, struct genl_ops *ops); - int genlRegisterFamily(struct genl_ops *ops); - int genlUnregisterFamily(struct genl_ops *ops); - void *nlaData(const struct nlattr *attr); - uint32_t nlaGetU32(const struct nlattr *attr); - uint64_t nlaGetU64(const struct nlattr *attr); - uint8_t nlaGetU8(const struct nlattr *attr); - int nlaIsNested(const struct nlattr *attr); - int nlaLen(const struct nlattr *attr); - struct nlattr *nlaNext(const struct nlattr *attr, int *remaining); - int nlaOk(const struct nlattr *attr, int remaining); - int nlaPutU16(struct nl_msg *msg, int id, uint16_t data); - int nlaPutU32(struct nl_msg *msg, int id, uint32_t data); - int nlaPutU64(struct nl_msg *msg, int id, uint64_t data); - int nlaPutU8(struct nl_msg *msg, int id, uint8_t data); - int nlaType(const struct nlattr *attr); - struct nl_msg *nlmsgAlloc(); - struct nlmsghdr *nlmsgHdr(struct nl_msg *msg); - struct nlattr *nlmsgAttrdata(const struct nlmsghdr *hdr, int attr); - int nlmsgAttrlen(const struct nlmsghdr *hdr, int attr); - void nlmsgFree(struct nl_msg *msg); - int nlRecvmsgsDefault(struct nl_sock *sock); - int nlSendAuto(struct nl_sock *sock, struct nl_msg *msg); - struct nl_sock *nlSocketAlloc(); - void nlSocketDisableSeqCheck(struct nl_sock *sock); - void nlSocketFree(struct nl_sock *sock); - int nlSocketModifyCb(struct nl_sock *sock, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t cb, void *arg); - - ~NlApi(); - static NlApi *create(); - - private: - template - bool getProcAddr(NEO::OsLibrary *lh, const std::string name, T &proc); - NlApi() = default; - - bool loadEntryPoints(); - - NEO::OsLibrary *genlLibraryHandle = nullptr; - - pGenlConnect genlConnectEntry = nullptr; - pGenlCtrlResolve genlCtrlResolveEntry = nullptr; - pGenlHandleMsg genlHandleMsgEntry = nullptr; - pGenlmsgPut genlmsgPutEntry = nullptr; - pGenlOpsResolve genlOpsResolveEntry = nullptr; - pGenlRegisterFamily genlRegisterFamilyEntry = nullptr; - pGenlUnregisterFamily genlUnregisterFamilyEntry = nullptr; - pNlaData nlaDataEntry = nullptr; - pNlaGetU32 nlaGetU32Entry = nullptr; - pNlaGetU64 nlaGetU64Entry = nullptr; - pNlaGetU8 nlaGetU8Entry = nullptr; - pNlaIsNested nlaIsNestedEntry = nullptr; - pNlaLen nlaLenEntry = nullptr; - pNlaNext nlaNextEntry = nullptr; - pNlaOk nlaOkEntry = nullptr; - pNlaPutU16 nlaPutU16Entry = nullptr; - pNlaPutU32 nlaPutU32Entry = nullptr; - pNlaPutU64 nlaPutU64Entry = nullptr; - pNlaPutU8 nlaPutU8Entry = nullptr; - pNlaType nlaTypeEntry = nullptr; - pNlmsgAlloc nlmsgAllocEntry = nullptr; - pNlmsgHdr nlmsgHdrEntry = nullptr; - pNlmsgAttrdata nlmsgAttrdataEntry = nullptr; - pNlmsgAttrlen nlmsgAttrlenEntry = nullptr; - pNlmsgFree nlmsgFreeEntry = nullptr; - pNlRecvmsgsDefault nlRecvmsgsDefaultEntry = nullptr; - pNlSendAuto nlSendAutoEntry = nullptr; - pNlSocketAlloc nlSocketAllocEntry = nullptr; - pNlSocketDisableSeqCheck nlSocketDisableSeqCheckEntry = nullptr; - pNlSocketFree nlSocketFreeEntry = nullptr; - pNlSocketModifyCb nlSocketModifyCbEntry = nullptr; -}; - -} // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/nl_api/CMakeLists.txt b/level_zero/tools/test/unit_tests/sources/sysman/linux/nl_api/CMakeLists.txt deleted file mode 100644 index 6001494c57..0000000000 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/nl_api/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# -# Copyright (C) 2020 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -if(UNIX) - if(LIBGENL_FOUND) - target_sources(${TARGET_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_nl_api.cpp - ) - endif() -endif() diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/nl_api/test_sysman_nl_api.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/nl_api/test_sysman_nl_api.cpp deleted file mode 100644 index 123c75ecbb..0000000000 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/nl_api/test_sysman_nl_api.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" -#include "level_zero/tools/source/sysman/linux/nl_api/nl_api.h" -#include "level_zero/tools/source/sysman/sysman_imp.h" - -#include "gtest/gtest.h" - -namespace L0 { -namespace ult { - -class SysmanNlApiFixture : public ::testing::Test { - protected: - NlApi *pNlApi = nullptr; - struct nl_sock *pNlSock; - - void SetUp() override { - pNlApi = NlApi::create(); - - if (nullptr == pNlApi) { - GTEST_SKIP(); - } - pNlSock = pNlApi->nlSocketAlloc(); - EXPECT_NE(pNlSock, nullptr); - } - void TearDown() override { - if (nullptr != pNlSock) { - pNlApi->nlSocketFree(pNlSock); - pNlSock = nullptr; - } - if (nullptr != pNlApi) { - delete pNlApi; - pNlApi = nullptr; - } - } - - public: - static const char *testName; - static const int testFamilyId; - static const char *nlctrlName; - static const int nlctrlFamilyId; - static const int testAttrU8; - static const int testAttrU16; - static const int testAttrU32; - static const int testAttrU64; - static const int testAttrMax; - static const int testCmd; - static const char *testCmdName; -}; -const char *SysmanNlApiFixture::testName = "test_family"; -const int SysmanNlApiFixture::testFamilyId = 0x2000; -const char *SysmanNlApiFixture::nlctrlName = "nlctrl"; -const int SysmanNlApiFixture::nlctrlFamilyId = 0x10; // Well known number -const int SysmanNlApiFixture::testAttrU8 = 1; -const int SysmanNlApiFixture::testAttrU16 = 2; -const int SysmanNlApiFixture::testAttrU32 = 3; -const int SysmanNlApiFixture::testAttrU64 = 4; -const int SysmanNlApiFixture::testAttrMax = SysmanNlApiFixture::testAttrU64; -const int SysmanNlApiFixture::testCmd = 1; -const char *SysmanNlApiFixture::testCmdName = "test_command"; - -TEST_F(SysmanNlApiFixture, GivenValidNlSockWhenCallingGenlConnectVerifyGenlConnectReturnsSuccess) { - EXPECT_EQ(pNlApi->genlConnect(pNlSock), 0); -} -TEST_F(SysmanNlApiFixture, GivenValidNlSockWhenCallingGenlCtrlResolveVerifyGenlCtrlResolveReturnsSuccess) { - EXPECT_EQ(pNlApi->genlConnect(pNlSock), 0); - EXPECT_EQ(pNlApi->genlCtrlResolve(pNlSock, SysmanNlApiFixture::nlctrlName), SysmanNlApiFixture::nlctrlFamilyId); -} -TEST_F(SysmanNlApiFixture, GivenValidNlSockWhenCallingGenlOpsResolveVerifyGenlOpsResolveReturnsSuccess) { - EXPECT_EQ(pNlApi->genlConnect(pNlSock), 0); - struct genl_ops ops = {}; - ops.o_name = new char[strlen(SysmanNlApiFixture::nlctrlName + 1)]; - strcpy(ops.o_name, SysmanNlApiFixture::nlctrlName); - EXPECT_EQ(pNlApi->genlOpsResolve(pNlSock, &ops), 0); - delete ops.o_name; -} -TEST_F(SysmanNlApiFixture, GivenValidGenlOpsWhenCallingGenlRegisterFamilyVerifyGenlRegisterFamilyReturnsSuccess) { - EXPECT_EQ(pNlApi->genlConnect(pNlSock), 0); - struct genl_ops ops = {}; - ops.o_name = new char[strlen(SysmanNlApiFixture::testName) + 1]; - strcpy(ops.o_name, SysmanNlApiFixture::testName); - EXPECT_EQ(pNlApi->genlRegisterFamily(&ops), 0); - EXPECT_EQ(pNlApi->genlUnregisterFamily(&ops), 0); - delete ops.o_name; -} -TEST_F(SysmanNlApiFixture, GivenValidNlApiWhenCallingNlmsgAllocVerifyNlmsgAllocReturnsValidMessage) { - struct nl_msg *pNlMsg = pNlApi->nlmsgAlloc(); - EXPECT_NE(pNlMsg, nullptr); - pNlApi->nlmsgFree(pNlMsg); -} -TEST_F(SysmanNlApiFixture, GivenValidNlSockWhenCallingNlSocketDisableSeqCheckVerifyNSocketDisableSeqCheckReturns) { - // Void function, just verify that linkage works - pNlApi->nlSocketDisableSeqCheck(pNlSock); -} -extern "C" { -static int callback(struct nl_msg *msg, void *arg) { - NlApi *pNlApi = reinterpret_cast(arg); - return pNlApi->genlHandleMsg(msg, arg); -} -static int parser(struct nl_cache_ops *ops, struct genl_cmd *cmd, struct genl_info *info, void *arg) { - bool *complete = reinterpret_cast(arg); - *complete = true; - return NL_OK; -} -} -TEST_F(SysmanNlApiFixture, GivenValidNlSockWhenCallingNlSocketModifyCbVerifyNlSocketModifyCbReturnsSuccess) { - EXPECT_EQ(pNlApi->nlSocketModifyCb(pNlSock, NL_CB_VALID, NL_CB_CUSTOM, callback, reinterpret_cast(pNlApi)), 0); -} -TEST_F(SysmanNlApiFixture, GivenValidNlMsgWhenCallingNlaPutXVerifyNlaPutXReturnsSuccess) { - struct nl_msg *pNlMsg = pNlApi->nlmsgAlloc(); - EXPECT_NE(pNlMsg, nullptr); - EXPECT_NE(pNlApi->genlmsgPut(pNlMsg, NL_AUTO_PID, NL_AUTO_SEQ, SysmanNlApiFixture::testFamilyId, 0, 0, SysmanNlApiFixture::testCmd, 1), nullptr); - EXPECT_EQ(pNlApi->nlaPutU16(pNlMsg, SysmanNlApiFixture::testAttrU16, 0x7fffU), 0); - EXPECT_EQ(pNlApi->nlaPutU32(pNlMsg, SysmanNlApiFixture::testAttrU32, 0x7fffffffU), 0); - EXPECT_EQ(pNlApi->nlaPutU64(pNlMsg, SysmanNlApiFixture::testAttrU64, 0x7fffffffffffffffUL), 0); - EXPECT_EQ(pNlApi->nlaPutU8(pNlMsg, SysmanNlApiFixture::testAttrU8, 0x7fU), 0); - pNlApi->nlmsgFree(pNlMsg); -} -TEST_F(SysmanNlApiFixture, GivenValidNlattrWhenCallingNlaGetXVerifyNlaGetXReturnsSuccess) { - uint8_t buffer[NLA_HDRLEN + sizeof(uint64_t)]; - struct nlattr *attr = reinterpret_cast(&buffer[0]); - - attr->nla_type = SysmanNlApiFixture::testAttrU8; - attr->nla_len = NLA_HDRLEN + sizeof(uint8_t); - *reinterpret_cast(&buffer[NLA_HDRLEN]) = 0x7fU; - EXPECT_EQ(pNlApi->nlaGetU8(attr), *reinterpret_cast(&buffer[NLA_HDRLEN])); - attr->nla_type = SysmanNlApiFixture::testAttrU32; - attr->nla_len = NLA_HDRLEN + sizeof(uint32_t); - *reinterpret_cast(&buffer[NLA_HDRLEN]) = 0x7fffffffU; - EXPECT_EQ(pNlApi->nlaGetU32(attr), *reinterpret_cast(&buffer[NLA_HDRLEN])); - attr->nla_type = SysmanNlApiFixture::testAttrU64; - attr->nla_len = NLA_HDRLEN + sizeof(uint64_t); - *reinterpret_cast(&buffer[NLA_HDRLEN]) = 0x7fffffffffffffffUL; - EXPECT_EQ(pNlApi->nlaGetU64(attr), *reinterpret_cast(&buffer[NLA_HDRLEN])); -} -TEST_F(SysmanNlApiFixture, GivenValidNlattrWhenCallingNlaRoutinesVerifyNlaRoutinesReturnsSuccess) { - uint8_t buffer[NLA_HDRLEN + sizeof(uint64_t)]; - struct nlattr *attr = reinterpret_cast(&buffer[0]); - int length = sizeof(uint8_t); - attr->nla_type = SysmanNlApiFixture::testAttrU8; - attr->nla_len = NLA_HDRLEN + length; - *reinterpret_cast(&buffer[NLA_HDRLEN]) = 0x7fU; - - EXPECT_EQ(pNlApi->nlaData(attr), &buffer[NLA_HDRLEN]); - EXPECT_EQ(pNlApi->nlaType(attr), SysmanNlApiFixture::testAttrU8); - EXPECT_FALSE(pNlApi->nlaIsNested(attr)); - EXPECT_EQ(pNlApi->nlaLen(attr), length); - int remainder = NLA_ALIGN(attr->nla_len); - struct nlattr *next = nullptr; - EXPECT_TRUE(pNlApi->nlaOk(attr, remainder)); - next = pNlApi->nlaNext(attr, &remainder); - EXPECT_NE(next, nullptr); - EXPECT_EQ(remainder, 0); - EXPECT_FALSE(pNlApi->nlaOk(next, remainder)); -} -TEST_F(SysmanNlApiFixture, GivenValidNlMsghdrWhenCallingNlmsgAttrdataVerifyNmsgAttrdataReturnsSuccess) { - struct nl_msg *pNlMsg = pNlApi->nlmsgAlloc(); - EXPECT_NE(pNlMsg, nullptr); - pNlApi->genlmsgPut(pNlMsg, NL_AUTO_PID, NL_AUTO_SEQ, SysmanNlApiFixture::testFamilyId, 0, 0, SysmanNlApiFixture::testCmd, 1); - EXPECT_EQ(pNlApi->nlaPutU32(pNlMsg, SysmanNlApiFixture::testAttrU32, 0x7fffffffU), 0); - EXPECT_EQ(pNlApi->nlaPutU64(pNlMsg, SysmanNlApiFixture::testAttrU64, 0x7fffffffffffffffUL), 0); - EXPECT_EQ(pNlApi->nlaPutU8(pNlMsg, SysmanNlApiFixture::testAttrU8, 0x7fU), 0); - - struct nlmsghdr *hdr = pNlApi->nlmsgHdr(pNlMsg); - struct nlattr *attr = nullptr; - attr = pNlApi->nlmsgAttrdata(hdr, GENL_HDRLEN); - int remainder = pNlApi->nlmsgAttrlen(hdr, GENL_HDRLEN); - EXPECT_NE(attr, nullptr); - EXPECT_TRUE(pNlApi->nlaOk(attr, remainder)); - void *data = (struct nlattr *)pNlApi->nlaData(attr); - size_t len = pNlApi->nlaLen(attr); - EXPECT_EQ(pNlApi->nlaType(attr), SysmanNlApiFixture::testAttrU32); - EXPECT_EQ(len, sizeof(uint32_t)); - EXPECT_EQ(*reinterpret_cast(data), 0x7fffffffU); - attr = pNlApi->nlaNext(attr, &remainder); - EXPECT_NE(attr, nullptr); - EXPECT_TRUE(pNlApi->nlaOk(attr, remainder)); - data = (struct nlattr *)pNlApi->nlaData(attr); - len = pNlApi->nlaLen(attr); - EXPECT_EQ(pNlApi->nlaType(attr), SysmanNlApiFixture::testAttrU64); - EXPECT_EQ(len, sizeof(uint64_t)); - EXPECT_EQ(*reinterpret_cast(data), 0x7fffffffffffffffUL); - attr = pNlApi->nlaNext(attr, &remainder); - EXPECT_NE(attr, nullptr); - EXPECT_TRUE(pNlApi->nlaOk(attr, remainder)); - data = (struct nlattr *)pNlApi->nlaData(attr); - len = pNlApi->nlaLen(attr); - EXPECT_EQ(pNlApi->nlaType(attr), SysmanNlApiFixture::testAttrU8); - EXPECT_EQ(len, sizeof(uint8_t)); - EXPECT_EQ(*reinterpret_cast(data), 0x7fU); - - pNlApi->nlmsgFree(pNlMsg); -} -TEST_F(SysmanNlApiFixture, GivenValidNlMsghWhenCallingGenlHandleMsgVerifyGenlHandleMsgCallsMsgParserAndReturnsSuccess) { - struct genl_ops ops = {}; - struct genl_cmd cmd = {}; - struct nla_policy policy[SysmanNlApiFixture::testAttrMax + 1] = {}; - policy[SysmanNlApiFixture::testAttrU8].type = NLA_U8; - policy[SysmanNlApiFixture::testAttrU16].type = NLA_U16; - policy[SysmanNlApiFixture::testAttrU32].type = NLA_U32; - policy[SysmanNlApiFixture::testAttrU64].type = NLA_U64; - - cmd.c_id = SysmanNlApiFixture::testCmd; - cmd.c_name = new char[strlen(SysmanNlApiFixture::testCmdName) + 1]; - strcpy(cmd.c_name, SysmanNlApiFixture::testCmdName); - cmd.c_maxattr = SysmanNlApiFixture::testAttrMax; - cmd.c_attr_policy = policy; - cmd.c_msg_parser = &parser; - - ops.o_name = new char[strlen(SysmanNlApiFixture::testName) + 1]; - strcpy(ops.o_name, SysmanNlApiFixture::testName); - ops.o_id = SysmanNlApiFixture::testFamilyId; - ops.o_hdrsize = 0; - ops.o_cmds = &cmd; - ops.o_ncmds = 1; - - EXPECT_EQ(pNlApi->genlRegisterFamily(&ops), 0); - - struct nl_msg *pNlMsg = pNlApi->nlmsgAlloc(); - EXPECT_NE(pNlMsg, nullptr); - EXPECT_NE(pNlApi->genlmsgPut(pNlMsg, NL_AUTO_PID, NL_AUTO_SEQ, SysmanNlApiFixture::testFamilyId, 0, 0, SysmanNlApiFixture::testCmd, 1), nullptr); - bool complete = false; - EXPECT_EQ(pNlApi->genlHandleMsg(pNlMsg, reinterpret_cast(&complete)), NL_OK); - EXPECT_TRUE(complete); - - pNlApi->nlmsgFree(pNlMsg); - EXPECT_EQ(pNlApi->genlUnregisterFamily(&ops), 0); - delete ops.o_name; - delete cmd.c_name; -} -TEST_F(SysmanNlApiFixture, GivenUnconnectedSocketWhenCallingRecvmsgsDefaultVerifyRecvmsgsDefaultReturnsFailure) { - - // there is no netlink server to talk to, just verify that linkage to nl_recvmsgs_default is correct - EXPECT_LT(pNlApi->nlRecvmsgsDefault(pNlSock), 0); -} - -TEST_F(SysmanNlApiFixture, GivenUnconnectedSocketWhenCallingNlSendAutoVerifyNlSendAutoReturnsFailure) { - struct nl_msg *pNlMsg = pNlApi->nlmsgAlloc(); - EXPECT_NE(pNlMsg, nullptr); - EXPECT_NE(pNlApi->genlmsgPut(pNlMsg, NL_AUTO_PID, NL_AUTO_SEQ, SysmanNlApiFixture::testFamilyId, 0, 0, SysmanNlApiFixture::testCmd, 1), nullptr); - - // there is no netlink server to talk to, just verify that linkage to nl_send_auto is correct - EXPECT_LT(pNlApi->nlSendAuto(pNlSock, pNlMsg), 0); - pNlApi->nlmsgFree(pNlMsg); -} - -} // namespace ult -} // namespace L0