summaryrefslogtreecommitdiffstats
path: root/testsuite/ps.test
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/ps.test')
-rw-r--r--testsuite/ps.test/ps_output.exp63
-rw-r--r--testsuite/ps.test/ps_personality.exp18
-rw-r--r--testsuite/ps.test/ps_sched_batch.exp11
-rw-r--r--testsuite/ps.test/test-schedbatch.c46
4 files changed, 138 insertions, 0 deletions
diff --git a/testsuite/ps.test/ps_output.exp b/testsuite/ps.test/ps_output.exp
new file mode 100644
index 0000000..ff2a233
--- /dev/null
+++ b/testsuite/ps.test/ps_output.exp
@@ -0,0 +1,63 @@
+#
+# Dejagnu tests for ps (output options) - part of procps
+#
+set ps ${topdir}src/ps/pscommand
+
+set mypid [pid]
+set not_ppid [ expr { $mypid + 1 } ]
+set uid [ exec id -u ]
+set not_uid [ expr { $uid + 1 } ]
+set gid [ exec id -g ]
+set not_gid [ expr { $gid + 1 } ]
+
+# All the fields
+# Cannot do args,cmd,comm
+set ps_digit "\\d+\\s*"
+set ps_state "\[A-Z<sl+\]\\s*"
+#set ps_pct "\\d{1,2}\\.\\d\\s*"
+set ps_pct "\\d"
+set ps_hex "\[0-9a-f\]\\s*"
+set ps_time "\\d{1,3}:\\d{2}\\s*"
+set ps_time "\(\d+-\)?\\\d{1,3}:\\d{2}\\s*"
+set ps_class "\[A-Z?-\]\\s*"
+
+set flag_match {
+ "%cpu,pcpu,%mem,pmem" "%CPU\\s+%CPU\\s+%MEM\\s+%MEM\\s+\(\(\\d+\.\\d+\\s*\){4}\)+$"
+ "blocked,sig_block,sigmask,caught,sigcatch,sig_catch" "\(BLOCKED\\s+\){3}\(CAUGHT\\s+\){2}CATCHED\\s+\(<?\[0-9a-f\]+\\s*\)+$"
+ "bsdstart,start,lstart" "\\s*START\\s+STARTED\\s+STARTED\\s+\(\\s*\(\[A-Z\]\[a-z\]{2} \\d+|\\d+:\\d{2}\)\\s+\(\[A-Z\]\[a-z\]{2} \\d+|\\d+:\\d{2}:\\d{2}\)\\s+\[A-Z\]\[a-z\]{2} \[A-Z\]\[a-z\]{2}\\s+\\d+ \\d{2}:\\d{2}:\\d{2} \\d{4}\\s*\)+$"
+ "bsdtime,cputime,etime,etimes" "\\s*TIME\\s+TIME\\s+ELAPSED\\s+ELAPSED\\s*\(\\s*\\d+:\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\(\\d{2}:\)?\\d{2}:\\d{2}\\s+\\d+\\s*\)+$"
+ "user,ruser,group,rgroup,uid,ruid,gid,rgid" "\\s*USER\\s+RUSER\\s+GROUP\\s+RGROUP\\s+UID\\s+RUID\\s+GID\\s+RGID\\s+\(\(\\s*\[A-Za-z0-9_+-\]+\\s+\){4}\(\\d+\\s+\){4}\\s*\)+$"
+ "cputimes,times" "\\s*TIME\\s+TIME\\s+\\d+\\s+\\d+\\s*"
+}
+
+foreach { flag match } $flag_match {
+ set test "ps with output flag $flag"
+ spawn $ps -o $flag
+ expect_pass "$test" $match
+}
+
+set test "ps with correct AIX field"
+spawn $ps -o "%p"
+expect_pass "$test" "\\s*PID\\s+\(\\s*\\d+\\s+\)+$"
+
+set test "ps with improper AIX field"
+spawn $ps -o "%p %G{"
+expect_pass "$test" "error: improper AIX field descriptor"
+
+set test "ps with missing AIX field"
+spawn $ps -o "%p %%a"
+expect_pass "$test" "error: missing AIX field descriptor"
+
+set test "ps with unknown AIX field"
+spawn $ps -o "%p %Z"
+expect_pass "$test" "error: unknown AIX field descriptor"
+
+make_testproc
+set test "ps with c option"
+spawn $ps co command $testproc1_pid
+expect_pass "$test" "^COMMAND\\s+spcorp\\s*$"
+kill_testproc
+
+set test "ps with l and m options"
+spawn $ps -lm
+expect_fail "$test" "please report this bug"
diff --git a/testsuite/ps.test/ps_personality.exp b/testsuite/ps.test/ps_personality.exp
new file mode 100644
index 0000000..f873a19
--- /dev/null
+++ b/testsuite/ps.test/ps_personality.exp
@@ -0,0 +1,18 @@
+#
+# check the ps personalities
+#
+set ps ${topdir}src/ps/pscommand
+
+set pers_match {
+ bsd "\\s+PID\\s+TTY\\s+STAT\\s+TIME\\s+COMMAND\\r"
+ linux "\\s+PID\\s+TTY\\s+TIME\\s+CMD\\r"
+ old "\\s+PID\\s+TTY\\s+STAT\\s+TIME\\s+COMMAND\\r"
+ }
+
+foreach { pers match } $pers_match {
+ set test "ps with $pers personality"
+ set env(PS_PERSONALITY) $pers
+ spawn $ps
+ expect_pass "$test" $match
+}
+
diff --git a/testsuite/ps.test/ps_sched_batch.exp b/testsuite/ps.test/ps_sched_batch.exp
new file mode 100644
index 0000000..ff948db
--- /dev/null
+++ b/testsuite/ps.test/ps_sched_batch.exp
@@ -0,0 +1,11 @@
+#
+# check the ps SCHED_BATCH scheduler policy output
+#
+set ps "${topdir}src/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" "(?n)^test-schedbatch\\s+B\\s+18\\r?\$"
diff --git a/testsuite/ps.test/test-schedbatch.c b/testsuite/ps.test/test-schedbatch.c
new file mode 100644
index 0000000..9b4d334
--- /dev/null
+++ b/testsuite/ps.test/test-schedbatch.c
@@ -0,0 +1,46 @@
+/* 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>
+
+/* Defined in Linux headers only */
+#ifndef SCHED_BATCH
+#define SCHED_BATCH 3
+#endif
+
+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;
+#ifdef SCHED_BATCH
+ if (sched_setscheduler(0, SCHED_BATCH, &sp)) {
+ perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}");
+ }
+#endif /* SCHED_BATCH */
+ if (setpriority(PRIO_PROCESS, 0, nice) || errno) {
+ (void)snprintf(msg, sizeof(msg),
+ "setpriority(PRIO_PROCESS, 0, %d)", nice);
+ perror(msg);
+ }
+ while (1) {
+ getchar();
+ }
+}