]> granicus.if.org Git - strace/commitdiff
tests: check path tracing of poll syscall
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 17 Jan 2018 21:31:07 +0000 (21:31 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 17 Jan 2018 21:31:07 +0000 (21:31 +0000)
* tests/poll.c (main) [PATH_TRACING_FD]: Skip if /proc/self/fd/
is not available.  Add tests calls that use PATH_TRACING_FD.
(main): Conditionalize expected output for those calls
that do not use PATH_TRACING_FD with [!PATH_TRACING_FD].
* tests/poll-P.c: New file.
* tests/pure_executables.list: Add poll-P.
* tests/.gitignore: Likewise.
* tests/poll-P.test: New test.
* tests/Makefile.am (DECODER_TESTS): Add poll-P.test.

tests/.gitignore
tests/Makefile.am
tests/poll-P.c [new file with mode: 0644]
tests/poll-P.test [new file with mode: 0755]
tests/poll.c
tests/pure_executables.list

index becb265aea63e0a2269c5caa8f876214391a0e28..c4f3c5ad633581e900c4e0f547fd6e4c254722b5 100644 (file)
@@ -288,6 +288,7 @@ pkey_alloc
 pkey_free
 pkey_mprotect
 poll
+poll-P
 ppoll
 ppoll-v
 prctl-arg2-intptr
index c1fd9cd9a9041b4d24298cc9160194478b39d830..fd5548b59f767c4b9425382ec481fb48358b1a3a 100644 (file)
@@ -237,6 +237,7 @@ DECODER_TESTS = \
        oldselect.test \
        personality.test \
        pipe.test \
+       poll-P.test \
        poll.test \
        prctl-arg2-intptr.test \
        prctl-dumpable.test \
diff --git a/tests/poll-P.c b/tests/poll-P.c
new file mode 100644 (file)
index 0000000..7bbeb79
--- /dev/null
@@ -0,0 +1,2 @@
+#define PATH_TRACING_FD 9
+#include "poll.c"
diff --git a/tests/poll-P.test b/tests/poll-P.test
new file mode 100755 (executable)
index 0000000..a190572
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Check path tracing of poll syscall.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+run_strace -a16 -vepoll -P /dev/full 9>>/dev/full \
+       $args > "$EXP"
+match_diff "$LOG" "$EXP"
+
+for abbrev in 0 1 2 3 4 5; do
+       run_prog "../$NAME" $abbrev > /dev/null
+       run_strace -a16 -epoll -s$abbrev -P /dev/full 9>>/dev/full \
+               $args > "$EXP"
+       match_diff "$LOG" "$EXP"
+done
index 2bf8c1a1a0e7b16fb9f8243925311f1746990dd9..c5930a3ea153b02f4c995ffe2f8dd40c5fb0029b 100644 (file)
@@ -1,8 +1,7 @@
 /*
- * This file is part of poll strace test.
+ * Check decoding of poll syscall.
  *
- * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
- * Copyright (c) 2016-2017 The strace developers.
+ * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,6 +37,7 @@
 # include <poll.h>
 # include <stdio.h>
 # include <stdlib.h>
+# include <string.h>
 # include <unistd.h>
 
 #define PRINT_EVENT(flag, member)                      \
@@ -163,12 +163,19 @@ print_pollfd_array_exiting(const struct pollfd *const pfd,
 int
 main(int ac, char **av)
 {
+# ifdef PATH_TRACING_FD
+       skip_if_unavailable("/proc/self/fd/");
+# endif
+
        tprintf("%s", "");
 
        assert(syscall(__NR_poll, NULL, 42, 0) == -1);
        if (ENOSYS == errno)
                perror_msg_and_skip("poll");
+
+# ifndef PATH_TRACING_FD
        tprintf("poll(NULL, 42, 0) = -1 EFAULT (%m)\n");
+# endif
 
        int fds[2];
        if (pipe(fds) || pipe(fds))
@@ -187,11 +194,14 @@ main(int ac, char **av)
        int rc = syscall(__NR_poll, tail_fds0, 0, timeout);
        assert(rc == 0);
 
+# ifndef PATH_TRACING_FD
        tprintf("poll([], 0, %d) = %d (Timeout)\n", timeout, rc);
+# endif
 
        rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
        assert(rc == 3);
 
+# ifndef PATH_TRACING_FD
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
                                    ARRAY_SIZE(pfds0), abbrev);
@@ -199,6 +209,7 @@ main(int ac, char **av)
                (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
        print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
        tprintf(")\n");
+# endif /* !PATH_TRACING_FD */
 
        tail_fds0[0].fd = -1;
        tail_fds0[2].fd = -3;
@@ -206,6 +217,7 @@ main(int ac, char **av)
        rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
        assert(rc == 2);
 
+# ifndef PATH_TRACING_FD
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
                                    ARRAY_SIZE(pfds0), abbrev);
