]> granicus.if.org Git - procps-ng/commitdiff
free: Update tests and fix for previous patch
authorCraig Small <csmall@enc.com.au>
Sat, 13 Jan 2018 05:09:54 +0000 (16:09 +1100)
committerCraig Small <csmall@enc.com.au>
Sat, 13 Jan 2018 05:09:54 +0000 (16:09 +1100)
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 9365be7633d23a68837868875c7b157516cd3058
 procps-ng/procps#45

NEWS
free.c
testsuite/free.test/free.exp

diff --git a/NEWS b/NEWS
index 89a52b1000ea32cfba2745345bd62c260cfba6fb..b390b6af2709c29586659b736a6e16a41abbfc4f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/free.c b/free.c
index 6d81548e0ac60955d7e1b0513cac09009661fcb5..08cb73bda14fd2217dadc81b29bf43a45055ff79 100644 (file)
--- a/free.c
+++ b/free.c
@@ -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;
                }
index 83e197e4295febc81d71ba28e92186063ac153dd..d019eb4cbc8c363bfcd25a2da99abe160a7a6ad6 100644 (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"