Commit df8c294a authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

disable ThreadLocal.SharedLibrary when not building shared libs

Summary:
The `ThreadLocal.SharedLibrary` test depends on building a separate
`thread_local_test_lib.so`.  This can only be built when folly was compiled
with PIC.

This also fixes the test to fail normally rather than segfaulting if it cannot
load `thread_local_test_lib.so`.

Reviewed By: yfeldblum

Differential Revision: D6805683

fbshipit-source-id: b451b94c2a4b3184a8f61de3b7f83e69169205f0
parent cdb9225b
......@@ -337,6 +337,20 @@ if (BUILD_TESTS)
include(GoogleTest OPTIONAL RESULT_VARIABLE HAVE_CMAKE_GTEST)
enable_testing()
# The ThreadLocalTest code uses a helper shared library for one of its tests.
# This can only be built if folly itself was built as a shared library.
if (BUILD_SHARED_LIBS)
add_library(thread_local_test_lib MODULE
${FOLLY_DIR}/test/ThreadLocalTestLib.cpp
)
set_target_properties(thread_local_test_lib PROPERTIES PREFIX "")
apply_folly_compile_options_to_target(thread_local_test_lib)
target_link_libraries(thread_local_test_lib PUBLIC folly)
target_include_directories(
thread_local_test_lib
PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
endif()
add_library(folly_test_support
${FOLLY_DIR}/test/common/TestMain.cpp
${FOLLY_DIR}/test/DeterministicSchedule.cpp
......
......@@ -578,17 +578,25 @@ TEST(ThreadLocal, Fork2) {
}
}
// Elide this test when using any sanitizer. Otherwise, the dlopen'ed code
// would end up running without e.g., ASAN-initialized data structures and
// failing right away.
#if !defined FOLLY_SANITIZE_ADDRESS && !defined UNDEFINED_SANITIZER && \
!defined FOLLY_SANITIZE_THREAD
// Disable the SharedLibrary test when using any sanitizer. Otherwise, the
// dlopen'ed code would end up running without e.g., ASAN-initialized data
// structures and failing right away.
//
// We also cannot run this test unless folly was compiled with PIC support,
// since we cannot build thread_local_test_lib.so without PIC.
#if defined FOLLY_SANITIZE_ADDRESS || defined UNDEFINED_SANITIZER || \
defined FOLLY_SANITIZE_THREAD || !defined FOLLY_SUPPORT_SHARED_LIBRARY
#define SHARED_LIBRARY_TEST_NAME DISABLED_SharedLibrary
#else
#define SHARED_LIBRARY_TEST_NAME SharedLibrary
#endif
TEST(ThreadLocal, SharedLibrary) {
TEST(ThreadLocal, SHARED_LIBRARY_TEST_NAME) {
auto exe = fs::executable_path();
auto lib = exe.parent_path() / "thread_local_test_lib.so";
auto handle = dlopen(lib.string().c_str(), RTLD_LAZY);
EXPECT_NE(nullptr, handle);
ASSERT_NE(nullptr, handle)
<< "unable to load " << lib.string() << ": " << dlerror();
typedef void (*useA_t)();
dlerror();
......@@ -596,6 +604,7 @@ TEST(ThreadLocal, SharedLibrary) {
const char *dlsym_error = dlerror();
EXPECT_EQ(nullptr, dlsym_error);
ASSERT_NE(nullptr, useA);
useA();
......@@ -625,7 +634,6 @@ TEST(ThreadLocal, SharedLibrary) {
t2.join();
}
#endif
#endif
namespace folly { namespace threadlocal_detail {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment