]> arthur.barton.de Git - bup.git/blob - test/ext/test-comparative-split-join
Add test-comparative-split-join to test against another bup
[bup.git] / test / ext / test-comparative-split-join
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . dev/lib.sh
5
6 set -o pipefail
7
8 if test -z "$BUP_TEST_OTHER_BUP"; then
9     WVSKIP 'Other bup not specified by BUP_TEST_OTHER_BUP; skipping test'
10     exit 0
11 fi
12
13 seed="${BUP_TEST_RANDOM_SEED:-$RANDOM}"
14
15 WVSTART "split/join against $BUP_TEST_OTHER_BUP (random seed $seed)"
16
17 top="$(WVPASS pwd)" || exit $?
18
19 this_bup="${BUP_TEST_THIS_BUP:-$top/bup}"
20
21 this-bup() { "$this_bup" -d "$this_bup_dir" "$@"; }
22 other-bup() { "$BUP_TEST_OTHER_BUP" -d "$other_bup_dir" "$@"; }
23
24 this_version="$(WVPASS this-bup version)"
25 other_version="$(WVPASS other-bup version)"
26
27 packname-flavor ()
28 {
29     # In bb0e9cbf3900e65d2fddbe888e6cb21c59b308df the packfile name
30     # hashing was changed to match git, which itself may have changed
31     # over time.  Classify bup versions into categories based on the
32     # approach so we can know when we should expect the names to
33     # match.
34     local version="$1"
35     case "$version" in
36         # Versions are now generally 0.32 or 0.32+, but just look at
37         # the leading integers, and assume anything after indicates
38         # "newer".
39         0.?) echo 0 ;;
40
41         0.[0-9]) echo 0 ;;
42         0.[0-9][^0-9]*) echo 0 ;;
43
44         0.[12][0-9]) echo 0 ;;
45         0.[12][0-9][^0-9]*) echo 0 ;;
46
47         0.3[01]) echo 0 ;;
48         0.3[01][^0-9]*) echo 0 ;;
49
50         # Fix was added during 0.33~, but unfortunately, the
51         # base_version wasn't updated immediately after the release,
52         # so many of those commits report 0.32*.  Given that, just
53         # treat all 0.32* as "who knows".
54         0.32|0.32[^0-9]*) echo 1 ;;
55
56         *) echo 2 ;;
57     esac
58 }
59
60 case "$(packname-flavor "$this_version")""$(packname-flavor "$other_version")" in
61     00|22) test_packnames=true ;;
62     *) test_packnames='' ;;
63 esac
64
65 tmpdir="$(WVPASS wvmktempdir)" || exit $?
66
67 WVPASS cd "$tmpdir"
68
69 test-split-join()
70 {
71     local size="$1" orig_dir
72
73     orig_dir="$(WVPASS pwd)"
74
75     WVSTART "split/join of $(($size / 1024))kb"
76
77     WVPASS mkdir split-join
78     WVPASS cd split-join
79
80     this_bup_dir="$(WVPASS pwd)/this-bup"
81     other_bup_dir="$(WVPASS pwd)/other-bup"
82
83     WVPASS this-bup init
84     WVPASS other-bup init
85
86     WVPASS this-bup random --seed "$RANDOM" "$size" > data
87
88     WVPASS other-bup split -t data > other-split-tree
89     WVPASS this-bup split -t data > this-split-tree
90     WVPASSEQ "$(<other-split-tree)" "$(<this-split-tree)"
91
92     WVPASS other-bup join "$(<this-split-tree)" > other-join.data
93     WVPASS this-bup join "$(<this-split-tree)" > this-join.data
94     WVPASS cmp other-join.data this-join.data
95
96     if ! test "$test_packnames"; then
97         # Make sure there's just one of each file in each repo and
98         # compare those via cmp, then delete them.
99         WVPASS test -f other-bup/objects/pack/pack-*.idx
100         WVPASS test -f other-bup/objects/pack/pack-*.pack
101         WVPASS test -f this-bup/objects/pack/pack-*.idx
102         WVPASS test -f this-bup/objects/pack/pack-*.pack
103         WVPASS cmp {other,this}-bup/objects/pack/pack-*.idx
104         WVPASS cmp {other,this}-bup/objects/pack/pack-*.pack
105         WVPASS rm {other,this}-bup/objects/pack/pack-*.idx
106         WVPASS rm {other,this}-bup/objects/pack/pack-*.pack
107         # The bloom filter includes the (differing) idx names
108         WVPASS rm {other,this}-bup/objects/pack/bup.bloom
109     fi
110     WVPASS "$top/dev/compare-trees" --no-times other-bup/ this-bup/
111
112     WVPASS cd "$orig_dir"
113     WVPASS rm -r split-join
114 }
115
116 test-split-join 0
117
118 for i in {1..5}; do
119     test-split-join $(($RANDOM * 1024))
120 done
121
122 cd "$top"
123 WVPASS rm -rf "$tmpdir"