tests: add a test for "resuming interrupted nanosleep"

* tests/restart_syscall.test: New test.
* tests/restart_syscall.expected: New file.
* tests/restart_syscall_unknown.expected: Likewise.
* tests/Makefile.am (TESTS): Add restart_syscall.test.
(EXTRA_DIST): Add restart_syscall.expected
(TEST_LOG_COMPILER): Change to "env".
(OS, ARCH, AM_TEST_LOG_FLAGS): Define.
and restart_syscall_unknown.expected.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e5dae02..7ace705 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,7 @@
 # Automake input for strace tests.
 
+OS = linux
+ARCH = @arch@
 AM_CFLAGS = $(WARN_CFLAGS)
 AM_CPPFLAGS = -I$(top_builddir)/$(OS)/$(ARCH) \
 	      -I$(top_srcdir)/$(OS)/$(ARCH) \
@@ -91,11 +93,13 @@
 	detach-sleeping.test \
 	detach-stopped.test \
 	detach-running.test \
+	restart_syscall.test \
 	strace-k.test
 
 net-fd.log: net.log
 
-TEST_LOG_COMPILER = $(srcdir)/run.sh
+TEST_LOG_COMPILER = env
+AM_TEST_LOG_FLAGS = STRACE_ARCH=$(ARCH) $(srcdir)/run.sh
 
 EXTRA_DIST = init.sh run.sh match.awk \
 	     caps.awk \
@@ -112,6 +116,8 @@
 	     net-yy-accept.awk \
 	     net-yy-connect.awk \
 	     pipe.expected \
+	     restart_syscall.expected \
+	     restart_syscall_unknown.expected \
 	     select.awk \
 	     sigaction.awk \
 	     statfs.expected \
diff --git a/tests/restart_syscall.expected b/tests/restart_syscall.expected
new file mode 100644
index 0000000..af9267d
--- /dev/null
+++ b/tests/restart_syscall.expected
@@ -0,0 +1,2 @@
+restart_syscall(<... resuming interrupted nanosleep ...>) = 0
++++ exited with 0 +++
diff --git a/tests/restart_syscall.test b/tests/restart_syscall.test
new file mode 100755
index 0000000..5ae3a1d
--- /dev/null
+++ b/tests/restart_syscall.test
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Check how "resuming interrupted nanosleep" works.
+
+. "${srcdir=.}/init.sh"
+
+check_prog sleep
+check_prog grep
+run_strace -enanosleep sleep 1
+grep nanosleep < "$LOG" > /dev/null ||
+	framework_skip_ 'sleep does not use nanosleep'
+
+./set_ptracer_any sleep 2 &
+sleep 1
+run_strace -q -erestart_syscall -p $!
+
+case "$STRACE_ARCH" in
+	alpha|mips|or1k|s390|s390x)
+		# These architectures use the same register
+		# both for syscall number and syscall return code.
+		match_diff "$LOG" "$srcdir/restart_syscall_unknown.expected"
+		;;
+	*) match_diff
+		;;
+esac
diff --git a/tests/restart_syscall_unknown.expected b/tests/restart_syscall_unknown.expected
new file mode 100644
index 0000000..5f16895
--- /dev/null
+++ b/tests/restart_syscall_unknown.expected
@@ -0,0 +1,2 @@
+restart_syscall(<... resuming interrupted system call ...>) = 0
++++ exited with 0 +++