Commit 136b0408 authored by zyearn's avatar zyearn

Merge branch 'cmake_support' of github.com:brpc/brpc into cmake_support

parents 694b0290 a0c02eef
......@@ -233,9 +233,8 @@ void return_keytable(bthread_keytable_pool_t* pool, KeyTable* kt) {
pool->free_keytables = kt;
}
static void cleanup_pthread() {
KeyTable* kt = tls_bls.keytable;
//TODO(zhujiashun): thread local storage not works in macos using clang
static void cleanup_pthread(void* arg) {
KeyTable* kt = static_cast<KeyTable*>(arg);
if (kt) {
delete kt;
// After deletion: tls may be set during deletion.
......@@ -447,7 +446,7 @@ int bthread_setspecific(bthread_key_t key, void* data) {
}
if (!bthread::tls_ever_created_keytable) {
bthread::tls_ever_created_keytable = true;
CHECK_EQ(0, butil::thread_atexit(bthread::cleanup_pthread));
CHECK_EQ(0, butil::thread_atexit(bthread::cleanup_pthread, kt));
}
}
return kt->set_data(key, data);
......
......@@ -143,32 +143,48 @@ SET(TEST_BUTIL_SOURCES ${TEST_BUTIL_SOURCES}
${CMAKE_SOURCE_DIR}/test/test_file_util_linux.cc)
endif()
# bthread_* functions are used in logging.cc, and they need to be marked as
# weak symbols explicitly in Darwin system.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(DYNAMIC_LIB ${DYNAMIC_LIB}
"-Wl,-U,_bthread_getspecific"
"-Wl,-U,_bthread_setspecific"
"-Wl,-U,_bthread_key_create")
endif()
# create executable
add_library(TEST_PROTO_OBJ OBJECT ${TEST_PROTO_SRCS})
add_executable(test_butil ${TEST_BUTIL_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/iobuf.pb.cc
$<TARGET_OBJECTS:BUTIL_LIB>)
target_link_libraries(test_butil ${GTEST_LIB}
${GPERFTOOLS_LIBRARIES}
${DYNAMIC_LIB})
# -DBVAR_NOT_LINK_DEFAULT_VARIABLES not work for gcc >= 5.0, just remove the file to prevent linking into unit tests
list(REMOVE_ITEM BVAR_SOURCES ${CMAKE_SOURCE_DIR}/src/bvar/default_variables.cpp)
add_library(BVAR_OBJ OBJECT ${BVAR_SOURCES})
file(GLOB TEST_BVAR_SRCS "bvar_*_unittest.cpp")
add_executable(test_bvar $<TARGET_OBJECTS:BUTIL_LIB>
${BTHREAD_SOURCES}
${BVAR_SOURCES}
$<TARGET_OBJECTS:BVAR_OBJ>
${TEST_BVAR_SRCS})
target_link_libraries(test_bvar ${GTEST_LIB}
${GPERFTOOLS_LIBRARIES}
${DYNAMIC_LIB})
add_library(TEST_PROTO_OBJ OBJECT ${TEST_PROTO_SRCS})
add_executable(test_butil ${TEST_BUTIL_SOURCES}
$<TARGET_OBJECTS:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(test_butil ${GTEST_LIB} ${GPERFTOOLS_LIBRARIES} ${DYNAMIC_LIB})
add_library(BTHREAD_OBJ OBJECT ${BTHREAD_SOURCES})
add_library(PROTO_OBJ OBJECT ${PROTO_SRCS})
file(GLOB BTHREAD_UNITTESTS "bthread*unittest.cpp")
foreach(BTHREAD_UT ${BTHREAD_UNITTESTS})
get_filename_component(BTHREAD_UT_WE ${BTHREAD_UT} NAME_WE)
add_executable(${BTHREAD_UT_WE} ${BTHREAD_UT}
$<TARGET_OBJECTS:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
$<TARGET_OBJECTS:BVAR_OBJ>
$<TARGET_OBJECTS:BTHREAD_OBJ>
$<TARGET_OBJECTS:PROTO_OBJ>
$<TARGET_OBJECTS:TEST_PROTO_OBJ>)
target_link_libraries(${BTHREAD_UT_WE}
${GTEST_MAIN_LIB}
${GTEST_LIB}
......
......@@ -664,6 +664,7 @@ TEST_F(BuiltinServiceTest, pprof) {
EXPECT_FALSE(cntl.Failed());
CheckContent(cntl, "num_symbols");
}
#if defined(OS_LINUX)
{
ClosureChecker done;
brpc::Controller cntl;
......@@ -671,6 +672,7 @@ TEST_F(BuiltinServiceTest, pprof) {
EXPECT_FALSE(cntl.Failed());
CheckContent(cntl, "brpc_builtin_service_unittest");
}
#endif
}
TEST_F(BuiltinServiceTest, dir) {
......@@ -695,7 +697,11 @@ TEST_F(BuiltinServiceTest, dir) {
cntl.http_request()._unresolved_path = "/usr/include/errno.h";
service.default_method(&cntl, &req, &res, &done);
EXPECT_FALSE(cntl.Failed());
#if defined(OS_LINUX)
CheckContent(cntl, "ERRNO_H");
#elif defined(OS_MACOSX)
CheckContent(cntl, "sys/errno.h");
#endif
}
{
// Open a file that doesn't exist
......
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