From: Dmitry V. Levin Date: Tue, 7 Jan 2014 19:32:32 +0000 (+0000) Subject: tests: add a test for rt_sigaction output X-Git-Tag: v4.9~148 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66a15a5bb832032591e57a4fc2c6ec70bce0732a;p=strace 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. --- diff --git a/tests/.gitignore b/tests/.gitignore index a8b1cba1..c400a79b 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 f8f80543..d8262f07 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 00000000..ff89e3e1 --- /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 00000000..82666f9e --- /dev/null +++ b/tests/sigaction.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +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 00000000..33732e02 --- /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