[libc-commits] [libc] [libc][time] Implement timer_create and timer_delete. (PR #217920)

via libc-commits libc-commits at lists.llvm.org
Fri Aug 21 11:19:12 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: lntue

<details>
<summary>Changes</summary>

Implement timer_create and timer_delete functions according to POSIX.1-2024.

Assisted-by: Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/217920.diff


15 Files Affected:

- (modified) libc/config/linux/aarch64/entrypoints.txt (+3) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+3) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+3) 
- (modified) libc/include/time.yaml (+15) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+31) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/timer_create.h (+87) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/timer_delete.h (+38) 
- (modified) libc/src/time/CMakeLists.txt (+15) 
- (modified) libc/src/time/linux/CMakeLists.txt (+33) 
- (added) libc/src/time/linux/timer_create.cpp (+33) 
- (added) libc/src/time/linux/timer_delete.cpp (+31) 
- (added) libc/src/time/timer_create.h (+29) 
- (added) libc/src/time/timer_delete.h (+26) 
- (modified) libc/test/src/time/CMakeLists.txt (+20) 
- (added) libc/test/src/time/timer_test.cpp (+97) 


``````````diff
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 468b00efad35e..eb4ad38db3cd3 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1330,6 +1330,9 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.nanosleep
     libc.src.time.time
     libc.src.time.timespec_get
+    libc.src.time.timer_create
+    libc.src.time.timer_delete
+
 
     # unistd.h entrypoints
     libc.src.unistd.__llvm_libc_syscall
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index ca6a3d872c71d..12f004989597c 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1525,6 +1525,9 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.strftime_l
     libc.src.time.time
     libc.src.time.timespec_get
+    libc.src.time.timer_create
+    libc.src.time.timer_delete
+
 
     # locale.h entrypoints
     libc.src.locale.localeconv
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 9f7da5e10b66c..34733ed9346d4 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1539,6 +1539,9 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.strftime_l
     libc.src.time.time
     libc.src.time.timespec_get
+    libc.src.time.timer_create
+    libc.src.time.timer_delete
+
 
     # locale.h entrypoints
     libc.src.locale.localeconv
diff --git a/libc/include/time.yaml b/libc/include/time.yaml
index a7c0cc7cc3e8e..147bd6f5643a6 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -154,3 +154,18 @@ functions:
     arguments:
       - type: struct timespec *
       - type: int
+  - name: timer_create
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: clockid_t
+      - type: struct sigevent *__restrict
+      - type: timer_t *__restrict
+  - name: timer_delete
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: timer_t
+
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 0041db9a24cbd..50a0dc40bc719 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1005,3 +1005,34 @@ add_header_library(
     libc.src.__support.macros.config
     libc.include.sys_syscall
 )
