]> granicus.if.org Git - procps-ng/commitdiff
tests: add SCHED_BATCH test
authorMike Fleetwood <mike.fleetwood@googlemail.com>
Sun, 25 Sep 2011 09:15:43 +0000 (05:15 -0400)
committerSami Kerola <kerolasa@iki.fi>
Mon, 9 Jan 2012 20:37:41 +0000 (21:37 +0100)
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=741090
Acked-by:: Jaromir Capik <jcapik@redhat.com>
Acked-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
testsuite/.gitignore
testsuite/Makefile.am
testsuite/ps.test/ps_sched_batch.exp [new file with mode: 0644]
testsuite/ps.test/test-schedbatch.c [new file with mode: 0644]

index 96ef0306bf76213216bb105b6916aef59d69a425..b14d968d732331d07c0915f71264f553efb948b1 100644 (file)
@@ -2,3 +2,4 @@
 *.sum
 site.bak
 site.exp
+test-schedbatch
index d1682ac196c407d17a7c4d973a918bdb94598004..3f79532349b2db0baabf20c956a92c17337eb177 100644 (file)
@@ -4,6 +4,10 @@ export DEJAGNU
 # Programs that are expected across the board.
 DEJATOOL =
 
+noinst_PROGRAMS = test-schedbatch
+
+test_schedbatch_SOURCES = ps.test/test-schedbatch.c
+
 if LINUX
 # These should be in defined in 'across the board' scope, but are
 # temporarily disabled on other than linux systems, see commit
@@ -35,6 +39,7 @@ EXTRA_DIST = \
     pmap.test/pmap.exp \
     ps.test/ps_output.exp \
     ps.test/ps_personality.exp \
+    ps.test/ps_sched_batch.exp \
     pwdx.test/pwdx.exp \
     slabtop.test/slabtop.exp \
     sysctl.test/sysctl_read.exp \
diff --git a/testsuite/ps.test/ps_sched_batch.exp b/testsuite/ps.test/ps_sched_batch.exp
new file mode 100644 (file)
index 0000000..e0c31ff
--- /dev/null
@@ -0,0 +1,12 @@
+#
+# check the ps SCHED_BATCH scheduler policy output
+#
+set ps "${topdir}ps/pscommand"
+set schedbatch "${topdir}testsuite/test-schedbatch"
+
+spawn $schedbatch 18
+
+set test "ps SCHED_BATCH scheduler"
+spawn $ps --no-header -o comm,cls,nice -a
+expect_pass "$test" "\\s+test-schedbatch\\s+B\\s+18"
+untested "$test"
diff --git a/testsuite/ps.test/test-schedbatch.c b/testsuite/ps.test/test-schedbatch.c
new file mode 100644 (file)
index 0000000..13cd6f3
--- /dev/null
@@ -0,0 +1,39 @@
+/* test-schedbatch.c - Create a process using SCHED_BATCH scheduler
+ * policy and nice value.
+ * Compile: gcc -o test-schedbatch -Wall test-schedbatch.c
+ * Usage:   ./test-schedbatch [ <NICE> ]
+ *
+ * Author: Mike Fleetwood
+ * https://bugzilla.redhat.com/show_bug.cgi?id=741090
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sched.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+int main(int argc, const char *argv[])
+{
+       int nice = 19;
+       struct sched_param sp;
+       char msg[50];
+
+       if (argc >= 2) {
+               nice = atoi(argv[1]);
+       }
+       sp.sched_priority = 0;
+       if (sched_setscheduler(0, SCHED_BATCH, &sp)) {
+               perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}");
+       }
+       if (setpriority(PRIO_PROCESS, 0, nice) || errno) {
+               (void)snprintf(msg, sizeof(msg),
+                              "setpriority(PRIO_PROCESS, 0, %d)", nice);
+               perror(msg);
+       }
+       while (1) {
+               getchar();
+       }
+}