]> granicus.if.org Git - strace/commitdiff
tests: add mmap/mmap64 variants different xlat verbosity levels
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 4 Apr 2018 15:38:53 +0000 (17:38 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 28 Apr 2018 20:48:52 +0000 (20:48 +0000)
* tests/tests.h [!XLAT_RAW] (XLAT_RAW): Define.
[!XLAT_VERBOSE] (XLAT_VERBOSE): Likewise.
* tests/mmap-Xabbrev.c: New file.
* tests/mmap-Xraw.c: Likewise.
* tests/mmap-Xverbose.c: Likewise.
* tests/mmap64-Xabbrev.c: Likewise.
* tests/mmap64-Xraw.c: Likewise.
* tests/mmap64-Xverbose.c: Likewise.
* tests/mmap.c (main): Add handling of XLAT_RAW and XLAT_VERBOSE macros.
* tests/mmap.test: Add handling of optional test arguments that set
alignment and xlat verbosity options.
* tests/Makefile.am (mmap64_Xabbrev_CPPFLAGS, mmap64_Xraw_CPPFLAGS,
mmap64_Xverbose_CPPFLAGS): New variables, analogous to mmap64_CPPFLAGS.
* tests/pure_executables.list: Add mmap-Xabbrev, mmap-Xraw,
mmap-Xverbose, mmap64-Xabbrev, mmap64-Xraw, and mmap64-Xverbose.
* tests/.gitignore: Likewise.
* tests/gen_tests.in (mmap-Xabbrev, mmap-Xraw, mmap-Xverbose,
mmap64-Xabbrev, mmap64-Xraw, mmap64-Xverbose): New tests.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
13 files changed:
tests/.gitignore
tests/Makefile.am
tests/gen_tests.in
tests/mmap-Xabbrev.c [new file with mode: 0644]
tests/mmap-Xraw.c [new file with mode: 0644]
tests/mmap-Xverbose.c [new file with mode: 0644]
tests/mmap.c
tests/mmap.test
tests/mmap64-Xabbrev.c [new file with mode: 0644]
tests/mmap64-Xraw.c [new file with mode: 0644]
tests/mmap64-Xverbose.c [new file with mode: 0644]
tests/pure_executables.list
tests/tests.h

index 38e7624383c25b206d8760fe01ae08610763ea75..8887206628d8d3b3054dc05361aeea0a0f24904d 100644 (file)
@@ -193,7 +193,13 @@ mlock
 mlock2
 mlockall
 mmap
+mmap-Xabbrev
+mmap-Xraw
+mmap-Xverbose
 mmap64
+mmap64-Xabbrev
+mmap64-Xraw
+mmap64-Xverbose
 mmsg
 mmsg-silent
 mmsg_name
index 5c8ee5d3b29090fe2221a88c2b7336ba5d0aad09..be4284411e2a5bba9f1fe82f5a79cd851de988db 100644 (file)
@@ -179,6 +179,9 @@ ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 localtime_LDADD = $(clock_LIBS) $(LDADD)
 lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
+mmap64_Xabbrev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
+mmap64_Xraw_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
+mmap64_Xverbose_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 mq_LDADD = $(mq_LIBS) $(LDADD)
 newfstatat_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 pc_LDADD = $(dl_LIBS) $(LDADD)
index 531fd1222009dac6c7903f6af87bbb3ddfcbac41..c4c567158884d1219a9bd10f28166f977a37e0f1 100644 (file)
@@ -180,7 +180,13 @@ mknodat    -a35
 mlock  -a20 -e trace=mlock,munlock
 mlock2
 mlockall       -a12
+mmap-Xabbrev   +mmap.test abbrev
+mmap-Xraw      +mmap.test raw 14
+mmap-Xverbose  +mmap.test verbose
 mmap64 +mmap.test
+mmap64-Xabbrev +mmap.test abbrev
+mmap64-Xraw    +mmap.test raw 14
+mmap64-Xverbose        +mmap.test verbose
 mmsg   -e read=0 -e write=1 -e trace=recvmmsg,sendmmsg
 mmsg-silent    -a25 -e verbose=none -e trace=sendmmsg,recvmmsg
 mmsg_name      -a25 -e trace=sendmmsg,recvmmsg
diff --git a/tests/mmap-Xabbrev.c b/tests/mmap-Xabbrev.c
new file mode 100644 (file)
index 0000000..b31ce42
--- /dev/null
@@ -0,0 +1 @@
+#include "mmap.c"
diff --git a/tests/mmap-Xraw.c b/tests/mmap-Xraw.c
new file mode 100644 (file)
index 0000000..ef25c03
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW     1
+#include "mmap.c"
diff --git a/tests/mmap-Xverbose.c b/tests/mmap-Xverbose.c
new file mode 100644 (file)
index 0000000..08e9e30
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "mmap.c"
index 0321bf52c47167571fe749a1e83087a6896a1dce..10b4f51311b0d7edae09bceaa5804fa6062bd43e 100644 (file)
@@ -58,25 +58,60 @@ main(int ac, char **av)
 
        (void) close(0);
        (void) close(0);
+#if XLAT_RAW
+       printf("%s(NULL, 0, %#x, %#x, 0, 0) = -1 EBADF (%m)\n",
+              name, PROT_NONE, MAP_FILE);
+#elif XLAT_VERBOSE
+       printf("%s(NULL, 0, %#x /* PROT_NONE */, %#x /* MAP_FILE */, 0, 0) "
+              "= -1 EBADF (%m)\n",
+              name, PROT_NONE, MAP_FILE);
+#else
        printf("%s(NULL, 0, PROT_NONE, MAP_FILE, 0, 0) = -1 EBADF (%m)\n",
               name);
+#endif
        mmap(NULL, 0, PROT_NONE, MAP_FILE, 0, 0);
 
        p = mmap(addr, length1, PROT_READ | PROT_WRITE,
                 MAP_PRIVATE | MAP_ANONYMOUS, fd, offset);
        if (MAP_FAILED == p)
                perror_msg_and_fail("mmap");
+#if XLAT_RAW
+       printf("%s(%p, %lu, %#x, "
+              "%#x|%#x, %d, %#jx) = %p\n",
+              name, addr, length1, PROT_READ | PROT_WRITE, MAP_PRIVATE,
+              MAP_ANONYMOUS, fd, uoffset, p);
+#elif XLAT_VERBOSE
+       printf("%s(%p, %lu, %#x /* PROT_READ|PROT_WRITE */, "
+              "%#x /* MAP_PRIVATE */|%#x /* MAP_ANONYMOUS */, %d, %#jx) "
+              "= %p\n",
+              name, addr, length1, PROT_READ | PROT_WRITE, MAP_PRIVATE,
+              MAP_ANONYMOUS, fd, uoffset, p);
+#else
        printf("%s(%p, %lu, PROT_READ|PROT_WRITE, "
               "MAP_PRIVATE|MAP_ANONYMOUS, %d, %#jx) = %p\n",
               name, addr, length1, fd, uoffset, p);
+#endif
 
        if (msync(p, length1, MS_SYNC))
                perror_msg_and_fail("msync");
+#if XLAT_RAW
+       printf("msync(%p, %lu, %#x) = 0\n", p, length1, MS_SYNC);
+#elif XLAT_VERBOSE
+       printf("msync(%p, %lu, %#x /* MS_SYNC */) = 0\n", p, length1, MS_SYNC);
+#else
        printf("msync(%p, %lu, MS_SYNC) = 0\n", p, length1);
+#endif
 
        if (mprotect(p, length1, PROT_NONE))
                perror_msg_and_fail("mprotect");
+#if XLAT_RAW
+       printf("mprotect(%p, %lu, %#x) = 0\n", p, length1, PROT_NONE);
+#elif XLAT_VERBOSE
+       printf("mprotect(%p, %lu, %#x /* PROT_NONE */) = 0\n",
+              p, length1, PROT_NONE);
+#else
        printf("mprotect(%p, %lu, PROT_NONE) = 0\n", p, length1);
+#endif
 
        addr = mremap(p, length1, length2, 0);
        if (MAP_FAILED == addr)
@@ -87,8 +122,19 @@ main(int ac, char **av)
                    addr + length2);
        if (MAP_FAILED == p)
                perror_msg_and_fail("mremap");
