test-pdiff-usage 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'i386'
  7. LOWCOSTEXT='lz4'
  8. buildaptarchive
  9. setupflataptarchive
  10. changetowebserver
  11. cat >rootdir/etc/apt/apt.conf.d/contents.conf <<EOF
  12. Acquire::IndexTargets::deb::Contents {
  13. MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
  14. ShortDescription "Contents";
  15. Description "\$(RELEASE)/\$(COMPONENT) \$(ARCHITECTURE) Contents";
  16. MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
  17. flatMetaKey "Contents-\$(ARCHITECTURE)";
  18. flatDescription "\$(RELEASE) \$(ARCHITECTURE) Contents";
  19. };
  20. EOF
  21. PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
  22. echo 'contents for stuff' > aptarchive/Contents-i386
  23. compressfile aptarchive/Contents-i386
  24. echo 'hacked' > aptarchive/hacked-i386
  25. compressfile aptarchive/hacked-i386
  26. wasmergeused() {
  27. testsuccess apt update "$@" -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1 -o Debug::pkgAcquire=1
  28. msgtest 'No intermediate patch files' 'still exist'
  29. local EDS="$(find rootdir/var/lib/apt/lists -name '*.ed' -o -name '*.ed.*')"
  30. if [ -z "$EDS" ]; then
  31. msgpass
  32. else
  33. echo
  34. echo "$EDS"
  35. msgfail
  36. fi
  37. if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
  38. msgtest 'Check if pdiff was' 'not used'
  39. cp -a rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
  40. testsuccess --nomsg grep "diff/Index with Message: Couldn't parse pdiff index" rootdir/tmp/aptupdate.output
  41. return;
  42. fi
  43. msgtest 'Check if the right pdiff merger was used'
  44. if grep -q '^pkgAcqIndexMergeDiffs::Done(): rred' rootdir/tmp/testsuccess.output; then
  45. if echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
  46. msgpass
  47. else
  48. msgfail "Merge shouldn't have been used, but was"
  49. fi
  50. elif echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
  51. msgfail "Merge should have been used, but wasn't"
  52. else
  53. msgpass
  54. fi
  55. testequal '1' grep -c rred:601 rootdir/tmp/testsuccess.output
  56. }
  57. testrun() {
  58. configcompression '.' 'xz'
  59. msgmsg "Testcase: setup the base with: $*"
  60. find aptarchive -name 'Packages*' -type f -delete
  61. cp "${PKGFILE}" aptarchive/Packages
  62. compressfile 'aptarchive/Packages'
  63. generatereleasefiles
  64. signreleasefiles
  65. rm -rf aptarchive/Packages.diff rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
  66. testsuccess aptget update "$@"
  67. cp -a rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
  68. testnopackage newstuff
  69. testsuccessequal "$(cat "${PKGFILE}")
  70. " aptcache show apt oldstuff
  71. configcompression '.' 'gz'
  72. # see if the code deals properly with leftover partial files
  73. partialleftovers
  74. msgmsg "Testcase: apply with one patch: $*"
  75. find aptarchive -name 'Packages*' -type f -delete
  76. cp "${PKGFILE}-new" aptarchive/Packages
  77. compressfile 'aptarchive/Packages'
  78. mkdir -p aptarchive/Packages.diff
  79. PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
  80. diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
  81. cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
  82. PATCHINDEX='aptarchive/Packages.diff/Index'
  83. echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
  84. SHA256-History:
  85. 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
  86. $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
  87. SHA256-Patches:
  88. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
  89. $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
  90. SHA256-Download:
  91. d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
  92. $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
  93. generatereleasefiles '+1hour'
  94. signreleasefiles
  95. find aptarchive -name 'Packages*' -type f -delete
  96. wasmergeused "$@"
  97. testnopackage oldstuff
  98. testsuccessequal "$(cat "${PKGFILE}-new")
  99. " aptcache show apt newstuff
  100. msgmsg "Testcase: SHA1-only patches are not used: $*"
  101. find aptarchive -name 'Packages*' -type f -delete
  102. cp "${PKGFILE}-new" aptarchive/Packages
  103. compressfile 'aptarchive/Packages'
  104. mkdir -p aptarchive/Packages.diff
  105. PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
  106. diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
  107. cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
  108. PATCHINDEX='aptarchive/Packages.diff/Index'
  109. echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
  110. SHA1-History:
  111. 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
  112. $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
  113. SHA1-Patches:
  114. 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
  115. $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
  116. SHA1-Download:
  117. 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
  118. $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
  119. generatereleasefiles '+1hour'
  120. signreleasefiles
  121. rm -rf rootdir/var/lib/apt/lists
  122. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  123. wasmergeused "$@" -o test::cannot-use-pdiff=1
  124. testnopackage oldstuff
  125. testsuccessequal "$(cat "${PKGFILE}-new")
  126. " aptcache show apt newstuff
  127. msgmsg "Testcase: no download-hashes patches are not used: $*"
  128. find aptarchive -name 'Packages*' -type f -delete
  129. cp "${PKGFILE}-new" aptarchive/Packages
  130. compressfile 'aptarchive/Packages'
  131. mkdir -p aptarchive/Packages.diff
  132. PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
  133. diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
  134. cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
  135. PATCHINDEX='aptarchive/Packages.diff/Index'
  136. echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
  137. SHA256-History:
  138. 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
  139. $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
  140. SHA256-Patches:
  141. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
  142. $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > "$PATCHINDEX"
  143. generatereleasefiles '+1hour'
  144. signreleasefiles
  145. rm -rf rootdir/var/lib/apt/lists
  146. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  147. wasmergeused "$@" -o test::cannot-use-pdiff=1
  148. testnopackage oldstuff
  149. testsuccessequal "$(cat "${PKGFILE}-new")
  150. " aptcache show apt newstuff
  151. msgmsg "Testcase: apply with two patches: $*"
  152. cp "${PKGFILE}-new" aptarchive/Packages
  153. echo '
  154. Package: futurestuff
  155. Version: 1.0
  156. Architecture: i386
  157. Maintainer: Joe Sixpack <joe@example.org>
  158. Installed-Size: 202
  159. Filename: pool/futurestuff_1.0_i386.deb
  160. Size: 202200
  161. SHA256: b46fd154615edaae5ba33c56a5cc0e7deaef23e2da3e4f129727fd660f28f050
  162. Description: some cool and shiny future stuff
  163. This package will appear in the next next mirror update
  164. Description-md5: d5f89fbbc2ce34c455dfee9b67d82b6b' >> aptarchive/Packages
  165. compressfile 'aptarchive/Packages'
  166. PATCHFILE2="aptarchive/Packages.diff/$(date -d 'now + 1hour' '+%Y-%m-%d-%H%M.%S')"
  167. diff -e "${PKGFILE}-new" aptarchive/Packages > "${PATCHFILE2}" || true
  168. cat "$PATCHFILE2" | gzip > "${PATCHFILE2}.gz"
  169. echo "SHA256-Current: $(sha256sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
  170. SHA256-History:
  171. 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
  172. $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
  173. $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
  174. SHA256-Patches:
  175. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
  176. $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
  177. $(sha256sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")
  178. SHA256-Download:
  179. d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
  180. $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
  181. $(sha256sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")" > "$PATCHINDEX"
  182. generatereleasefiles '+2hour'
  183. signreleasefiles
  184. cp -a aptarchive/Packages Packages-future
  185. find aptarchive -name 'Packages*' -type f -delete
  186. rm -rf rootdir/var/lib/apt/lists
  187. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  188. wasmergeused "$@"
  189. testnopackage oldstuff
  190. testsuccessequal "$(cat Packages-future)
  191. " aptcache show apt newstuff futurestuff
  192. # we reuse the archive state of the previous test here
  193. msgmsg "Testcase: pdiff handling is stopped if transaction fails $*"
  194. rm -rf rootdir/var/lib/apt/lists
  195. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  196. cp Packages-future aptarchive/Packages
  197. rm -f rootdir/var/lib/apt/lists/*_Contents-*
  198. webserverconfig 'aptwebserver::overwrite::.*Contents-.*::filename' '/hacked-i386.gz'
  199. testfailure apt update "$@"
  200. webserverconfig 'aptwebserver::overwrite::.*Contents-.*::filename' '/Contents-i386.gz'
  201. cp rootdir/tmp/testfailure.output patchdownload.output
  202. testfailure grep 'rred:600' patchdownload.output
  203. testnopackage newstuff futurestuff
  204. testsuccessequal "$(cat "${PKGFILE}")
  205. " aptcache show apt oldstuff
  206. # we reuse the archive state of the previous test here
  207. msgmsg "Testcase: downloading a patch fails, but successful fallback: $*"
  208. rm -rf rootdir/var/lib/apt/lists
  209. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  210. cp Packages-future aptarchive/Packages
  211. rm "${PATCHFILE}.gz"
  212. testsuccess apt update "$@"
  213. cp rootdir/tmp/testsuccess.output patchdownload.output
  214. testsuccess grep '^Falling back to normal index file acquire' patchdownload.output
  215. testnopackage oldstuff
  216. testsuccessequal "$(cat Packages-future)
  217. " aptcache show apt newstuff futurestuff
  218. msgmsg "Testcase: patch applying fails, but successful fallback: $*"
  219. rm -rf rootdir/var/lib/apt/lists
  220. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  221. cp "${PKGFILE}-new" aptarchive/Packages
  222. compressfile 'aptarchive/Packages'
  223. mkdir -p aptarchive/Packages.diff
  224. PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
  225. diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
  226. cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
  227. PATCHINDEX='aptarchive/Packages.diff/Index'
  228. echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
  229. SHA256-History:
  230. 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
  231. $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
  232. SHA256-Patches:
  233. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
  234. $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
  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") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
  238. # needs to look like a valid command, otherwise the parser will fail before hashes are checked
  239. echo '1d' > "$PATCHFILE"
  240. cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
  241. generatereleasefiles '+1hour'
  242. signreleasefiles
  243. testsuccess apt update "$@"
  244. cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
  245. testsuccess grep 'Hash Sum mismatch' rootdir/tmp/aptupdate.output
  246. testnopackage oldstuff
  247. testsuccessequal "$(cat "${PKGFILE}-new")
  248. " aptcache show apt newstuff
  249. msgmsg "Testcase: pdiff patch bigger than index itself: $*"
  250. rm -rf rootdir/var/lib/apt/lists
  251. cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
  252. # the general testcode checks for leftovers in partial, but as this file
  253. # is never touched in this test as it exits earlier its not a leftover…
  254. rm -f rootdir/var/lib/apt/lists/partial/localhost:${APTHTTPPORT}_Packages
  255. cp "${PKGFILE}-new" aptarchive/Packages
  256. compressfile 'aptarchive/Packages'
  257. mkdir -p aptarchive/Packages.diff
  258. PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
  259. diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
  260. cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
  261. PATCHINDEX='aptarchive/Packages.diff/Index'
  262. echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
  263. SHA256-History:
  264. 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
  265. $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
  266. SHA256-Patches:
  267. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
  268. $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
  269. SHA256-Download:
  270. d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
  271. $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
  272. generatereleasefiles '+1hour'
  273. signreleasefiles
  274. testsuccess apt update -o Debug::pkgAcquire::Diffs=1 "$@"
  275. cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
  276. testsuccess grep 'bytes (Limit is' rootdir/tmp/aptupdate.output
  277. testnopackage oldstuff
  278. testsuccessequal "$(cat "${PKGFILE}-new")
  279. " aptcache show apt newstuff
  280. }
  281. echo 'Debug::pkgAcquire::Diffs "true";
  282. Debug::Acquire::Transaction "true";
  283. Debug::pkgAcquire::rred "true";' > rootdir/etc/apt/apt.conf.d/rreddebug.conf
  284. testcase() {
  285. testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
  286. testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
  287. testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=0 "$@"
  288. testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=0 "$@"
  289. }
  290. partialleftovers() { touch "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_Packages"; }
  291. aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages"; }
  292. testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=false
  293. partialleftovers() { touch "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_Packages.$LOWCOSTEXT"; }
  294. aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages.$LOWCOSTEXT"; }
  295. testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true
  296. partialleftovers() { touch "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_redirectme_Packages.$LOWCOSTEXT"; }
  297. webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "http://0.0.0.0:${APTHTTPPORT}/"
  298. rewritesourceslist "http://localhost:${APTHTTPPORT}/redirectme"
  299. aptautotest_apt_update() {
  300. aptautotest_aptget_update "$@"
  301. testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_redirectme_Packages.$LOWCOSTEXT"
  302. testempty find rootdir/var/lib/apt/lists -type f \! \( -name lock -o -name '*_redirectme_*' \)
  303. }
  304. testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true