2011-11-23 17:18:49 +05:30
|
|
|
#
|
|
|
|
# Testsuite for free program
|
|
|
|
#
|
|
|
|
|
|
|
|
set free "${topdir}free"
|
2011-11-24 17:36:06 +05:30
|
|
|
set meminfo [ exec cat /proc/meminfo ]
|
|
|
|
regexp "MemTotal:\\s+\(\\d+\)" $meminfo -> memtotal_kb
|
|
|
|
regexp "SwapTotal:\\s+\(\\d+\)" $meminfo -> swaptotal_kb
|
|
|
|
|
2014-08-19 18:13:33 +05:30
|
|
|
set free_header "\\s+total\\s+used\\s+free\\s+shared\\s+buff\\/cache\\s+available\\s*"
|
2011-11-24 17:36:06 +05:30
|
|
|
|
2011-11-23 17:18:49 +05:30
|
|
|
set test "free with no arguments"
|
2011-12-02 19:02:14 +05:30
|
|
|
spawn $free
|
2014-08-19 18:13:33 +05:30
|
|
|
expect_pass "$test" "^${free_header}Mem:\\s+${memtotal_kb}\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal_kb}\\s+\\d+\\s+\\d+\\s*"
|
2011-11-24 17:36:06 +05:30
|
|
|
|
|
|
|
set test "free with -b argument"
|
|
|
|
set memtotal [ expr { $memtotal_kb * 1024 } ]
|
|
|
|
set swaptotal [ expr { $swaptotal_kb * 1024 } ]
|
2011-12-02 19:02:14 +05:30
|
|
|
spawn $free -b
|
2014-08-19 18:13:33 +05:30
|
|
|
expect_pass "$test" "^${free_header}Mem:\\s+${memtotal}\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal}\\s+\\d+\\s+\\d+\\s*"
|
2011-11-24 17:36:06 +05:30
|
|
|
|
2018-01-13 10:39:54 +05:30
|
|
|
foreach {arg divisor } {-k 1024 -m 1048576 -g 1073741824 --kilo 1000 --mega 1000000 --giga 1000000000 } {
|
2011-11-24 17:36:06 +05:30
|
|
|
set test "free with $arg argument"
|
2018-01-13 10:39:54 +05:30
|
|
|
set memtest [ expr { $memtotal / $divisor } ]
|
|
|
|
set swaptest [ expr { $swaptotal / $divisor } ]
|
2011-12-02 19:02:14 +05:30
|
|
|
spawn $free $arg
|
2018-01-13 10:39:54 +05:30
|
|
|
expect_pass "$test" "^${free_header}Mem:\\s+$memtest\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptest}\\s+\\d+\\s+\\d+\\s*"
|
2011-11-24 17:36:06 +05:30
|
|
|
}
|
|
|
|
|
2011-12-02 19:02:14 +05:30
|
|
|
#set test "free with human readable output"
|
|
|
|
#spawn $free -h
|
|
|
|
#expect_pass "$test" "${free_header}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*"
|
2011-11-24 17:36:06 +05:30
|
|
|
|
|
|
|
set test "free with lo and hi memory statistics"
|
2011-12-02 19:02:14 +05:30
|
|
|
spawn $free -l
|
2014-08-19 18:13:33 +05:30
|
|
|
expect_pass "$test" "^${free_header}Mem:\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Low:\\s+\\d+\\s+\\d+\\s+\\d+\\s*High:\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+\\d+\\s+\\d+\\s+\\d+"
|
2011-11-27 10:00:04 +05:30
|
|
|
|
|
|
|
set test "free with total"
|
2011-12-02 19:02:14 +05:30
|
|
|
spawn $free -t
|
2014-08-19 18:13:33 +05:30
|
|
|
expect_pass "$test" "^${free_header}Mem:\\s+${memtotal_kb}\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s*Swap:\\s+${swaptotal_kb}\\s+\\d+\\s+\\d+\\s*Total:\\s+\\d+\\s+\\d+\\s+\\d+\\s*"
|
2011-11-27 10:00:04 +05:30
|
|
|
|
2012-01-04 04:37:31 +05:30
|
|
|
set test "free with negative repeat count"
|
|
|
|
spawn $free -c -2
|
|
|
|
expect_pass "$test" "\(lt-\)\?free: failed to parse count argument: '-2': Numerical result out of range"
|
|
|
|
|
|
|
|
set test "free with zero repeat count"
|
|
|
|
spawn $free -c 0
|
|
|
|
expect_pass "$test" "\(lt-\)\?free: failed to parse count argument: '0': Numerical result out of range"
|
|
|
|
|
2012-04-23 22:20:49 +05:30
|
|
|
set test "free with positive repeat count"
|
2012-01-04 04:37:31 +05:30
|
|
|
spawn $free -c 2
|
|
|
|
expect_continue "$test" "^${free_header}"
|
|
|
|
expect_pass "$test" "${free_header}"
|