[libc-commits] [libc] [libc] Implement `timespec_get` (PR #116102)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Fri Nov 15 12:09:32 PST 2024
================
@@ -0,0 +1,32 @@
+//===-- Unittests for timespec_get ----------------------------------------===//
+//
+// 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/__support/macros/properties/architectures.h"
+#include "src/time/timespec_get.h"
+#include "test/UnitTest/Test.h"
+
+#include <time.h>
+
+TEST(LlvmLibcTimespecGet, Utc) {
+#ifndef LIBC_TARGET_ARCH_IS_GPU
+ timespec ts;
+ int result;
+ result = LIBC_NAMESPACE::timespec_get(&ts, TIME_UTC);
+ ASSERT_EQ(result, TIME_UTC);
+ ASSERT_GT(ts.tv_sec, time_t(0));
+#endif
+}
+
+TEST(LlvmLibcTimespecGet, Unknown) {
+#ifndef LIBC_TARGET_ARCH_IS_GPU
+ timespec ts;
+ int result;
+ result = LIBC_NAMESPACE::timespec_get(&ts, 0);
+ ASSERT_EQ(result, 0);
+#endif
----------------
petrhosek wrote:
GPU doesn't support UTC clock, it only [implements monotonic clock](https://github.com/llvm/llvm-project/blob/94eebf721a2f8630412730f51d5071816a686ea0/libc/src/time/gpu/clock_gettime.cpp). I could do the same for `TIME_MONOTONIC` and for `TIME_UTC` just return `0`. @jhuber6 what do you think?
https://github.com/llvm/llvm-project/pull/116102
More information about the libc-commits
mailing list