@@ -213,12 +225,14 @@ main(int ac, char **av)
                (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
        print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
        tprintf(")\n");
+# endif /* !PATH_TRACING_FD */
 
        tail_fds0[1].fd = -2;
        tail_fds0[4].fd = -5;
        rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
        assert(rc == 1);
 
+# ifndef PATH_TRACING_FD
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
                                    ARRAY_SIZE(pfds0), abbrev);
@@ -226,6 +240,7 @@ main(int ac, char **av)
                (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
        print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
        tprintf(")\n");
+# endif /* !PATH_TRACING_FD */
 
        struct pollfd pfds1[] = {
                { .fd = 1, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND },
@@ -235,25 +250,58 @@ main(int ac, char **av)
        rc = syscall(__NR_poll, tail_fds1, ARRAY_SIZE(pfds1), timeout);
        assert(rc == 0);
 
+# ifndef PATH_TRACING_FD
        tprintf("poll(");
        print_pollfd_array_entering(tail_fds1, ARRAY_SIZE(pfds1),
                                    ARRAY_SIZE(pfds1), abbrev);
        tprintf(", %u, %d) = %d (Timeout)\n",
                (unsigned int) ARRAY_SIZE(pfds1), timeout, rc);
+# endif /* !PATH_TRACING_FD */
 
        const void *const efault = tail_fds0 + ARRAY_SIZE(pfds0);
        rc = syscall(__NR_poll, efault, 1, 0);
        assert(rc == -1);
+
+# ifndef PATH_TRACING_FD
        tprintf("poll(%p, 1, 0) = -1 EFAULT (%m)\n", efault);
+# endif
 
        const unsigned int valid = 1;
        const void *const epfds = tail_fds0 + ARRAY_SIZE(pfds0) - valid;
        rc = syscall(__NR_poll, epfds, valid + 1, 0);
        assert(rc == -1);
+
+# ifndef PATH_TRACING_FD
+       tprintf("poll(");
+       print_pollfd_array_entering(epfds, valid + 1, valid, abbrev);
+       errno = EFAULT;
+       tprintf(", %u, 0) = -1 EFAULT (%m)\n", valid + 1);
+# endif /* !PATH_TRACING_FD */
+
+# ifdef PATH_TRACING_FD
+       memcpy(tail_fds0, pfds0, sizeof(pfds0));
+       tail_fds0[4].fd = PATH_TRACING_FD;
+
+       rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
+       assert(rc == 3);
+
+       tprintf("poll(");
+       print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
+                                   ARRAY_SIZE(pfds0), abbrev);
+       tprintf(", %u, %d) = %d (",
+               (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
+       print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
+       tprintf(")\n");
+
+       rc = syscall(__NR_poll, epfds, valid + 1, 0);
+       assert(rc == -1);
+
+       /* the 1st pollfd element is readable and contains PATH_TRACING_FD */
        tprintf("poll(");
        print_pollfd_array_entering(epfds, valid + 1, valid, abbrev);
        errno = EFAULT;
        tprintf(", %u, 0) = -1 EFAULT (%m)\n", valid + 1);
+# endif /* PATH_TRACING_FD */
 
        tprintf("+++ exited with 0 +++\n");
        return 0;
index 274d95ed81523d87774538c819c11836bb9fb517..126545b151de9d975bb98729f87eaa78a597b50a 100755 (executable)
@@ -242,6 +242,7 @@ pkey_alloc
 pkey_free
 pkey_mprotect
 poll
+poll-P
 ppoll
 prctl-arg2-intptr
 prctl-dumpable