[PATCH v2 2/2] tests: add syslog.test

Fei Jie feij.fnst at cn.fujitsu.com
Thu Mar 17 09:32:12 UTC 2016


* tests/syslog.c: New file.
* tests/syslog.test: New test.
* tests/.gitignore: Add syslog.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add syslog.test.
---
 tests/.gitignore  |  1 +
 tests/Makefile.am |  2 ++
 tests/syslog.c    | 40 ++++++++++++++++++++++++++++++++++++++++
 tests/syslog.test | 11 +++++++++++
 4 files changed, 54 insertions(+)
 create mode 100644 tests/syslog.c
 create mode 100755 tests/syslog.test

diff --git a/tests/.gitignore b/tests/.gitignore
index d5c4a2c..3edcb70 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -120,6 +120,7 @@ stat
 stat64
 statfs
 sysinfo
+syslog
 tee
 time
 timer_create
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c6c293e..a5a4c29 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -168,6 +168,7 @@ check_PROGRAMS = \
 	stat64 \
 	statfs \
 	sysinfo \
+	syslog \
 	tee \
 	time \
 	timer_create \
@@ -338,6 +339,7 @@ TESTS = \
 	statfs.test \
 	sun_path.test \
 	sysinfo.test \
+	syslog.test \
 	tee.test \
 	time.test \
 	timer_create.test \
diff --git a/tests/syslog.c b/tests/syslog.c
new file mode 100644
index 0000000..8f909d8
--- /dev/null
+++ b/tests/syslog.c
@@ -0,0 +1,40 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_syslog
+
+# include <errno.h>
+# include <stdio.h>
+# include <unistd.h>
+
+# define SYSLOG_ACTION_READ 2
+
+static char buf[1024];
+
+int
+main(void)
+{
+	int rc = syscall(__NR_syslog, SYSLOG_ACTION_READ, buf, -1);
+	const char *errno_text;
+	switch (errno) {
+		case ENOSYS:
+			errno_text = "ENOSYS";
+			break;
+		case EPERM:
+			errno_text = "EPERM";
+			break;
+		default:
+			errno_text = "EINVAL";
+	}
+	printf("syslog(SYSLOG_ACTION_READ, %p, -1) = %d %s (%m)\n",
+	       buf, rc, errno_text);
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_syslog")
+
+#endif
diff --git a/tests/syslog.test b/tests/syslog.test
new file mode 100755
index 0000000..cc43806
--- /dev/null
+++ b/tests/syslog.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check syslog syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -esyslog -a36 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list