]> arthur.barton.de Git - bup.git/commitdiff
Compute exact sizes via t/data-size in test-gc.sh
authorRob Browning <rlb@defaultvalue.org>
Tue, 24 May 2016 00:15:30 +0000 (19:15 -0500)
committerRob Browning <rlb@defaultvalue.org>
Tue, 24 May 2016 23:13:56 +0000 (18:13 -0500)
Add a t/data-size helper that computes the total data size of all named
paths and use it instead of du in test-gc.sh to determine the
before/after repository sizes.

This should fix spurious test failures on filesystems with a large block
size.  (Observed on ppc64el and powerpc tmpfs filesystems.)

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
t/data-size [new file with mode: 0755]
t/test-gc.sh

diff --git a/t/data-size b/t/data-size
new file mode 100755 (executable)
index 0000000..d7da545
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+from os.path import getsize, isdir
+from sys import argv, stderr
+import os
+
+def listdir_failure(ex):
+    raise ex
+
+def usage():
+    print >> stderr, "Usage: data-size PATH ..."
+
+total = 0
+for path in argv[1:]:
+    if isdir(path):
+        for root, dirs, files in os.walk(path, onerror=listdir_failure):
+            total += sum(getsize(os.path.join(root, name)) for name in files)
+    else:
+        total += getsize(path)
+
+print total
index face6e5421ed7ad7e950719025c3c9cabddc4f88..0119f467048f54b58161ebef61055bb59858e851 100755 (executable)
@@ -13,6 +13,7 @@ GC_OPTS=--unsafe
 
 bup() { "$top/bup" "$@"; }
 compare-trees() { "$top/t/compare-trees" "$@"; }
+data-size() { "$top/t/data-size" "$@"; }
 
 WVPASS cd "$tmpdir"
 WVPASS bup init
@@ -51,13 +52,13 @@ WVPASS compare-trees src-2/ "$tmpdir/restore/latest/"
 
 WVSTART "gc (removed branch)"
 
-size_before=$(WVPASS du -k -s "$BUP_DIR" | WVPASS cut -f1) || exit $?
+size_before=$(WVPASS data-size "$BUP_DIR") || exit $?
 WVPASS rm "$BUP_DIR/refs/heads/src-2"
 WVPASS bup gc $GC_OPTS -v
-size_after=$(WVPASS du -k -s "$BUP_DIR" | WVPASS cut -f1) || exit $?
+size_after=$(WVPASS data-size "$BUP_DIR") || exit $?
 
-WVPASS [ "$size_before" -gt 5000 ]
-WVPASS [ "$size_after" -lt 500 ]
+WVPASS [ "$size_before" -gt 5000000 ]
+WVPASS [ "$size_after" -lt 50000 ]
 
 WVPASS rm -r "$tmpdir/restore"
 WVPASS bup restore -C "$tmpdir/restore" /src-1/latest
@@ -85,13 +86,13 @@ WVPASS bup index --clear
 WVPASS bup index src-ab
 WVPASS bup save -vvv --strip -n a src-ab/a
 
-size_before=$(WVPASS du -k -s "$BUP_DIR" | WVPASS cut -f1) || exit $?
+size_before=$(WVPASS data-size "$BUP_DIR") || exit $?
 WVPASS rm "$BUP_DIR/refs/heads/src-ab"
 WVPASS bup gc $GC_OPTS -v
-size_after=$(WVPASS du -k -s "$BUP_DIR" | WVPASS cut -f1) || exit $?
+size_after=$(WVPASS data-size "$BUP_DIR") || exit $?
 
-WVPASS [ "$size_before" -gt 5000 ]
-WVPASS [ "$size_after" -lt 500 ]
+WVPASS [ "$size_before" -gt 5000000 ]
+WVPASS [ "$size_after" -lt 100000 ]
 
 WVPASS rm -r "$tmpdir/restore"
 WVPASS bup restore -C "$tmpdir/restore" /a/latest
@@ -115,13 +116,13 @@ WVPASS bup index --clear
 WVPASS bup index src-ab
 WVPASS bup save -r :bup-remote -vvv --strip -n a src-ab/a
 
-size_before=$(WVPASS du -k -s bup-remote | WVPASS cut -f1) || exit $?
+size_before=$(WVPASS data-size bup-remote) || exit $?
 WVPASS rm bup-remote/refs/heads/src-ab
 WVPASS bup -d bup-remote gc $GC_OPTS -v
-size_after=$(WVPASS du -k -s bup-remote | WVPASS cut -f1) || exit $?
+size_after=$(WVPASS data-size bup-remote) || exit $?
 
-WVPASS [ "$size_before" -gt 5000 ]
-WVPASS [ "$size_after" -lt 500 ]
+WVPASS [ "$size_before" -gt 5000000 ]
+WVPASS [ "$size_after" -lt 100000 ]
 
 WVPASS rm -rf "$tmpdir/restore"
 WVPASS bup -d bup-remote restore -C "$tmpdir/restore" /a/latest
@@ -151,13 +152,13 @@ WVPASS bup index --clear
 WVPASS bup on - index src-ab
 WVPASS bup on - save -vvv --strip -n a src-ab/a
 
-size_before=$(WVPASS du -k -s "$BUP_DIR" | WVPASS cut -f1) || exit $?
+size_before=$(WVPASS data-size "$BUP_DIR") || exit $?
 WVPASS rm "$BUP_DIR/refs/heads/src-ab"
 WVPASS bup gc $GC_OPTS -v
-size_after=$(WVPASS du -k -s "$BUP_DIR" | WVPASS cut -f1) || exit $?
+size_after=$(WVPASS data-size "$BUP_DIR") || exit $?
 
-WVPASS [ "$size_before" -gt 5000 ]
-WVPASS [ "$size_after" -lt 500 ]
+WVPASS [ "$size_before" -gt 5000000 ]
+WVPASS [ "$size_after" -lt 100000 ]
 
 WVPASS rm -r "$tmpdir/restore"
 WVPASS bup restore -C "$tmpdir/restore" /a/latest