Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libc/test/src/time/clock_gettime_test.cpp')
-rw-r--r--libc/test/src/time/clock_gettime_test.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/libc/test/src/time/clock_gettime_test.cpp b/libc/test/src/time/clock_gettime_test.cpp
new file mode 100644
index 000000000000..3214ca19c72a
--- /dev/null
+++ b/libc/test/src/time/clock_gettime_test.cpp
@@ -0,0 +1,36 @@
+//===-- Unittests for clock_gettime ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/time/clock_gettime.h"
+#include "utils/UnitTest/Test.h"
+
+#include <time.h>
+
+TEST(LlvmLibcClockGetTime, RealTime) {
+ struct timespec tp;
+ int result;
+ result = clock_gettime(CLOCK_REALTIME, &tp);
+ ASSERT_EQ(result, 0);
+ ASSERT_GT(tp.tv_sec, time_t(0));
+}
+
+#ifdef CLOCK_MONOTONIC
+TEST(LlvmLibcClockGetTime, MonotonicTime) {
+ struct timespec tp1, tp2;
+ int result;
+ result = clock_gettime(CLOCK_MONOTONIC, &tp1);
+ ASSERT_EQ(result, 0);
+ ASSERT_GT(tp1.tv_sec, time_t(0));
+ result = clock_gettime(CLOCK_MONOTONIC, &tp2);
+ ASSERT_EQ(result, 0);
+ ASSERT_GE(tp2.tv_sec, tp1.tv_sec); // The monotonic clock should increase.
+ if (tp2.tv_sec == tp1.tv_sec) {
+ ASSERT_GE(tp2.tv_nsec, tp1.tv_nsec);
+ }
+}
+#endif // CLOCK_MONOTONIC