Add clock_settime and clock_nanosleep.
Add the missing prototypes, fix the existing prototypes to use clockid_t rather than int, fix clock_nanosleep's failure behavior, and add simple tests. Bug: 17644443 Bug: https://code.google.com/p/android/issues/detail?id=77372 Change-Id: I03fba369939403918abcabae9551a7123953d780 Signed-off-by: Haruki Hasegawa <h6a.h4i.0@gmail.com>
This commit is contained in:

committed by
Elliott Hughes

parent
c229705051
commit
1816025684
@@ -406,9 +406,22 @@ TEST(time, clock_gettime) {
|
||||
}
|
||||
|
||||
TEST(time, clock) {
|
||||
// clock(3) is hard to test, but a 1s sleep should cost less than 1ms.
|
||||
clock_t t0 = clock();
|
||||
sleep(1);
|
||||
clock_t t1 = clock();
|
||||
ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000);
|
||||
// clock(3) is hard to test, but a 1s sleep should cost less than 1ms.
|
||||
clock_t t0 = clock();
|
||||
sleep(1);
|
||||
clock_t t1 = clock();
|
||||
ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000);
|
||||
}
|
||||
|
||||
TEST(time, clock_settime) {
|
||||
errno = 0;
|
||||
timespec ts;
|
||||
ASSERT_EQ(-1, clock_settime(-1, &ts));
|
||||
ASSERT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(time, clock_nanosleep) {
|
||||
timespec in;
|
||||
timespec out;
|
||||
ASSERT_EQ(EINVAL, clock_nanosleep(-1, 0, &in, &out));
|
||||
}
|
||||
|
Reference in New Issue
Block a user