[RFC 3/4] Add test for --decode-fds=eventfd
Sahil Siddiq
icegambit91 at gmail.com
Mon Apr 29 03:31:46 UTC 2024
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);
+
+ close(efd);
+ close(efd2);
+ return 0;
+}
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index e0e079727..2769738aa 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -113,6 +113,7 @@ epoll_pwait2-P --trace=epoll_pwait2 -P /dev/full
epoll_pwait2-y --trace=epoll_pwait2 -y
epoll_wait -a26
erestartsys -a34 -e signal=none -e trace=recvfrom
+eventfd-yy -a10 --trace=dup,eventfd2,poll -yy -qq
execve--secontext +execve.test --secontext
execve--secontext_full +execve.test --secontext=full
execve--secontext_full_mismatch +execve.test --secontext=full,mismatch
--
2.44.0
More information about the Strace-devel
mailing list