]> granicus.if.org Git - strace/commitdiff
tests: add a test for rt_sigaction output
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 7 Jan 2014 19:32:32 +0000 (19:32 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 8 Jan 2014 17:48:25 +0000 (17:48 +0000)
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.

tests/.gitignore
tests/Makefile.am
tests/sigaction.awk [new file with mode: 0644]
tests/sigaction.c [new file with mode: 0644]
tests/sigaction.sh [new file with mode: 0755]

index a8b1cba1eae443be8fdd171f2460cbf30a634112..c400a79b88556559dd0fa752d91857d43fa079bf 100644 (file)
@@ -1,5 +1,6 @@
 net-accept-connect
 set_ptracer_any
+sigaction
 *.log
 *.log.*
 *.o
index f8f80543eb1303d82537f098f7f2faca81404ee4..d8262f0791712681a2dd17f7c88b873b05c50b70 100644 (file)
@@ -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 (file)
index 0000000..ff89e3e
--- /dev/null
@@ -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 (file)
index 0000000..82666f9
--- /dev/null
@@ -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 (executable)
index 0000000..33732e0
--- /dev/null
@@ -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