Use VDSO for clock_gettime(2) and gettimeofday(2).

Bug: 15387103
Change-Id: Ifc3608ea65060c1dc38120b10b6e79874f182a36
This commit is contained in:
Elliott Hughes
2014-07-15 16:53:13 -07:00
parent 770d0f6177
commit 625993dfbb
14 changed files with 250 additions and 22 deletions

View File

@@ -21,6 +21,7 @@
#include <gtest/gtest.h>
#include <pthread.h>
#include <signal.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -419,3 +420,23 @@ TEST(time, timer_delete_from_timer_thread) {
ASSERT_EQ(ESRCH, pthread_detach(tdd.thread_id));
#endif
}
TEST(time, clock_gettime) {
// Try to ensure that our vdso clock_gettime is working.
timespec ts1;
ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts1));
timespec ts2;
ASSERT_EQ(0, syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts2));
// What's the difference between the two?
ts2.tv_sec -= ts1.tv_sec;
ts2.tv_nsec -= ts1.tv_nsec;
if (ts2.tv_nsec < 0) {
--ts2.tv_sec;
ts2.tv_nsec += 1000000000;
}
// Should be less than (a very generous, to try to avoid flakiness) 1000000ns.
ASSERT_EQ(0, ts2.tv_sec);
ASSERT_LT(ts2.tv_nsec, 1000000);
}