From 451f6e61117571e6447d7c230ac6e183e8f33d50 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Wed, 23 Nov 2011 21:44:51 +1100 Subject: [PATCH 01/10] testsuite fixes --- Makefile.am | 2 +- configure.ac | 7 +++++++ testsuite/.gitignore | 2 ++ testsuite/Makefile.am | 5 +++++ testsuite/config/unix.exp | 8 ++++++++ testsuite/pwdx.test/pwdx.exp | 30 ++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 testsuite/.gitignore create mode 100644 testsuite/Makefile.am create mode 100644 testsuite/config/unix.exp create mode 100644 testsuite/pwdx.test/pwdx.exp diff --git a/Makefile.am b/Makefile.am index 5338f532..a748c7e8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ AM_CPPFLAGS = -include $(top_builddir)/config.h ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = proc ps +SUBDIRS = proc ps testsuite AM_CFLAGS = -Iproc AM_LDFLAGS = ./proc/libproc-ng.la diff --git a/configure.ac b/configure.ac index 88aaafda..c832005f 100644 --- a/configure.ac +++ b/configure.ac @@ -135,10 +135,17 @@ if test "x$enable_w_from" = xyes; then AC_DEFINE(W_SHOWFROM, 1, [enable w from field by default]) fi +if test x"$DEJAGNU" = x +then + DEJAGNU="\$(top_srcdir)/testsuite/global-conf.exp" +fi +AC_SUBST(DEJAGNU) + AC_CONFIG_FILES([ Makefile proc/Makefile proc/libproc-ng.pc ps/Makefile +testsuite/Makefile ]) AC_OUTPUT diff --git a/testsuite/.gitignore b/testsuite/.gitignore new file mode 100644 index 00000000..1e6f9352 --- /dev/null +++ b/testsuite/.gitignore @@ -0,0 +1,2 @@ +*.log +*.sum diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am new file mode 100644 index 00000000..dc57c450 --- /dev/null +++ b/testsuite/Makefile.am @@ -0,0 +1,5 @@ +AUTOMAKE_OPTIONS = dejagnu +export DEJAGNU + +DEJATOOL = \ + pwdx diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp new file mode 100644 index 00000000..d329d7ec --- /dev/null +++ b/testsuite/config/unix.exp @@ -0,0 +1,8 @@ + +proc pwdx_load { arg } { } +proc pwdx_exit {} {} +proc pwdx_version {} { + set tmp [ exec pwdx -V ] + regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version + clone_output "pwdx version $version\n" +} diff --git a/testsuite/pwdx.test/pwdx.exp b/testsuite/pwdx.test/pwdx.exp new file mode 100644 index 00000000..cd60c211 --- /dev/null +++ b/testsuite/pwdx.test/pwdx.exp @@ -0,0 +1,30 @@ + +# Run pwdx with no arguments +set test "pwdx no args" +spawn pwdx +expect { + -re "^Usage: pwdx pid\.\.\." { pass "$test" } + eof { fail "$test" } + timeout { fail "$test" } +} + +# Run pwdx with pid 1 which is not reachable +set test "pwdx pid 1 should give permission denied" +spawn pwdx 1 +expect { + -re "^1: Permission denied" { pass "$test" } + eof { fail "$test" } + timeout { fail "$test" } +} + +# Run pwdx with existing pid +set test "pwdx finds sleep in cwd" +set sleep_pid [ exec sleep 600 & ] +set sleep_pwd [ pwd ] +spawn pwdx $sleep_pid +expect { + -re "^$sleep_pid: $sleep_pwd" { pass "$test" } + eof { fail "$test" } + timeout { fail "$test" } +} + From 82eafe3fe85073c1ab682c23edec0ff27e464b3d Mon Sep 17 00:00:00 2001 From: Craig Small Date: Wed, 23 Nov 2011 22:48:49 +1100 Subject: [PATCH 02/10] new free commands --- testsuite/.gitignore | 2 ++ testsuite/Makefile.am | 2 +- testsuite/config/unix.exp | 33 ++++++++++++++++++- testsuite/global-conf.exp | 0 testsuite/procps-ng.test/free.test/free.exp | 9 +++++ .../{ => procps-ng.test}/pwdx.test/pwdx.exp | 1 + 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 testsuite/global-conf.exp create mode 100644 testsuite/procps-ng.test/free.test/free.exp rename testsuite/{ => procps-ng.test}/pwdx.test/pwdx.exp (96%) diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 1e6f9352..96ef0306 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -1,2 +1,4 @@ *.log *.sum +site.bak +site.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index dc57c450..e0f2bc00 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -2,4 +2,4 @@ AUTOMAKE_OPTIONS = dejagnu export DEJAGNU DEJATOOL = \ - pwdx + procps-ng diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index d329d7ec..c0dac447 100644 --- a/testsuite/config/unix.exp +++ b/testsuite/config/unix.exp @@ -1,8 +1,39 @@ +regexp "(.*\/)testsuite" $objdir objdir topdir + proc pwdx_load { arg } { } proc pwdx_exit {} {} proc pwdx_version {} { + global topdir set tmp [ exec pwdx -V ] regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version - clone_output "pwdx version $version\n" + clone_output "${topdir}pwdx version $version\n" +} + +# free functions +proc free_load { arg } { } +proc free_exit {} {} +proc free_version {} { + set tmp [ exec free --version ] + regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version + clone_output "free version $version\n" +} + +# +# +# common utilities +proc expect_continue { testname reg } { + expect { + -re "$reg" { } + eof { fail "$testname" } + timeout { fail "$testname" } + } +} + +proc expect_pass { testname reg } { + expect { + -re "$reg" { pass "$testname" } + eof { fail "$testname" } + timeout { fail "$testname" } + } } diff --git a/testsuite/global-conf.exp b/testsuite/global-conf.exp new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/procps-ng.test/free.test/free.exp b/testsuite/procps-ng.test/free.test/free.exp new file mode 100644 index 00000000..a5f251f5 --- /dev/null +++ b/testsuite/procps-ng.test/free.test/free.exp @@ -0,0 +1,9 @@ +# +# Testsuite for free program +# + +set free "${topdir}free" +set test "free with no arguments" +spawn free +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+\\d+\\s+\\d+\\s+\\d+" + diff --git a/testsuite/pwdx.test/pwdx.exp b/testsuite/procps-ng.test/pwdx.test/pwdx.exp similarity index 96% rename from testsuite/pwdx.test/pwdx.exp rename to testsuite/procps-ng.test/pwdx.test/pwdx.exp index cd60c211..7f830372 100644 --- a/testsuite/pwdx.test/pwdx.exp +++ b/testsuite/procps-ng.test/pwdx.test/pwdx.exp @@ -1,4 +1,5 @@ +set pwdx "${topdir}pwdx" # Run pwdx with no arguments set test "pwdx no args" spawn pwdx From 49c99b118967f528f47b573bfba1002da88ce3c9 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Thu, 24 Nov 2011 23:06:06 +1100 Subject: [PATCH 03/10] Additional tests for free command --- testsuite/procps-ng.test/free.test/free.exp | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/testsuite/procps-ng.test/free.test/free.exp b/testsuite/procps-ng.test/free.test/free.exp index a5f251f5..58c6acc7 100644 --- a/testsuite/procps-ng.test/free.test/free.exp +++ b/testsuite/procps-ng.test/free.test/free.exp @@ -3,7 +3,37 @@ # set free "${topdir}free" +set meminfo [ exec cat /proc/meminfo ] +regexp "MemTotal:\\s+\(\\d+\)" $meminfo -> memtotal_kb +regexp "SwapTotal:\\s+\(\\d+\)" $meminfo -> swaptotal_kb + + set test "free with no arguments" spawn free -expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+\\d+\\s+\\d+\\s+\\d+" +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+${memtotal_kb}\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal_kb}\\s+\\d+\\s+\\d+\\s*" +set test "free with -b argument" +set memtotal [ expr { $memtotal_kb * 1024 } ] +set swaptotal [ expr { $swaptotal_kb * 1024 } ] +spawn free -b +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+${memtotal}\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal}\\s+\\d+\\s+\\d+\\s*" + +foreach {arg divisor } {-k 1 -m 1024 -g 1048576 } { + set test "free with $arg argument" + set memtotal [ expr { $memtotal_kb / $divisor } ] + set swaptotal [ expr { $swaptotal_kb / $divisor } ] + spawn free $arg + expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+$memtotal\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal}\\s+\\d+\\s+\\d+\\s*" +} + +set test "free with human readable output" +spawn free -h +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s*-\\/\\+ buffers\\/cache:\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s*Swap:\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s+\[0-9.\]+\[BKMGT\]\\s*" + +set test "free with lo and hi memory statistics" +spawn free -l +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+\\d+\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*Low:\\s+\\d+\\s+\\d+\\s+\\d+\\s*High:\\s+\\d+\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+\\d+\\s+\\d+\\s+\\d+" + +set test "free old argument" +spawn free -o +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+\\d+\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*Swap:\\s+\\d+\\s+\\d+\\s+\\d+" From 2cad7c5667f1ec822fefe251020d9d57f31507ae Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 27 Nov 2011 15:30:04 +1100 Subject: [PATCH 04/10] more free tests and pgrep tests Almost fully testing all features of pgrep now. free had additional tests added to it --- testsuite/config/unix.exp | 8 ++ testsuite/procps-ng.test/free.test/free.exp | 5 + testsuite/procps-ng.test/pgrep.test/pgrep.exp | 125 ++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 testsuite/procps-ng.test/pgrep.test/pgrep.exp diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index c0dac447..f11f7933 100644 --- a/testsuite/config/unix.exp +++ b/testsuite/config/unix.exp @@ -37,3 +37,11 @@ proc expect_pass { testname reg } { timeout { fail "$testname" } } } + +proc expect_blank { testname } { + expect { + -re "\\w" { fail "$testname" } + eof { pass "$testname" } + timeout { pass "$testname" } + } +} diff --git a/testsuite/procps-ng.test/free.test/free.exp b/testsuite/procps-ng.test/free.test/free.exp index 58c6acc7..6dace6e7 100644 --- a/testsuite/procps-ng.test/free.test/free.exp +++ b/testsuite/procps-ng.test/free.test/free.exp @@ -37,3 +37,8 @@ expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\ set test "free old argument" spawn free -o expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+\\d+\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*Swap:\\s+\\d+\\s+\\d+\\s+\\d+" + +set test "free with total" +spawn free -t +expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\s*Mem:\\s+${memtotal_kb}\\s+\\d+\\s+\\d+\\s+0\\s+\\d+\\s+\\d+\\s*-\\/\\+ buffers\\/cache:\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal_kb}\\s+\\d+\\s+\\d+\\s*Total:\\s+\\d+\\s+\\d+\\s+\\d+\\s*" + diff --git a/testsuite/procps-ng.test/pgrep.test/pgrep.exp b/testsuite/procps-ng.test/pgrep.test/pgrep.exp new file mode 100644 index 00000000..98c938d4 --- /dev/null +++ b/testsuite/procps-ng.test/pgrep.test/pgrep.exp @@ -0,0 +1,125 @@ +# +# Dejagnu tests for pgrep - part of procps +# +set mypid [pid] +set not_ppid [ expr { $mypid + 1 } ] +set pgrep "${topdir}pgrep" +set uid [ exec id -u ] +set not_uid [ expr { $uid + 1 } ] +set gid [ exec id -g ] +set not_gid [ expr { $gid + 1 } ] +set raw_tty [ exec tty ] +regexp "/dev/(.+)" $raw_tty > tty + +set newsleep_path [ exec mktemp -u ] +exec ln -s "/bin/sleep" $newsleep_path +set sleep1_pid [ exec $newsleep_path 600 & ] +set sleep2_pid [ exec $newsleep_path 600 & ] +set newsleep [ exec basename $newsleep_path ] +set newsleep_len [ string length $newsleep ] +set newsleep_trim [ string range $newsleep 0 [ expr { $newsleep_len - 2 } ] ] +set sleep1_sid [ exec ps --no-headers -o sid $sleep1_pid ] + +spawn readlink $newsleep_path +expect { + -re "^/bin/sleep\\s*$" { } + timeout { fail "sleep symlink broken in prgrep tests" } + eof { fail "sleep symlink broken in prgrep tests" } +} + +set test "pgprep with no arguments" +spawn $pgrep +expect_pass "$test" "^pgrep: No matching criteria specified\\s*" + +set test "pgrep find both test pids" +spawn $pgrep $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +# In Debian only +#set test "pgrep counts 2 test pids" +#spawn $pgrep -c $newsleep +#expect_pass "$test" "^2\\s*" + +set test "pgrep with : delimiter" +spawn $pgrep -d : $newsleep +expect_pass "$test" "^${sleep1_pid}:${sleep2_pid}\\s*$" + +# FIXME - Need to test against -f flag +set test "pgrep match against full process name" +untested $test + +set test "pgrep with matching gid" +spawn $pgrep -G $gid $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep with not matching gid" +spawn $pgrep -G $not_gid $newsleep +expect_blank $test + +set test "pgrep with process name" +spawn $pgrep -l $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$newsleep\\s+$sleep2_pid\\s+$newsleep\\s*$" + +set test "pgrep find newest test pid" +spawn $pgrep -n $newsleep +expect_pass "$test" "^$sleep2_pid\\s*$" + +set test "pgrep find oldest test pid" +spawn $pgrep -o $newsleep +expect_pass "$test" "^$sleep1_pid\\s*$" + +set test "pgrep matches with parent pid" +spawn $pgrep -P $mypid $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep doesn't match with bogus parent pid" +spawn $pgrep -P $not_ppid $newsleep +expect_blank "$test" + +set test "pgrep matches with its own sid" +spawn $pgrep -s $sleep1_sid $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep doesn't match with bogus sid" +spawn $pgrep -s 1 $newsleep +expect_blank "$test" + +set test "pgrep matches on tty" +spawn $pgrep -t $tty $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep doesn't match with bogus tty" +spawn $pgrep -t glass $newsleep +expect_blank "$test" + +set test "pgrep with matching euid" +spawn $pgrep -u $uid $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep with not matching euid" +spawn $pgrep -u $not_uid $newsleep +expect_blank $test + +set test "pgrep with matching uid" +spawn $pgrep -U $uid $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep with not matching uid" +spawn $pgrep -U $not_uid $newsleep +expect_blank $test + +set test "pgrep matches on substring" +spawn $pgrep $newsleep_trim +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep matches full string with exact" +spawn $pgrep -x $newsleep +expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" + +set test "pgrep does not match substring with exact" +spawn $pgrep -x $newsleep_trim +expect_blank $test + + +# Cleanup +exec rm $newsleep_path From 5c48d8b79a65e7a3ce9d7a72be3ffd4d53538e3b Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 27 Nov 2011 18:32:10 +1100 Subject: [PATCH 05/10] rearranged testsuite --- testsuite/Makefile.am | 9 +++- testsuite/config/unix.exp | 31 ++++++++++- .../{procps-ng.test => }/free.test/free.exp | 0 .../{procps-ng.test => }/pgrep.test/pgrep.exp | 6 ++- testsuite/pmap.test/pmap.exp | 5 ++ .../{procps-ng.test => }/pwdx.test/pwdx.exp | 0 testsuite/w.test/w.exp | 53 +++++++++++++++++++ 7 files changed, 99 insertions(+), 5 deletions(-) rename testsuite/{procps-ng.test => }/free.test/free.exp (100%) rename testsuite/{procps-ng.test => }/pgrep.test/pgrep.exp (96%) create mode 100644 testsuite/pmap.test/pmap.exp rename testsuite/{procps-ng.test => }/pwdx.test/pwdx.exp (100%) create mode 100644 testsuite/w.test/w.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index e0f2bc00..7786ee1b 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -2,4 +2,11 @@ AUTOMAKE_OPTIONS = dejagnu export DEJAGNU DEJATOOL = \ - procps-ng + free \ + pgrep \ + pmap \ + pwdx \ + w + + + diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index f11f7933..57870bce 100644 --- a/testsuite/config/unix.exp +++ b/testsuite/config/unix.exp @@ -14,9 +14,20 @@ proc pwdx_version {} { proc free_load { arg } { } proc free_exit {} {} proc free_version {} { - set tmp [ exec free --version ] + global topdir + set tmp [ exec ${topdir}free --version ] regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version - clone_output "free version $version\n" + clone_output "${topdir}free version $version\n" +} + +# w functions +proc w_load { arg } { } +proc w_exit {} {} +proc w_version {} { + global topdir + set tmp [ exec ${topdir}w -V ] + regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version + clone_output "${topdir}w version $version\n" } # @@ -45,3 +56,19 @@ proc expect_blank { testname } { timeout { pass "$testname" } } } + +proc make_testproc { } { + global testproc_path testproc_comm testproc1_pid testproc2_pid + + set testproc_path [ exec mktemp -u ] + exec ln -s "/bin/sleep" $testproc_path + set testproc1_pid [ exec $testproc_path 600 & ] + set testproc2_pid [ exec $testproc_path 600 & ] + set testproc_comm [ exec basename $testproc_path ] + spawn readlink $testproc_path + expect { + -re "^/bin/sleep\\s*$" { } + timeout { perror "test proc does not link to sleep 1" } + eof { perror "test proc does not link to sleep 1" } + } +} diff --git a/testsuite/procps-ng.test/free.test/free.exp b/testsuite/free.test/free.exp similarity index 100% rename from testsuite/procps-ng.test/free.test/free.exp rename to testsuite/free.test/free.exp diff --git a/testsuite/procps-ng.test/pgrep.test/pgrep.exp b/testsuite/pgrep.test/pgrep.exp similarity index 96% rename from testsuite/procps-ng.test/pgrep.test/pgrep.exp rename to testsuite/pgrep.test/pgrep.exp index 98c938d4..dedef793 100644 --- a/testsuite/procps-ng.test/pgrep.test/pgrep.exp +++ b/testsuite/pgrep.test/pgrep.exp @@ -45,8 +45,8 @@ spawn $pgrep -d : $newsleep expect_pass "$test" "^${sleep1_pid}:${sleep2_pid}\\s*$" # FIXME - Need to test against -f flag -set test "pgrep match against full process name" -untested $test +#set test "pgrep match against full process name" +#untested $test set test "pgrep with matching gid" spawn $pgrep -G $gid $newsleep @@ -122,4 +122,6 @@ expect_blank $test # Cleanup +exec kill $sleep1_pid +exec kill $sleep2_pid exec rm $newsleep_path diff --git a/testsuite/pmap.test/pmap.exp b/testsuite/pmap.test/pmap.exp new file mode 100644 index 00000000..2d592ce3 --- /dev/null +++ b/testsuite/pmap.test/pmap.exp @@ -0,0 +1,5 @@ +# +# Dejagnu tests for pgrep - part of procps +# +set pmap "${topdir}pmap" + diff --git a/testsuite/procps-ng.test/pwdx.test/pwdx.exp b/testsuite/pwdx.test/pwdx.exp similarity index 100% rename from testsuite/procps-ng.test/pwdx.test/pwdx.exp rename to testsuite/pwdx.test/pwdx.exp diff --git a/testsuite/w.test/w.exp b/testsuite/w.test/w.exp new file mode 100644 index 00000000..d96787c0 --- /dev/null +++ b/testsuite/w.test/w.exp @@ -0,0 +1,53 @@ +# +# Dejagnu tests for w - part of procps +# +# FIXME - the user lines only go to idle +set w "${topdir}w" + +set w_uptime "\\s+\\d{2}:\\d{2}:\\d{2} up (\\d+ days?,)\\s*\\d+(min|:\\d+), +\\d+ users, +load average: \[0-9.\]+, \[0-9.\]+, \[0-9.\]+\\s+" +set w_std_header "${w_uptime}USER\\s+TTY\\s+LOGIN@\\s+IDLE\\s+JCPU\\s+PCPU\\s+WHAT\\s+" +set w_short_header "${w_uptime}USER\\s+TTY\\s+IDLE\\s+WHAT\\s+" +set w_from_header "${w_uptime}USER\\s+TTY\\s+FROM\\s+LOGIN@\\s+IDLE\\s+JCPU\\s+PCPU\\s+WHAT\\s+" +set w_fromshort_header "${w_uptime}USER\\s+TTY\\s+FROM\\s+IDLE\\s+WHAT\\s+" + +set w_user "\[A-Za-z0-9_-\]+" +set w_tty "\[a-z0-9/]+" +set w_from "\[A-Za-z0-9.:-\]+" +set w_login "\(\\d+\[A-Z\]\[a-z\]{2}\\d+\|\[A-Z\]\[a-z\]{2}\\d+\|\\d+:\\d+\)" +set w_idle "\(\\?xdm\\?\|\\?\|\\d+days\|\\d+:\\d+m?\|\\d+.\\d+s\)" +set w_ival7 "\(\\?\|\\d+days\|\\d+:\\d+m?\|\\d+.\\d+s\)" +set w_what "\[A-Za-z0-9_\/\\-\]+" +set w_std_userlines "\(${w_user}\\s+${w_tty}\\s+${w_login}\\s+${w_idle}\\s+${w_ival7}\\s+${w_ival7}\\s+${w_what}\\s*\){1,}" +set w_short_userlines "\(${w_user}\\s+${w_tty}\\s+${w_idle}\\s+${w_what}\\s*\){1,}" +set w_from_userlines "\(${w_user}\\s+${w_tty}\\s+${w_from}\\s+${w_login}\\s+${w_idle}\\s+${w_ival7}\\s+${w_ival7}\\s+${w_what}\\s*\){1,}" +set w_fromshort_userlines "\(${w_user}\\s+${w_tty}\\s+${w_from}\\s+${w_idle}\\s+${w_what}\\s*\){1,}" + +set test "w with no arguments" +spawn $w +expect_pass "$test" "^${w_std_header}${w_std_userlines}" + + +set test "w with no headers" +spawn $w -h +expect_pass "$test" "^${w_std_userlines}" + +set test "w with -u flag" +spawn $w -u +expect_pass "$test" "^${w_std_header}${w_std_userlines}" + +set test "w with short output" +spawn $w -s +expect_pass "$test" "^${w_short_header}${w_short_userlines}" + +set test "w with from flag" +spawn $w -f +expect_pass "$test" "^${w_from_header}${w_from_userlines}" + +set test "w with from and short flags" +spawn $w -fs +expect_pass "$test" "^${w_fromshort_header}${w_fromshort_userlines}" + +set test "w with short and from flags" +spawn $w -sf +expect_pass "$test" "^${w_fromshort_header}${w_fromshort_userlines}" + From 919e37787e1b4e62a80be6a58ec3b2eb06d55ae7 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 27 Nov 2011 19:12:56 +1100 Subject: [PATCH 06/10] added uptime and vmstat tests --- testsuite/Makefile.am | 2 ++ testsuite/config/unix.exp | 10 +++++++++ testsuite/uptime.test/uptime.exp | 8 +++++++ testsuite/vmstat.test/vmstat.exp | 36 ++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 testsuite/uptime.test/uptime.exp create mode 100644 testsuite/vmstat.test/vmstat.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 7786ee1b..35a41d3f 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -6,6 +6,8 @@ DEJATOOL = \ pgrep \ pmap \ pwdx \ + uptime \ + vmstat \ w diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index 57870bce..5ffb3eca 100644 --- a/testsuite/config/unix.exp +++ b/testsuite/config/unix.exp @@ -20,6 +20,16 @@ proc free_version {} { clone_output "${topdir}free version $version\n" } +# uptime functions +proc uptime_load { arg } { } +proc uptime_exit {} {} +proc uptime_version {} { + global topdir + set tmp [ exec ${topdir}uptime -V ] + regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version + clone_output "${topdir}uptime version $version\n" +} + # w functions proc w_load { arg } { } proc w_exit {} {} diff --git a/testsuite/uptime.test/uptime.exp b/testsuite/uptime.test/uptime.exp new file mode 100644 index 00000000..4177ac92 --- /dev/null +++ b/testsuite/uptime.test/uptime.exp @@ -0,0 +1,8 @@ +# +# Dejagnu tests for uptime - part of procps +# +set uptime "${topdir}uptime" + +set test "uptime" +spawn $uptime +expect_pass "$test" "^\\s+\\d{2}:\\d{2}:\\d{2} up (\\d+ days?,)\\s*\\d+(min|:\\d+), +\\d+ users, +load average: \[0-9.\]+, \[0-9.\]+, \[0-9.\]+\\s*$" diff --git a/testsuite/vmstat.test/vmstat.exp b/testsuite/vmstat.test/vmstat.exp new file mode 100644 index 00000000..0adf75a8 --- /dev/null +++ b/testsuite/vmstat.test/vmstat.exp @@ -0,0 +1,36 @@ + +# +# Dejagnu tests for vmstat - part of procps + +set vmstat "${topdir}vmstat" + +# Run vmstat with no arguments +set test "vmstat with no arguments" +spawn $vmstat +expect_pass "$test" "^procs\[ -\]+memory\[ -\]+swap\[ -\]+io\[ -\]+system\[ -\]+cpu\[ -\]+\\s*r\\s+b\\s+swpd\\s+free\\s+buff\\s+cache\\s+si\\s+so\\s+bi\\s+bo\\s+in\\s+cs us sy id wa\\s*\(\\s+\\d+\){16}\\s*$" + +set test "vmstat with -a flag" +spawn $vmstat -a +expect_pass "$test" "^procs\[ -\]+memory\[ -\]+swap\[ -\]+io\[ -\]+system\[ -\]+cpu\[ -\]+\\s*r\\s+b\\s+swpd\\s+free\\s+inact\\s+active\\s+si\\s+so\\s+bi\\s+bo\\s+in\\s+cs us sy id wa\\s*\(\\s+\\d+\){16}\\s*$" + +set test "vmstat fork option" +spawn $vmstat -f +expect_pass "$test" "^\\s+\\d+ forks\\s*$" + +set test "vmstat slabinfo (-m option)" +spawn $vmstat -m +expect_pass "$test" "^Cache\\s+Num\\s+Total\\s+Size\\s+Pages\\s+\(\[\(\)A-Za-z0-9_-\]+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*\){1,}" + + +set test "vmstat disk information (-d option)" +spawn $vmstat -d +expect_pass "$test" "^disk\[ -\]+reads\[ -\]+writes\[ -\]+IO\[ -\]+\\s+total\\s+merged\\s+sectors\\s+ms\\s+total\\s+merged\\s+sectors\\s+ms\\s+cur\\s+sec\\s+" + +# Need a partition +set diskstats [ exec cat /proc/diskstats ] +regexp "\\s+\\d+\\s+\\d+\\s+\(\[a-z\]+\\d+\)" $diskstats -> partition +set test "vmstat partition" +spawn $vmstat -p $partition +expect_pass "$test" "^${partition}\\s+reads" +#\\s+read sectors\\s+writes\\s+requested writes" +#\(\\s+\\d+\){4}\\s*$" From b36fe6efc5e44dcc0f8b3b5838d6e10105a46e6a Mon Sep 17 00:00:00 2001 From: Craig Small Date: Mon, 28 Nov 2011 22:02:27 +1100 Subject: [PATCH 07/10] Add sysctl check and tests to extra_dist --- testsuite/Makefile.am | 13 ++++++++++++- testsuite/sysctl.test/sysctl_read.exp | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 testsuite/sysctl.test/sysctl_read.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 35a41d3f..50676f97 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -11,4 +11,15 @@ DEJATOOL = \ w - +EXTRA_DIST = \ + w.test/w.exp \ + pgrep.test/pgrep.exp \ + site.exp \ + config/unix.exp \ + uptime.test/uptime.exp \ + pmap.test/pmap.exp \ + pwdx.test/pwdx.exp \ + free.test/free.exp \ + global-conf.exp \ + sysctl.test/sysctl_read.exp \ + vmstat.test/vmstat.exp diff --git a/testsuite/sysctl.test/sysctl_read.exp b/testsuite/sysctl.test/sysctl_read.exp new file mode 100644 index 00000000..aa2b185c --- /dev/null +++ b/testsuite/sysctl.test/sysctl_read.exp @@ -0,0 +1,25 @@ +# +# Dejagnu tests for sysctl (read only) - part of procps +# +set sysctl ${topdir}sysctl +set hostname [ exec cat "/proc/sys/kernel/hostname" ] + +set test "sysctl with no arguments" +spawn $sysctl +expect_pass "$test" "^usage:\\s+\(lt-\)?sysctl \\\[-n\\\] \\\[-e\\\] variable \\.\\.\\.\\s+" + +set test "sysctl reading a variable using slash delimiter" +spawn $sysctl kernel/hostname +expect_pass "$test" "kernel.hostname = ${hostname}" + +set test "sysctl reading a variable using dot delimiter" +spawn $sysctl kernel.hostname +expect_pass "$test" "kernel.hostname = ${hostname}" + +set test "sysctl reading a variable suppress key" +spawn $sysctl -n kernel.hostname +expect_pass "$test" "${hostname}" + +set test "sysctl reading a variable suppress value" +spawn $sysctl -N kernel.hostname +expect_pass "$test" "kernel.hostname" From 261a3fae83980a76bfe17243c393d1fb988e3bba Mon Sep 17 00:00:00 2001 From: Craig Small Date: Tue, 29 Nov 2011 22:55:03 +1100 Subject: [PATCH 08/10] fixed pgrep and added ps tests --- testsuite/Makefile.am | 3 +++ testsuite/pgrep.test/pgrep.exp | 4 +-- testsuite/ps.test/ps_output.exp | 38 ++++++++++++++++++++++++++++ testsuite/ps.test/ps_personality.exp | 18 +++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 testsuite/ps.test/ps_output.exp create mode 100644 testsuite/ps.test/ps_personality.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 50676f97..3951ec42 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -5,6 +5,7 @@ DEJATOOL = \ free \ pgrep \ pmap \ + ps \ pwdx \ uptime \ vmstat \ @@ -18,6 +19,8 @@ EXTRA_DIST = \ config/unix.exp \ uptime.test/uptime.exp \ pmap.test/pmap.exp \ + ps.test/ps_output.exp \ + ps.test/ps_personality.exp \ pwdx.test/pwdx.exp \ free.test/free.exp \ global-conf.exp \ diff --git a/testsuite/pgrep.test/pgrep.exp b/testsuite/pgrep.test/pgrep.exp index dedef793..99d1fff1 100644 --- a/testsuite/pgrep.test/pgrep.exp +++ b/testsuite/pgrep.test/pgrep.exp @@ -45,8 +45,8 @@ spawn $pgrep -d : $newsleep expect_pass "$test" "^${sleep1_pid}:${sleep2_pid}\\s*$" # FIXME - Need to test against -f flag -#set test "pgrep match against full process name" -#untested $test +set test "pgrep match against full process name" +untested $test set test "pgrep with matching gid" spawn $pgrep -G $gid $newsleep diff --git a/testsuite/ps.test/ps_output.exp b/testsuite/ps.test/ps_output.exp new file mode 100644 index 00000000..740e026c --- /dev/null +++ b/testsuite/ps.test/ps_output.exp @@ -0,0 +1,38 @@ +# +# Dejagnu tests for ps (output options) - part of procps +# +set ps ${topdir}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 } ] +set raw_tty [ exec tty ] +regexp "/dev/(.+)" $raw_tty > tty + +# All the fields +# Cannot do args,cmd,comm +set ps_digit "\\d+\\s*" +set ps_state "\[A-Z Date: Wed, 30 Nov 2011 23:11:35 +1100 Subject: [PATCH 09/10] More testing added for procps --- testsuite/Makefile.am | 6 +- testsuite/config/unix.exp | 58 ++++++-------- testsuite/kill.test/kill.exp | 42 ++++++++++ testsuite/pgrep.test/pgrep.exp | 92 ++++++++++------------ testsuite/pkill.test/pkill.exp | 127 +++++++++++++++++++++++++++++++ testsuite/pwdx.test/pwdx.exp | 25 ++---- testsuite/uptime.test/uptime.exp | 2 +- testsuite/w.test/w.exp | 2 +- 8 files changed, 246 insertions(+), 108 deletions(-) create mode 100644 testsuite/kill.test/kill.exp create mode 100644 testsuite/pkill.test/pkill.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 3951ec42..73df0c26 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -3,7 +3,9 @@ export DEJAGNU DEJATOOL = \ free \ + kill \ pgrep \ + pkill \ pmap \ ps \ pwdx \ @@ -13,8 +15,11 @@ DEJATOOL = \ EXTRA_DIST = \ + free.test/free.exp \ + kill.test/kill.exp \ w.test/w.exp \ pgrep.test/pgrep.exp \ + pkill.test/pkill.exp \ site.exp \ config/unix.exp \ uptime.test/uptime.exp \ @@ -22,7 +27,6 @@ EXTRA_DIST = \ ps.test/ps_output.exp \ ps.test/ps_personality.exp \ pwdx.test/pwdx.exp \ - free.test/free.exp \ global-conf.exp \ sysctl.test/sysctl_read.exp \ vmstat.test/vmstat.exp diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index 5ffb3eca..4ed01a60 100644 --- a/testsuite/config/unix.exp +++ b/testsuite/config/unix.exp @@ -1,44 +1,25 @@ regexp "(.*\/)testsuite" $objdir objdir topdir -proc pwdx_load { arg } { } -proc pwdx_exit {} {} -proc pwdx_version {} { +proc procps_v_version { tool } { global topdir - set tmp [ exec pwdx -V ] + set toolpath ${topdir}${tool} +send_user "$toolpath -V" + set tmp [ exec $toolpath -V ] regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version - clone_output "${topdir}pwdx version $version\n" + clone_output "$toolpath version $version\n" } -# free functions -proc free_load { arg } { } -proc free_exit {} {} -proc free_version {} { - global topdir - set tmp [ exec ${topdir}free --version ] - regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version - clone_output "${topdir}free version $version\n" -} - -# uptime functions -proc uptime_load { arg } { } -proc uptime_exit {} {} -proc uptime_version {} { - global topdir - set tmp [ exec ${topdir}uptime -V ] - regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version - clone_output "${topdir}uptime version $version\n" -} - -# w functions -proc w_load { arg } { } -proc w_exit {} {} -proc w_version {} { - global topdir - set tmp [ exec ${topdir}w -V ] - regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version - clone_output "${topdir}w version $version\n" -} +proc free_version {} { procps_v_version free } +proc kill_version {} { procps_v_version kill } +proc pgrep_version {} { procps_v_version pgrep } +proc pkill_version {} { procps_v_version pkill } +proc pmap_version {} { procps_v_version pmap } +proc pwdx_version {} { procps_v_version pwdx } +proc sysctl_version {} { procps_v_version sysctl } +proc uptime_version {} { procps_v_version uptime } +proc vmstat_version {} { procps_v_version vmstat } +proc w_version {} { procps_v_version w } # # @@ -68,17 +49,22 @@ proc expect_blank { testname } { } proc make_testproc { } { + # Time to run the whole job + set sleep_time 300 + global testproc_path testproc_comm testproc1_pid testproc2_pid set testproc_path [ exec mktemp -u ] exec ln -s "/bin/sleep" $testproc_path - set testproc1_pid [ exec $testproc_path 600 & ] - set testproc2_pid [ exec $testproc_path 600 & ] set testproc_comm [ exec basename $testproc_path ] + spawn readlink $testproc_path expect { -re "^/bin/sleep\\s*$" { } timeout { perror "test proc does not link to sleep 1" } eof { perror "test proc does not link to sleep 1" } } + + set testproc1_pid [ exec $testproc_path $sleep_time & ] + set testproc2_pid [ exec $testproc_path $sleep_time & ] } diff --git a/testsuite/kill.test/kill.exp b/testsuite/kill.test/kill.exp new file mode 100644 index 00000000..08495400 --- /dev/null +++ b/testsuite/kill.test/kill.exp @@ -0,0 +1,42 @@ +# +# Dejagnu testsuite for kill - part of procps +# +set kill ${topdir}kill + + +set test "kill with no arguments" +spawn $kill +expect_pass "$test" "Usage:\\s+kill pid ...\\s+Send SIGTERM to every process listed.\\r\\s+kill signal pid ...\\s+Send a signal to every process listed.\\r\\s+kill -s signal pid ...\\s+Send a signal to every process listed.\\r\\s+kill -l\\s+List all signal names.\\r\\s+kill -L\\s+List all signal names in a nice table.\\r\\s+kill -l signal\\s+Convert between signal numbers and names." + +set test "kill list signal names" +spawn $kill -l +expect_pass "$test" "^\(\[A-Z12\]\\s*\)+$" + +set test "kill list signal names in table" +spawn $kill -L +expect_pass "$test" "^\(\\s+\\d+ \[A-Z12\]+\)+\\s*$" + +set test "kill convert signal name to number" +spawn $kill -l HUP +expect_pass "$test" "^1\\s*" + +set test "kill convert signal number to name" +spawn $kill -l 1 +expect_pass "$test" "^HUP\\s*" + +set test "kill numbered process" +make_testproc +if { [ file isdirectory "/proc/$testproc1_pid" ] && [ file isdirectory "/proc/$testproc2_pid" ] } { +} else { + perror "Could not start test processes" +} +set foo [ exec $kill -KILL $testproc1_pid $testproc2_pid ] +wait +wait +if { [ file exists "/proc/$testproc1_pid" ] || [ file exists "/proc/$testproc2_pid" ] } { + fail "$test" +} else { + pass "$test" +} + + diff --git a/testsuite/pgrep.test/pgrep.exp b/testsuite/pgrep.test/pgrep.exp index 99d1fff1..c030092b 100644 --- a/testsuite/pgrep.test/pgrep.exp +++ b/testsuite/pgrep.test/pgrep.exp @@ -11,117 +11,107 @@ set not_gid [ expr { $gid + 1 } ] set raw_tty [ exec tty ] regexp "/dev/(.+)" $raw_tty > tty -set newsleep_path [ exec mktemp -u ] -exec ln -s "/bin/sleep" $newsleep_path -set sleep1_pid [ exec $newsleep_path 600 & ] -set sleep2_pid [ exec $newsleep_path 600 & ] -set newsleep [ exec basename $newsleep_path ] -set newsleep_len [ string length $newsleep ] -set newsleep_trim [ string range $newsleep 0 [ expr { $newsleep_len - 2 } ] ] -set sleep1_sid [ exec ps --no-headers -o sid $sleep1_pid ] +make_testproc -spawn readlink $newsleep_path -expect { - -re "^/bin/sleep\\s*$" { } - timeout { fail "sleep symlink broken in prgrep tests" } - eof { fail "sleep symlink broken in prgrep tests" } -} +set testproc_len [ string length $testproc_comm ] +set testproc_trim [ string range $testproc_comm 0 [ expr { $testproc_len - 2 } ] ] +set testproc1_sid [ string trim [ exec ps --no-headers -o sid $testproc1_pid ] ] set test "pgprep with no arguments" spawn $pgrep expect_pass "$test" "^pgrep: No matching criteria specified\\s*" set test "pgrep find both test pids" -spawn $pgrep $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" # In Debian only #set test "pgrep counts 2 test pids" -#spawn $pgrep -c $newsleep +#spawn $pgrep -c $testproc_comm #expect_pass "$test" "^2\\s*" set test "pgrep with : delimiter" -spawn $pgrep -d : $newsleep -expect_pass "$test" "^${sleep1_pid}:${sleep2_pid}\\s*$" +spawn $pgrep -d : $testproc_comm +expect_pass "$test" "^${testproc1_pid}:${testproc2_pid}\\s*$" # FIXME - Need to test against -f flag set test "pgrep match against full process name" untested $test set test "pgrep with matching gid" -spawn $pgrep -G $gid $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -G $gid $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep with not matching gid" -spawn $pgrep -G $not_gid $newsleep +spawn $pgrep -G $not_gid $testproc_comm expect_blank $test set test "pgrep with process name" -spawn $pgrep -l $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$newsleep\\s+$sleep2_pid\\s+$newsleep\\s*$" +spawn $pgrep -l $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc_comm\\s+$testproc2_pid\\s+$testproc_comm\\s*$" set test "pgrep find newest test pid" -spawn $pgrep -n $newsleep -expect_pass "$test" "^$sleep2_pid\\s*$" +spawn $pgrep -n $testproc_comm +expect_pass "$test" "^$testproc2_pid\\s*$" set test "pgrep find oldest test pid" -spawn $pgrep -o $newsleep -expect_pass "$test" "^$sleep1_pid\\s*$" +spawn $pgrep -o $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s*$" set test "pgrep matches with parent pid" -spawn $pgrep -P $mypid $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -P $mypid $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep doesn't match with bogus parent pid" -spawn $pgrep -P $not_ppid $newsleep +spawn $pgrep -P $not_ppid $testproc_comm expect_blank "$test" set test "pgrep matches with its own sid" -spawn $pgrep -s $sleep1_sid $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -s $testproc1_sid $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep doesn't match with bogus sid" -spawn $pgrep -s 1 $newsleep +spawn $pgrep -s 1 $testproc_comm expect_blank "$test" set test "pgrep matches on tty" -spawn $pgrep -t $tty $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -t $tty $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep doesn't match with bogus tty" -spawn $pgrep -t glass $newsleep +spawn $pgrep -t glass $testproc_comm expect_blank "$test" set test "pgrep with matching euid" -spawn $pgrep -u $uid $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -u $uid $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep with not matching euid" -spawn $pgrep -u $not_uid $newsleep +spawn $pgrep -u $not_uid $testproc_comm expect_blank $test set test "pgrep with matching uid" -spawn $pgrep -U $uid $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -U $uid $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep with not matching uid" -spawn $pgrep -U $not_uid $newsleep +spawn $pgrep -U $not_uid $testproc_comm expect_blank $test set test "pgrep matches on substring" -spawn $pgrep $newsleep_trim -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep $testproc_trim +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep matches full string with exact" -spawn $pgrep -x $newsleep -expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +spawn $pgrep -x $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" set test "pgrep does not match substring with exact" -spawn $pgrep -x $newsleep_trim +spawn $pgrep -x $testproc_trim expect_blank $test # Cleanup -exec kill $sleep1_pid -exec kill $sleep2_pid -exec rm $newsleep_path +exec kill $testproc1_pid +exec kill $testproc2_pid +exec rm $testproc_path diff --git a/testsuite/pkill.test/pkill.exp b/testsuite/pkill.test/pkill.exp new file mode 100644 index 00000000..50d73387 --- /dev/null +++ b/testsuite/pkill.test/pkill.exp @@ -0,0 +1,127 @@ +# +# Dejagnu tests for pkill - part of procps +# +set mypid [pid] +set not_ppid [ expr { $mypid + 1 } ] +set pkill "${topdir}pkill" +set uid [ exec id -u ] +set not_uid [ expr { $uid + 1 } ] +set gid [ exec id -g ] +set not_gid [ expr { $gid + 1 } ] +set raw_tty [ exec tty ] +regexp "/dev/(.+)" $raw_tty > tty + +make_testproc +set testproc_len [ string length $testproc_comm ] +set testproc_trim [ string range $testproc_comm 0 [ expr { $testproc_len - 2 } ] ] +set testproc1_sid [ exec ps --no-headers -o sid $testproc1_pid ] + +set test "pkill with no arguments" +spawn $pkill +expect_pass "$test" "^pkill: No matching criteria specified\\s*" + +set test "pkill find both test pids" +#spawn $pkill $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +# In Debian only +#set test "pkill counts 2 test pids" +#spawn $pkill -c $testproc +#expect_pass "$test" "^2\\s*" + +set test "pkill with matching gid" +#spawn $pkill -G $gid $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill with not matching gid" +#spawn $pkill -G $not_gid $testproc +#expect_blank $test +untested "$test" + +set test "pkill with process name" +#spawn $pkill -l $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$testproc\\s+$sleep2_pid\\s+$testproc\\s*$" +untested "$test" + +set test "pkill find newest test pid" +#spawn $pkill -n $testproc +#expect_pass "$test" "^$sleep2_pid\\s*$" +untested "$test" + +set test "pkill find oldest test pid" +#spawn $pkill -o $testproc +#expect_pass "$test" "^$sleep1_pid\\s*$" +untested "$test" + +set test "pkill matches with parent pid" +#spawn $pkill -P $mypid $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill doesn't match with bogus parent pid" +#spawn $pkill -P $not_ppid $testproc +#expect_blank "$test" +untested "$test" + +set test "pkill matches with its own sid" +#spawn $pkill -s $sleep1_sid $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill doesn't match with bogus sid" +#spawn $pkill -s 1 $testproc +#expect_blank "$test" +untested "$test" + +set test "pkill matches on tty" +#spawn $pkill -t $tty $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill doesn't match with bogus tty" +#spawn $pkill -t glass $testproc +#expect_blank "$test" +untested "$test" + +set test "pkill with matching euid" +#spawn $pkill -u $uid $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill with not matching euid" +#spawn $pkill -u $not_uid $testproc +#expect_blank $test +untested "$test" + +set test "pkill with matching uid" +#spawn $pkill -U $uid $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill with not matching uid" +#spawn $pkill -U $not_uid $testproc +#expect_blank $test +untested "$test" + +set test "pkill matches on substring" +#spawn $pkill $testproc_trim +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill matches full string with exact" +#spawn $pkill -x $testproc +#expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" +untested "$test" + +set test "pkill does not match substring with exact" +#spawn $pkill -x $testproc_trim +#expect_blank $test +untested "$test" + + +# Cleanup +exec kill $testproc1_pid +exec kill $testproc2_pid +exec rm $testproc_path diff --git a/testsuite/pwdx.test/pwdx.exp b/testsuite/pwdx.test/pwdx.exp index 7f830372..c1182fdc 100644 --- a/testsuite/pwdx.test/pwdx.exp +++ b/testsuite/pwdx.test/pwdx.exp @@ -2,30 +2,19 @@ set pwdx "${topdir}pwdx" # Run pwdx with no arguments set test "pwdx no args" -spawn pwdx -expect { - -re "^Usage: pwdx pid\.\.\." { pass "$test" } - eof { fail "$test" } - timeout { fail "$test" } -} +spawn $pwdx +expect_pass "$test" "^Usage: pwdx pid\.\.\." # Run pwdx with pid 1 which is not reachable set test "pwdx pid 1 should give permission denied" -spawn pwdx 1 -expect { - -re "^1: Permission denied" { pass "$test" } - eof { fail "$test" } - timeout { fail "$test" } -} +spawn $pwdx 1 +expect_pass "$test" "^1: Permission denied" # Run pwdx with existing pid set test "pwdx finds sleep in cwd" set sleep_pid [ exec sleep 600 & ] set sleep_pwd [ pwd ] -spawn pwdx $sleep_pid -expect { - -re "^$sleep_pid: $sleep_pwd" { pass "$test" } - eof { fail "$test" } - timeout { fail "$test" } -} +spawn $pwdx $sleep_pid +expect_pass "$test" "^$sleep_pid: $sleep_pwd" +exec kill $sleep_pid diff --git a/testsuite/uptime.test/uptime.exp b/testsuite/uptime.test/uptime.exp index 4177ac92..001c4e7f 100644 --- a/testsuite/uptime.test/uptime.exp +++ b/testsuite/uptime.test/uptime.exp @@ -5,4 +5,4 @@ set uptime "${topdir}uptime" set test "uptime" spawn $uptime -expect_pass "$test" "^\\s+\\d{2}:\\d{2}:\\d{2} up (\\d+ days?,)\\s*\\d+(min|:\\d+), +\\d+ users, +load average: \[0-9.\]+, \[0-9.\]+, \[0-9.\]+\\s*$" +expect_pass "$test" "^\\s+\\d{2}:\\d{2}:\\d{2} up (\\d+ days?,)?\\s*\\d+(min|:\\d+), +\\d+ users, +load average: \[0-9.\]+, \[0-9.\]+, \[0-9.\]+\\s*$" diff --git a/testsuite/w.test/w.exp b/testsuite/w.test/w.exp index d96787c0..93418276 100644 --- a/testsuite/w.test/w.exp +++ b/testsuite/w.test/w.exp @@ -4,7 +4,7 @@ # FIXME - the user lines only go to idle set w "${topdir}w" -set w_uptime "\\s+\\d{2}:\\d{2}:\\d{2} up (\\d+ days?,)\\s*\\d+(min|:\\d+), +\\d+ users, +load average: \[0-9.\]+, \[0-9.\]+, \[0-9.\]+\\s+" +set w_uptime "\\s+\\d{2}:\\d{2}:\\d{2} up (\\d+ days?,)?\\s*\\d+(min|:\\d+), +\\d+ users, +load average: \[0-9.\]+, \[0-9.\]+, \[0-9.\]+\\s+" set w_std_header "${w_uptime}USER\\s+TTY\\s+LOGIN@\\s+IDLE\\s+JCPU\\s+PCPU\\s+WHAT\\s+" set w_short_header "${w_uptime}USER\\s+TTY\\s+IDLE\\s+WHAT\\s+" set w_from_header "${w_uptime}USER\\s+TTY\\s+FROM\\s+LOGIN@\\s+IDLE\\s+JCPU\\s+PCPU\\s+WHAT\\s+" From 23afed732a48aaa98079c5a03bb16b796f8fba62 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Thu, 1 Dec 2011 22:42:23 +1100 Subject: [PATCH 10/10] fixed small tests for pmap and ps checks --- testsuite/config/unix.exp | 21 +++++++++++++--- testsuite/pmap.test/pmap.exp | 43 +++++++++++++++++++++++++++++++++ testsuite/ps.test/ps_output.exp | 2 +- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index 4ed01a60..eb984b81 100644 --- a/testsuite/config/unix.exp +++ b/testsuite/config/unix.exp @@ -4,7 +4,6 @@ regexp "(.*\/)testsuite" $objdir objdir topdir proc procps_v_version { tool } { global topdir set toolpath ${topdir}${tool} -send_user "$toolpath -V" set tmp [ exec $toolpath -V ] regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version clone_output "$toolpath version $version\n" @@ -35,8 +34,7 @@ proc expect_continue { testname reg } { proc expect_pass { testname reg } { expect { -re "$reg" { pass "$testname" } - eof { fail "$testname" } - timeout { fail "$testname" } + default { fail "$testname" } } } @@ -48,6 +46,23 @@ proc expect_blank { testname } { } } +proc expect_table { test match_header match_items match_footer } { + expect { + -re "$match_header" { + expect { + -re "$match_items" { + expect { + -re "$match_footer" { pass "$test" } + default { fail "$test (footer)" } + } + } + default { fail "$test (items)" } + } + } + default { fail "$test (header)" } + } +} + proc make_testproc { } { # Time to run the whole job set sleep_time 300 diff --git a/testsuite/pmap.test/pmap.exp b/testsuite/pmap.test/pmap.exp index 2d592ce3..5dce21e7 100644 --- a/testsuite/pmap.test/pmap.exp +++ b/testsuite/pmap.test/pmap.exp @@ -2,4 +2,47 @@ # Dejagnu tests for pgrep - part of procps # set pmap "${topdir}pmap" +set mypid [pid] + +set pmap_procname "${mypid}:\\s+\\S+\[^\\r\]+\\s+" +set pmap_std_header $pmap_procname +set pmap_device_header "${pmap_procname}Address\\s+Kbytes\\s+Mode\\s+Offset\\s+Device\\s+Mapping\\s+" +set pmap_ext_header "${pmap_procname}Address\\s+Kbytes\\s+RSS\\s+Anon\\s+Locked\\s+Mode\\s+Mapping\\s+" + +set pmap_std_items "\(\[0-9a-f\]+\\s+\\d+K \[rwx-\]{5}\\s+\\S+\[^\\r\]+\\s*\)+" +set pmap_device_items "\(\[0-9a-f\]+\\s+\\d+ \[rwx-\]{5}\\s+\[0-9a-f\]+\\s+\[0-9a-f\]{3}:\[0-9a-f\]{5}\\s+\\S+\[^\\r\]+\\s*\)+" +set pmap_ext_items "\(\[0-9a-f\]+\\s+\\d+\\s+-\\s+-\\s+- \[rwx-\]{5}\\s+\\S+\[^\\r\]+\\s*\)+" + +set pmap_std_footer "total\\s+\\d+K\\s*\$" +set pmap_device_footer "mapped:\\s+\\d+K\\s+writeable\/private:\\s+\\d+K\\s+shared:\\s+\\d+K\\s*\$" +set pmap_ext_footer "\[ -\]+\\s+total kB\\s+\\d+\\s+-\\s+-\\s+-\\s*\$" + +set test "pmap with no arguments" +spawn $pmap +expect_pass "$test" "^Usage: pmap \\\[-x | -d\\\] \\\[-q\\\] \\\[-A low,high\\\] pid\\.\\.\\.\\s+-x\\s+show details\\s+-d\\s+show offset and device number\\s+-q\\s+quiet; less header/footer info\\s+-V\\s+show the version number\\s+-A\\s+limit results to the given range\\s*" + +set test "pmap standard output" +spawn $pmap $mypid +expect_table $test $pmap_std_header $pmap_std_items $pmap_std_footer + +set test "pmap standard output with quiet" +spawn $pmap -q $mypid +expect_table $test $pmap_procname $pmap_std_items "\$" + +set test "pmap device output" +spawn $pmap -d $mypid +expect_table $test $pmap_device_header $pmap_device_items $pmap_device_footer + + +set test "pmap device output quiet (dq)" +spawn $pmap -dq $mypid +expect_table $test $pmap_procname $pmap_device_items "\$" + +set test "pmap device output quiet (qd)" +spawn $pmap -qd $mypid +expect_table $test $pmap_procname $pmap_device_items "\$" + +set test "pmap extended output" +spawn $pmap -x $mypid +expect_table $test $pmap_ext_header $pmap_ext_items $pmap_ext_footer diff --git a/testsuite/ps.test/ps_output.exp b/testsuite/ps.test/ps_output.exp index 740e026c..abc7bd5e 100644 --- a/testsuite/ps.test/ps_output.exp +++ b/testsuite/ps.test/ps_output.exp @@ -26,7 +26,7 @@ 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*\){6}$" - "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} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4}\\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*\)+$" }