[libc-commits] [libc] [libc] Implement ppoll in poll (PR #225767)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Thu Sep 24 02:13:10 PDT 2026
================
@@ -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
+/// Unittests for ppoll.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/limits_macros.h"
+#include "hdr/poll_macros.h"
+#include "hdr/types/sigset_t.h"
+#include "hdr/types/struct_pollfd.h"
+#include "hdr/types/struct_timespec.h"
+#include "src/__support/CPP/scope.h"
+#include "src/poll/ppoll.h"
+#include "src/unistd/close.h"
+#include "src/unistd/pipe.h"
+#include "src/unistd/read.h"
+#include "src/unistd/write.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/Test.h"
+
+using LlvmLibcPPollTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcPPollTest, SmokeTest) {
+ timespec ts{0, 0};
+ int ret = LIBC_NAMESPACE::ppoll(nullptr, 0, &ts, nullptr);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_EQ(0, ret);
+}
+
+TEST_F(LlvmLibcPPollTest, SmokeFailureTest) {
+ int ret = LIBC_NAMESPACE::ppoll(nullptr, UINT_MAX, nullptr, nullptr);
+ ASSERT_ERRNO_EQ(EINVAL);
+ ASSERT_EQ(-1, ret);
+}
+
+TEST_F(LlvmLibcPPollTest, TimeoutNotMutated) {
+ const timespec orig_ts{0, 0};
----------------
labath wrote:
This test is weak because there's no reason why the syscall would mutate the argument. The interesting case is where the function returns *before* the timeout expires. Probably the easiest way to set that up is via signals. Sleep 1s but arrange to get a signal after 100ms (setitimer). Then make sure the value still says 1s.
And I think that will show you do need to make a copy of the value somewhere, as the manpage says:
> C library/kernel differences: The Linux ppoll() system call modifies its tmo_p argument.
It's an interesting question whether to do the copy on the entry point or the syscall wrapper level. I'd probably go with entry point as the wrappers are supposed to be thin, and the linux behavior can be potentially useful. Either way, make sure to document the behavior of the wrapper.
https://github.com/llvm/llvm-project/pull/225767
More information about the libc-commits
mailing list