free: Update tests and fix for previous patch

The previous two patches updated free, but needed a tweak and the tests
also needed to be updated. I've hand-calculated the results using bc and
both the testsuite and bc results equal what free prints out.

References:
 commit 9365be7633
 procps-ng/procps#45
This commit is contained in:
Craig Small 2018-01-13 16:09:54 +11:00
parent ff700abc72
commit 233b5228be
3 changed files with 6 additions and 5 deletions

1
NEWS
View File

@ -1,6 +1,7 @@
procps-ng-NEXT
----------------
* doc: Document I idle state in ps.1 and top.1 Debian #886967
* free: fix some of the SI multiples issue #45
* kill: -l space between name parses correctly Debian #854407
* library: dont use vm_min_free on non Linux Debian #831396
* library: dont use SIGPWR on FreeBSD Debian #832148

2
free.c
View File

@ -133,7 +133,7 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
if (args.exponent > 1) {
/* In desired scale. */
snprintf(buf, sizeof(buf), "%ld",
(long int)((size / 1024) * base / power(base, args.exponent - 2))
(long int)((size * 1024) / power(base, args.exponent-1))
);
return buf;
}

View File

@ -19,12 +19,12 @@ set swaptotal [ expr { $swaptotal_kb * 1024 } ]
spawn $free -b
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*"
foreach {arg divisor } {-k 1 -m 1024 -g 1048576 --mega 1000 --giga 1000000 } {
foreach {arg divisor } {-k 1024 -m 1048576 -g 1073741824 --kilo 1000 --mega 1000000 --giga 1000000000 } {
set test "free with $arg argument"
set memtotal [ expr { $memtotal_kb / $divisor } ]
set swaptotal [ expr { $swaptotal_kb / $divisor } ]
set memtest [ expr { $memtotal / $divisor } ]
set swaptest [ expr { $swaptotal / $divisor } ]
spawn $free $arg
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*"
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*"
}
#set test "free with human readable output"