refactor: don't call OsLibrary::load directly, use function pointer

this allows mocking this call in ULT

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2024-08-19 12:50:05 +00:00
committed by Compute-Runtime-Automation
parent 006285105d
commit 579af57161
51 changed files with 124 additions and 137 deletions

View File

@@ -453,13 +453,11 @@ struct WhiteBoxNumaLibrary : Linux::NumaLibrary {
using Linux::NumaLibrary::procGetMemPolicyStr;
using Linux::NumaLibrary::procNumaAvailableStr;
using Linux::NumaLibrary::procNumaMaxNodeStr;
using OsLibraryLoadPtr = NumaLibrary::OsLibraryLoadPtr;
using GetMemPolicyPtr = NumaLibrary::GetMemPolicyPtr;
using NumaAvailablePtr = NumaLibrary::NumaAvailablePtr;
using NumaMaxNodePtr = NumaLibrary::NumaMaxNodePtr;
using Linux::NumaLibrary::getMemPolicyFunction;
using Linux::NumaLibrary::osLibrary;
using Linux::NumaLibrary::osLibraryLoadFunction;
};
TEST(MemoryInfo, givenValidNumaLibraryPtrAndMemoryInfoWithoutMemoryPolicyEnabledWhenMemoryInfoIsCreatedThenNumaLibraryIsNotLoaded) {
@@ -490,7 +488,7 @@ TEST(MemoryInfo, givenValidNumaLibraryPtrAndMemoryInfoWithoutMemoryPolicyEnabled
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_FALSE(memoryInfo->isMemPolicySupported());
@@ -528,7 +526,7 @@ TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledWhenCallingCreateGemExtWi
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_TRUE(memoryInfo->isMemPolicySupported());
@@ -586,7 +584,7 @@ TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledWhenCallingCreateGemExtFo
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
@@ -647,7 +645,7 @@ TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledAndOverrideMemoryPolicyMo
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
@@ -699,7 +697,7 @@ TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledWhenCallingCreateGemExtWi
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_TRUE(memoryInfo->isMemPolicySupported());
@@ -735,7 +733,7 @@ TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledAndInvalidOsLibraryWhenCa
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_FALSE(memoryInfo->isMemPolicySupported());

View File

@@ -7,6 +7,7 @@
#include "shared/source/helpers/string.h"
#include "shared/source/os_interface/linux/numa_library.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_os_library.h"
#include "shared/test/common/test_macros/test.h"
@@ -21,13 +22,11 @@ struct WhiteBoxNumaLibrary : NumaLibrary {
using NumaLibrary::procGetMemPolicyStr;
using NumaLibrary::procNumaAvailableStr;
using NumaLibrary::procNumaMaxNodeStr;
using OsLibraryLoadPtr = NumaLibrary::OsLibraryLoadPtr;
using GetMemPolicyPtr = NumaLibrary::GetMemPolicyPtr;
using NumaAvailablePtr = NumaLibrary::NumaAvailablePtr;
using NumaMaxNodePtr = NumaLibrary::NumaMaxNodePtr;
using NumaLibrary::getMemPolicyFunction;
using NumaLibrary::osLibrary;
using NumaLibrary::osLibraryLoadFunction;
};
TEST(NumaLibraryTests, givenNumaLibraryWithValidMockOsLibraryWhenCallingGetMemPolicyThenZeroIsReturned) {
@@ -44,7 +43,7 @@ TEST(NumaLibraryTests, givenNumaLibraryWithValidMockOsLibraryWhenCallingGetMemPo
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
EXPECT_TRUE(WhiteBoxNumaLibrary::init());
EXPECT_TRUE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(reinterpret_cast<WhiteBoxNumaLibrary::GetMemPolicyPtr>(memPolicyHandler), WhiteBoxNumaLibrary::getMemPolicyFunction);
@@ -72,7 +71,7 @@ TEST(NumaLibraryTests, givenNumaLibraryWithInvalidMockOsLibraryWhenCallingLoadTh
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = nullptr;
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = nullptr;
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibraryCustom::load};
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, MockOsLibrary::loadLibraryNewObject);
@@ -122,7 +121,7 @@ TEST(NumaLibraryTests, givenNumaLibraryWithInvalidMockOsLibraryWhenCallingLoadTh
TEST(NumaLibraryTests, givenNumaLibraryWithInvalidOsLibraryWhenCallingGetMemPolicyThenErrorIsReturned) {
MockOsLibrary::loadLibraryNewObject = new MockOsLibrary(nullptr, false);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibrary::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibrary::load};
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
@@ -132,7 +131,7 @@ TEST(NumaLibraryTests, givenNumaLibraryWithInvalidOsLibraryWhenCallingGetMemPoli
TEST(NumaLibraryTests, givenNumaLibraryWithInvalidGetMemPolicyWhenCallingGetMemPolicyThenErrorIsReturned) {
MockOsLibrary::loadLibraryNewObject = new MockOsLibrary(nullptr, true);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibrary::load;
VariableBackup<decltype(NEO::OsLibrary::loadFunc)> funcBackup{&NEO::OsLibrary::loadFunc, MockOsLibrary::load};
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, WhiteBoxNumaLibrary::getMemPolicyFunction);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -34,14 +34,14 @@ TEST(OsLibraryTest, GivenValidNameWhenGettingFullPathAndDlinfoFailsThenPathIsEmp
}
return 0;
});
std::unique_ptr<OsLibrary> library(OsLibrary::load(Os::testDllName));
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc(Os::testDllName));
EXPECT_NE(nullptr, library);
std::string path = library->getFullPath();
EXPECT_EQ(0u, path.size());
}
TEST(OsLibraryTest, GivenValidLibNameWhenGettingFullPathThenPathIsNotEmpty) {
std::unique_ptr<OsLibrary> library(OsLibrary::load(Os::testDllName));
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc(Os::testDllName));
EXPECT_NE(nullptr, library);
std::string path = library->getFullPath();
EXPECT_NE(0u, path.size());