more free tests and pgrep tests
Almost fully testing all features of pgrep now. free had additional tests added to it
This commit is contained in:
parent
49c99b1189
commit
2cad7c5667
@ -37,3 +37,11 @@ proc expect_pass { testname reg } {
|
|||||||
timeout { fail "$testname" }
|
timeout { fail "$testname" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc expect_blank { testname } {
|
||||||
|
expect {
|
||||||
|
-re "\\w" { fail "$testname" }
|
||||||
|
eof { pass "$testname" }
|
||||||
|
timeout { pass "$testname" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -37,3 +37,8 @@ expect_pass "$test" "^\\s+total\\s+used\\s+free\\s+shared\\s+buffers\\s+cached\\
|
|||||||
set test "free old argument"
|
set test "free old argument"
|
||||||
spawn free -o
|
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+"
|
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*"
|
||||||
|
|
||||||
|
125
testsuite/procps-ng.test/pgrep.test/pgrep.exp
Normal file
125
testsuite/procps-ng.test/pgrep.test/pgrep.exp
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user