1 //===-- Unittests for clock_gettime ---------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/time/clock_gettime.h"
10 #include "test/UnitTest/Test.h"
14 TEST(LlvmLibcClockGetTime
, RealTime
) {
17 result
= clock_gettime(CLOCK_REALTIME
, &tp
);
19 ASSERT_GT(tp
.tv_sec
, time_t(0));
22 #ifdef CLOCK_MONOTONIC
23 TEST(LlvmLibcClockGetTime
, MonotonicTime
) {
24 struct timespec tp1
, tp2
;
26 result
= clock_gettime(CLOCK_MONOTONIC
, &tp1
);
28 ASSERT_GT(tp1
.tv_sec
, time_t(0));
29 result
= clock_gettime(CLOCK_MONOTONIC
, &tp2
);
31 ASSERT_GE(tp2
.tv_sec
, tp1
.tv_sec
); // The monotonic clock should increase.
32 if (tp2
.tv_sec
== tp1
.tv_sec
) {
33 ASSERT_GE(tp2
.tv_nsec
, tp1
.tv_nsec
);
36 #endif // CLOCK_MONOTONIC