Skip to content

Commit 59a42b0

Browse files
committed
selftests/pidfd: add pidfs file handle selftests
Add selftests for pidfs file handles. Link: https://lore.kernel.org/r/20241202-imstande-einsicht-d78753e1c632@brauner Reviewed-by: Amir Goldstein <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 8ce3528 commit 59a42b0

File tree

6 files changed

+567
-73
lines changed

6 files changed

+567
-73
lines changed

tools/testing/selftests/pidfd/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pidfd_wait
66
pidfd_fdinfo_test
77
pidfd_getfd_test
88
pidfd_setns_test
9+
pidfd_file_handle_test

tools/testing/selftests/pidfd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
CFLAGS += -g $(KHDR_INCLUDES) -pthread -Wall
33

44
TEST_GEN_PROGS := pidfd_test pidfd_fdinfo_test pidfd_open_test \
5-
pidfd_poll_test pidfd_wait pidfd_getfd_test pidfd_setns_test
5+
pidfd_poll_test pidfd_wait pidfd_getfd_test pidfd_setns_test \
6+
pidfd_file_handle_test
67

78
include ../lib.mk
89

tools/testing/selftests/pidfd/pidfd.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <sys/wait.h>
1818

1919
#include "../kselftest.h"
20+
#include "../clone3/clone3_selftests.h"
2021

2122
#ifndef P_PIDFD
2223
#define P_PIDFD 3
@@ -68,6 +69,11 @@
6869
#define PIDFD_SKIP 3
6970
#define PIDFD_XFAIL 4
7071

72+
static inline int sys_waitid(int which, pid_t pid, siginfo_t *info, int options)
73+
{
74+
return syscall(__NR_waitid, which, pid, info, options, NULL);
75+
}
76+
7177
static inline int wait_for_pid(pid_t pid)
7278
{
7379
int status, ret;
@@ -114,4 +120,37 @@ static inline int sys_memfd_create(const char *name, unsigned int flags)
114120
return syscall(__NR_memfd_create, name, flags);
115121
}
116122

123+
static inline pid_t create_child(int *pidfd, unsigned flags)
124+
{
125+
struct __clone_args args = {
126+
.flags = CLONE_PIDFD | flags,
127+
.exit_signal = SIGCHLD,
128+
.pidfd = ptr_to_u64(pidfd),
129+
};
130+
131+
return sys_clone3(&args, sizeof(struct __clone_args));
132+
}
133+
134+
static inline ssize_t read_nointr(int fd, void *buf, size_t count)
135+
{
136+
ssize_t ret;
137+
138+
do {
139+
ret = read(fd, buf, count);
140+
} while (ret < 0 && errno == EINTR);
141+
142+
return ret;
143+
}
144+
145+
static inline ssize_t write_nointr(int fd, const void *buf, size_t count)
146+
{
147+
ssize_t ret;
148+
149+
do {
150+
ret = write(fd, buf, count);
151+
} while (ret < 0 && errno == EINTR);
152+
153+
return ret;
154+
}
155+
117156
#endif /* __PIDFD_H */

0 commit comments

Comments
 (0)