+
+add_header_library(
+  timer_create
+  HDRS
+    timer_create.h
+  DEPENDS
+    libc.hdr.signal_macros
+    libc.hdr.types.clockid_t
+    libc.hdr.types.pid_t
+    libc.hdr.types.struct_sigevent
+    libc.hdr.types.timer_t
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  timer_delete
+  HDRS
+    timer_delete.h
+  DEPENDS
+    libc.hdr.types.timer_t
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_create.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_create.h
new file mode 100644
index 0000000000000..89563416db165
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_create.h
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Implementation header for timer_create syscall wrapper.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_CREATE_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_CREATE_H
+
+#include "hdr/signal_macros.h"
+#include "hdr/types/clockid_t.h"
+#include "hdr/types/pid_t.h"
+#include "hdr/types/struct_sigevent.h"
+#include "hdr/types/timer_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+#define __SIGEV_MAX_SIZE 64
+#define __SIGEV_PAD_SIZE                                                       \
+  ((__SIGEV_MAX_SIZE - sizeof(int) * 2 - sizeof(sigval)) / sizeof(int))
+
+// Linux kernel ABI layout for struct sigevent (64 bytes total):
+// https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h
+// https://man7.org/linux/man-pages/man2/timer_create.2.html
+struct KernelSigevent {
+  sigval sigev_value;
+  int sigev_signo;
+  int sigev_notify;
+  union {
+    int _pad[__SIGEV_PAD_SIZE];
+    pid_t _tid;
+    struct {
+      void (*_function)(sigval);
+      void *_attribute;
+    } _sigev_thread;
+  } _sigev_un;
+
+  LIBC_INLINE KernelSigevent() = default;
+
+  LIBC_INLINE KernelSigevent(const sigevent &sev) : _sigev_un{} {
+    sigev_value = sev.sigev_value;
+    sigev_signo = sev.sigev_signo;
+    sigev_notify = sev.sigev_notify;
+    for (unsigned i = 0; i < __SIGEV_PAD_SIZE; ++i)
+      _sigev_un._pad[i] = 0;
+    if ((sev.sigev_notify & SIGEV_THREAD_ID) != 0) {
+      _sigev_un._tid = sev.sigev_notify_thread_id;
+    } else if (sev.sigev_notify == SIGEV_THREAD) {
+      _sigev_un._sigev_thread._function = sev.sigev_notify_function;
+      _sigev_un._sigev_thread._attribute = sev.sigev_notify_attributes;
+    }
+  }
+};
+
+#undef __SIGEV_MAX_SIZE
+#undef __SIGEV_PAD_SIZE
+
+LIBC_INLINE ErrorOr<int> timer_create(clockid_t clockid, const sigevent *sevp,
+                                      timer_t *timerid) {
+#ifdef SYS_timer_create
+  if (!sevp)
+    return syscall_checked<int>(SYS_timer_create, clockid, nullptr, timerid);
+
+  KernelSigevent ksev(*sevp);
+  return syscall_checked<int>(SYS_timer_create, clockid, &ksev, timerid);
+#else
+#error "SYS_timer_create syscall not available."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_CREATE_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_delete.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_delete.h
new file mode 100644
index 0000000000000..bc41a6d6d2ed1
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_delete.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Implementation header for timer_delete syscall wrapper.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_DELETE_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_DELETE_H
+
+#include "hdr/types/timer_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> timer_delete(timer_t timerid) {
+#ifdef SYS_timer_delete
+  return syscall_checked<int>(SYS_timer_delete, timerid);
+#else
+#error "SYS_timer_delete syscall not available."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_DELETE_H
diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index 8a4c71968712c..49ca72376090c 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -299,3 +299,18 @@ add_entrypoint_object(
   DEPENDS
     .${LIBC_TARGET_OS}.clock_settime
 )
+
+add_entrypoint_object(
+  timer_create
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.timer_create
+)
+
+add_entrypoint_object(
+  timer_delete
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.timer_delete
+)
+
diff --git a/libc/src/time/linux/CMakeLists.txt b/libc/src/time/linux/CMakeLists.txt
index f3cd822498a57..3f91aa3528405 100644
--- a/libc/src/time/linux/CMakeLists.txt
+++ b/libc/src/time/linux/CMakeLists.txt
@@ -72,3 +72,36 @@ add_entrypoint_object(
     libc.src.__support.time.clock_settime
     libc.src.errno.errno
 )
+
+add_entrypoint_object(
+  timer_create
+  SRCS
+    timer_create.cpp
+  HDRS
+    ../timer_create.h
+  DEPENDS
+    libc.hdr.types.clockid_t
+    libc.hdr.types.struct_sigevent
+    libc.hdr.types.timer_t
+    libc.src.__support.OSUtil.linux.syscall_wrappers.timer_create
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
+    libc.src.errno.errno
+)
+
+add_entrypoint_object(
+  timer_delete
+  SRCS
+    timer_delete.cpp
+  HDRS
+    ../timer_delete.h
+  DEPENDS
+    libc.hdr.types.timer_t
+    libc.src.__support.OSUtil.linux.syscall_wrappers.timer_delete
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
+    libc.src.errno.errno
+)
+
diff --git a/libc/src/time/linux/timer_create.cpp b/libc/src/time/linux/timer_create.cpp
new file mode 100644
index 0000000000000..a5ca734c10da6
--- /dev/null
+++ b/libc/src/time/linux/timer_create.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Linux implementation of timer_create function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/timer_create.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/timer_create.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, timer_create,
+                   (clockid_t clockid, sigevent *__restrict sevp,
+                    timer_t *__restrict timerid)) {
+  auto result = linux_syscalls::timer_create(clockid, sevp, timerid);
+  if (!result) {
+    libc_errno = result.error();
+    return -1;
+  }
+  return result.value();
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/linux/timer_delete.cpp b/libc/src/time/linux/timer_delete.cpp
new file mode 100644
index 0000000000000..bbf2d621003e1
--- /dev/null
+++ b/libc/src/time/linux/timer_delete.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Linux implementation of timer_delete function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/timer_delete.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/timer_delete.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, timer_delete, (timer_t timerid)) {
+  auto result = linux_syscalls::timer_delete(timerid);
+  if (!result) {
+    libc_errno = result.error();
+    return -1;
+  }
+  return result.value();
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/timer_create.h b/libc/src/time/timer_create.h
new file mode 100644
index 0000000000000..c8466536b7d4e
--- /dev/null
+++ b/libc/src/time/timer_create.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Implementation header for timer_create function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_TIME_TIMER_CREATE_H
+#define LLVM_LIBC_SRC_TIME_TIMER_CREATE_H
+
+#include "hdr/types/clockid_t.h"
+#include "hdr/types/struct_sigevent.h"
+#include "hdr/types/timer_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int timer_create(clockid_t clockid, sigevent *__restrict sevp,
+                 timer_t *__restrict timerid);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_TIMER_CREATE_H
diff --git a/libc/src/time/timer_delete.h b/libc/src/time/timer_delete.h
new file mode 100644
index 0000000000000..cc326b1a16e2a
--- /dev/null
+++ b/libc/src/time/timer_delete.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Implementation header for timer_delete function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_TIME_TIMER_DELETE_H
+#define LLVM_LIBC_SRC_TIME_TIMER_DELETE_H
+
+#include "hdr/types/timer_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int timer_delete(timer_t timerid);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_TIMER_DELETE_H
diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index 58f19ebf0d060..a2247ed4cd679 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -143,6 +143,26 @@ add_libc_test(
     libc.test.UnitTest.ErrnoCheckingTest
 )
 
+add_libc_test(
+  timer_test
+  SUITE
+    libc_time_unittests
+  SRCS
+    timer_test.cpp
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.signal_macros
+    libc.hdr.time_macros
+    libc.hdr.types.clockid_t
+    libc.hdr.types.struct_sigevent
+    libc.hdr.types.timer_t
+    libc.src.__support.OSUtil.osutil
+    libc.src.time.timer_create
+    libc.src.time.timer_delete
+    libc.test.UnitTest.ErrnoCheckingTest
+    libc.test.UnitTest.ErrnoSetterMatcher
+)
+
 add_libc_test(
   difftime_test
   SUITE
diff --git a/libc/test/src/time/timer_test.cpp b/libc/test/src/time/timer_test.cpp
new file mode 100644
index 0000000000000..3d9d02f6c84eb
--- /dev/null
+++ b/libc/test/src/time/timer_test.cpp
@@ -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);
+  timer_t timerid;
+  ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_REALTIME, &se, &timerid),
+              Succeeds(0));
+  ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
+}
+#endif
+
+TEST_F(LlvmLibcTimerTest, InvalidClockId) {
+  timer_t timerid;
+  ASSERT_THAT(LIBC_NAMESPACE::timer_create(static_cast<clockid_t>(-1), nullptr,
+                                           &timerid),
+              Fails(EINVAL));
+}
+
+TEST_F(LlvmLibcTimerTest, NullTimerId) {
+  ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_REALTIME, nullptr, nullptr),
+              Fails(any_of(EINVAL, EFAULT)));
+}
+
+TEST_F(LlvmLibcTimerTest, DeleteInvalidTimerId) {
+  ASSERT_THAT(LIBC_NAMESPACE::timer_delete(reinterpret_cast<timer_t>(-1)),
+              Fails(EINVAL));
+}
+
+TEST_F(LlvmLibcTimerTest, CreateAndDelete) {
+  timer_t timerid;
+  ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_REALTIME, nullptr, &timerid),
+              Succeeds(0));
+  ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
+  ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Fails(EINVAL));
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/217920


More information about the libc-commits mailing list