DEJATOOL = \
free \
+ kill \
pgrep \
+ pkill \
pmap \
ps \
pwdx \
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 \
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
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 }
#
#
}
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 & ]
}
--- /dev/null
+#
+# 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"
+}
+
+
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" }
-}
+make_testproc
+
+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
--- /dev/null
+#
+# 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
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
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*$"
# 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+"