[PATCH 1/2] Self checking test for sigaction output

Chris Dearman chris.dearman at imgtec.com
Tue Dec 10 03:58:41 UTC 2013


Tested on MIPS O32 big/little endian, MIPS N64 big endian and x86-64.

Signed-off-by: Chris Dearman <chris.dearman at imgtec.com>
---
 tests/Makefile.am         |  4 +--
 tests/sigaction-check     | 31 ++++++++++++++++++++++++
 tests/sigaction-check.awk | 31 ++++++++++++++++++++++++
 tests/sigaction.c         | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+), 2 deletions(-)
 create mode 100755 tests/sigaction-check
 create mode 100644 tests/sigaction-check.awk
 create mode 100644 tests/sigaction.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index f8f8054..9f41226 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,10 +2,10 @@
 
 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 \
-	detach-sleeping detach-stopped detach-running
+	detach-sleeping detach-stopped detach-running sigaction-check
 
 LOG_COMPILER = $(srcdir)/run.sh
 
diff --git a/tests/sigaction-check b/tests/sigaction-check
new file mode 100755
index 0000000..1f6fc1b
--- /dev/null
+++ b/tests/sigaction-check
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Check how sigaction arguments are reported
+
+. "${srcdir=.}/init.sh"
+
+check_prog rm
+check_prog awk
+
+rm -f $LOG.*
+
+./sigaction ||
+	fail_ 'sigaction failed'
+
+args="-tt -ff -o $LOG -ert_sigaction ./sigaction"
+$STRACE $args ||
+	fail_ "strace $args failed"
+
+"$srcdir"/../strace-log-merge $LOG > $LOG || {
+	cat $LOG
+	fail_ 'strace-log-merge failed'
+}
+
+rm -f $LOG.*
+
+awk -f "$srcdir"/sigaction-check.awk $LOG || {
+	cat $LOG
+	fail_ 'unexpected output'
+}
+
+exit 0
diff --git a/tests/sigaction-check.awk b/tests/sigaction-check.awk
new file mode 100644
index 0000000..4f18b5a
--- /dev/null
+++ b/tests/sigaction-check.awk
@@ -0,0 +1,31 @@
+# Patterns work for MIPS, x86
+
+/rt_sigaction\(SIGUSR2, {SIG_IGN, \[HUP INT\], (SA_RESTORER\|)?SA_RESTART(, 0x[0-9a-f]+)?}, {SIG_DFL, \[\], 0}, (8|16)\) = 0$/ {
+  # print "line matches with pattern 1"
+  next
+}
+
+/rt_sigaction\(SIGUSR2, {0x[0-9a-f]+, \[QUIT ILL\], (SA_RESTORER\|)?SA_SIGINFO(, 0x[0-9a-f]+)?}, {SIG_IGN, \[HUP INT\], (SA_RESTORER\|)?SA_RESTART(, 0x[0-9a-f]+)?}, (8|16)\) = 0$/ {
+  # print "line matches with pattern 2"
+  next
+}
+
+/rt_sigaction\(SIGUSR2, {SIG_DFL, \[\], (SA_RESTORER, 0x[0-9a-f]+|0)}, {0x[0-9a-f]+, \[QUIT ILL\], (SA_RESTORER\|)?SA_SIGINFO(, 0x[0-9a-f]+)?}, (8|16)\) = 0$/ {
+  # print "line matches with pattern 3"
+  next
+}
+
+/exit_group\(0\) += \?$/ {
+  # print "line matches pattern 4"
+  next
+}
+
+/\+\+\+ exited with 0 \+\+\+$/ {
+  # print "line matches pattern 5"
+  next
+}
+
+{
+  print "Unmatched input"
+  exit 1
+}
diff --git a/tests/sigaction.c b/tests/sigaction.c
new file mode 100644
index 0000000..5519642
--- /dev/null
+++ b/tests/sigaction.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+void handle_signal(int signal)
+{
+        fprintf(stderr, "Unexpected signal %d\n", signal);
+        exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+        struct sigaction sa;
+
+        sa.sa_handler = SIG_IGN;
+        sigemptyset(&sa.sa_mask);
+        sigaddset(&sa.sa_mask, 1);
+        sigaddset(&sa.sa_mask, 2);
+        sa.sa_flags = SA_RESTART;
+
+        /*
+         * Expected output:
+         * MIPS: rt_sigaction(SIGUSR2, {SIG_IGN, [HUP INT], SA_RESTART}, {SIG_DFL, [], 0}, 16) = 0
+         * x86:  rt_sigaction(SIGUSR2, {SIG_IGN, [HUP INT], SA_RESTORER|SA_RESTART, 0x7f094daa5be0}, {SIG_DFL, [], 0}, 8) = 0
+         */
+        if (sigaction(SIGUSR2, &sa, &sa)) {
+                perror("sigaction 1");
+                exit(1);
+        }
+
+        sa.sa_handler = handle_signal;
+        sigemptyset(&sa.sa_mask);
+        sigaddset(&sa.sa_mask, 3);
+        sigaddset(&sa.sa_mask, 4);
+        sa.sa_flags = SA_SIGINFO;
+
+        /*
+         * Expected output:
+         * MIPS: rt_sigaction(SIGUSR2, {0x400730, [QUIT ILL], SA_SIGINFO}, {SIG_IGN, [HUP INT], SA_RESTART}, 16) = 0
+         * x86:  rt_sigaction(SIGUSR2, {0x4006f4, [QUIT ILL], SA_RESTORER|SA_SIGINFO, 0x7f094daa5be0}, {SIG_IGN, [HUP INT], SA_RESTORER|SA_RESTART, 0x7f094daa5be0}, 8) = 0
+          */
+        if (sigaction(SIGUSR2, &sa, &sa)) {
+                perror("sigaction 2");
+                exit(1);
+        }
+
+        sa.sa_handler = SIG_DFL;
+        sigemptyset(&sa.sa_mask);
+        sa.sa_flags = 0;
+
+        /*
+         * Expected output:
+         * MIPS: rt_sigaction(SIGUSR2, {SIG_DFL, [], 0}, {0x400730, [QUIT ILL], SA_SIGINFO}, 16) = 0
+         * x86:  rt_sigaction(SIGUSR2, {SIG_DFL, [], SA_RESTORER, 0x7f094daa5be0}, {0x4006f4, [QUIT ILL], SA_RESTORER|SA_SIGINFO, 0x7f094daa5be0}, 8) = 0
+         */
+        if (sigaction(SIGUSR2, &sa, &sa)) {
+                perror("sigaction 3");
+                exit(1);
+        }
+        return 0;
+}
-- 
1.8.3.4.837.g0bde8c0





More information about the Strace-devel mailing list