[libc-commits] [libc] [libc][time] Implement timer_create and timer_delete. (PR #217920)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Fri Aug 21 11:13:03 PDT 2026
================
@@ -0,0 +1,97 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for posix timers (timer_create, timer_delete).
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/signal_macros.h"
+#include "hdr/time_macros.h"
+#include "hdr/types/clockid_t.h"
+#include "hdr/types/struct_sigevent.h"
+#include "hdr/types/timer_t.h"
+#include "src/__support/OSUtil/syscall.h"
+#include "src/time/timer_create.h"
+#include "src/time/timer_delete.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+#include <sys/syscall.h>
+
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::any_of;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+using LlvmLibcTimerTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcTimerTest, NullSigevent) {
+ timer_t timerid;
+ ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_REALTIME, nullptr, &timerid),
+ Succeeds(0));
+ ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
+}
+
+TEST_F(LlvmLibcTimerTest, ValidSigeventSigevNone) {
+ struct sigevent se;
+ se.sigev_notify = SIGEV_NONE;
+ timer_t timerid;
+ ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_MONOTONIC, &se, &timerid),
+ Succeeds(0));
+ ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
+}
+
+TEST_F(LlvmLibcTimerTest, ValidSigeventSigevSignal) {
+ struct sigevent se;
+ se.sigev_notify = SIGEV_SIGNAL;
+ se.sigev_signo = SIGALRM;
+ se.sigev_value.sival_int = 42;
+ timer_t timerid;
+ ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_REALTIME, &se, &timerid),
+ Succeeds(0));
+ ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
+}
+
+#if defined(SYS_gettid) && defined(SIGEV_THREAD_ID)
+TEST_F(LlvmLibcTimerTest, ValidSigeventSigevThreadId) {
+ struct sigevent se;
+ se.sigev_notify = SIGEV_THREAD_ID;
+ se.sigev_signo = SIGALRM;
+ se.sigev_value.sival_int = 42;
+ se.sigev_notify_thread_id = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
----------------
vonosmas wrote:
Can we use LIBC_NAMESPACE::gettid() ?
https://github.com/llvm/llvm-project/pull/217920
More information about the libc-commits
mailing list