aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sys_time_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-07-15 16:53:13 -0700
committerElliott Hughes <enh@google.com>2014-07-16 14:27:43 -0700
commit625993dfbb085a3cde7492eda8ec1cdc1ee39a78 (patch)
tree4385fee1dde6d90f42c616a2afc6766824f72835 /tests/sys_time_test.cpp
parent770d0f6177ca1ad242b509151fb612f07ef8a07b (diff)
downloadandroid_bionic-625993dfbb085a3cde7492eda8ec1cdc1ee39a78.tar.gz
android_bionic-625993dfbb085a3cde7492eda8ec1cdc1ee39a78.tar.bz2
android_bionic-625993dfbb085a3cde7492eda8ec1cdc1ee39a78.zip
Use VDSO for clock_gettime(2) and gettimeofday(2).
Bug: 15387103 Change-Id: Ifc3608ea65060c1dc38120b10b6e79874f182a36
Diffstat (limited to 'tests/sys_time_test.cpp')
-rw-r--r--tests/sys_time_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/sys_time_test.cpp b/tests/sys_time_test.cpp
index 730992fca..bb142bc5f 100644
--- a/tests/sys_time_test.cpp
+++ b/tests/sys_time_test.cpp
@@ -17,6 +17,7 @@
#include <gtest/gtest.h>
#include <errno.h>
+#include <sys/syscall.h>
#include <sys/time.h>
#include "TemporaryFile.h"
@@ -46,3 +47,23 @@ TEST(sys_time, utimes_NULL) {
TemporaryFile tf;
ASSERT_EQ(0, utimes(tf.filename, NULL));
}
+
+TEST(sys_time, gettimeofday) {
+ // Try to ensure that our vdso gettimeofday is working.
+ timeval tv1;
+ ASSERT_EQ(0, gettimeofday(&tv1, NULL));
+ timeval tv2;
+ ASSERT_EQ(0, syscall(__NR_gettimeofday, &tv2, NULL));
+
+ // What's the difference between the two?
+ tv2.tv_sec -= tv1.tv_sec;
+ tv2.tv_usec -= tv1.tv_usec;
+ if (tv2.tv_usec < 0) {
+ --tv2.tv_sec;
+ tv2.tv_usec += 1000000;
+ }
+
+ // Should be less than (a very generous, to try to avoid flakiness) 1000us.
+ ASSERT_EQ(0, tv2.tv_sec);
+ ASSERT_LT(tv2.tv_usec, 1000);
+}