[libc-commits] [libc] 5e56808 - [libc][time] Implement timer_create and timer_delete. (#217920)
via libc-commits
libc-commits at lists.llvm.org
Fri Aug 21 22:20:06 PDT 2026
Author: lntue
Date: 2026-08-22T01:20:01-04:00
New Revision: 5e56808c2dcafd80270831a0d7d4f9f40dac1f1a
URL: https://github.com/llvm/llvm-project/commit/5e56808c2dcafd80270831a0d7d4f9f40dac1f1a
DIFF: https://github.com/llvm/llvm-project/commit/5e56808c2dcafd80270831a0d7d4f9f40dac1f1a.diff
LOG: [libc][time] Implement timer_create and timer_delete. (#217920)
Implement timer_create and timer_delete functions according to
POSIX.1-2024.
Assisted-by: Gemini
Added:
libc/src/__support/OSUtil/linux/syscall_wrappers/timer_create.h
libc/src/__support/OSUtil/linux/syscall_wrappers/timer_delete.h
libc/src/time/linux/timer_create.cpp
libc/src/time/linux/timer_delete.cpp
libc/src/time/timer_create.h
libc/src/time/timer_delete.h
libc/test/src/time/timer_test.cpp
Modified:
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/riscv/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/include/time.yaml
libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
libc/src/time/CMakeLists.txt
libc/src/time/linux/CMakeLists.txt
libc/test/src/time/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 0fc7e59f466e4..dd20e979745c0 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1334,6 +1334,8 @@ 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 938b2cfd557c6..52f30060acea1 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1530,6 +1530,8 @@ 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 b4066db3e5827..e78b4d47edd9f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1543,6 +1543,8 @@ 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 6a306766658b3..e01f2a5789e37 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1006,3 +1006,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..25abfffe7ac3b
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_create.h
@@ -0,0 +1,91 @@
+//===----------------------------------------------------------------------===//
+//
+// 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;
+ // Linux kernel treats SIGEV_THREAD_ID as a bitwise mask, while the
+ // remaining POSIX values as distinct enums:
+ // https://github.com/torvalds/linux/blob/master/kernel/time/posix-timers.c#L405
+ // https://github.com/torvalds/linux/blob/master/kernel/time/posix-timers.c#L525
+ 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..cf4c18e8d9d37 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.time.timer_create
+ libc.src.time.timer_delete
+ libc.src.unistd.gettid
+ libc.test.UnitTest.ErrnoCheckingTest
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
+
add_libc_test(
diff time_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..e9b20d9615314
--- /dev/null
+++ b/libc/test/src/time/timer_test.cpp
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/time/timer_create.h"
+#include "src/time/timer_delete.h"
+#include "src/unistd/gettid.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.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));
+}
+
+#ifdef 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::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));
+}
More information about the libc-commits
mailing list