Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
8adbabc6
Commit
8adbabc6
authored
Jan 18, 2018
by
zyearn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make test compiled in macos
parent
14acce29
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
2 deletions
+46
-2
CMakeLists.txt
CMakeLists.txt
+4
-0
fd.cpp
src/bthread/fd.cpp
+10
-0
task_group.h
src/bthread/task_group.h
+4
-0
CMakeLists.txt
test/CMakeLists.txt
+6
-2
baidu_time_unittest.cpp
test/baidu_time_unittest.cpp
+12
-0
bthread_butex_unittest.cpp
test/bthread_butex_unittest.cpp
+10
-0
No files found.
CMakeLists.txt
View file @
8adbabc6
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
brpc C CXX
)
# Enable MACOSX_RPATH. Run "cmake --help-policy CMP0042" for policy details.
cmake_policy
(
SET CMP0042 NEW
)
if
(
CMAKE_CXX_COMPILER_ID STREQUAL
"GNU"
)
# require at least gcc 4.8
if
(
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8
)
...
...
@@ -123,6 +126,7 @@ set(DYNAMIC_LIB
${
LEVELDB_LIB
}
${
PROTOC_LIB
}
${
CMAKE_THREAD_LIBS_INIT
}
pthread
rt
ssl
crypto
...
...
src/bthread/fd.cpp
View file @
8adbabc6
...
...
@@ -385,7 +385,17 @@ int pthread_fd_wait(int fd, unsigned epoll_events,
int
diff_ms
=
-
1
;
if
(
abstime
)
{
timespec
now
;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t
cclock
;
mach_timespec_t
mts
;
host_get_clock_service
(
mach_host_self
(),
CALENDAR_CLOCK
,
&
cclock
);
clock_get_time
(
cclock
,
&
mts
);
mach_port_deallocate
(
mach_task_self
(),
cclock
);
now
.
tv_sec
=
mts
.
tv_sec
;
now
.
tv_nsec
=
mts
.
tv_nsec
;
#else
clock_gettime
(
CLOCK_REALTIME
,
&
now
);
#endif
int64_t
now_us
=
butil
::
timespec_to_microseconds
(
now
);
int64_t
abstime_us
=
butil
::
timespec_to_microseconds
(
*
abstime
);
if
(
abstime_us
<=
now_us
)
{
...
...
src/bthread/task_group.h
View file @
8adbabc6
...
...
@@ -127,6 +127,10 @@ public:
// Routine of the main task which should be called from a dedicated pthread.
void
run_main_task
();
// current_task is a function in macOS 10.0+
#ifdef current_task
#undef current_task
#endif
// Meta/Identifier of current task in this group.
TaskMeta
*
current_task
()
const
{
return
_cur_meta
;
}
bthread_t
current_tid
()
const
{
return
_cur_meta
->
tid
;
}
...
...
test/CMakeLists.txt
View file @
8adbabc6
...
...
@@ -53,7 +53,6 @@ SET(TEST_BUTIL_SOURCES
${
CMAKE_SOURCE_DIR
}
/test/cpu_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/crash_logging_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/leak_tracker_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/proc_maps_linux_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/stack_trace_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/environment_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/file_util_unittest.cc
...
...
@@ -134,11 +133,16 @@ SET(TEST_BUTIL_SOURCES
${
CMAKE_SOURCE_DIR
}
/test/iobuf_unittest.cpp
${
CMAKE_SOURCE_DIR
}
/test/test_switches.cc
${
CMAKE_SOURCE_DIR
}
/test/scoped_locale.cc
${
CMAKE_SOURCE_DIR
}
/test/test_file_util_linux.cc
${
CMAKE_SOURCE_DIR
}
/test/butil_unittest_main.cpp
${
CMAKE_SOURCE_DIR
}
/test/butil_unittest_main.cpp
)
if
(
CMAKE_SYSTEM_NAME STREQUAL
"Linux"
)
SET
(
TEST_BUTIL_SOURCES
${
TEST_BUTIL_SOURCES
}
${
CMAKE_SOURCE_DIR
}
/test/proc_maps_linux_unittest.cc
${
CMAKE_SOURCE_DIR
}
/test/test_file_util_linux.cc
)
endif
()
# -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
)
...
...
test/baidu_time_unittest.cpp
View file @
8adbabc6
...
...
@@ -19,7 +19,17 @@ namespace {
TEST
(
BaiduTimeTest
,
diff_between_gettimeofday_and_REALTIME
)
{
long
t1
=
butil
::
gettimeofday_us
();
timespec
time
;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t
cclock
;
mach_timespec_t
mts
;
host_get_clock_service
(
mach_host_self
(),
CALENDAR_CLOCK
,
&
cclock
);
clock_get_time
(
cclock
,
&
mts
);
mach_port_deallocate
(
mach_task_self
(),
cclock
);
time
.
tv_sec
=
mts
.
tv_sec
;
time
.
tv_nsec
=
mts
.
tv_nsec
;
#else
clock_gettime
(
CLOCK_REALTIME
,
&
time
);
#endif
long
t2
=
butil
::
timespec_to_microseconds
(
time
);
LOG
(
INFO
)
<<
"t1="
<<
t1
<<
" t2="
<<
t2
;
}
...
...
@@ -100,6 +110,7 @@ TEST(BaiduTimeTest, cost_of_timer) {
clock_desc
[
i
],
t1
.
n_elapsed
()
/
N
);
}
#endif
#if !defined(OS_MACOSX)
if
(
0
==
clock_gettime
((
clockid_t
)
i
,
&
ts
))
{
t1
.
start
();
for
(
size_t
j
=
0
;
j
<
N
;
++
j
)
{
...
...
@@ -109,6 +120,7 @@ TEST(BaiduTimeTest, cost_of_timer) {
printf
(
"glibc clock_gettime(%s) takes %"
PRId64
"ns
\n
"
,
clock_desc
[
i
],
t1
.
n_elapsed
()
/
N
);
}
#endif
}
}
...
...
test/bthread_butex_unittest.cpp
View file @
8adbabc6
...
...
@@ -25,7 +25,17 @@ TEST(ButexTest, wait_on_already_timedout_butex) {
uint32_t
*
butex
=
bthread
::
butex_create_checked
<
uint32_t
>
();
ASSERT_TRUE
(
butex
);
timespec
now
;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t
cclock
;
mach_timespec_t
mts
;
host_get_clock_service
(
mach_host_self
(),
CALENDAR_CLOCK
,
&
cclock
);
ASSERT_EQ
(
0
,
clock_get_time
(
cclock
,
&
mts
));
mach_port_deallocate
(
mach_task_self
(),
cclock
);
now
.
tv_sec
=
mts
.
tv_sec
;
now
.
tv_nsec
=
mts
.
tv_nsec
;
#else
ASSERT_EQ
(
0
,
clock_gettime
(
CLOCK_REALTIME
,
&
now
));
#endif
*
butex
=
1
;
ASSERT_EQ
(
-
1
,
bthread
::
butex_wait
(
butex
,
1
,
&
now
));
ASSERT_EQ
(
ETIMEDOUT
,
errno
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment