On Tue 24-06-25 10:29:14, Christian Brauner wrote: > Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx> Looks good. Feel free to add: Reviewed-by: Jan Kara <jack@xxxxxxx> Honza > --- > tools/testing/selftests/pidfd/Makefile | 2 +- > tools/testing/selftests/pidfd/pidfd.h | 4 ++ > .../selftests/pidfd/pidfd_file_handle_test.c | 60 ++++++++++++++++++++++ > 3 files changed, 65 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/pidfd/Makefile b/tools/testing/selftests/pidfd/Makefile > index 03a6eede9c9e..764a8f9ecefa 100644 > --- a/tools/testing/selftests/pidfd/Makefile > +++ b/tools/testing/selftests/pidfd/Makefile > @@ -1,5 +1,5 @@ > # SPDX-License-Identifier: GPL-2.0-only > -CFLAGS += -g $(KHDR_INCLUDES) -pthread -Wall > +CFLAGS += -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) -pthread -Wall > > TEST_GEN_PROGS := pidfd_test pidfd_fdinfo_test pidfd_open_test \ > pidfd_poll_test pidfd_wait pidfd_getfd_test pidfd_setns_test \ > diff --git a/tools/testing/selftests/pidfd/pidfd.h b/tools/testing/selftests/pidfd/pidfd.h > index 5dfeb1bdf399..b427a2636402 100644 > --- a/tools/testing/selftests/pidfd/pidfd.h > +++ b/tools/testing/selftests/pidfd/pidfd.h > @@ -19,6 +19,10 @@ > #include "../kselftest.h" > #include "../clone3/clone3_selftests.h" > > +#ifndef FD_INVALID > +#define FD_INVALID -10009 /* Invalid file descriptor. */ > +#endif > + > #ifndef P_PIDFD > #define P_PIDFD 3 > #endif > diff --git a/tools/testing/selftests/pidfd/pidfd_file_handle_test.c b/tools/testing/selftests/pidfd/pidfd_file_handle_test.c > index 439b9c6c0457..ff1bf51bca5e 100644 > --- a/tools/testing/selftests/pidfd/pidfd_file_handle_test.c > +++ b/tools/testing/selftests/pidfd/pidfd_file_handle_test.c > @@ -500,4 +500,64 @@ TEST_F(file_handle, valid_name_to_handle_at_flags) > ASSERT_EQ(close(pidfd), 0); > } > > +/* > + * That we decode a file handle without having to pass a pidfd. > + */ > +TEST_F(file_handle, decode_purely_based_on_file_handle) > +{ > + int mnt_id; > + struct file_handle *fh; > + int pidfd = -EBADF; > + struct stat st1, st2; > + > + fh = malloc(sizeof(struct file_handle) + MAX_HANDLE_SZ); > + ASSERT_NE(fh, NULL); > + memset(fh, 0, sizeof(struct file_handle) + MAX_HANDLE_SZ); > + fh->handle_bytes = MAX_HANDLE_SZ; > + > + ASSERT_EQ(name_to_handle_at(self->child_pidfd1, "", fh, &mnt_id, AT_EMPTY_PATH), 0); > + > + ASSERT_EQ(fstat(self->child_pidfd1, &st1), 0); > + > + pidfd = open_by_handle_at(FD_INVALID, fh, 0); > + ASSERT_GE(pidfd, 0); > + > + ASSERT_EQ(fstat(pidfd, &st2), 0); > + ASSERT_TRUE(st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); > + > + ASSERT_EQ(close(pidfd), 0); > + > + pidfd = open_by_handle_at(FD_INVALID, fh, O_CLOEXEC); > + ASSERT_GE(pidfd, 0); > + > + ASSERT_EQ(fstat(pidfd, &st2), 0); > + ASSERT_TRUE(st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); > + > + ASSERT_EQ(close(pidfd), 0); > + > + pidfd = open_by_handle_at(FD_INVALID, fh, O_NONBLOCK); > + ASSERT_GE(pidfd, 0); > + > + ASSERT_EQ(fstat(pidfd, &st2), 0); > + ASSERT_TRUE(st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); > + > + ASSERT_EQ(close(pidfd), 0); > + > + pidfd = open_by_handle_at(self->pidfd, fh, 0); > + ASSERT_GE(pidfd, 0); > + > + ASSERT_EQ(fstat(pidfd, &st2), 0); > + ASSERT_TRUE(st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); > + > + ASSERT_EQ(close(pidfd), 0); > + > + pidfd = open_by_handle_at(-EBADF, fh, 0); > + ASSERT_LT(pidfd, 0); > + > + pidfd = open_by_handle_at(AT_FDCWD, fh, 0); > + ASSERT_LT(pidfd, 0); > + > + free(fh); > +} > + > TEST_HARNESS_MAIN > > -- > 2.47.2 > -- Jan Kara <jack@xxxxxxxx> SUSE Labs, CR