From 23d2e0b0b723b2cc64808fc2c21da27759e42c56 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 25 Sep 2011 05:15:43 -0400 Subject: [PATCH] tests: add SCHED_BATCH test Reference: https://bugzilla.redhat.com/show_bug.cgi?id=741090 Acked-by:: Jaromir Capik Acked-by: Sami Kerola Signed-off-by: Mike Fleetwood --- testsuite/.gitignore | 1 + testsuite/Makefile.am | 5 ++++ testsuite/ps.test/ps_sched_batch.exp | 12 +++++++++ testsuite/ps.test/test-schedbatch.c | 39 ++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 testsuite/ps.test/ps_sched_batch.exp create mode 100644 testsuite/ps.test/test-schedbatch.c diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 96ef0306..b14d968d 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -2,3 +2,4 @@ *.sum site.bak site.exp +test-schedbatch diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index d1682ac1..3f795323 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -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 index 00000000..e0c31ffd --- /dev/null +++ b/testsuite/ps.test/ps_sched_batch.exp @@ -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 index 00000000..13cd6f33 --- /dev/null +++ b/testsuite/ps.test/test-schedbatch.c @@ -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 [ ] + * + * Author: Mike Fleetwood + * https://bugzilla.redhat.com/show_bug.cgi?id=741090 + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +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(); + } +}