[PATCH 3/3] tests: add semop.test

Fei Jie feij.fnst at cn.fujitsu.com
Tue Apr 12 06:57:47 UTC 2016


* tests/semop.c: New file.
* tests/semop.test: New test.
* tests/.gitignore: Add semop.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add semop.test.
---
 tests/.gitignore  |  1 +
 tests/Makefile.am |  2 ++
 tests/semop.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tests/semop.test  |  6 ++++++
 4 files changed, 54 insertions(+)
 create mode 100644 tests/semop.c
 create mode 100755 tests/semop.test

diff --git a/tests/.gitignore b/tests/.gitignore
index aee70a4..9bcb695 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -133,6 +133,7 @@ seccomp-filter
 seccomp-filter-v
 seccomp-strict
 select
+semop
 sendfile
 sendfile64
 set_ptracer_any
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9446ce8..9162f4a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -182,6 +182,7 @@ check_PROGRAMS = \
 	seccomp-filter-v \
 	seccomp-strict \
 	select \
+	semop \
 	sendfile \
 	sendfile64 \
 	set_ptracer_any \
@@ -384,6 +385,7 @@ DECODER_TESTS = \
 	seccomp-filter.test \
 	seccomp-strict.test \
 	select.test \
+	semop.test \
 	sendfile.test \
 	sendfile64.test \
 	sethostname.test \
diff --git a/tests/semop.c b/tests/semop.c
new file mode 100644
index 0000000..7f48525
--- /dev/null
+++ b/tests/semop.c
@@ -0,0 +1,45 @@
+#include "tests.h"
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <stdio.h>
+#include <unistd.h>
+
+union semun
+{
+	int val;
+	struct semid_ds *buf;
+	unsigned short *array;
+	struct seminfo *__buf;
+};
+
+int
+main(void)
+{
+	int sem_id = semget(IPC_PRIVATE, 1, 0600);
+	if (sem_id <0)
+		perror_msg_and_fail("semget");
+	union semun sem_union;
+	sem_union.val = 0;
+	if (semctl(sem_id, 0, SETVAL, sem_union) == -1)
+		perror_msg_and_fail("semctl");
+
+	struct sembuf sem_b;
+	sem_b.sem_num = 0;
+	sem_b.sem_op = 1;
+	sem_b.sem_flg = SEM_UNDO;
+
+	if (semop(sem_id, &sem_b, 1))
+		perror_msg_and_fail("semop 1");
+	printf("semop(%d, [{0, 1, SEM_UNDO}], 1) = 0\n", sem_id);
+
+	sem_b.sem_op = -1;
+	if (semop(sem_id, &sem_b, 1))
+		perror_msg_and_fail("semop -1");
+	printf("semop(%d, [{0, -1, SEM_UNDO}], 1) = 0\n", sem_id);
+
+	semctl(sem_id, 0, IPC_RMID, 0);
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
diff --git a/tests/semop.test b/tests/semop.test
new file mode 100755
index 0000000..7e8f32c
--- /dev/null
+++ b/tests/semop.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check semop syscall decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a32
-- 
1.8.3.1







More information about the Strace-devel mailing list