]> git.saurik.com Git - apt.git/blob - test/integration/test-pdiff-usage
allow pdiff bootstrap from all supported compressors
[apt.git] / test / integration / test-pdiff-usage
1 #!/bin/sh
2 set -e
3
4 TESTDIR="$(readlink -f "$(dirname "$0")")"
5 . "$TESTDIR/framework"
6
7 setupenvironment
8 configarchitecture 'i386'
9 confighashes 'SHA1' 'SHA256'
10
11 buildaptarchive
12 setupflataptarchive
13 changetowebserver -o aptwebserver::support::modified-since=false
14
15 PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
16
17 wasmergeused() {
18 testsuccess apt update "$@"
19
20 msgtest 'No intermediate patch files' 'still exist'
21 local EDS="$(find rootdir/var/lib/apt/lists -name '*.ed' -o -name '*.ed.*')"
22 if [ -z "$EDS" ]; then
23 msgpass
24 else
25 echo
26 echo "$EDS"
27 msgfail
28 fi
29
30 msgtest 'Check if the right pdiff merger was used'
31 if grep -q '^pkgAcqIndexMergeDiffs::Done(): rred' rootdir/tmp/testsuccess.output; then
32 if echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
33 msgpass
34 else
35 msgfail "Merge shouldn't have been used, but was"
36 fi
37 elif echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
38 msgfail "Merge should have been used, but wasn't"
39 else
40 msgpass
41 fi
42 }
43
44 testrun() {
45 configcompression '.' 'xz'
46 msgmsg "Testcase: setup the base with: $*"
47 local DOWNLOADHASH=true
48 if [ "$1" = 'nohash' ]; then DOWNLOADHASH=false; shift; fi
49 find aptarchive -name 'Packages*' -type f -delete
50 cp "${PKGFILE}" aptarchive/Packages
51 compressfile 'aptarchive/Packages'
52 generatereleasefiles
53 signreleasefiles
54 rm -rf aptarchive/Packages.diff rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
55 testsuccess aptget update "$@"
56 cp -a rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
57 testnopackage newstuff
58 testsuccessequal "$(cat "${PKGFILE}")
59 " aptcache show apt oldstuff
60 configcompression '.' 'gz'
61
62 msgmsg "Testcase: apply with one patch: $*"
63 find aptarchive -name 'Packages*' -type f -delete
64 cp "${PKGFILE}-new" aptarchive/Packages
65 compressfile 'aptarchive/Packages'
66 mkdir -p aptarchive/Packages.diff
67 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
68 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
69 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
70 PATCHINDEX='aptarchive/Packages.diff/Index'
71 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
72 SHA1-History:
73 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
74 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
75 SHA1-Patches:
76 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
77 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
78 SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
79 SHA256-History:
80 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
81 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
82 SHA256-Patches:
83 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
84 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > "$PATCHINDEX"
85 if $DOWNLOADHASH; then
86 echo "SHA1-Download:
87 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
88 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
89 SHA256-Download:
90 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
91 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" >> "$PATCHINDEX"
92 fi
93
94 generatereleasefiles '+1hour'
95 signreleasefiles
96 find aptarchive -name 'Packages*' -type f -delete
97 wasmergeused "$@"
98 testnopackage oldstuff
99 testsuccessequal "$(cat "${PKGFILE}-new")
100 " aptcache show apt newstuff
101
102 msgmsg "Testcase: apply with two patches: $*"
103 cp "${PKGFILE}-new" aptarchive/Packages
104 echo '
105 Package: futurestuff
106 Version: 1.0
107 Architecture: i386
108 Maintainer: Joe Sixpack <joe@example.org>
109 Installed-Size: 202
110 Filename: pool/futurestuff_1.0_i386.deb
111 Size: 202200
112 MD5sum: 311aeeaaae5ba33aff1ceaf3e1f76671
113 SHA1: 3c695e028f7a1ae324deeaae5ba332desa81088c
114 SHA256: b46fd154615edaae5ba33c56a5cc0e7deaef23e2da3e4f129727fd660f28f050
115 Description: some cool and shiny future stuff
116 This package will appear in the next next mirror update
117 Description-md5: d5f89fbbc2ce34c455dfee9b67d82b6b' >> aptarchive/Packages
118
119 compressfile 'aptarchive/Packages'
120 PATCHFILE2="aptarchive/Packages.diff/$(date -d 'now + 1hour' '+%Y-%m-%d-%H%M.%S')"
121 diff -e "${PKGFILE}-new" aptarchive/Packages > "${PATCHFILE2}" || true
122 cat "$PATCHFILE2" | gzip > "${PATCHFILE2}.gz"
123 echo "SHA1-Current: $(sha1sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
124 SHA1-History:
125 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
126 $(sha1sum "${PKGFILE}" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}") $(basename "${PATCHFILE}")
127 $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
128 SHA1-Patches:
129 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
130 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
131 $(sha1sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")
132 SHA256-Current: $(sha256sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
133 SHA256-History:
134 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
135 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
136 $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
137 SHA256-Patches:
138 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
139 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
140 $(sha256sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")" > "$PATCHINDEX"
141 if $DOWNLOADHASH; then
142 echo "SHA1-Download:
143 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
144 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
145 $(sha1sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")
146 SHA256-Download:
147 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
148 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
149 $(sha256sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")" >> "$PATCHINDEX"
150 fi
151
152 generatereleasefiles '+2hour'
153 signreleasefiles
154 cp -a aptarchive/Packages Packages-future
155 find aptarchive -name 'Packages*' -type f -delete
156 rm -rf rootdir/var/lib/apt/lists
157 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
158 wasmergeused "$@"
159 testnopackage oldstuff
160 testsuccessequal "$(cat Packages-future)
161 " aptcache show apt newstuff futurestuff
162
163 msgmsg "Testcase: patch applying fails, but successful fallback: $*"
164 rm -rf rootdir/var/lib/apt/lists
165 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
166 cp "${PKGFILE}-new" aptarchive/Packages
167 compressfile 'aptarchive/Packages'
168 mkdir -p aptarchive/Packages.diff
169 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
170 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
171 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
172 PATCHINDEX='aptarchive/Packages.diff/Index'
173 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
174 SHA1-History:
175 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
176 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
177 SHA1-Patches:
178 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
179 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
180 SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
181 SHA256-History:
182 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
183 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
184 SHA256-Patches:
185 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
186 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > $PATCHINDEX
187 if $DOWNLOADHASH; then
188 echo "SHA1-Download:
189 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
190 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
191 SHA256-Download:
192 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
193 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" >> $PATCHINDEX
194 fi
195 # needs to look like a valid command, otherwise the parser will fail before hashes are checked
196 echo '1d' > "$PATCHFILE"
197 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
198 generatereleasefiles '+1hour'
199 signreleasefiles
200 testsuccess apt update "$@"
201 cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
202 testsuccess grep 'Hash Sum mismatch' rootdir/tmp/aptupdate.output
203 testnopackage oldstuff
204 testsuccessequal "$(cat "${PKGFILE}-new")
205 " aptcache show apt newstuff
206
207 msgmsg "Testcase: pdiff patch bigger than index itself: $*"
208 rm -rf rootdir/var/lib/apt/lists
209 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
210 cp "${PKGFILE}-new" aptarchive/Packages
211 compressfile 'aptarchive/Packages'
212 mkdir -p aptarchive/Packages.diff
213 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
214 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
215 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
216 PATCHINDEX='aptarchive/Packages.diff/Index'
217 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
218 SHA1-History:
219 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
220 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
221 SHA1-Patches:
222 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
223 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE")000 $(basename "$PATCHFILE")
224 SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
225 SHA256-History:
226 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
227 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
228 SHA256-Patches:
229 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
230 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE")000 $(basename "$PATCHFILE")" > "$PATCHINDEX"
231 if $DOWNLOADHASH; then
232 echo "SHA1-Download:
233 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
234 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")
235 SHA256-Download:
236 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
237 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")" >> "$PATCHINDEX"
238 fi
239 generatereleasefiles '+1hour'
240 signreleasefiles
241 testsuccess apt update -o Debug::pkgAcquire::Diffs=1 "$@"
242 cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
243 testsuccess grep 'bytes (Limit is' rootdir/tmp/aptupdate.output
244 testnopackage oldstuff
245 testsuccessequal "$(cat "${PKGFILE}-new")
246 " aptcache show apt newstuff
247 }
248 echo 'Debug::pkgAcquire::Diffs "true";
249 Debug::Acquire::Transaction "true";
250 Debug::pkgAcquire::rred "true";' > rootdir/etc/apt/apt.conf.d/rreddebug.conf
251
252 testcase() {
253 testrun nohash -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
254 testrun nohash -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
255
256 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
257 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
258 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=0 "$@"
259 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=0 "$@"
260
261 sha256sum() {
262 echo '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b -'
263 }
264 testrun -o Acquire::PDiffs::Merge=0 -o Acquire::ForceHash=SHA1 "$@"
265 testrun -o Acquire::PDiffs::Merge=1 -o Acquire::ForceHash=SHA1 "$@"
266 unset -f sha256sum
267
268 sha1sum() {
269 echo 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc -'
270 }
271 testrun -o Acquire::PDiffs::Merge=0 -o Acquire::ForceHash=SHA256 "$@"
272 testrun -o Acquire::PDiffs::Merge=1 -o Acquire::ForceHash=SHA256 "$@"
273 unset -f sha1sum
274 }
275 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages"; }
276 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=false
277 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages.gz"; }
278 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true