More testing added for procps

This commit is contained in:
Craig Small 2011-11-30 23:11:35 +11:00
parent 261a3fae83
commit f05e15e830
8 changed files with 246 additions and 108 deletions

View File

@ -3,7 +3,9 @@ export DEJAGNU
DEJATOOL = \ DEJATOOL = \
free \ free \
kill \
pgrep \ pgrep \
pkill \
pmap \ pmap \
ps \ ps \
pwdx \ pwdx \
@ -13,8 +15,11 @@ DEJATOOL = \
EXTRA_DIST = \ EXTRA_DIST = \
free.test/free.exp \
kill.test/kill.exp \
w.test/w.exp \ w.test/w.exp \
pgrep.test/pgrep.exp \ pgrep.test/pgrep.exp \
pkill.test/pkill.exp \
site.exp \ site.exp \
config/unix.exp \ config/unix.exp \
uptime.test/uptime.exp \ uptime.test/uptime.exp \
@ -22,7 +27,6 @@ EXTRA_DIST = \
ps.test/ps_output.exp \ ps.test/ps_output.exp \
ps.test/ps_personality.exp \ ps.test/ps_personality.exp \
pwdx.test/pwdx.exp \ pwdx.test/pwdx.exp \
free.test/free.exp \
global-conf.exp \ global-conf.exp \
sysctl.test/sysctl_read.exp \ sysctl.test/sysctl_read.exp \
vmstat.test/vmstat.exp vmstat.test/vmstat.exp

View File

@ -1,44 +1,25 @@
regexp "(.*\/)testsuite" $objdir objdir topdir regexp "(.*\/)testsuite" $objdir objdir topdir
proc pwdx_load { arg } { } proc procps_v_version { tool } {
proc pwdx_exit {} {}
proc pwdx_version {} {
global topdir 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 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_version {} { procps_v_version free }
proc free_load { arg } { } proc kill_version {} { procps_v_version kill }
proc free_exit {} {} proc pgrep_version {} { procps_v_version pgrep }
proc free_version {} { proc pkill_version {} { procps_v_version pkill }
global topdir proc pmap_version {} { procps_v_version pmap }
set tmp [ exec ${topdir}free --version ] proc pwdx_version {} { procps_v_version pwdx }
regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version proc sysctl_version {} { procps_v_version sysctl }
clone_output "${topdir}free version $version\n" proc uptime_version {} { procps_v_version uptime }
} proc vmstat_version {} { procps_v_version vmstat }
proc w_version {} { procps_v_version w }
# 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"
}
# #
# #
@ -68,17 +49,22 @@ proc expect_blank { testname } {
} }
proc make_testproc { } { proc make_testproc { } {
# Time to run the whole job
set sleep_time 300
global testproc_path testproc_comm testproc1_pid testproc2_pid global testproc_path testproc_comm testproc1_pid testproc2_pid
set testproc_path [ exec mktemp -u ] set testproc_path [ exec mktemp -u ]
exec ln -s "/bin/sleep" $testproc_path 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 ] set testproc_comm [ exec basename $testproc_path ]
spawn readlink $testproc_path spawn readlink $testproc_path
expect { expect {
-re "^/bin/sleep\\s*$" { } -re "^/bin/sleep\\s*$" { }
timeout { perror "test proc does not link to sleep 1" } timeout { perror "test proc does not link to sleep 1" }
eof { 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 & ]
} }

View File

@ -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"
}

View File