+#if XLAT_RAW
+       printf("mremap(%p, %lu, %lu, %#x, %p) = %p\n",
+              addr, length2, length3, MREMAP_MAYMOVE | MREMAP_FIXED,
+              addr + length2, p);
+#elif XLAT_VERBOSE
+       printf("mremap(%p, %lu, %lu, %#x /* MREMAP_MAYMOVE|MREMAP_FIXED */"
+              ", %p) = %p\n",
+              addr, length2, length3, MREMAP_MAYMOVE | MREMAP_FIXED,
+              addr + length2, p);
+#else
        printf("mremap(%p, %lu, %lu, MREMAP_MAYMOVE|MREMAP_FIXED"
               ", %p) = %p\n", addr, length2, length3, addr + length2, p);
+#endif
 
        if (munmap(p, length3))
                perror_msg_and_fail("munmap");
@@ -96,7 +142,13 @@ main(int ac, char **av)
 
        if (mlockall(MCL_FUTURE))
                perror_msg_and_fail("mlockall");
+#if XLAT_RAW
+       printf("mlockall(%#x) = 0\n", MCL_FUTURE);
+#elif XLAT_VERBOSE
+       printf("mlockall(%#x /* MCL_FUTURE */) = 0\n", MCL_FUTURE);
+#else
        puts("mlockall(MCL_FUTURE) = 0");
