[PATCH v5 2/2] tests: add signal_receive.test
Fei Jie
feij.fnst at cn.fujitsu.com
Thu Jun 16 02:42:14 UTC 2016
* tests/signal_receive.c: New file.
* tests/signal_receive.test: New test.
* tests/.gitignore: Add signal_receive.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add signal_receive.test.
---
tests/.gitignore | 1 +
tests/Makefile.am | 2 ++
tests/signal_receive.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
tests/signal_receive.test | 6 ++++++
4 files changed, 54 insertions(+)
create mode 100644 tests/signal_receive.c
create mode 100755 tests/signal_receive.test
diff --git a/tests/.gitignore b/tests/.gitignore
index 67d0d66..72e93d8 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -231,6 +231,7 @@ shmxt
sigaction
sigaltstack
siginfo
+signal_receive
signalfd
sigreturn
sleep
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a136e2a..94d3d23 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -285,6 +285,7 @@ check_PROGRAMS = \
sigaction \
sigaltstack \
siginfo \
+ signal_receive \
signalfd \
sigreturn \
sleep \
@@ -662,6 +663,7 @@ MISC_TESTS = \
qual_syscall.test \
redirect.test \
restart_syscall.test \
+ signal_receive.test \
strace-E.test \
strace-S.test \
strace-T.test \
diff --git a/tests/signal_receive.c b/tests/signal_receive.c
new file mode 100644
index 0000000..9036ad5
--- /dev/null
+++ b/tests/signal_receive.c
@@ -0,0 +1,45 @@
+#include "tests.h"
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void sig_print(const char *signame, const int pid, const int uid)
+{
+ printf("kill(%d, %s) = 0\n"
+ "--- %s {si_signo=%s, si_code=SI_USER, si_pid=%d,"
+ " si_uid=%d} ---\n",
+ pid, signame, signame, signame, pid, uid);
+}
+
+static void
+handler(int sig)
+{
+}
+
+int
+main(void)
+{
+ int sig, pid = getpid(), uid = getuid();
+ const struct sigaction act = { .sa_handler = handler };
+ sigset_t mask;
+ sigemptyset(&mask);
+
+ for (sig = 1; sig <= 31; sig++) {
+ if( sig != SIGKILL && sig != SIGSTOP) {
+ sigaction(sig, &act, NULL);
+ sigaddset(&mask, sig);
+ }
+ }
+ sigprocmask(SIG_UNBLOCK, &mask, NULL);
+
+ for (sig = 1; sig <= 31; sig++) {
+ if(sig != SIGKILL && sig != SIGSTOP) {
+ if (kill(pid, sig) != 0)
+ perror_msg_and_fail("%s fail!", signal2name(sig));
+ sig_print(signal2name(sig), pid, uid);
+ }
+ }
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
diff --git a/tests/signal_receive.test b/tests/signal_receive.test
new file mode 100755
index 0000000..9685b66
--- /dev/null
+++ b/tests/signal_receive.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check whether strace traces signals properly.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a16 -e trace=kill
--
1.8.3.1
More information about the Strace-devel
mailing list