From 119b6a1a1d94f52873e9b830ffb24cd003e4612d Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 17 Jan 2018 21:31:07 +0000
Subject: [PATCH] tests: check path tracing of ppoll syscall

* tests/ppoll.c (main) [PATH_TRACING_FD]: Skip if /proc/self/fd/
is not available.  Add a test call that use PATH_TRACING_FD.
(main): Conditionalize expected output for those calls
that do not use PATH_TRACING_FD with [!PATH_TRACING_FD].
* tests/ppoll-P.c: New file.
* tests/pure_executables.list: Add ppoll-P.
* tests/.gitignore: Likewise.
* tests/gen_tests.in (ppoll-P): New entry.
---
 tests/.gitignore            |  1 +
 tests/gen_tests.in          |  1 +
 tests/ppoll-P.c             |  2 ++
 tests/ppoll.c               | 60 +++++++++++++++++++++++++++++++++----
 tests/pure_executables.list |  1 +
 5 files changed, 59 insertions(+), 6 deletions(-)
 create mode 100644 tests/ppoll-P.c

diff --git a/tests/.gitignore b/tests/.gitignore
index c4f3c5ad..4c545890 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -290,6 +290,7 @@ pkey_mprotect
 poll
 poll-P
 ppoll
+ppoll-P
 ppoll-v
 prctl-arg2-intptr
 prctl-dumpable
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 1e2453a2..93b16871 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -257,6 +257,7 @@ pkey_alloc	-a17
 pkey_free	-a13
 pkey_mprotect	-a37
 ppoll	-s2
+ppoll-P	-s2 -e trace=ppoll -P /dev/full 9>>/dev/full
 ppoll-v	-v -s2 -e trace=ppoll
 pread64-pwrite64	-a21 -eread=0 -ewrite=1 -e trace=pread64,pwrite64 -P pread64-pwrite64-tmpfile -P /dev/zero -P /dev/null
 preadv	-a21
