[PATCH 1/4] tests: add sethostname.test

Fei Jie feij.fnst at cn.fujitsu.com
Thu Mar 31 08:06:49 UTC 2016


* tests/sethostname.c: New file.
* tests/sethostname.test: New test.
* tests/.gitignore: Add sethostname.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add sethostname.test.
---
 tests/.gitignore       |  1 +
 tests/Makefile.am      |  2 ++
 tests/sethostname.c    | 38 ++++++++++++++++++++++++++++++++++++++
 tests/sethostname.test |  6 ++++++
 4 files changed, 47 insertions(+)
 create mode 100644 tests/sethostname.c
 create mode 100755 tests/sethostname.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 92ab696..b709f49 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -118,6 +118,7 @@ select
 sendfile
 sendfile64
 set_ptracer_any
+sethostname
 sigaction
 sigaltstack
 signalfd
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 29d7873..98be3a4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -167,6 +167,7 @@ check_PROGRAMS = \
 	sendfile \
 	sendfile64 \
 	set_ptracer_any \
+	sethostname \
 	sigaction \
 	sigaltstack \
 	signalfd \
@@ -343,6 +344,7 @@ DECODER_TESTS = \
 	select.test \
 	sendfile.test \
 	sendfile64.test \
+	sethostname.test \
 	sigaction.test \
 	sigaltstack.test \
 	signalfd.test \
diff --git a/tests/sethostname.c b/tests/sethostname.c
new file mode 100644
index 0000000..8b4eca2
--- /dev/null
+++ b/tests/sethostname.c
@@ -0,0 +1,38 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_sethostname
+
+# include <errno.h>
+# include <stdio.h>
+# include <sys/utsname.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	static const char *hostname = NULL;
+	int rc = syscall(__NR_sethostname, hostname, _UTSNAME_LENGTH - 1);
+	const char *errno_text;
+	switch (errno) {
+		case ENOSYS:
+			errno_text = "ENOSYS";
+			break;
+		case EPERM:
+			errno_text = "EPERM";
+			break;
+		default:
+			errno_text = "EFAULT";
+	}
+	printf("sethostname(NULL, %d) = %d %s (%m)\n",
+	       _UTSNAME_LENGTH - 1, rc, errno_text);
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_sethostname")
+
+#endif
diff --git a/tests/sethostname.test b/tests/sethostname.test
new file mode 100755
index 0000000..78f8c58
--- /dev/null
+++ b/tests/sethostname.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check sethostname syscall decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a22
-- 
1.8.3.1







More information about the Strace-devel mailing list