[PATCH v2 4/4] tests: add sched_xetscheduler.test
Fei Jie
feij.fnst at cn.fujitsu.com
Thu Mar 10 09:12:25 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 | 52 +++++++++++++++++++++++++++++++++++++++++++
tests/sched_xetscheduler.test | 11 +++++++++
4 files changed, 66 insertions(+)
create mode 100644 tests/sched_xetscheduler.c
create mode 100755 tests/sched_xetscheduler.test
diff --git a/tests/.gitignore b/tests/.gitignore
index 82f08ee..2e7f72f 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -95,6 +95,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 27acefd..f68a447 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -143,6 +143,7 @@ check_PROGRAMS = \
sched_xetaffinity \
sched_xetattr \
sched_xetparam \
+ sched_xetscheduler \
scm_rights \
seccomp \
select \
@@ -307,6 +308,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..7d30e6b
--- /dev/null
+++ b/tests/sched_xetscheduler.c
@@ -0,0 +1,52 @@
+#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 __USE_GNU
+ case SCHED_BATCH:
+ scheduler = "SCHED_BATCH";
+ break;
+ case SCHED_IDLE:
+ scheduler = "SCHED_IDLE";
+ 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