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