]> granicus.if.org Git - strace/commitdiff
tests: add a test for mmap/mprotect/munmap decoding
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 19 Mar 2015 22:03:32 +0000 (22:03 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 20 Mar 2015 02:15:11 +0000 (02:15 +0000)
* tests/mmap.c: New file.
* tests/mmap64.c: New file.
* tests/mmap.test: New test.
* tests/mmap64.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add mmap and mmap64.
(mmap64_CFLAGS): Define.
(TESTS): Add mmap.test and mmap64.test.
* tests/.gitignore: Add mmap and mmap64.

tests/.gitignore
tests/Makefile.am
tests/mmap.c [new file with mode: 0644]
tests/mmap.test [new file with mode: 0755]
tests/mmap64.c [new file with mode: 0644]
tests/mmap64.test [new file with mode: 0755]

index 9fdbe4d86308b40f693c6d44ed2728a51119647b..61ff1498af7b9ae5e9cee394b0de9fd56c7a3a11 100644 (file)
@@ -6,6 +6,8 @@ ioctl
 ipc_msg
 ipc_sem
 ipc_shm
+mmap
+mmap64
 mmsg
 net-accept-connect
 netlink_inet_diag
index 930f6d95ed1d4bdf1933b8d19d2be5a34890b918..b8475accd15e1bed9fbee5e198071f1d95c4bcd8 100644 (file)
@@ -15,6 +15,8 @@ check_PROGRAMS = \
        ipc_msg \
        ipc_sem \
        ipc_shm \
+       mmap \
+       mmap64 \
        mmsg \
        net-accept-connect \
        netlink_inet_diag \
@@ -36,6 +38,7 @@ check_PROGRAMS = \
        uio \
        unix-pair-send-recv
 
+mmap64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 pc_LDADD = $(dl_LIBS)
 stat_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 statfs_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
@@ -65,6 +68,8 @@ TESTS = \
        stat32-v.test \
        stat64-v.test \
        statfs.test \
+       mmap.test \
+       mmap64.test \
        mmsg.test \
        net.test \
        net-fd.test \
diff --git a/tests/mmap.c b/tests/mmap.c
new file mode 100644 (file)
index 0000000..d4d3e66
--- /dev/null
@@ -0,0 +1,46 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/mman.h>
+
+int
+main(void)
+{
+       const intmax_t pagesize = sysconf(_SC_PAGESIZE);
+       const unsigned long length = pagesize * 3;
+       const int fd = -1;
+       off_t offset;
+       void *addr, *p;
+
+#if ULONG_MAX > 4294967295UL
+       offset = 0xcafedeadbeef000 & -pagesize;
+       addr = (void *) (uintmax_t) (0xfacefeed000 & -pagesize);
+#else
+       offset = 0xdeadbeef000 & -pagesize;
+       addr = (void *) (unsigned int) (0xfaced000 & -pagesize);
+#endif
+
+       p = mmap(addr, length, PROT_READ | PROT_WRITE,
+                MAP_PRIVATE | MAP_ANONYMOUS, fd, offset);
+       if (p == MAP_FAILED ||
+           mprotect(p, length, PROT_NONE) ||
+           munmap(p, length))
+               return 77;
+
+       if (sizeof(offset) == sizeof(int))
+               printf("(mmap2?|old_mmap)\\(%p, %lu, PROT_READ\\|PROT_WRITE, "
+                      "MAP_PRIVATE\\|MAP_ANONYMOUS, %d, %#x\\) = %p\n",
+                      addr, length, fd, (unsigned int) offset, p);
+       else
+               printf("(mmap2?|old_mmap)\\(%p, %lu, PROT_READ\\|PROT_WRITE, "
+                      "MAP_PRIVATE\\|MAP_ANONYMOUS, %d, %#jx\\) = %p\n",
+                      addr, length, fd, (uintmax_t) offset, p);
+       printf("mprotect\\(%p, %lu, PROT_NONE\\) += 0\n", p, length);
+       printf("munmap\\(%p, %lu\\) += 0\n", p, length);
+       return 0;
+}
diff --git a/tests/mmap.test b/tests/mmap.test
new file mode 100755 (executable)
index 0000000..e9c9b3a
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Check mmap/mprotect/munmap syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+syscall=mprotect,munmap
+for n in mmap mmap2 old_mmap; do
+       $STRACE -e$n -h > /dev/null && syscall=$syscall,$n
+done
+
+OUT="$LOG.out"
+
+run_prog > /dev/null
+run_strace -e$syscall $args > "$OUT"
+match_grep "$LOG" "$OUT"
+
+rm -f "$OUT"
+
+exit 0
diff --git a/tests/mmap64.c b/tests/mmap64.c
new file mode 100644 (file)
index 0000000..b31ce42
--- /dev/null
@@ -0,0 +1 @@
+#include "mmap.c"
diff --git a/tests/mmap64.test b/tests/mmap64.test
new file mode 100755 (executable)
index 0000000..51f1896
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check mmap/mprotect/munmap syscalls decoding.
+# Target executable was compiled with -D_FILE_OFFSET_BITS=64.
+
+. "${srcdir=.}/mmap.test"