[libc-commits] [libc] [libc] Add sys/eventfd.h header and eventfd function. (PR #234028)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Wed Oct 21 02:53:00 PDT 2026
================
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Unit tests for eventfd.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/stdint_proxy.h"
+#include "hdr/sys_eventfd_macros.h"
+#include "src/sys/eventfd/eventfd.h"
+#include "src/unistd/close.h"
+#include "src/unistd/read.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcEventfdTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcEventfdTest, ZeroFlags) {
+ int fd;
+ ASSERT_THAT(fd = LIBC_NAMESPACE::eventfd(42, 0),
+ returns(GE(0)).with_errno(EQ(0)));
+ uint64_t val = 0;
+ ASSERT_THAT(LIBC_NAMESPACE::read(fd, &val, sizeof(val)),
+ Succeeds<ssize_t>(sizeof(val)));
+ EXPECT_EQ(val, static_cast<uint64_t>(42));
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
+}
+
+TEST_F(LlvmLibcEventfdTest, EfdSemaphore) {
+ int fd;
+ ASSERT_THAT(fd = LIBC_NAMESPACE::eventfd(42, EFD_CLOEXEC | EFD_NONBLOCK |
----------------
labath wrote:
I think it'd be worth checking that the resulting FD actually has the CLOEXEC and NONBLOCK flags set.
https://github.com/llvm/llvm-project/pull/234028
More information about the libc-commits
mailing list