[PATCH v2 2/2] tests: add shmxt.test

Fei Jie feij.fnst at cn.fujitsu.com
Mon Apr 18 07:10:54 UTC 2016


* 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  |  1 +
 tests/Makefile.am |  2 ++
 tests/shmxt.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tests/shmxt.test  |  6 ++++++
 4 files changed, 54 insertions(+)
 create mode 100644 tests/shmxt.c
 create mode 100755 tests/shmxt.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 3d1dbef..851751b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -147,6 +147,7 @@ sigaction
 sigaltstack
 signalfd
 sigreturn
+shmxt
 sleep
 splice
 stack-fcall
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f31b600..8bf1e84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -197,6 +197,7 @@ check_PROGRAMS = \
 	sigaltstack \
 	signalfd \
 	sigreturn \
+	shmxt \
 	sleep \
 	splice \
 	stack-fcall \
@@ -403,6 +404,7 @@ DECODER_TESTS = \
 	sigaltstack.test \
 	signalfd.test \
 	sigreturn.test \
+	shmxt.test \
 	splice.test \
 	stat.test \
 	stat64.test \
diff --git a/tests/shmxt.c b/tests/shmxt.c
new file mode 100644
index 0000000..08cc816
--- /dev/null
+++ b/tests/shmxt.c
@@ -0,0 +1,45 @@
+#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;
+}
+
+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("shmat(%d, NULL, SHM_REMAP) = -1 %s (%m)\n",
+	       id, errno == ENOSYS ? "ENOSYS" : "EINVAL");
+
+	void *shmaddr = shmat(id, NULL, SHM_RDONLY);
+	if (shmaddr == (void *)(-1))
+		perror_msg_and_skip("shmat_SHM_RDONLY");
+	printf("shmat(%d, NULL, SHM_RDONLY) = %p\n", 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("shmat(%d, %p, SHM_RND) = %p\n",
+	       id, shmaddr, shmaddr2);
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
diff --git a/tests/shmxt.test b/tests/shmxt.test
new file mode 100755
index 0000000..59df835
--- /dev/null
+++ b/tests/shmxt.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check shmat and shmdt syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -e trace=shmat,shmdt -a11
-- 
1.8.3.1







More information about the Strace-devel mailing list