diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index 449d2b0a6b..0d5fc2e88b 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -187,7 +187,7 @@ TEST(L0DeviceTest, givenDeviceWithoutFCLCompilerLibraryThenInvalidDependencyRetu auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); auto oldFclDllName = Os::frontEndDllName; - Os::frontEndDllName = "invalidFCL"; + Os::frontEndDllName = "_invalidFCL"; auto device = std::unique_ptr(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue)); ASSERT_NE(nullptr, device); @@ -205,7 +205,7 @@ TEST(L0DeviceTest, givenDeviceWithoutIGCCompilerLibraryThenInvalidDependencyRetu auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); auto oldIgcDllName = Os::igcDllName; - Os::igcDllName = "invalidIGC"; + Os::igcDllName = "_invalidIGC"; auto device = std::unique_ptr(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue)); ASSERT_NE(nullptr, device); @@ -224,8 +224,8 @@ TEST(L0DeviceTest, givenDeviceWithoutAnyCompilerLibraryThenInvalidDependencyRetu auto oldFclDllName = Os::frontEndDllName; auto oldIgcDllName = Os::igcDllName; - Os::frontEndDllName = "invalidFCL"; - Os::igcDllName = "invalidIGC"; + Os::frontEndDllName = "_invalidFCL"; + Os::igcDllName = "_invalidIGC"; auto device = std::unique_ptr(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue)); ASSERT_NE(nullptr, device); diff --git a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp index 14024afaa9..eb5d325348 100644 --- a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp @@ -382,8 +382,8 @@ TEST(DriverTest, givenInvalidCompilerEnvironmentThenDependencyUnavailableErrorIs DriverImp driverImp; auto oldFclDllName = Os::frontEndDllName; auto oldIgcDllName = Os::igcDllName; - Os::frontEndDllName = "invalidFCL"; - Os::igcDllName = "invalidIGC"; + Os::frontEndDllName = "_invalidFCL"; + Os::igcDllName = "_invalidIGC"; driverImp.initialize(&result); EXPECT_EQ(result, ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE); diff --git a/opencl/test/unit_test/os_interface/linux/os_library_linux_tests.cpp b/opencl/test/unit_test/os_interface/linux/os_library_linux_tests.cpp index ac84032043..11d2077abc 100644 --- a/opencl/test/unit_test/os_interface/linux/os_library_linux_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/os_library_linux_tests.cpp @@ -34,7 +34,7 @@ TEST(OsLibraryTest, GivenDisableDeepBindFlagWhenOpeningLibraryThenRtldDeepBindFl VariableBackup dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false}; DebugManager.flags.DisableDeepBind.set(1); - auto lib = std::make_unique("abc", nullptr); + auto lib = std::make_unique("_abc.so", nullptr); EXPECT_TRUE(NEO::SysCalls::dlOpenCalled); EXPECT_EQ(0, NEO::SysCalls::dlOpenFlags & RTLD_DEEPBIND); } @@ -43,7 +43,7 @@ TEST(OsLibraryTest, GivenInvalidLibraryWhenOpeningLibraryThenDlopenErrorIsReturn VariableBackup dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false}; std::string errorValue; - auto lib = std::make_unique("abc", &errorValue); + auto lib = std::make_unique("_abc.so", &errorValue); EXPECT_FALSE(errorValue.empty()); EXPECT_TRUE(NEO::SysCalls::dlOpenCalled); } diff --git a/opencl/test/unit_test/os_interface/os_library_tests.cpp b/opencl/test/unit_test/os_interface/os_library_tests.cpp index 249a6d572e..ae352b141e 100644 --- a/opencl/test/unit_test/os_interface/os_library_tests.cpp +++ b/opencl/test/unit_test/os_interface/os_library_tests.cpp @@ -20,8 +20,6 @@ #include namespace Os { -extern const char *frontEndDllName; -extern const char *igcDllName; extern const char *testDllName; } // namespace Os const std::string fakeLibName = "_fake_library_name_"; diff --git a/shared/test/common/mocks/CMakeLists.txt b/shared/test/common/mocks/CMakeLists.txt index 351eb2f8d6..f5a7c9e31a 100644 --- a/shared/test/common/mocks/CMakeLists.txt +++ b/shared/test/common/mocks/CMakeLists.txt @@ -87,6 +87,7 @@ if(WIN32) ) else() list(APPEND NEO_CORE_tests_mocks + ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_dlopen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_command_stream_receiver.h ${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.h diff --git a/shared/test/common/mocks/linux/mock_dlopen.cpp b/shared/test/common/mocks/linux/mock_dlopen.cpp new file mode 100644 index 0000000000..0d427155c2 --- /dev/null +++ b/shared/test/common/mocks/linux/mock_dlopen.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include +#include +#include + +void *(*dlopenFunc)(const char *filename, int flags) = nullptr; +char *(*dlerrorFunc)() = nullptr; + +static char dlerrorString[][16] = {"denied", "fake"}; +static int dlopenError = -1; + +void *dlopen(const char *filename, int flags) { + if (dlerrorFunc == nullptr) { + dlerrorFunc = reinterpret_cast(dlsym(RTLD_NEXT, "dlerror")); + } + if (dlopenFunc == nullptr) { + dlopenFunc = reinterpret_cast(dlsym(RTLD_NEXT, "dlopen")); + } + + dlopenError = -1; + if (filename == nullptr || + strcmp(filename, "libtest_dynamic_lib.so") == 0) { + return dlopenFunc(filename, flags); + } + if (filename[0] == '_') { + dlopenError = 1; + return nullptr; + } + dlopenError = 0; + return nullptr; +} + +char *dlerror() { + if (dlerrorFunc == nullptr) { + dlerrorFunc = reinterpret_cast(dlsym(RTLD_NEXT, "dlerror")); + } + if (dlopenError >= 0 && dlopenError < 2) { + return dlerrorString[dlopenError]; + } + return dlerrorFunc(); +} diff --git a/shared/test/common/os_interface/linux/options.cpp b/shared/test/common/os_interface/linux/options.cpp index afca65f8b4..cae7f25dc2 100644 --- a/shared/test/common/os_interface/linux/options.cpp +++ b/shared/test/common/os_interface/linux/options.cpp @@ -16,13 +16,10 @@ namespace Os { // the runtime unit tests /////////////////////////////////////////////////////////////////////////////// #if defined(__linux__) -const char *frontEndDllName = "libmock_igdfcl.so"; -const char *igcDllName = "libmock_igc.so"; +const char *frontEndDllName = "_invalidFCL"; +const char *igcDllName = "_invalidIGC"; const char *libvaDllName = nullptr; const char *testDllName = "libtest_dynamic_lib.so"; -const char *gmmDllName = "libmock_gmm.so"; -const char *gmmInitFuncName = "initMockGmm"; -const char *gmmDestroyFuncName = "destroyMockGmm"; const char *metricsLibraryDllName = ""; const char *gdiDllName = ""; const char *dxcoreDllName = ""; diff --git a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp index a0b1e8bb06..94275cf542 100644 --- a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp +++ b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp @@ -633,7 +633,7 @@ TEST(LoadCompilerTest, whenCouldNotLoadLibraryThenReturnFalseAndNullOutputs) { MockCompilerEnableGuard mock; std::unique_ptr retLib; CIF::RAII::UPtr_t retMain; - bool retVal = loadCompiler("falseName.notRealLib", retLib, retMain); + bool retVal = loadCompiler("_falseName.notRealLib", retLib, retMain); EXPECT_FALSE(retVal); EXPECT_EQ(nullptr, retLib.get()); EXPECT_EQ(nullptr, retMain.get());