fix: correct loading L0 loader functions

- don't load ze_loader.dll from file system
- to perform self-open on Windows use getModuleHandleA with proper module name
- don't free library loaded with getModuleHandleA
- as loader may be not available during runtime teardown:
- load translate handle function during global setup
- load setDriverTeardown function during global teardown
- when loader is not available during teardown, unset translate handle
function

Related-To: GSD-10147

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2024-10-16 19:53:07 +00:00
committed by Compute-Runtime-Automation
parent 9d6d6e85f1
commit 4154e6666b
38 changed files with 300 additions and 123 deletions

View File

@@ -22,7 +22,7 @@ const std::string fnName = "testDynamicLibraryFunc";
using namespace NEO;
TEST(OSLibraryTest, whenLibraryNameIsEmptyThenCurrentProcesIsUsedAsLibrary) {
std::unique_ptr<OsLibrary> library{OsLibrary::loadFunc("")};
std::unique_ptr<OsLibrary> library{OsLibrary::loadFunc({""})};
EXPECT_NE(nullptr, library);
void *ptr = library->getProcAddress("selfDynamicLibraryFunc");
EXPECT_NE(nullptr, ptr);
@@ -35,32 +35,36 @@ TEST(OSLibraryTest, GivenFakeLibNameWhenLoadingLibraryThenNullIsReturned) {
TEST(OSLibraryTest, GivenFakeLibNameWhenLoadingLibraryThenNullIsReturnedAndErrorString) {
std::string errorValue;
OsLibrary *library = OsLibrary::loadAndCaptureError(fakeLibName, &errorValue);
OsLibraryCreateProperties properties(fakeLibName);
properties.errorValue = &errorValue;
OsLibrary *library = OsLibrary::loadFunc(properties);
EXPECT_FALSE(errorValue.empty());
EXPECT_EQ(nullptr, library);
}
TEST(OSLibraryTest, GivenValidLibNameWhenLoadingLibraryThenLibraryIsLoaded) {
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc(Os::testDllName));
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc({Os::testDllName}));
EXPECT_NE(nullptr, library);
}
TEST(OSLibraryTest, GivenValidLibNameWhenLoadingLibraryThenLibraryIsLoadedWithNoErrorString) {
std::string errorValue;
std::unique_ptr<OsLibrary> library(OsLibrary::loadAndCaptureError(Os::testDllName, &errorValue));
OsLibraryCreateProperties properties(Os::testDllName);
properties.errorValue = &errorValue;
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc(properties));
EXPECT_TRUE(errorValue.empty());
EXPECT_NE(nullptr, library);
}
TEST(OSLibraryTest, whenSymbolNameIsValidThenGetProcAddressReturnsNonNullPointer) {
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc(Os::testDllName));
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc({Os::testDllName}));
EXPECT_NE(nullptr, library);
void *ptr = library->getProcAddress(fnName);
EXPECT_NE(nullptr, ptr);
}
TEST(OSLibraryTest, whenSymbolNameIsInvalidThenGetProcAddressReturnsNullPointer) {
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc(Os::testDllName));
std::unique_ptr<OsLibrary> library(OsLibrary::loadFunc({Os::testDllName}));
EXPECT_NE(nullptr, library);
void *ptr = library->getProcAddress(fnName + "invalid");
EXPECT_EQ(nullptr, ptr);