tests: add a test for sigreturn/rt_sigreturn decoding

Convert test/sigreturn.c into a regular test.

* test/Makefile (PROGS): Remove sigreturn.
* test/.gitignore: Likewise.
* test/sigreturn.c: Rewrite to ...
* tests/sigreturn.c: ... new file.
* tests/sigreturn.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add sigreturn.
(TESTS): Add sigreturn.test.
* tests/.gitignore: Add sigreturn.
diff --git a/test/.gitignore b/test/.gitignore
index b91be8b..b69ccab 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -6,7 +6,6 @@
 seccomp
 sig
 sigkill_rain
-sigreturn
 skodic
 threaded_execve
 ubi
diff --git a/test/Makefile b/test/Makefile
index 419b5ca..56fcd4c 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -3,7 +3,7 @@
 PROGS = \
     vfork fork sig skodic clone leaderkill childthread \
     sigkill_rain wait_must_be_interruptible threaded_execve \
-    mtd ubi sigreturn seccomp
+    mtd ubi seccomp
 
 all: $(PROGS)
 
diff --git a/test/sigreturn.c b/test/sigreturn.c
deleted file mode 100644
index 246a3ce..0000000
--- a/test/sigreturn.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Check that strace output contains RT_1 RT_3 RT_31 RT_32 here:
- *  rt_sigprocmask(SIG_BLOCK, [CHLD RT_1 RT_3 RT_31 RT_32], NULL, 8) = 0
- * and here:
- *  sigreturn() (mask [CHLD RT_1 RT_3 RT_31 RT_32]) = 0
- *
- * On x86, both 32-bit and 64-bit strace needs to be checked.
- */
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-
-void null_handler(int sig)
-{
-}
-
-int main(int argc, char *argv[])
-{
-	sigset_t set;
-	sigemptyset(&set);
-	sigaddset(&set, SIGCHLD);
-	sigaddset(&set, 33);
-	sigaddset(&set, 35);
-	sigaddset(&set, 63);
-	sigaddset(&set, 64);
-	sigprocmask(SIG_BLOCK, &set, NULL);
-	signal(SIGWINCH, null_handler);
-	raise(SIGWINCH);
-	return 0;
-}
diff --git a/tests/.gitignore b/tests/.gitignore
index a55b556..8efb0ef 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -15,6 +15,7 @@
 select
 set_ptracer_any
 sigaction
+sigreturn
 stack-fcall
 stat
 stat32
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 36a187d..ff5e136 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@
 	select \
 	set_ptracer_any \
 	sigaction \
+	sigreturn \
 	stack-fcall \
 	stat \
 	stat32 \
@@ -57,6 +58,7 @@
 	scm_rights-fd.test \
 	select.test \
 	sigaction.test \
+	sigreturn.test \
 	stat.test \
 	stat32-v.test \
 	stat64-v.test \
diff --git a/tests/sigreturn.c b/tests/sigreturn.c
new file mode 100644
index 0000000..252f152
--- /dev/null
+++ b/tests/sigreturn.c
@@ -0,0 +1,24 @@
+#include <stdlib.h>
+#include <signal.h>
+
+static void handler(int sig)
+{
+}
+
+#define RT_0 32
+
+int main(void) {
+	sigset_t set;
+	sigemptyset(&set);
+	sigaddset(&set, SIGUSR2);
+	sigaddset(&set, SIGCHLD);
+	sigaddset(&set, RT_0 +  2);
+	sigaddset(&set, RT_0 +  3);
+	sigaddset(&set, RT_0 +  4);
+	sigaddset(&set, RT_0 + 31);
+	sigaddset(&set, RT_0 + 32);
+	sigprocmask(SIG_SETMASK, &set, NULL);
+	signal(SIGUSR1, handler);
+	raise(SIGUSR1);
+	return 0;
+}
diff --git a/tests/sigreturn.test b/tests/sigreturn.test
new file mode 100755
index 0000000..0395e82
--- /dev/null
+++ b/tests/sigreturn.test
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Check rt_sigprocmask and sigreturn/rt_sigreturn decoding.
+
+. "${srcdir=.}/init.sh"
+
+check_prog grep
+
+./sigreturn ||
+	fail_ 'sigreturn failed'
+
+args='-esignal ./sigreturn'
+$STRACE -o "$LOG" $args ||
+	fail_ "$STRACE $args does not work"
+
+grep_log()
+{
+	LC_ALL=C grep -E -x -e "$*" < "$LOG" > /dev/null || {
+		cat "$LOG"
+		fail_ "$STRACE $args output mismatch"
+	}
+}
+
+mask='\[(USR2 CHLD|CHLD USR2) RT_2 RT_3 RT_4 RT_31 RT_32\]'
+rt_sigprocmask='rt_sigprocmask\(SIG_SETMASK, '"$mask"', NULL, [[:digit:]]+\) += 0'
+osf_sigprocmask='osf_sigprocmask\(SIG_SETMASK, '"$mask"'\) += 0 +\(old mask \[[^]]*\]\)'
+grep_log "$rt_sigprocmask|$osf_sigprocmask"
+grep_log '(rt_)?sigreturn\((\{mask='"$mask"'\})?\) += 0'
+
+
+exit 0