tests: add ksysent.test

Check that syscall names and numbers defined in syscallent files
match kernel __NR_* constants defined by <asm/unistd.h>.

Tested on various platforms, including the following combinations
of architectures and kernel headers:

x86_64: 4.4-rc, 4.3, 4.2, 4.1, 3.19, 3.17, 3.16, 3.12, 3.11,
3.10-rhel, 2.6.32-rhel, 2.6.27-sle, 2.6.18-rhel
i386: 4.4-rc, 4.3, 4.2, 4.1, 3.19, 3.17, 3.16, 3.11,
3.10-rhel, 2.6.32-rhel, 2.6.27-sle, 2.6.18-rhel
aarch64: 4.4-rc
alpha: 4.3
arm eabi: 4.4-rc, 4.2, 4.1
hppa: 3.18
ia64: 3.18
mips o32: 4.1
ppc: 3.18
ppc64: 3.10-rhel, 2.6.32-rhel
s390: 3.18
s390x: 3.18
sparc: 4.1
sparc: 3.18
x32: 3.19

The only platform which is known at this moment to fail the test
is CentOS-5 provided by OBS.  On x86_64 instance it fails with
error: "prlimit64" syscall #300 is "fanotify_init" in syscallent.h
and on i586 it similarly fails with
error: "prlimit64" syscall #338 is "fanotify_init" in syscallent.h
So this is a real platform bug that is not likely to be worked around
on the strace side.

* tests/ksysent.c: New file.
* tests/ksysent.sed: Likewise.
* tests/ksysent.test: New test.
* tests/Makefile.am (AM_CPPFLAGS): Add -I$(builddir).
(check_PROGRAMS): Add ksysent.
(TESTS): Add ksysent.test.
(EXTRA_DIST): Add ksysent.sed.
(ksysent.h): New rule.
(BUILT_SOURCES, CLEANFILES): Add ksysent.h.
* tests/.gitignore: Add ksysent.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a13dc30..fdeb5ec 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@
 ARCH_MFLAGS =
 AM_CFLAGS = $(WARN_CFLAGS)
 AM_CPPFLAGS = $(ARCH_MFLAGS) \
+	      -I$(builddir) \
 	      -I$(top_builddir)/$(OS)/$(ARCH) \
 	      -I$(top_srcdir)/$(OS)/$(ARCH) \
 	      -I$(top_builddir)/$(OS) \
@@ -46,6 +47,7 @@
 	ipc_msgbuf \
 	ipc_sem \
 	ipc_shm \
+	ksysent \
 	llseek \
 	lseek \
 	lstat \
@@ -136,6 +138,7 @@
 TESTS = \
 	strace-f.test \
 	qual_syscall.test \
+	ksysent.test \
 	\
 	_newselect.test \
 	adjtimex.test \
@@ -264,6 +267,7 @@
 	     ip_mreq.expected \
 	     ipc.sh \
 	     ipc_msgbuf.expected \
+	     ksysent.sed \
 	     lstatx.c \
 	     memfd_create.expected \
 	     mmsg.expected \
@@ -294,4 +298,12 @@
 	     xstatx.c \
 	     $(TESTS)
 
-CLEANFILES = $(TESTS:=.tmp)
+ksysent.h: $(srcdir)/ksysent.sed
+	echo '#include <asm/unistd.h>' | \
+		$(CPP) $(AM_CPPFLAGS) $(CPPFLAGS) -dD - > $@.t1
+	LC_COLLATE=C sed -n -f $(srcdir)/ksysent.sed < $@.t1 > $@.t2
+	mv -f $@.t2 $@
+	rm -f $@.t1
+
+BUILT_SOURCES = ksysent.h
+CLEANFILES = ksysent.h $(TESTS:=.tmp)