[libc-commits] [libc] [libc] Use the gettid syscall wrapper in tests (PR #244825)
via libc-commits
libc-commits at lists.llvm.org
Fri Nov 20 22:14:45 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Connector Switch (c8ef)
<details>
<summary>Changes</summary>
This PR move gettid calls in libc tests behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
Full diff: https://github.com/llvm/llvm-project/pull/244825.diff
9 Files Affected:
- (modified) libc/test/integration/src/pthread/CMakeLists.txt (+1)
- (modified) libc/test/integration/src/pthread/pthread_rwlock_test.cpp (+2-1)
- (modified) libc/test/integration/src/unistd/CMakeLists.txt (+1-2)
- (modified) libc/test/integration/src/unistd/fork_test.cpp (+2-4)
- (modified) libc/test/src/sched/CMakeLists.txt (+2-4)
- (modified) libc/test/src/sched/affinity_test.cpp (+3-4)
- (modified) libc/test/src/sched/cpu_count_test.cpp (+2-2)
- (modified) libc/test/src/sched/linux/CMakeLists.txt (+1-2)
- (modified) libc/test/src/sched/linux/clone_test.cpp (+2-4)
``````````diff
diff --git a/libc/test/integration/src/pthread/CMakeLists.txt b/libc/test/integration/src/pthread/CMakeLists.txt
index 729a2f8769bb5f..d566d0fc39a3a2 100644
--- a/libc/test/integration/src/pthread/CMakeLists.txt
+++ b/libc/test/integration/src/pthread/CMakeLists.txt
@@ -82,6 +82,7 @@ add_integration_test(
libc.src.stdlib.exit
libc.src.__support.CPP.atomic
libc.src.__support.CPP.new
+ libc.src.__support.OSUtil.linux.syscall_wrappers.gettid
libc.src.__support.threads.sleep
)
diff --git a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
index 1cc85caa89aa56..63bd92bdd1716b 100644
--- a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
@@ -11,6 +11,7 @@
#include "hdr/time_macros.h"
#include "src/__support/CPP/atomic.h"
#include "src/__support/CPP/new.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/gettid.h"
#include "src/__support/OSUtil/syscall.h"
#include "src/__support/macros/config.h"
#include "src/__support/threads/raw_mutex.h"
@@ -327,7 +328,7 @@ struct ThreadGuard {
if (!LIBC_NAMESPACE::getenv("LIBC_PTHREAD_RWLOCK_TEST_VERBOSE"))
return;
pid_t pid = static_cast<pid_t>(LIBC_NAMESPACE::syscall_impl(SYS_getpid));
- pid_t tid = static_cast<pid_t>(LIBC_NAMESPACE::syscall_impl(SYS_gettid));
+ pid_t tid = LIBC_NAMESPACE::linux_syscalls::gettid();
io_mutex->lock(LIBC_NAMESPACE::cpp::nullopt, true);
LIBC_NAMESPACE::printf("process %d thread %d: ", pid, tid);
for (size_t i = 0; i < cursor; ++i)
diff --git a/libc/test/integration/src/unistd/CMakeLists.txt b/libc/test/integration/src/unistd/CMakeLists.txt
index 72d718e118a3ed..d0b4525ab65c85 100644
--- a/libc/test/integration/src/unistd/CMakeLists.txt
+++ b/libc/test/integration/src/unistd/CMakeLists.txt
@@ -24,6 +24,7 @@ add_integration_test(
libc.include.signal
libc.include.sys_wait
libc.include.unistd
+ libc.src.__support.OSUtil.linux.syscall_wrappers.gettid
libc.src.pthread.pthread_atfork
libc.src.signal.raise
libc.src.sys.wait.wait
@@ -32,9 +33,7 @@ add_integration_test(
libc.src.sys.wait.waitpid
libc.src.unistd.fork
libc.src.unistd.gettid
- libc.src.__support.OSUtil.osutil
libc.src.stdlib.exit
- libc.include.sys_syscall
)
add_integration_test(
diff --git a/libc/test/integration/src/unistd/fork_test.cpp b/libc/test/integration/src/unistd/fork_test.cpp
index 74d480437ac82e..77dd2f46b2fe73 100644
--- a/libc/test/integration/src/unistd/fork_test.cpp
+++ b/libc/test/integration/src/unistd/fork_test.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/gettid.h"
#include "src/pthread/pthread_atfork.h"
#include "src/signal/raise.h"
#include "src/stdlib/exit.h"
@@ -20,7 +20,6 @@
#include "test/IntegrationTest/test.h"
#include <signal.h>
-#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -179,8 +178,7 @@ void fork_with_atfork_callbacks() {
void gettid_test() {
// fork and verify tid is consistent with the syscall result.
int pid = LIBC_NAMESPACE::fork();
- ASSERT_EQ(LIBC_NAMESPACE::gettid(),
- LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid));
+ ASSERT_EQ(LIBC_NAMESPACE::gettid(), LIBC_NAMESPACE::linux_syscalls::gettid());
if (pid == 0)
LIBC_NAMESPACE::exit(0);
// make sure child process exits normally
diff --git a/libc/test/src/sched/CMakeLists.txt b/libc/test/src/sched/CMakeLists.txt
index 9ded3416cbc1e5..c8f0d45ed11abf 100644
--- a/libc/test/src/sched/CMakeLists.txt
+++ b/libc/test/src/sched/CMakeLists.txt
@@ -13,8 +13,7 @@ add_libc_test(
DEPENDS
libc.hdr.types.cpu_set_t
libc.hdr.types.pid_t
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.gettid
libc.src.sched.sched_getaffinity
libc.src.sched.sched_setaffinity
libc.test.UnitTest.ErrnoCheckingTest
@@ -143,8 +142,7 @@ add_libc_test(
libc.hdr.sched_macros
libc.hdr.types.cpu_set_t
libc.hdr.types.pid_t
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.gettid
libc.src.sched.sched_getaffinity
libc.src.sched.__sched_clrcpuset
libc.src.sched.__sched_getcpucount
diff --git a/libc/test/src/sched/affinity_test.cpp b/libc/test/src/sched/affinity_test.cpp
index 51159bae7907c2..a9d473bf56add2 100644
--- a/libc/test/src/sched/affinity_test.cpp
+++ b/libc/test/src/sched/affinity_test.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/gettid.h"
#include "src/sched/sched_getaffinity.h"
#include "src/sched/sched_setaffinity.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
@@ -14,14 +14,13 @@
#include "hdr/types/cpu_set_t.h"
#include "hdr/types/pid_t.h"
-#include <sys/syscall.h>
using LlvmLibcSchedAffinityTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
TEST_F(LlvmLibcSchedAffinityTest, SmokeTest) {
cpu_set_t mask;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
- pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
+ pid_t tid = LIBC_NAMESPACE::linux_syscalls::gettid();
ASSERT_GT(tid, pid_t(0));
// We just get and set the same mask.
ASSERT_THAT(LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), &mask),
@@ -32,7 +31,7 @@ TEST_F(LlvmLibcSchedAffinityTest, SmokeTest) {
TEST_F(LlvmLibcSchedAffinityTest, BadMask) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
- pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
+ pid_t tid = LIBC_NAMESPACE::linux_syscalls::gettid();
ASSERT_THAT(
LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr),
diff --git a/libc/test/src/sched/cpu_count_test.cpp b/libc/test/src/sched/cpu_count_test.cpp
index e3399b0de76022..e99a2887b0897c 100644
--- a/libc/test/src/sched/cpu_count_test.cpp
+++ b/libc/test/src/sched/cpu_count_test.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/gettid.h"
#include "src/sched/sched_clrcpuset.h"
#include "src/sched/sched_getaffinity.h"
#include "src/sched/sched_getcpucount.h"
@@ -25,7 +25,7 @@ using LlvmLibcSchedCpuCountTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
TEST_F(LlvmLibcSchedCpuCountTest, SmokeTest) {
cpu_set_t mask;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
- pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
+ pid_t tid = LIBC_NAMESPACE::linux_syscalls::gettid();
ASSERT_GT(tid, pid_t(0));
ASSERT_THAT(LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), &mask),
Succeeds(0));
diff --git a/libc/test/src/sched/linux/CMakeLists.txt b/libc/test/src/sched/linux/CMakeLists.txt
index 2cce58f654b03c..3da5f515e4a920 100644
--- a/libc/test/src/sched/linux/CMakeLists.txt
+++ b/libc/test/src/sched/linux/CMakeLists.txt
@@ -12,8 +12,7 @@ add_libc_test(
libc.hdr.sys_wait_macros
libc.hdr.types.pid_t
libc.hdr.types.size_t
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.gettid
libc.src.sched.clone
libc.src.sys.wait.waitpid
libc.src.unistd.gettid
diff --git a/libc/test/src/sched/linux/clone_test.cpp b/libc/test/src/sched/linux/clone_test.cpp
index 9201ed641e9293..49aa96bfe797c8 100644
--- a/libc/test/src/sched/linux/clone_test.cpp
+++ b/libc/test/src/sched/linux/clone_test.cpp
@@ -18,7 +18,7 @@
#include "hdr/sys_wait_macros.h"
#include "hdr/types/pid_t.h"
#include "hdr/types/size_t.h"
-#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/gettid.h"
#include "src/sched/clone.h"
#include "src/sys/wait/waitpid.h"
#include "src/unistd/gettid.h"
@@ -26,8 +26,6 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <sys/syscall.h>
-
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
using LlvmLibcSchedCloneTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
@@ -52,7 +50,7 @@ struct TidArgs {
static int check_tid_child(void *arg) {
auto *args = reinterpret_cast<TidArgs *>(arg);
pid_t cached = LIBC_NAMESPACE::gettid();
- pid_t sys = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
+ pid_t sys = LIBC_NAMESPACE::linux_syscalls::gettid();
if (args) {
args->cached_tid = cached;
args->sys_tid = sys;
``````````
</details>
https://github.com/llvm/llvm-project/pull/244825
More information about the libc-commits
mailing list