test-external-dependency-solver-protocol 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64' 'i386'
  7. insertinstalledpackage 'cool' 'all' '1'
  8. insertinstalledpackage 'stuff' 'all' '1'
  9. insertinstalledpackage 'somestuff' 'all' '1' 'Depends: cool, stuff'
  10. insertpackage 'unstable' 'cool' 'all' '2' 'Multi-Arch: foreign'
  11. insertpackage 'unstable' 'stuff' 'all' '2' 'Multi-Arch: foreign'
  12. insertpackage 'unstable' 'coolstuff' 'i386,amd64' '2' 'Depends: cool, stuff'
  13. insertpackage 'unstable' 'awesome' 'all' '2' 'Multi-Arch: foreign
  14. Conflicts: badstuff'
  15. insertpackage 'unstable' 'badstuff' 'all' '2' 'Multi-Arch: foreign
  16. Conflicts: awesome'
  17. insertpackage 'unstable' 'awesomecoolstuff' 'i386' '2' 'Depends: coolstuff, awesome'
  18. insertpackage 'experimental' 'cool' 'all' '3' 'Multi-Arch: foreign'
  19. insertpackage 'experimental' 'stuff' 'all' '3' 'Multi-Arch: foreign'
  20. insertpackage 'experimental' 'coolstuff' 'i386,amd64' '3' 'Depends: cool, stuff'
  21. setupaptarchive
  22. testsuccess aptget install --solver apt coolstuff -s
  23. testempty find . -name 'edsp.last.*'
  24. echo 'Dir::Log::Solver "edsp.last.xz";' > rootdir/etc/apt/apt.conf.d/log-edsp.conf
  25. testfailure aptget install --solver dump coolstuff -s
  26. testsuccess grep 'ERR_NO_FILENAME' rootdir/tmp/testfailure.output
  27. testfailure test -s rootdir/var/log/apt/edsp.last.xz
  28. export APT_EDSP_DUMP_FILENAME="/nonexistent/apt/edsp.dump"
  29. testfailure aptget install --solver dump coolstuff -s
  30. testsuccess grep 'ERR_CREATE_FILE' rootdir/tmp/testfailure.output
  31. testfailure test -s rootdir/var/log/apt/edsp.last.xz
  32. export APT_EDSP_DUMP_FILENAME="${TMPWORKINGDIRECTORY}/downloaded/dump.edsp"
  33. testfailureequal 'Reading package lists...
  34. Building dependency tree...
  35. Execute external solver...
  36. The solver encountered an error of type: ERR_JUST_DUMPING
  37. The following information might help you to understand what is wrong:
  38. I am too dumb, i can just dump!
  39. Please use one of my friends instead!
  40. E: External solver failed with: I am too dumb, i can just dump!' aptget install --solver dump coolstuff -s
  41. testfailure test -s rootdir/var/log/apt/edsp.last.xz
  42. testsuccess test -s "$APT_EDSP_DUMP_FILENAME"
  43. testsuccessequal 'Reading package lists...
  44. Building dependency tree...
  45. Execute external solver...
  46. The following NEW packages will be installed:
  47. coolstuff
  48. 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
  49. Inst coolstuff (2 unstable [amd64])
  50. Conf coolstuff (2 unstable [amd64])' aptget install --solver apt coolstuff -s
  51. testsuccess test -s rootdir/var/log/apt/edsp.last.xz
  52. sed -i -e 's#^Solver: dump$#Solver: apt#' "$APT_EDSP_DUMP_FILENAME"
  53. testequal "$(cat "$APT_EDSP_DUMP_FILENAME")
  54. " apthelper cat-file rootdir/var/log/apt/edsp.last.xz
  55. cp rootdir/var/log/apt/edsp.last.xz rootdir/var/log/apt/edsp.last.xz.1
  56. rm -f "$APT_EDSP_DUMP_FILENAME"
  57. testsuccessequal 'Reading package lists...
  58. Building dependency tree...
  59. Execute external solver...
  60. The following NEW packages will be installed:
  61. coolstuff
  62. 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
  63. Inst coolstuff (3 experimental [amd64])
  64. Conf coolstuff (3 experimental [amd64])' aptget install --solver apt coolstuff -s -t experimental
  65. testfailure cmp rootdir/var/log/apt/edsp.last.xz rootdir/var/log/apt/edsp.last.xz.1
  66. testsuccessequal "Reading package lists...
  67. Building dependency tree...
  68. Selected version '3' (experimental [amd64]) for 'coolstuff'
  69. Execute external solver...
  70. The following NEW packages will be installed:
  71. coolstuff
  72. 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
  73. Inst coolstuff (3 experimental [amd64])
  74. Conf coolstuff (3 experimental [amd64])" aptget install --solver apt coolstuff/experimental -sq=0
  75. testsuccessequal 'Reading package lists...
  76. Building dependency tree...
  77. Execute external solver...
  78. The following NEW packages will be installed:
  79. coolstuff
  80. 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
  81. Inst coolstuff (3 experimental [amd64])
  82. Conf coolstuff (3 experimental [amd64])' aptget install --solver apt coolstuff=3 -sq=0
  83. testsuccessequal 'Reading package lists...
  84. Building dependency tree...
  85. Execute external solver...
  86. The following packages will be REMOVED:
  87. somestuff
  88. 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
  89. Remv somestuff [1]' aptget autoremove --solver apt somestuff -s
  90. testsuccess aptmark auto cool stuff
  91. testsuccessequal 'Reading package lists...
  92. Building dependency tree...
  93. Reading state information...
  94. Execute external solver...
  95. The following packages will be REMOVED:
  96. cool somestuff stuff
  97. 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
  98. Remv somestuff [1]
  99. Remv cool [1]
  100. Remv stuff [1]' aptget autoremove --solver apt somestuff -s
  101. AUTOREMOVE='apt autoremove'
  102. if [ -n "$SUDO_USER" ]; then
  103. AUTOREMOVE="sudo $AUTOREMOVE"
  104. fi
  105. testsuccessequal "Reading package lists...
  106. Building dependency tree...
  107. Reading state information...
  108. Execute external solver...
  109. The following package was automatically installed and is no longer required:
  110. stuff
  111. Use '$AUTOREMOVE' to remove it.
  112. The following packages will be REMOVED:
  113. cool* somestuff*
  114. 0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
  115. Purg somestuff [1]
  116. Purg cool [1]" aptget purge --solver apt cool -s
  117. testsuccess aptget install awesomecoolstuff:i386 -s
  118. testsuccess aptget install --solver apt awesomecoolstuff:i386 -s
  119. rm -f "$APT_EDSP_DUMP_FILENAME"
  120. testfailure aptget install --solver dump awesomecoolstuff:i386 -s
  121. testsuccess test -s "$APT_EDSP_DUMP_FILENAME"
  122. testequal 'Install: awesomecoolstuff:i386' grep :i386 "$APT_EDSP_DUMP_FILENAME"
  123. testfailure grep -e ':amd64' -e 'Architecture: any' "$APT_EDSP_DUMP_FILENAME"
  124. testsuccess aptget dist-upgrade -s
  125. testsuccess aptget dist-upgrade -s --solver apt
  126. testsuccess aptget upgrade -s
  127. testsuccess aptget upgrade -s --solver apt
  128. testfailure aptget install awesome badstuff -s
  129. testfailure aptget install awesome badstuff -s --solver apt
  130. testsuccess grep 'ERR_UNSOLVABLE' rootdir/tmp/testfailure.output
  131. configarchitecture 'armel'
  132. testfailure aptget install --solver apt awesomecoolstuff:i386 -s
  133. msgtest 'An invalid EDSP file generates a' 'hard error'
  134. if printf "%b\n" "Request: This is a test\nFoo: bar\n\n" | aptinternalsolver > solver.result 2>&1; then
  135. cat solver.result
  136. msgfail
  137. else
  138. msgpass
  139. fi
  140. msgtest 'Test direct calling is okay for' 'apt-internal-solver'
  141. cat "$APT_EDSP_DUMP_FILENAME" | aptinternalsolver > solver.result 2>&1 || true
  142. if [ "$(tail -n2 solver.result | head -n1 )" = "Message: Done" ]; then
  143. msgpass
  144. else
  145. cat solver.result
  146. msgfail
  147. fi
  148. testsuccess grep '^APT-ID: 1$' "$APT_EDSP_DUMP_FILENAME"
  149. sed -i -e 's#^APT-ID: 1$#APT-ID: 10000#' "$APT_EDSP_DUMP_FILENAME"
  150. cat "$APT_EDSP_DUMP_FILENAME" | aptinternalsolver > solver.result 2>&1 || true
  151. testsuccessequal 'Message: Done
  152. ' tail -n2 solver.result
  153. rm -f "$APT_EDSP_DUMP_FILENAME"
  154. testsuccess aptinternalsolver scenario
  155. testsuccessequal 'Package: stuff
  156. Architecture: all
  157. Version: 3
  158. APT-ID: 1
  159. Multi-Arch: foreign
  160. Source: stuff
  161. Source-Version: 3
  162. Priority: optional
  163. Section: other
  164. APT-Release:
  165. a=experimental,n=experimental,c=main,b=all
  166. APT-Pin: 1
  167. Package: stuff
  168. Architecture: all
  169. Version: 2
  170. APT-ID: 3
  171. Multi-Arch: foreign
  172. Source: stuff
  173. Source-Version: 2
  174. Priority: optional
  175. Section: other
  176. APT-Release:
  177. a=unstable,n=sid,c=main,b=all
  178. APT-Pin: 500
  179. APT-Candidate: yes
  180. Package: stuff
  181. Architecture: all
  182. Version: 1
  183. APT-ID: 8
  184. Source: stuff
  185. Source-Version: 1
  186. Priority: optional
  187. Section: other
  188. Installed: yes
  189. APT-Pin: 100
  190. ' aptinternalsolver scenario stuff
  191. cat > rootdir/usr/lib/apt/solvers/explicitremove << EOF
  192. #!/bin/sh
  193. set -e
  194. while read line; do
  195. if [ "APT-ID" = "\${line%:*}" ]; then
  196. cat << APT
  197. Install: \${line#*:}
  198. Remove: \${line#*:}
  199. APT
  200. fi
  201. done
  202. EOF
  203. chmod +x rootdir/usr/lib/apt/solvers/explicitremove
  204. testfailure apt full-upgrade -s --solver explicitremove
  205. testsuccess grep 'had a previous stanza' rootdir/tmp/testfailure.output
  206. cat > rootdir/usr/lib/apt/solvers/removeall << EOF
  207. #!/bin/sh
  208. set -e
  209. while read line; do
  210. if [ "APT-ID" = "\${line%:*}" ]; then
  211. cat << APT
  212. Remove: \${line#*:}
  213. APT
  214. fi
  215. done
  216. EOF
  217. chmod +x rootdir/usr/lib/apt/solvers/removeall
  218. testwarning apt full-upgrade -s --solver removeall
  219. testsuccess grep "which isn't installed!" rootdir/tmp/testwarning.output
  220. cat > rootdir/usr/lib/apt/solvers/installall << EOF
  221. #!/bin/sh
  222. set -e
  223. while read line; do
  224. if [ "APT-ID" = "\${line%:*}" ]; then
  225. cat << APT
  226. Install: \${line#*:}
  227. APT
  228. fi
  229. done
  230. EOF
  231. chmod +x rootdir/usr/lib/apt/solvers/installall
  232. testfailure apt full-upgrade -s --solver installall
  233. testsuccess grep "is already installed!" rootdir/tmp/testfailure.output
  234. testsolverfailuremsg() {
  235. local SOLVER="rootdir/usr/lib/apt/solvers/$1"
  236. echo "$2" > "$SOLVER"
  237. chmod +x "$SOLVER"
  238. testfailuremsg "$3" apt full-upgrade -s --solver $1
  239. }
  240. testsolverfailuremsg 'exit0withmsg' "#!/bin/sh
  241. echo 'Error: instant-exit
  242. Message: This solver exits instantly'
  243. exit 0" 'E: External solver failed with: This solver exits instantly'
  244. testsolverfailuremsg 'exit1withoutmsg' "#!/bin/sh
  245. exit 1" 'E: Sub-process exit1withoutmsg returned an error code (1)'
  246. testsolverfailuremsg 'exit1withmsg' "#!/bin/sh
  247. echo 'Error: instant-exit
  248. Message: This solver exits instantly'
  249. exit 1" 'E: External solver failed with: This solver exits instantly
  250. E: Sub-process exit1withmsg returned an error code (1)'