[PATCH v4 1/2] tests: add xetpriority.test

Fei Jie feij.fnst at cn.fujitsu.com
Thu Mar 10 02:41:30 UTC 2016


* resource.c (SYS_FUNC(getpriority)): Print the second syscall
argument using %d format.
* resource.c (SYS_FUNC(setpriority)): Print the second syscall
argument using %d format.
* tests/xetpriority.c: New file.
* tests/xetpriority.test: New test.
* tests/.gitignore: Add xetpriority.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add xetpriority.test.
---
 resource.c             |  4 ++--
 tests/.gitignore       |  1 +
 tests/Makefile.am      |  2 ++
 tests/xetpriority.c    | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xetpriority.test | 11 +++++++++++
 5 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 tests/xetpriority.c
 create mode 100755 tests/xetpriority.test

diff --git a/resource.c b/resource.c
index c68f045..9aacfbe 100644
--- a/resource.c
+++ b/resource.c
@@ -184,7 +184,7 @@ SYS_FUNC(osf_getrusage)
 SYS_FUNC(getpriority)
 {
 	printxval(priorities, tcp->u_arg[0], "PRIO_???");
-	tprintf(", %lu", tcp->u_arg[1]);
+	tprintf(", %d", (int) tcp->u_arg[1]);
 
 	return RVAL_DECODED;
 }
@@ -192,7 +192,7 @@ SYS_FUNC(getpriority)
 SYS_FUNC(setpriority)
 {
 	printxval(priorities, tcp->u_arg[0], "PRIO_???");
-	tprintf(", %lu, %d", tcp->u_arg[1], (int) tcp->u_arg[2]);
+	tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
 
 	return RVAL_DECODED;
 }
diff --git a/tests/.gitignore b/tests/.gitignore
index 4b9595d..ca392cb 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -140,4 +140,5 @@ xattr
 xet_robust_list
 xetitimer
 xetpgid
+xetpriority
 xettimeofday
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 21d07cd..5f9d67e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -188,6 +188,7 @@ check_PROGRAMS = \
 	xet_robust_list \
 	xetitimer \
 	xetpgid \
+	xetpriority \
 	xettimeofday \
 	# end of check_PROGRAMS
 
@@ -346,6 +347,7 @@ TESTS = \
 	xet_robust_list.test \
 	xetitimer.test \
 	xetpgid.test \
+	xetpriority.test \
 	xettimeofday.test \
 	\
 	count.test \
diff --git a/tests/xetpriority.c b/tests/xetpriority.c
new file mode 100644
index 0000000..9a144ba
--- /dev/null
+++ b/tests/xetpriority.c
@@ -0,0 +1,51 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#if defined __NR_getpriority && defined __NR_setpriority
+
+# include <errno.h>
+# include <stdio.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	const int pid = getpid();
+	int rc = syscall(__NR_getpriority, PRIO_PROCESS,
+			 (unsigned long) 0xffffffff00000000 | pid);
+	printf("getpriority(PRIO_PROCESS, %d) = %d\n",
+	       pid, rc);
+
+	rc = syscall(__NR_setpriority, PRIO_PROCESS,
+	     (unsigned long) 0xffffffff00000000 | pid,
+	     (unsigned long) 0xffffffff00000000);
+
+	printf("setpriority(PRIO_PROCESS, %d, 0) = ", pid);
+	if (rc == 0) {
+		printf("%d\n", rc);
+	} else {
+		const char *errno_text;
+		switch (errno) {
+			case EACCES:
+				errno_text = "EACCES";
+				break;
+			case ENOSYS:
+				errno_text = "ENOSYS";
+				break;
+			default:
+				errno_text = "EPERM";
+		}
+		printf("%d %s (%m)\n", rc, errno_text);
+	}
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_getpriority && _NR_setpriority")
+
+#endif
diff --git a/tests/xetpriority.test b/tests/xetpriority.test
new file mode 100755
index 0000000..f9b0251
--- /dev/null
+++ b/tests/xetpriority.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check getpriority and setpriority syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -egetpriority,setpriority -a29 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list