From: Craig Small Date: Thu, 24 Nov 2011 12:06:06 +0000 (+1100) Subject: Additional tests for free command X-Git-Tag: v3.3.1~14^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49c99b118967f528f47b573bfba1002da88ce3c9;p=procps-ng Additional tests for free command --- 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+"