@ -11,117 +11,107 @@ set not_gid [ expr { $gid + 1 } ]
set raw_tty [ exec tty ] set raw_tty [ exec tty ]
regexp "/dev/(.+)" $raw_tty > tty regexp "/dev/(.+)" $raw_tty > tty
set newsleep_path [ exec mktemp -u ] make_testproc
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 set testproc_len [ string length $testproc_comm ]
expect { set testproc_trim [ string range $testproc_comm 0 [ expr { $testproc_len - 2 } ] ]
-re "^/bin/sleep\\s*$" { } set testproc1_sid [ string trim [ exec ps --no-headers -o sid $testproc1_pid ] ]
timeout { fail "sleep symlink broken in prgrep tests" }
eof { fail "sleep symlink broken in prgrep tests" }
}
set test "pgprep with no arguments" set test "pgprep with no arguments"
spawn $pgrep spawn $pgrep
expect_pass "$test" "^pgrep: No matching criteria specified\\s*" expect_pass "$test" "^pgrep: No matching criteria specified\\s*"
set test "pgrep find both test pids" set test "pgrep find both test pids"
spawn $pgrep $newsleep spawn $pgrep $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
# In Debian only # In Debian only
#set test "pgrep counts 2 test pids" #set test "pgrep counts 2 test pids"
#spawn $pgrep -c $newsleep #spawn $pgrep -c $testproc_comm
#expect_pass "$test" "^2\\s*" #expect_pass "$test" "^2\\s*"
set test "pgrep with : delimiter" set test "pgrep with : delimiter"
spawn $pgrep -d : $newsleep spawn $pgrep -d : $testproc_comm
expect_pass "$test" "^${sleep1_pid}:${sleep2_pid}\\s*$" expect_pass "$test" "^${testproc1_pid}:${testproc2_pid}\\s*$"
# FIXME - Need to test against -f flag # FIXME - Need to test against -f flag
set test "pgrep match against full process name" set test "pgrep match against full process name"
untested $test untested $test
set test "pgrep with matching gid" set test "pgrep with matching gid"
spawn $pgrep -G $gid $newsleep spawn $pgrep -G $gid $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep with not matching gid" set test "pgrep with not matching gid"
spawn $pgrep -G $not_gid $newsleep spawn $pgrep -G $not_gid $testproc_comm
expect_blank $test expect_blank $test
set test "pgrep with process name" set test "pgrep with process name"
spawn $pgrep -l $newsleep spawn $pgrep -l $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$newsleep\\s+$sleep2_pid\\s+$newsleep\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc_comm\\s+$testproc2_pid\\s+$testproc_comm\\s*$"
set test "pgrep find newest test pid" set test "pgrep find newest test pid"
spawn $pgrep -n $newsleep spawn $pgrep -n $testproc_comm
expect_pass "$test" "^$sleep2_pid\\s*$" expect_pass "$test" "^$testproc2_pid\\s*$"
set test "pgrep find oldest test pid" set test "pgrep find oldest test pid"
spawn $pgrep -o $newsleep spawn $pgrep -o $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s*$"
set test "pgrep matches with parent pid" set test "pgrep matches with parent pid"
spawn $pgrep -P $mypid $newsleep spawn $pgrep -P $mypid $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep doesn't match with bogus parent pid" 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" expect_blank "$test"
set test "pgrep matches with its own sid" set test "pgrep matches with its own sid"
spawn $pgrep -s $sleep1_sid $newsleep spawn $pgrep -s $testproc1_sid $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep doesn't match with bogus sid" set test "pgrep doesn't match with bogus sid"
spawn $pgrep -s 1 $newsleep spawn $pgrep -s 1 $testproc_comm
expect_blank "$test" expect_blank "$test"
set test "pgrep matches on tty" set test "pgrep matches on tty"
spawn $pgrep -t $tty $newsleep spawn $pgrep -t $tty $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep doesn't match with bogus tty" set test "pgrep doesn't match with bogus tty"
spawn $pgrep -t glass $newsleep spawn $pgrep -t glass $testproc_comm
expect_blank "$test" expect_blank "$test"
set test "pgrep with matching euid" set test "pgrep with matching euid"
spawn $pgrep -u $uid $newsleep spawn $pgrep -u $uid $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep with not matching euid" set test "pgrep with not matching euid"
spawn $pgrep -u $not_uid $newsleep spawn $pgrep -u $not_uid $testproc_comm
expect_blank $test expect_blank $test
set test "pgrep with matching uid" set test "pgrep with matching uid"
spawn $pgrep -U $uid $newsleep spawn $pgrep -U $uid $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep with not matching uid" set test "pgrep with not matching uid"
spawn $pgrep -U $not_uid $newsleep spawn $pgrep -U $not_uid $testproc_comm
expect_blank $test expect_blank $test
set test "pgrep matches on substring" set test "pgrep matches on substring"
spawn $pgrep $newsleep_trim spawn $pgrep $testproc_trim
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep matches full string with exact" set test "pgrep matches full string with exact"
spawn $pgrep -x $newsleep spawn $pgrep -x $testproc_comm
expect_pass "$test" "^$sleep1_pid\\s+$sleep2_pid\\s*$" expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$"
set test "pgrep does not match substring with exact" set test "pgrep does not match substring with exact"
spawn $pgrep -x $newsleep_trim spawn $pgrep -x $testproc_trim
expect_blank $test expect_blank $test
# Cleanup # Cleanup
exec kill $sleep1_pid exec kill $testproc1_pid
exec kill $sleep2_pid exec kill $testproc2_pid
exec rm $newsleep_path exec rm $testproc_path

View File

@ -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

View File

@ -2,30 +2,19 @@
set pwdx "${topdir}pwdx" set pwdx "${topdir}pwdx"
# Run pwdx with no arguments # Run pwdx with no arguments
set test "pwdx no args" set test "pwdx no args"
spawn pwdx spawn $pwdx
expect { expect_pass "$test" "^Usage: pwdx pid\.\.\."
-re "^Usage: pwdx pid\.\.\." { pass "$test" }
eof { fail "$test" }
timeout { fail "$test" }
}
# Run pwdx with pid 1 which is not reachable # Run pwdx with pid 1 which is not reachable
set test "pwdx pid 1 should give permission denied" set test "pwdx pid 1 should give permission denied"
spawn pwdx 1 spawn $pwdx 1
expect { expect_pass "$test" "^1: Permission denied"
-re "^1: Permission denied" { pass "$test" }
eof { fail "$test" }
timeout { fail "$test" }
}
# Run pwdx with existing pid # Run pwdx with existing pid
set test "pwdx finds sleep in cwd" set test "pwdx finds sleep in cwd"
set sleep_pid [ exec sleep 600 & ] set sleep_pid [ exec sleep 600 & ]
set sleep_pwd [ pwd ] set sleep_pwd [ pwd ]
spawn pwdx $sleep_pid spawn $pwdx $sleep_pid
expect { expect_pass "$test" "^$sleep_pid: $sleep_pwd"
-re "^$sleep_pid: $sleep_pwd" { pass "$test" } exec kill $sleep_pid
eof { fail "$test" }
timeout { fail "$test" }
}

View File

@ -5,4 +5,4 @@ set uptime "${topdir}uptime"
set test "uptime" set test "uptime"
spawn $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*$"

View File

@ -4,7 +4,7 @@
# FIXME - the user lines only go to idle # FIXME - the user lines only go to idle
set w "${topdir}w" 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_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_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_from_header "${w_uptime}USER\\s+TTY\\s+FROM\\s+LOGIN@\\s+IDLE\\s+JCPU\\s+PCPU\\s+WHAT\\s+"