+#endif
 
        puts("+++ exited with 0 +++");
        return 0;
index 7ba664ec19f9d8e7bced9c87f8138d293c188172..4c30a65d9bce5950d758b1bf554d9febc11292b1 100755 (executable)
@@ -35,15 +35,20 @@ check_prog grep
 check_prog sed
 run_prog > /dev/null
 
+xlat_opt=""
+[ "$#" -gt 0 ] && xlat_opt="-X$1"
+align=20
+[ "$#" -gt 1 ] && align="$2"
+
 syscall=
 for n in mmap mmap2; do
        $STRACE -e$n -h > /dev/null && syscall=$syscall,$n
 done
 run_strace -e$syscall $args > /dev/null
 
-if grep '^mmap(NULL, 0, PROT_NONE,' < "$LOG" > /dev/null; then
+if grep '^mmap(NULL, 0, \(0 /* PROT_NONE */\|0\|PROT_NONE\),' < "$LOG" > /dev/null; then
        mmap=mmap
-elif grep '^mmap2(NULL, 0, PROT_NONE,' < "$LOG" > /dev/null; then
+elif grep '^mmap2(NULL, 0, \(0 \/\* PROT_NONE \*\/\|0\|PROT_NONE\),' < "$LOG" > /dev/null; then
        mmap=mmap2
 else
        dump_log_and_fail_with "mmap/mmap2 not found in $STRACE $args output"
@@ -52,6 +57,6 @@ fi
 syscall=$mmap,madvise,mlockall,mprotect,mremap,msync,munmap
 
 run_prog "../$NAME" $mmap > /dev/null
-run_strace -a20 -e$syscall $args > "$EXP"
-sed -n "/^$mmap(NULL, 0, PROT_NONE,/,\$p" < "$LOG" > "$OUT"
+run_strace -a$align -e$syscall $xlat_opt $args > "$EXP"
+sed -n "/^$mmap(NULL, 0, \(0 \/\* PROT_NONE \*\/\|0\|PROT_NONE\),/,\$p" < "$LOG" > "$OUT"
 match_diff "$OUT" "$EXP"
diff --git a/tests/mmap64-Xabbrev.c b/tests/mmap64-Xabbrev.c
new file mode 100644 (file)
index 0000000..cbd7789
--- /dev/null
@@ -0,0 +1 @@
+#include "mmap64.c"
diff --git a/tests/mmap64-Xraw.c b/tests/mmap64-Xraw.c
new file mode 100644 (file)
index 0000000..f75f235
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW     1
+#include "mmap64.c"
diff --git a/tests/mmap64-Xverbose.c b/tests/mmap64-Xverbose.c
new file mode 100644 (file)
index 0000000..f72513e
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "mmap64.c"
index 17b3e972d7118e92a263e6afb917fc7a43c95737..faf56bae6a12c2ca3c763d7b6448d8766b73c5ae 100755 (executable)
@@ -154,7 +154,13 @@ mlock
 mlock2
 mlockall
 mmap
+mmap-Xabbrev
+mmap-Xraw
+mmap-Xverbose
 mmap64
+mmap64-Xabbrev
+mmap64-Xraw
+mmap64-Xverbose
 mmsg
 mmsg_name
 modify_ldt
index 3bf454dd525b90edf0aaf24e05487625300b6654..1712294c698045db61a8e446a412d83a5e06ca97 100644 (file)
 # define VERBOSE 0
 #endif
 
+/* xlat verbosity defaults */
+#ifndef XLAT_RAW
+# define XLAT_RAW 0
+#endif
+#ifndef XLAT_VERBOSE
+# define XLAT_VERBOSE 0
+#endif
+
 #ifndef DEFAULT_STRLEN
 /* Default maximum # of bytes printed in printstr et al. */
 # define DEFAULT_STRLEN 32