[PATCH v3] tests: add sched_xetscheduler.test

Fei Jie feij.fnst at cn.fujitsu.com
Tue Mar 15 08:38:17 UTC 2016


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

diff --git a/tests/.gitignore b/tests/.gitignore
index b89796a..ecbb17e 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -100,6 +100,7 @@ sched_get_priority_mxx
 sched_xetaffinity
 sched_xetattr
 sched_xetparam
+sched_xetscheduler
 scm_rights
 seccomp
 select
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 59e7e78..2a8b147 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -148,6 +148,7 @@ check_PROGRAMS = \
 	sched_xetaffinity \
 	sched_xetattr \
 	sched_xetparam \
+	sched_xetscheduler \
 	scm_rights \
 	seccomp \
 	select \
@@ -317,6 +318,7 @@ TESTS = \
 	sched_xetaffinity.test \
 	sched_xetattr.test \
 	sched_xetparam.test \
+	sched_xetscheduler.test \
 	scm_rights-fd.test \
 	seccomp.test \
 	select.test \
diff --git a/tests/sched_xetscheduler.c b/tests/sched_xetscheduler.c
new file mode 100644
index 0000000..dbf3c1f
--- /dev/null
+++ b/tests/sched_xetscheduler.c
@@ -0,0 +1,64 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#if defined __NR_sched_getscheduler && defined __NR_sched_setscheduler
+
+# include <errno.h>
+# include <sched.h>
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	struct sched_param *const param = tail_alloc(sizeof(struct sched_param));
+	int rc = syscall(__NR_sched_getscheduler, 0);
+	const char *scheduler;
+	switch (rc) {
+		case SCHED_FIFO:
+			scheduler = "SCHED_FIFO";
+			break;
+		case SCHED_RR:
+			scheduler = "SCHED_RR";
+			break;
+# ifdef SCHED_BATCH
+		case SCHED_BATCH:
+			scheduler = "SCHED_BATCH";
+			break;
+# endif
+# ifdef SCHED_IDLE
+		case SCHED_IDLE:
+			scheduler = "SCHED_IDLE";
+			break;
+# endif
+# ifdef SCHED_ISO
+		case SCHED_ISO:
+			scheduler = "SCHED_ISO";
+			break;
+# endif
+# ifdef SCHED_DEADLINE
+		case SCHED_DEADLINE:
+			scheduler = "SCHED_DEADLINE";
+			break;
+# endif
+		default:
+			scheduler = "SCHED_OTHER";
+	}
+	printf("sched_getscheduler(0) = %d (%s)\n",
+	       rc, scheduler);
+
+	param->sched_priority = -1;
+	rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, param);
+	printf("sched_setscheduler(0, SCHED_FIFO, [%d]) = %d %s (%m)\n",
+	       param->sched_priority, rc,
+	       errno == EPERM ? "EPERM" : "EINVAL");
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_sched_getscheduler && __NR_sched_setscheduler")
+
+#endif
diff --git a/tests/sched_xetscheduler.test b/tests/sched_xetscheduler.test
new file mode 100755
index 0000000..15d6d73
--- /dev/null
+++ b/tests/sched_xetscheduler.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Check sched_getscheduler and sched_setscheduler syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -esched_getscheduler,sched_setscheduler -a22 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
-- 
1.8.3.1







More information about the Strace-devel mailing list