summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2014-01-07 19:32:32 +0000
committerDmitry V. Levin <ldv@altlinux.org>2014-01-08 17:48:25 +0000
commit66a15a5bb832032591e57a4fc2c6ec70bce0732a (patch)
tree6b71a5ed164eacbc5a94f0a5ebfbfd7b60ef7080
parentb5530a1f8983e5692c37f73b9fa664ee0605d8fb (diff)
downloadstrace-66a15a5bb832032591e57a4fc2c6ec70bce0732a.tar.gz
strace-66a15a5bb832032591e57a4fc2c6ec70bce0732a.tar.bz2
strace-66a15a5bb832032591e57a4fc2c6ec70bce0732a.tar.xz
tests: add a test for rt_sigaction output
Since "struct sigaction" varies between architectures, rt_sigaction decoding sometimes produces incorrect output. This test is expected to catch basic rt_sigaction decoding bugs. Based on a patch proposed by Chris Dearman. * tests/sigaction.c: New file. * tests/sigaction.awk: Likewise. * tests/sigaction.sh: New test. * tests/Makefile.am (check_PROGRAMS): Add sigaction. (TESTS): Add sigaction.sh. (EXTRA_DIST): Add sigaction.awk. * tests/.gitignore: Add sigaction.
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/sigaction.awk30
-rw-r--r--tests/sigaction.c36
-rwxr-xr-xtests/sigaction.sh19
5 files changed, 89 insertions, 3 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index a8b1cba..c400a79 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,6 @@
net-accept-connect
set_ptracer_any
+sigaction
*.log
*.log.*
*.o
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f8f8054..d8262f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,13 +2,13 @@
AM_CFLAGS = $(WARN_CFLAGS)
-check_PROGRAMS = net-accept-connect set_ptracer_any
+check_PROGRAMS = net-accept-connect set_ptracer_any sigaction
-TESTS = ptrace_setoptions strace-f qual_syscall stat net \
+TESTS = ptrace_setoptions strace-f qual_syscall sigaction.sh stat net \
detach-sleeping detach-stopped detach-running
LOG_COMPILER = $(srcdir)/run.sh
-EXTRA_DIST = init.sh run.sh $(TESTS)
+EXTRA_DIST = init.sh run.sh sigaction.awk $(TESTS)
CLEANFILES = $(TESTS:=.tmp)
diff --git a/tests/sigaction.awk b/tests/sigaction.awk
new file mode 100644
index 0000000..ff89e3e
--- /dev/null
+++ b/tests/sigaction.awk
@@ -0,0 +1,30 @@
+# rt_sigaction on ALPHA has 5 args: sig, act, oact, sigsetsize, restorer.
+# rt_sigaction on SPARC has 5 args: sig, act, oact, restorer, sigsetsize.
+# rt_sigaction on other architectures has 4 args: sig, act, oact, sigsetsize.
+# Some architectures have SA_RESTORER, some don't;
+# in particular, SPARC has and ALPHA hasn't.
+#
+# There are two regexps for each test:
+# the 1st is for any architecture with SA_RESTORER, including SPARC;
+# the 2nd is for any architecture without SA_RESTORER, including ALPHA.
+
+# Test 1.
+NR == 1 && /^rt_sigaction\(SIGUSR2, {SIG_IGN, \[HUP INT\], SA_RESTORER\|SA_RESTART, 0x[0-9a-f]+}, {SIG_DFL, \[\], 0}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next}
+NR == 1 && /^rt_sigaction\(SIGUSR2, {SIG_IGN, \[HUP INT\], SA_RESTART}, {SIG_DFL, \[\], 0}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next}
+
+# Test 2.
+NR == 2 && /^rt_sigaction\(SIGUSR2, {0x[0-9a-f]+, \[QUIT TERM\], SA_RESTORER\|SA_SIGINFO, 0x[0-9a-f]+}, {SIG_IGN, \[HUP INT\], SA_RESTORER\|SA_RESTART, 0x[0-9a-f]+}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next}
+NR == 2 && /^rt_sigaction\(SIGUSR2, {0x[0-9a-f]+, \[QUIT TERM\], SA_SIGINFO}, {SIG_IGN, \[HUP INT\], SA_RESTART}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next}
+
+# Test 3.
+NR == 3 && /^rt_sigaction\(SIGUSR2, {SIG_DFL, \[\], SA_RESTORER, 0x[0-9a-f]+}, {0x[0-9a-f]+, \[QUIT TERM\], SA_RESTORER\|SA_SIGINFO, 0x[0-9a-f]+}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next}
+NR == 3 && /^rt_sigaction\(SIGUSR2, {SIG_DFL, \[\], 0}, {0x[0-9a-f]+, \[QUIT TERM\], SA_SIGINFO}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next}
+
+# The last line.
+NR == 4 && /^\+\+\+ exited with 0 \+\+\+$/ {next}
+
+{
+ print "Line " NR " does not match:"
+ print
+ exit 1
+}
diff --git a/tests/sigaction.c b/tests/sigaction.c
new file mode 100644
index 0000000..82666f9
--- /dev/null
+++ b/tests/sigaction.c
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+static void handle_signal(int no)
+{
+ _exit(128 + no);
+}
+
+int
+main(void)
+{
+ struct sigaction sa, sa1, sa2, sa3;
+
+ sa.sa_handler = SIG_IGN;
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, SIGHUP);
+ sigaddset(&sa.sa_mask, SIGINT);
+ sa.sa_flags = SA_RESTART;
+ assert(!sigaction(SIGUSR2, &sa, &sa1));
+
+ sa.sa_handler = handle_signal;
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, SIGQUIT);
+ sigaddset(&sa.sa_mask, SIGTERM);
+ sa.sa_flags = SA_SIGINFO;
+ assert(!sigaction(SIGUSR2, &sa, &sa2));
+
+ sa.sa_handler = SIG_DFL;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ assert(!sigaction(SIGUSR2, &sa, &sa3));
+
+ return 0;
+}
diff --git a/tests/sigaction.sh b/tests/sigaction.sh
new file mode 100755
index 0000000..33732e0
--- /dev/null
+++ b/tests/sigaction.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Check rt_sigaction decoding.
+
+. "${srcdir=.}/init.sh"
+
+check_prog awk
+
+./sigaction ||
+ fail_ 'sigaction failed'
+
+args="-o $LOG -ert_sigaction ./sigaction"
+$STRACE $args ||
+ fail_ "strace $args failed"
+
+awk -f "$srcdir"/sigaction.awk $LOG ||
+ { cat $LOG; fail_ 'unexpected output'; }
+
+exit 0