diff --git a/tests/ppoll-P.c b/tests/ppoll-P.c
new file mode 100644
index 00000000..c2c572e2
--- /dev/null
+++ b/tests/ppoll-P.c
@@ -0,0 +1,2 @@
+#define PATH_TRACING_FD 9
+#include "ppoll.c"
diff --git a/tests/ppoll.c b/tests/ppoll.c
index 62241839..b33f9593 100644
--- a/tests/ppoll.c
+++ b/tests/ppoll.c
@@ -1,7 +1,7 @@
 /*
  * Check decoding of ppoll syscall.
  *
- * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,10 @@ sys_ppoll(const kernel_ulong_t ufds,
 int
 main(void)
 {
+# ifdef PATH_TRACING_FD
+	skip_if_unavailable("/proc/self/fd/");
+# endif
+
 	static const kernel_ulong_t bogus_nfds =
 		(kernel_ulong_t) 0xdeadbeeffacefeedULL;
 	static const kernel_ulong_t bogus_sigsetsize =
@@ -76,28 +80,36 @@ main(void)
 	sys_ppoll(0, bogus_nfds, 0, 0, bogus_sigsetsize);
 	if (ENOSYS == errno)
 		perror_msg_and_skip("ppoll");
+# ifndef PATH_TRACING_FD
 	printf("ppoll(NULL, %u, NULL, NULL, %llu) = %s\n",
 	       (unsigned) bogus_nfds, (unsigned long long) bogus_sigsetsize,
 	       errstr);
+# endif
 
 	sys_ppoll((unsigned long) efault, 42, (unsigned long) efault + 8,
 		  (unsigned long) efault + 16, sigset_size);
+# ifndef PATH_TRACING_FD
 	printf("ppoll(%p, %u, %p, %p, %u) = %s\n",
 	       efault, 42, efault + 8, efault + 16, sigset_size, errstr);
+# endif
 
 	ts->tv_sec = 0xdeadbeefU;
 	ts->tv_nsec = 0xfacefeedU;
 	sys_ppoll(0, 0, (unsigned long) ts, 0, sigset_size);
+# ifndef PATH_TRACING_FD
 	printf("ppoll(NULL, 0, {tv_sec=%lld, tv_nsec=%llu}, NULL, %u) = %s\n",
 	       (long long) ts->tv_sec, zero_extend_signed_to_ull(ts->tv_nsec),
 	       sigset_size, errstr);
+# endif
 
 	ts->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
 	ts->tv_nsec = (long) 0xbadc0dedfacefeedL;
 	sys_ppoll(0, 0, (unsigned long) ts, 0, sigset_size);
+# ifndef PATH_TRACING_FD
 	printf("ppoll(NULL, 0, {tv_sec=%lld, tv_nsec=%llu}, NULL, %u) = %s\n",
 	       (long long) ts->tv_sec, zero_extend_signed_to_ull(ts->tv_nsec),
 	       sigset_size, errstr);
+# endif
 
 	if (pipe(pipe_fd) || pipe(pipe_fd + 2))
 		perror_msg_and_fail("pipe");
@@ -124,24 +136,56 @@ main(void)
 		       (unsigned long) sigmask, sigset_size);
 	if (rc != 2)
 		perror_msg_and_fail("ppoll 1");
+# ifndef PATH_TRACING_FD
 	printf("ppoll([{fd=%d, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}"
 	       ", {fd=%d, events=POLLOUT%s|POLLWRBAND}"
-#if VERBOSE
+#  if VERBOSE
 	       ", {fd=%d, events=POLLIN|POLLPRI}, {fd=%d, events=POLLOUT}]"
-#else
+#  else
 	       ", ...]"
-#endif
+#  endif
 	       ", %u, {tv_sec=42, tv_nsec=999999999}, [%s], %u) = %ld"
 	       " ([{fd=%d, revents=POLLOUT%s}, {fd=%d, revents=POLLOUT}]"
 	       ", left {tv_sec=%u, tv_nsec=%u})\n",
 	       pipe_fd[0], pipe_fd[1], POLLWRNORM_str,
-#if VERBOSE
+#  if VERBOSE
 	       pipe_fd[2], pipe_fd[3],
-#endif
+#  endif
 	       (unsigned int) ARRAY_SIZE(fds1), USR2_CHLD_str,
 	       (unsigned int) sigset_size, rc, pipe_fd[1], POLLWRNORM_str,
 	       pipe_fd[3], (unsigned int) ts->tv_sec,
 	       (unsigned int) ts->tv_nsec);
+# endif /* !PATH_TRACING_FD */
+
+# ifdef PATH_TRACING_FD
+	ts->tv_sec = 123;
+	ts->tv_nsec = 987654321;
+	fds[3].fd = PATH_TRACING_FD;
+
+	rc = sys_ppoll((unsigned long) fds,
+		       F8ILL_KULONG_MASK | ARRAY_SIZE(fds1), (unsigned long) ts,
+		       (unsigned long) sigmask, sigset_size);
+	if (rc != 2)
+		perror_msg_and_fail("ppoll -P");
+	printf("ppoll([{fd=%d, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}"
+	       ", {fd=%d, events=POLLOUT%s|POLLWRBAND}"
+#  if VERBOSE
+	       ", {fd=%d, events=POLLIN|POLLPRI}, {fd=%d, events=POLLOUT}]"
+#  else
+	       ", ...]"
+#  endif
+	       ", %u, {tv_sec=123, tv_nsec=987654321}, [%s], %u) = %ld"
+	       " ([{fd=%d, revents=POLLOUT%s}, {fd=%d, revents=POLLOUT}]"
+	       ", left {tv_sec=%u, tv_nsec=%u})\n",
+	       pipe_fd[0], pipe_fd[1], POLLWRNORM_str,
+#  if VERBOSE
+	       pipe_fd[2], PATH_TRACING_FD,
+#  endif
+	       (unsigned int) ARRAY_SIZE(fds1), USR2_CHLD_str,
+	       (unsigned int) sigset_size, rc, pipe_fd[1], POLLWRNORM_str,
+	       PATH_TRACING_FD, (unsigned int) ts->tv_sec,
+	       (unsigned int) ts->tv_nsec);
+# endif /* PATH_TRACING_FD */
 
 	ts->tv_sec = 0;
 	ts->tv_nsec = 999;
@@ -163,23 +207,27 @@ main(void)
 		       (unsigned long) sigmask, sigset_size);
 	if (rc != 0)
 		perror_msg_and_fail("ppoll 2");
+# ifndef PATH_TRACING_FD
 	printf("ppoll([{fd=%d, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}"
 	       ", {fd=%d, events=POLLOUT%s|POLLWRBAND}], %u"
 	       ", {tv_sec=0, tv_nsec=999}, ~[HUP KILL STOP], %u)"
 	       " = %ld (Timeout)\n",
 	       pipe_fd[1], pipe_fd[0], POLLWRNORM_str,
 	       (unsigned) ARRAY_SIZE(fds2), sigset_size, rc);
+# endif /* !PATH_TRACING_FD */
 
 	if (F8ILL_KULONG_SUPPORTED) {
 		sys_ppoll(f8ill_ptr_to_kulong(fds), ARRAY_SIZE(fds2),
 			  f8ill_ptr_to_kulong(ts), f8ill_ptr_to_kulong(sigmask),
 			  sigset_size);
+# ifndef PATH_TRACING_FD
 		printf("ppoll(%#llx, %u, %#llx, %#llx, %u) = %s\n",
 		       (unsigned long long) f8ill_ptr_to_kulong(fds),
 		       (unsigned) ARRAY_SIZE(fds2),
 		       (unsigned long long) f8ill_ptr_to_kulong(ts),
 		       (unsigned long long) f8ill_ptr_to_kulong(sigmask),
 		       (unsigned) sigset_size, errstr);
+# endif /* !PATH_TRACING_FD */
 	}
 
 	puts("+++ exited with 0 +++");
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index 126545b1..8f5ff311 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -244,6 +244,7 @@ pkey_mprotect
 poll
 poll-P
 ppoll
+ppoll-P
 prctl-arg2-intptr
 prctl-dumpable
 prctl-name