]> granicus.if.org Git - strace/commitdiff
tests: add semop.test
authorFei Jie <feij.fnst@cn.fujitsu.com>
Mon, 18 Apr 2016 07:10:53 +0000 (15:10 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 20 Apr 2016 00:11:27 +0000 (00:11 +0000)
* 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
tests/Makefile.am
tests/semop.c [new file with mode: 0644]
tests/semop.test [new file with mode: 0755]

index f3ee62940437ec8a678c45dd3b798c82729caf38..3d1dbef773693d06ebc90afccf1abb7291a94835 100644 (file)
@@ -138,6 +138,7 @@ seccomp-filter
 seccomp-filter-v
 seccomp-strict
 select
+semop
 sendfile
 sendfile64
 set_ptracer_any
index e9cd625410ba5ca2685cec7cbd4ff727d83a88eb..f31b600757e02c0ae559fa2cc2821857a534475a 100644 (file)
@@ -188,6 +188,7 @@ check_PROGRAMS = \
        seccomp-filter-v \
        seccomp-strict \
        select \
+       semop \
        sendfile \
        sendfile64 \
        set_ptracer_any \
@@ -394,6 +395,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 (file)
index 0000000..214ce32
--- /dev/null
@@ -0,0 +1,54 @@
+#include "tests.h"
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+union semun
+{
+       int val;
+       struct semid_ds *buf;
+       unsigned short *array;
+       struct seminfo *__buf;
+};
+
+static int id = -1;
+
+static void
+cleanup(void)
+{
+       semctl(id, 0, IPC_RMID, 0);
+       id = -1;
+}
+
+int
+main(void)
+{
+       id = semget(IPC_PRIVATE, 1, 0600);
+       if (id < 0)
+               perror_msg_and_skip("semget");
+       atexit(cleanup);
+
+       union semun sem_union = { .val = 0 };
+       if (semctl(id, 0, SETVAL, sem_union) == -1)
+               perror_msg_and_skip("semctl");
+
+       struct sembuf *const sem_b = tail_alloc(sizeof(*sem_b));
+       sem_b->sem_num = 0;
+       sem_b->sem_op = 1;
+       sem_b->sem_flg = SEM_UNDO;
+
+       if (semop(id, sem_b, 1))
+               perror_msg_and_skip("semop, 1");
+       printf("semop(%d, [{0, 1, SEM_UNDO}], 1) = 0\n", id);
+
+       sem_b->sem_op = -1;
+       if (semop(id, sem_b, 1))
+               perror_msg_and_skip("semop, -1");
+       printf("semop(%d, [{0, -1, SEM_UNDO}], 1) = 0\n", id);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
diff --git a/tests/semop.test b/tests/semop.test
new file mode 100755 (executable)
index 0000000..7e8f32c
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check semop syscall decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a32