]> granicus.if.org Git - strace/commitdiff
tests: add shmxt.test
authorFei Jie <feij.fnst@cn.fujitsu.com>
Mon, 18 Apr 2016 07:10:54 +0000 (15:10 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 20 Apr 2016 01:08:12 +0000 (01:08 +0000)
* tests/shmxt.c: New file.
* tests/shmxt.test: New test.
* tests/.gitignore: Add shmxt.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add shmxt.test.

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

index 3d1dbef773693d06ebc90afccf1abb7291a94835..9f96e3a761a8eee1ff50b4735c6419f75f363bb5 100644 (file)
@@ -143,6 +143,7 @@ sendfile
 sendfile64
 set_ptracer_any
 sethostname
+shmxt
 sigaction
 sigaltstack
 signalfd
index f31b600757e02c0ae559fa2cc2821857a534475a..5069c19947c543af20712606fff72ae5fd9f214b 100644 (file)
@@ -193,6 +193,7 @@ check_PROGRAMS = \
        sendfile64 \
        set_ptracer_any \
        sethostname \
+       shmxt \
        sigaction \
        sigaltstack \
        signalfd \
@@ -399,6 +400,7 @@ DECODER_TESTS = \
        sendfile.test \
        sendfile64.test \
        sethostname.test \
+       shmxt.test \
        sigaction.test \
        sigaltstack.test \
        signalfd.test \
diff --git a/tests/shmxt.c b/tests/shmxt.c
new file mode 100644 (file)
index 0000000..628f5b2
--- /dev/null
@@ -0,0 +1,51 @@
+#include "tests.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/shm.h>
+
+static int id = -1;
+
+static void
+cleanup(void)
+{
+       shmctl(id, IPC_RMID, NULL);
+       id = -1;
+}
+
+#ifdef __alpha__
+# define SHMAT "osf_shmat"
+#else
+# define SHMAT "shmat"
+#endif
+
+int
+main(void)
+{
+       id = shmget(IPC_PRIVATE, 1, 0600);
+       if (id < 0)
+               perror_msg_and_skip("shmget");
+       atexit(cleanup);
+
+       shmat(id, NULL, SHM_REMAP);
+       printf("%s(%d, NULL, SHM_REMAP) = -1 %s (%m)\n",
+              SHMAT, id, errno == ENOSYS ? "ENOSYS" : "EINVAL");
+
+       void *shmaddr = shmat(id, NULL, SHM_RDONLY);
+       if (shmaddr == (void *)(-1))
+               perror_msg_and_skip("shmat SHM_RDONLY");
+       printf("%s(%d, NULL, SHM_RDONLY) = %p\n", SHMAT, id, shmaddr);
+
+       if (shmdt(shmaddr))
+               perror_msg_and_skip("shmdt");
+       printf("shmdt(%p) = 0\n", shmaddr);
+
+       void *shmaddr2 = shmat(id, shmaddr, SHM_RND);
+       if (shmaddr2 == (void *)(-1))
+               perror_msg_and_skip("shmat SHM_RND");
+       printf("%s(%d, %p, SHM_RND) = %p\n",
+              SHMAT, id, shmaddr, shmaddr2);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
diff --git a/tests/shmxt.test b/tests/shmxt.test
new file mode 100755 (executable)
index 0000000..3757cfa
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# Check shmat and shmdt syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+case "$STRACE_ARCH" in
+       alpha) shmat=osf_shmat ;;
+       *) shmat=shmat ;;
+esac
+
+run_strace_match_diff -e trace=$shmat,shmdt -a11