[RFC 3/4] Add test for --decode-fds=eventfd
Dmitry V. Levin
ldv at strace.io
Mon Apr 29 11:11:06 UTC 2024
On Mon, Apr 29, 2024 at 09:01:46AM +0530, Sahil Siddiq wrote:
> Add test for --decode-fds=eventfd.
>
> * tests/.gitignore: Add eventfd-yy.
> * tests/Makefile.am: Add eventfd-yy.
> * tests/eventfd-yy.c: New file.
> * tests/gen_tests.in: Add rule to generate test.
>
> Signed-off-by: Sahil Siddiq <icegambit91 at gmail.com>
> ---
> tests/.gitignore | 1 +
> tests/Makefile.am | 1 +
> tests/eventfd-yy.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
> tests/gen_tests.in | 1 +
> 4 files changed, 59 insertions(+)
> create mode 100644 tests/eventfd-yy.c
>
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 26274e727..8252d4d4f 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -129,6 +129,7 @@ epoll_pwait2-y
> epoll_wait
> erestartsys
> eventfd
> +eventfd-yy
> execve
> execve-v
> execveat
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index ef6889862..64f32edd7 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -142,6 +142,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
> count-f \
> delay \
> detach-vfork \
> + eventfd-yy \
> execve-v \
> execveat-v \
> fcntl--pidns-translation \
> diff --git a/tests/eventfd-yy.c b/tests/eventfd-yy.c
> new file mode 100644
> index 000000000..37cf60e84
> --- /dev/null
> +++ b/tests/eventfd-yy.c
> @@ -0,0 +1,56 @@
> +/*
> + * Test --decode-fds=eventfd option.
> + *
> + * Copyright (c) 2024 The strace developers.
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#include "tests.h"
> +
> +#include <inttypes.h>
> +#include <poll.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <sys/eventfd.h>
> +
> +#define SKIP_IF_PROC_IS_UNAVAILABLE skip_if_unavailable("/proc/self/fd/")
> +
> +int
> +main(void)
> +{
> + SKIP_IF_PROC_IS_UNAVAILABLE;
> +
> + uint64_t u = 5;
> + uint64_t efd_counter = u;
> +
> + int efd = eventfd((unsigned int)u, 0);
> + if (efd == -1)
> + perror_msg_and_fail("eventfd");
> +
> + printf("eventfd2(5, 0) = %d<eventfd-count:%"PRIu64">\n", efd, efd_counter);
> +
> + efd_counter += u;
> + if (write(efd, &u, sizeof(uint64_t)) == -1)
> + perror_msg_and_fail("write");
> +
> + int efd2 = dup(efd);
> + printf("dup(%d<eventfd-count:%"PRIu64">) = %d<eventfd-count:%"PRIu64">\n",
> + efd, efd_counter, efd2, efd_counter);
> +
> + struct pollfd fds[1];
> + fds[0].fd = efd2;
> + fds[0].events = POLLIN;
> +
> + int ret = poll(fds, 1, -1);
> + if (ret == -1)
> + perror_msg_and_fail("eventfd");
> +
> + printf("poll([{fd=%d<eventfd-count:%"PRIu64">, events=POLLIN}], 1, -1) = %d ([{fd=%d, revents=POLLIN}])\n",
> + efd2, efd_counter, ret, efd2);
The use of poll is problematic as this system call is not implemented on
recently introduced architectures.
--
ldv
More information about the Strace-devel
mailing list