Skip to content

Commit e11f2f5

Browse files
author
zhujiashun
committedDec 28, 2017
add test(except test/popen_unittest.cpp)
1 parent 8359711 commit e11f2f5

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed
 

‎cmake/FindGperftools.cmake

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Tries to find Gperftools.
2+
#
3+
# Usage of this module as follows:
4+
#
5+
# find_package(Gperftools)
6+
#
7+
# Variables used by this module, they can change the default behaviour and need
8+
# to be set before calling find_package:
9+
#
10+
# Gperftools_ROOT_DIR Set this variable to the root installation of
11+
# Gperftools if the module has problems finding
12+
# the proper installation path.
13+
#
14+
# Variables defined by this module:
15+
#
16+
# GPERFTOOLS_FOUND System has Gperftools libs/headers
17+
# GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler)
18+
# GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers
19+
20+
find_library(GPERFTOOLS_TCMALLOC
21+
NAMES tcmalloc
22+
HINTS ${Gperftools_ROOT_DIR}/lib)
23+
24+
find_library(GPERFTOOLS_PROFILER
25+
NAMES profiler
26+
HINTS ${Gperftools_ROOT_DIR}/lib)
27+
28+
find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER
29+
NAMES tcmalloc_and_profiler
30+
HINTS ${Gperftools_ROOT_DIR}/lib)
31+
32+
find_path(GPERFTOOLS_INCLUDE_DIR
33+
NAMES gperftools/heap-profiler.h
34+
HINTS ${Gperftools_ROOT_DIR}/include)
35+
36+
set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER})
37+
38+
include(FindPackageHandleStandardArgs)
39+
find_package_handle_standard_args(
40+
Gperftools
41+
DEFAULT_MSG
42+
GPERFTOOLS_LIBRARIES
43+
GPERFTOOLS_INCLUDE_DIR)
44+
45+
mark_as_advanced(
46+
Gperftools_ROOT_DIR
47+
GPERFTOOLS_TCMALLOC
48+
GPERFTOOLS_PROFILER
49+
GPERFTOOLS_TCMALLOC_AND_PROFILER
50+
GPERFTOOLS_LIBRARIES
51+
GPERFTOOLS_INCLUDE_DIR)

‎test/CMakeLists.txt

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
find_package(Gperftools)
2+
include_directories(${GPERFTOOLS_INCLUDE_DIR})
13
include_directories(${CMAKE_CURRENT_BINARY_DIR})
24
file(GLOB PROTOS "*.proto")
35
list(APPEND PROTO_FLAGS -I${CMAKE_CURRENT_BINARY_DIR})
@@ -12,12 +14,14 @@ endforeach()
1214

1315
find_path(GTEST_HEADER NAMES gtest/gtest.h)
1416
find_library(GTEST_LIB NAMES gtest)
17+
find_library(GTEST_MAIN_LIB NAMES gtest_main)
1518

1619
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES -include ${CMAKE_SOURCE_DIR}/test/sstream_workaround.h")
17-
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -std=c++0x")
20+
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer")
1821

1922

2023
SET(TEST_BUTIL_SOURCES
24+
#${CMAKE_SOURCE_DIR}/test/popen_unittest.cpp
2125
${CMAKE_SOURCE_DIR}/test/at_exit_unittest.cc
2226
${CMAKE_SOURCE_DIR}/test/atomicops_unittest.cc
2327
${CMAKE_SOURCE_DIR}/test/base64_unittest.cc
@@ -113,10 +117,28 @@ SET(TEST_BUTIL_SOURCES
113117
${CMAKE_SOURCE_DIR}/test/test_switches.cc
114118
${CMAKE_SOURCE_DIR}/test/scoped_locale.cc
115119
${CMAKE_SOURCE_DIR}/test/test_file_util_linux.cc
116-
${CMAKE_SOURCE_DIR}/test/popen_unittest.cpp
117120
${CMAKE_SOURCE_DIR}/test/butil_unittest_main.cpp
118121
${CMAKE_SOURCE_DIR}/test/butil_unittest_main.cpp
119122
)
120123

124+
file(GLOB TEST_BVAR_SRCS "bvar_*_unittest.cpp")
125+
add_executable(test_bvar ${TEST_BVAR_SRCS} ${PROTO_SRCS})
126+
target_link_libraries(test_bvar brpc ${GTEST_LIB} ${GPERFTOOLS_LIBRARIES})
127+
121128
add_executable(test_butil ${TEST_BUTIL_SOURCES} ${PROTO_SRCS})
122129
target_link_libraries(test_butil brpc ${GTEST_LIB})
130+
131+
file(GLOB BTHREAD_UNITTESTS "bthread*unittest.cpp")
132+
foreach(BTHREAD_UT ${BTHREAD_UNITTESTS})
133+
get_filename_component(BTHREAD_UT_WE ${BTHREAD_UT} NAME_WE)
134+
add_executable(${BTHREAD_UT_WE} ${BTHREAD_UT} ${PROTO_SRCS})
135+
target_link_libraries(${BTHREAD_UT_WE} brpc ${GTEST_MAIN_LIB} ${GPERFTOOLS_LIBRARIES} ${GTEST_LIB})
136+
endforeach()
137+
138+
file(GLOB BRPC_UNITTESTS "brpc_*_unittest.cpp")
139+
foreach(BRPC_UT ${BRPC_UNITTESTS})
140+
get_filename_component(BRPC_UT_WE ${BRPC_UT} NAME_WE)
141+
add_executable(${BRPC_UT_WE} ${BRPC_UT} ${PROTO_SRCS})
142+
target_link_libraries(${BRPC_UT_WE} brpc ${GTEST_MAIN_LIB} ${GPERFTOOLS_LIBRARIES} ${GTEST_LIB})
143+
endforeach()
144+

0 commit comments

Comments
 (0)
Please sign in to comment.