From: Dmitry V. Levin Date: Wed, 17 Jan 2018 21:31:07 +0000 (+0000) Subject: tests: check path tracing of poll syscall X-Git-Tag: v4.21~122 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96dbdc342d6fee432eefc6ffb2637d08d1719d0f;p=strace tests: check path tracing of poll syscall * 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. --- diff --git a/tests/.gitignore b/tests/.gitignore index becb265a..c4f3c5ad 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -288,6 +288,7 @@ pkey_alloc pkey_free pkey_mprotect poll +poll-P ppoll ppoll-v prctl-arg2-intptr diff --git a/tests/Makefile.am b/tests/Makefile.am index c1fd9cd9..fd5548b5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..7bbeb795 --- /dev/null +++ b/tests/poll-P.c @@ -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 index 00000000..a1905723 --- /dev/null +++ b/tests/poll-P.test @@ -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 diff --git a/tests/poll.c b/tests/poll.c index 2bf8c1a1..c5930a3e 100644 --- a/tests/poll.c +++ b/tests/poll.c @@ -1,8 +1,7 @@ /* - * This file is part of poll strace test. + * Check decoding of poll syscall. * - * Copyright (c) 2016 Dmitry V. Levin - * Copyright (c) 2016-2017 The strace developers. + * Copyright (c) 2016-2018 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,6 +37,7 @@ # include # include # include +# include # include #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; diff --git a/tests/pure_executables.list b/tests/pure_executables.list index 274d95ed..126545b1 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -242,6 +242,7 @@ pkey_alloc pkey_free pkey_mprotect poll +poll-P ppoll prctl-arg2-intptr prctl-dumpable