mock dlopen in tests to block unwanted interactions

- explicitly specify files allowed to dlopen()
- use underscore to prefix fake library name that we want dlopen to
return nullptr


Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:
Artur Harasimiuk
2021-11-18 22:25:02 +00:00
committed by Compute-Runtime-Automation
parent 2e68f0abbd
commit 7eb5b6aa42
8 changed files with 59 additions and 16 deletions

View File

@ -34,7 +34,7 @@ TEST(OsLibraryTest, GivenDisableDeepBindFlagWhenOpeningLibraryThenRtldDeepBindFl
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
DebugManager.flags.DisableDeepBind.set(1);
auto lib = std::make_unique<Linux::OsLibrary>("abc", nullptr);
auto lib = std::make_unique<Linux::OsLibrary>("_abc.so", nullptr);
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
EXPECT_EQ(0, NEO::SysCalls::dlOpenFlags & RTLD_DEEPBIND);
}
@ -43,7 +43,7 @@ TEST(OsLibraryTest, GivenInvalidLibraryWhenOpeningLibraryThenDlopenErrorIsReturn
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
std::string errorValue;
auto lib = std::make_unique<Linux::OsLibrary>("abc", &errorValue);
auto lib = std::make_unique<Linux::OsLibrary>("_abc.so", &errorValue);
EXPECT_FALSE(errorValue.empty());
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
}

View File

@ -20,8 +20,6 @@
#include <memory>
namespace Os {
extern const char *frontEndDllName;
extern const char *igcDllName;
extern const char *testDllName;
} // namespace Os
const std::string fakeLibName = "_fake_library_name_";