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 83cb56f0..3ab70930 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..96ef0306 --- /dev/null +++ b/testsuite/.gitignore @@ -0,0 +1,4 @@ +*.log +*.sum +site.bak +site.exp diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am new file mode 100644 index 00000000..73df0c26 --- /dev/null +++ b/testsuite/Makefile.am @@ -0,0 +1,32 @@ +AUTOMAKE_OPTIONS = dejagnu +export DEJAGNU + +DEJATOOL = \ + free \ + kill \ + pgrep \ + pkill \ + pmap \ + ps \ + pwdx \ + uptime \ + vmstat \ + w + + +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 \ + pmap.test/pmap.exp \ + ps.test/ps_output.exp \ + ps.test/ps_personality.exp \ + pwdx.test/pwdx.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 new file mode 100644 index 00000000..eb984b81 --- /dev/null +++ b/testsuite/config/unix.exp @@ -0,0 +1,85 @@ + +regexp "(.*\/)testsuite" $objdir objdir topdir + +proc procps_v_version { tool } { + global topdir + set toolpath ${topdir}${tool} + set tmp [ exec $toolpath -V ] + regexp "procps-ng version (\[0-9.\]*)" $tmp tmp version + clone_output "$toolpath 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 } + +# +# +# 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" } + default { fail "$testname" } + } +} + +proc expect_blank { testname } { + expect { + -re "\\w" { fail "$testname" } + eof { pass "$testname" } + timeout { pass "$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 + + global testproc_path testproc_comm testproc1_pid testproc2_pid + + set testproc_path [ exec mktemp -u ] + exec ln -s "/bin/sleep" $testproc_path + 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/free.test/free.exp b/testsuite/free.test/free.exp new file mode 100644 index 00000000..6dace6e7 --- /dev/null +++ b/testsuite/free.test/free.exp @@ -0,0 +1,44 @@ +# +# Testsuite for free program +# + +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+${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+" + +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/global-conf.exp b/testsuite/global-conf.exp new file mode 100644 index 00000000..e69de29b 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 new file mode 100644 index 00000000..c030092b --- /dev/null +++ b/testsuite/pgrep.test/pgrep.exp @@ -0,0 +1,117 @@ +# +# 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 + +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 $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" + +# In Debian only +#set test "pgrep counts 2 test pids" +#spawn $pgrep -c $testproc_comm +#expect_pass "$test" "^2\\s*" + +set test "pgrep with : delimiter" +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 $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" + +set test "pgrep with not matching gid" +spawn $pgrep -G $not_gid $testproc_comm +expect_blank $test + +set test "pgrep with process name" +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 $testproc_comm +expect_pass "$test" "^$testproc2_pid\\s*$" + +set test "pgrep find oldest test pid" +spawn $pgrep -o $testproc_comm +expect_pass "$test" "^$testproc1_pid\\s*$" + +set test "pgrep matches with parent pid" +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 $testproc_comm +expect_blank "$test" + +set test "pgrep matches with its own sid" +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 $testproc_comm +expect_blank "$test" + +set test "pgrep matches on tty" +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 $testproc_comm +expect_blank "$test" + +set test "pgrep with matching euid" +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 $testproc_comm +expect_blank $test + +set test "pgrep with matching uid" +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 $testproc_comm +expect_blank $test + +set test "pgrep matches on substring" +spawn $pgrep $testproc_trim +expect_pass "$test" "^$testproc1_pid\\s+$testproc2_pid\\s*$" + +set test "pgrep matches full string with exact" +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 $testproc_trim +expect_blank $test + + +# Cleanup +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/pmap.test/pmap.exp b/testsuite/pmap.test/pmap.exp new file mode 100644 index 00000000..5dce21e7 --- /dev/null +++ b/testsuite/pmap.test/pmap.exp @@ -0,0 +1,48 @@ +# +# 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 new file mode 100644 index 00000000..abc7bd5e --- /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 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*$" diff --git a/testsuite/w.test/w.exp b/testsuite/w.test/w.exp new file mode 100644 index 00000000..93418276 --- /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}" +