[PATCH v2 4/5] tests: Move return code printing into a separate file
* tests/tests.h: Add sprintrc declaration. * tests/futex.c (sprintrc): Remove. * tests/sprintrc.c: New file. * tests/Makefile.am (libtests_a_SOURCES): Add sprintrc.c. --- tests/Makefile.am |1 + tests/futex.c | 20 tests/sprintrc.c | 33 + tests/tests.h |3 +++ 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 tests/sprintrc.c diff --git a/tests/Makefile.am b/tests/Makefile.am index b879bf4..2cf9674 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -54,6 +54,7 @@ libtests_a_SOURCES = \ printflags.c \ printxval.c \ signal2name.c \ + sprintrc.c \ tail_alloc.c \ tests.h \ tprintf.c \ diff --git a/tests/futex.c b/tests/futex.c index 09a6c25..63669d2 100644 --- a/tests/futex.c +++ b/tests/futex.c @@ -143,26 +143,6 @@ void invalid_op(int *val, int op, uint32_t argmask, ...) printf(") = -1 ENOSYS (%m)\n"); } -const char *sprintrc(long rc) -{ - static char buf[4096]; - - if (rc == 0) - return "0"; - - int ret = (rc == -1) - ? snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name()) - : snprintf(buf, sizeof(buf), "%ld", rc); - - if (ret < 0) - perror_msg_and_fail("snprintf"); - if ((size_t) ret >= sizeof(buf)) - error_msg_and_fail("snprintf overflow: got %d, expected " - "no more than %zu", ret, sizeof(buf)); - - return buf; -} - # define CHECK_INVALID_CLOCKRT(op, ...) \ do { \ invalid_op(uaddr, FUTEX_CLOCK_REALTIME | (op), __VA_ARGS__); \ diff --git a/tests/sprintrc.c b/tests/sprintrc.c new file mode 100644 index 000..a12dc24 --- /dev/null +++ b/tests/sprintrc.c @@ -0,0 +1,33 @@ +#include "tests.h" + +#include +#include + +/** + * Provides pointer to static string buffer with printed return code in format + * used by strace - with errno and error message. + * + * @param rc Return code. + * @return Pointer to (statically allocated) buffer containing decimal + * representation of return code and errno/error message in case @rc + * is equal to -1. + */ +const char *sprintrc(long rc) +{ + static char buf[4096]; + + if (rc == 0) + return "0"; + + int ret = (rc == -1) + ? snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name()) + : snprintf(buf, sizeof(buf), "%ld", rc); + + if (ret < 0) + perror_msg_and_fail("snprintf"); + if ((size_t) ret >= sizeof(buf)) + error_msg_and_fail("snprintf overflow: got %d, expected " + "no more than %zu", ret, sizeof(buf)); + + return buf; +} diff --git a/tests/tests.h b/tests/tests.h index 81abe82..3043f97 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -99,6 +99,9 @@ const char *errno2name(void); /* Translate signal number to its name. */ const char *signal2name(int); +/* Print return code and, in case return code is -1, errno information. */ +const char *sprintrc(long rc); + struct xlat; /* Print flags in symbolic form according to xlat table. */ -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH v2 5/5] tests: check decoding of readahead syscall
* tests/readahead.c: New file. * tests/readahead.test: New test. * tests/.gitignore: Add readahead. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add readahead.test. --- tests/.gitignore |1 + tests/Makefile.am|2 ++ tests/readahead.c| 62 ++ tests/readahead.test |6 + 4 files changed, 71 insertions(+) create mode 100644 tests/readahead.c create mode 100755 tests/readahead.test diff --git a/tests/.gitignore b/tests/.gitignore index 5c5d092..8c41bea 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -185,6 +185,7 @@ pselect6 ptrace pwritev read-write +readahead readdir readlink readlinkat diff --git a/tests/Makefile.am b/tests/Makefile.am index 2cf9674..0b3b818 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -242,6 +242,7 @@ check_PROGRAMS = \ ptrace \ pwritev \ read-write \ + readahead \ readdir \ readlink \ readlinkat \ @@ -569,6 +570,7 @@ DECODER_TESTS = \ ptrace.test \ pwritev.test \ read-write.test \ + readahead.test \ readdir.test \ readlink.test \ readlinkat.test \ diff --git a/tests/readahead.c b/tests/readahead.c new file mode 100644 index 000..e58fcac --- /dev/null +++ b/tests/readahead.c @@ -0,0 +1,62 @@ +#include "tests.h" +#include + +#ifdef __NR_readahead + +# include +# include + +static const int fds[] = { + -0x8000, + -100, + -1, + 0, + 1, + 2, + 0x7fff, +}; + +static const off64_t offsets[] = { + -0x8000LL, + -0x5060708090a0b0c0LL, + -1LL, +0, +1, +0xbadfaced, +0x7fffLL, +}; + +static const unsigned long counts[] = { + 0UL, + 0xdeadca75, + (unsigned long)0xface1e55beeff00dULL, + (unsigned long)0xULL, +}; + +int +main(void) +{ + unsigned i; + unsigned j; + unsigned k; + ssize_t rc; + + for (i = 0; i < ARRAY_SIZE(fds); i++) + for (j = 0; j < ARRAY_SIZE(offsets); j++) + for (k = 0; k < ARRAY_SIZE(counts); k++) { + rc = readahead(fds[i], offsets[j], counts[k]); + + printf("readahead(%d, %lld, %lu) = %s\n", + fds[i], (long long)offsets[j], + counts[k], sprintrc(rc)); + } + + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_readahead") + +#endif diff --git a/tests/readahead.test b/tests/readahead.test new file mode 100755 index 000..397c690 --- /dev/null +++ b/tests/readahead.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check readahead syscall decoding. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a1 -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH v2 3/5] tests/futex: Add support for return codes other than 0 and -1 to sprintrc
* tests/futex.c (sprintrc): Print the actual return code provided, not just "0"; checks for snprintf return code added. --- tests/futex.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/futex.c b/tests/futex.c index 28d9df8..09a6c25 100644 --- a/tests/futex.c +++ b/tests/futex.c @@ -150,7 +150,15 @@ const char *sprintrc(long rc) if (rc == 0) return "0"; - snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name()); + int ret = (rc == -1) + ? snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name()) + : snprintf(buf, sizeof(buf), "%ld", rc); + + if (ret < 0) + perror_msg_and_fail("snprintf"); + if ((size_t) ret >= sizeof(buf)) + error_msg_and_fail("snprintf overflow: got %d, expected " + "no more than %zu", ret, sizeof(buf)); return buf; } -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH v2 2/5] tests/futex: Increase static sprintrc buffer size
* tests/futex.c (sprintrc) : Value increased from 256 to 4096. --- tests/futex.c |3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/futex.c b/tests/futex.c index fe3741a..28d9df8 100644 --- a/tests/futex.c +++ b/tests/futex.c @@ -145,8 +145,7 @@ void invalid_op(int *val, int op, uint32_t argmask, ...) const char *sprintrc(long rc) { - enum { RES_BUF_SIZE = 256 }; - static char buf[RES_BUF_SIZE]; + static char buf[4096]; if (rc == 0) return "0"; -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH v2 1/5] tests/futex: Rename retstr to sprintrc
* tests/futex.c (retstr): Rename to sprintstr, (main): Convert all retstr calls to sprintrc. --- tests/futex.c | 88 + 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/tests/futex.c b/tests/futex.c index dfdf68d..fe3741a 100644 --- a/tests/futex.c +++ b/tests/futex.c @@ -143,7 +143,7 @@ void invalid_op(int *val, int op, uint32_t argmask, ...) printf(") = -1 ENOSYS (%m)\n"); } -const char *retstr(int rc) +const char *sprintrc(long rc) { enum { RES_BUF_SIZE = 256 }; static char buf[RES_BUF_SIZE]; @@ -204,34 +204,34 @@ main(int argc, char *argv[]) (rc == -1) && (errno == EFAULT)); printf("futex(NULL, FUTEX_WAIT, %u, {%jd, %jd}) = %s\n", VAL_PR, (intmax_t)tmout->tv_sec, (intmax_t)tmout->tv_nsec, - retstr(rc)); + sprintrc(rc)); /* uaddr is faulty */ CHECK_FUTEX(uaddr + 1, FUTEX_WAIT, VAL, tmout, uaddr2, VAL3, (rc == -1) && (errno == EFAULT)); printf("futex(%p, FUTEX_WAIT, %u, {%jd, %jd}) = %s\n", uaddr + 1, VAL_PR, (intmax_t)tmout->tv_sec, - (intmax_t)tmout->tv_nsec, retstr(rc)); + (intmax_t)tmout->tv_nsec, sprintrc(rc)); /* timeout is faulty */ CHECK_FUTEX(uaddr, FUTEX_WAIT, VAL, tmout + 1, uaddr2, VAL3, (rc == -1) && (errno == EFAULT)); printf("futex(%p, FUTEX_WAIT, %u, %p) = %s\n", - uaddr, 0xfacefeed, tmout + 1, retstr(rc)); + uaddr, 0xfacefeed, tmout + 1, sprintrc(rc)); /* uaddr is not as provided; uaddr2 is faulty but ignored */ CHECK_FUTEX(uaddr, FUTEX_WAIT, VAL, tmout, uaddr2 + 1, VAL3, (rc == -1) && (errno == EAGAIN)); printf("futex(%p, FUTEX_WAIT, %u, {%jd, %jd}) = %s\n", uaddr, VAL_PR, (intmax_t)tmout->tv_sec, - (intmax_t)tmout->tv_nsec, retstr(rc)); + (intmax_t)tmout->tv_nsec, sprintrc(rc)); /* uaddr is not as provided; uaddr2 is faulty but ignored */ CHECK_FUTEX_ENOSYS(uaddr, FUTEX_PRIVATE_FLAG | FUTEX_WAIT, VAL, tmout, uaddr2 + 1, VAL3, (rc == -1) && (errno == EAGAIN)); printf("futex(%p, FUTEX_WAIT_PRIVATE, %u, {%jd, %jd}) = %s\n", uaddr, VAL_PR, (intmax_t)tmout->tv_sec, - (intmax_t)tmout->tv_nsec, retstr(rc)); + (intmax_t)tmout->tv_nsec, sprintrc(rc)); /* Next 2 tests are with CLOCKRT bit set */ @@ -241,14 +241,16 @@ main(int argc, char *argv[]) VAL, tmout, uaddr2, VAL3, (rc == -1) && (errno == EAGAIN)); printf("futex(%p, FUTEX_WAIT|FUTEX_CLOCK_REALTIME, %u, " "{%jd, %jd}) = %s\n", uaddr, VAL_PR, - (intmax_t)tmout->tv_sec, (intmax_t)tmout->tv_nsec, retstr(rc)); + (intmax_t)tmout->tv_sec, (intmax_t)tmout->tv_nsec, + sprintrc(rc)); CHECK_FUTEX_ENOSYS(uaddr, FUTEX_CLOCK_REALTIME | FUTEX_PRIVATE_FLAG | FUTEX_WAIT , VAL, tmout, uaddr2, 0, (rc == -1) && (errno == EAGAIN)); printf("futex(%p, FUTEX_WAIT_PRIVATE|FUTEX_CLOCK_REALTIME, %u, " "{%jd, %jd}) = %s\n", uaddr, VAL_PR, - (intmax_t)tmout->tv_sec, (intmax_t)tmout->tv_nsec, retstr(rc)); + (intmax_t)tmout->tv_sec, (intmax_t)tmout->tv_nsec, + sprintrc(rc)); /* FUTEX_WAIT_BITSET - FUTEX_WAIT which provides additional bitmask * which should be matched at least in one bit with @@ -266,20 +268,20 @@ main(int argc, char *argv[]) VAL3, (rc == -1) && (errno == EAGAIN)); printf("futex(%p, FUTEX_WAIT_BITSET, %u, {%jd, %jd}, %#x) = %s\n", uaddr, VAL_PR, (intmax_t)tmout->tv_sec, - (intmax_t)tmout->tv_nsec, VAL3_PR, retstr(rc)); + (intmax_t)tmout->tv_nsec, VAL3_PR, sprintrc(rc)); /* val3 of 0 is invalid */ CHECK_FUTEX_ENOSYS(uaddr, FUTEX_WAIT_BITSET, VAL, tmout, uaddr2 + 1, 0, (rc == -1) && (errno == EINVAL)); printf("futex(%p, FUTEX_WAIT_BITSET, %u, {%jd, %jd}, %#x) = %s\n", uaddr, VAL_PR, (intmax_t)tmout->tv_sec, - (intmax_t)tmout->tv_nsec, 0, retstr(rc)); + (intmax_t)tmout->tv_nsec, 0, sprintrc(rc)); CHECK_FUTEX_ENOSYS(uaddr, FUTEX_PRIVATE_FLAG | FUTEX_WAIT_BITSET, VAL, tmout, uaddr2 + 1, VAL3, (rc == -1) && (errno == EAGAIN)); printf("futex(%p, FUTEX_WAIT_BITSET_PRIVATE, %u, {%jd, %jd}, %#x) = " "%s\n", uaddr, VAL_PR, (intmax_t)tmout->tv_sec, - (intmax_t)tmout->tv_nsec, VAL3_PR, retstr(rc)); + (intmax_t)tmout->tv_nsec, VAL3_PR, sprintrc(rc)); /* Next 3 tests are with CLOCKRT bit set */ @@ -288,7 +290,7 @@ main(int argc, char *argv[]) printf("futex(%p,