Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/backup_lib.sh
2649 views
1
#! /usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
5
tests_init \
6
basic \
7
split_upgrade \
8
depends \
9
multiple_upgrade
10
11
basic_body() {
12
atf_skip_on Darwin The macOS linker uses different flags
13
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
14
cat << EOF >> test.ucl
15
files: {
16
${TMPDIR}/libempty.so.1: "",
17
}
18
EOF
19
20
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "1"
21
cat << EOF >> foo.ucl
22
files: {
23
${TMPDIR}/libfoo.so.1: "",
24
}
25
EOF
26
mkdir ${TMPDIR}/target
27
touch empty.c
28
cc -shared -Wl,-soname=libempty.so.1 empty.c -o libempty.so.1
29
cc -shared -Wl,-soname=libfoo.so.1 empty.c -o libfoo.so.1
30
sum=$(openssl dgst -sha256 -hex libempty.so.1)
31
32
atf_check pkg create -M test.ucl
33
34
atf_check pkg create -M foo.ucl
35
36
atf_check \
37
pkg -o BACKUP_LIBRARIES=true -o REPOS_DIR=/dev/null \
38
-r ${TMPDIR}/target \
39
install -qfy ${TMPDIR}/test-1.pkg
40
41
atf_check \
42
pkg -o BACKUP_LIBRARIES=true -o REPOS_DIR=/dev/null \
43
-r ${TMPDIR}/target \
44
install -qfy ${TMPDIR}/foo-1.pkg
45
46
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
47
48
atf_check pkg create -M test.ucl
49
50
rm test-1.pkg
51
atf_check -o ignore pkg repo .
52
53
mkdir reposconf
54
cat <<EOF >> reposconf/repo.conf
55
local: {
56
url: file:///${TMPDIR},
57
enabled: true
58
}
59
EOF
60
61
atf_check -o ignore \
62
pkg -o BACKUP_LIBRARY_PATH=/back/ -o BACKUP_LIBRARIES=true \
63
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
64
upgrade -y
65
atf_check -o ignore \
66
ls target/back/libempty.so.1
67
atf_check -o inline:"/back/libempty.so.1\n" \
68
pkg -r ${TMPDIR}/target query "%Fp" test-backup-libraries
69
rm foo-1.pkg
70
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "2"
71
atf_check pkg create -M foo.ucl
72
atf_check -o ignore pkg repo .
73
atf_check -o ignore \
74
pkg -o BACKUP_LIBRARY_PATH=/back/ -o BACKUP_LIBRARIES=true \
75
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
76
update -f
77
78
version1=$(pkg -r ${TMPDIR}/target query "%v" test-backup-libraries)
79
atf_check -o ignore \
80
pkg -o BACKUP_LIBRARY_PATH=/back/ -o BACKUP_LIBRARIES=true \
81
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
82
upgrade -y
83
atf_check -o inline:"/back/libempty.so.1\n" \
84
pkg -r ${TMPDIR}/target query "%Fp" test-backup-libraries
85
atf_check -o inline:"/back/libfoo.so.1\n" \
86
pkg -r ${TMPDIR}/target query "%Fp" foo-backup-libraries
87
version2=$(pkg -r ${TMPDIR}/target query "%v" test-backup-libraries)
88
[ ${version2} -ge ${version1} ] || \
89
atf_fail "the version hasn't been bumped ${version2} >= ${version1}"
90
}
91
92
# Make sure that we back up libraries properly when a package upgrade is
93
# split into separate deletion and installation steps.
94
split_upgrade_body()
95
{
96
atf_skip_on Darwin The macOS linker uses different flags
97
98
atf_check touch a b empty.c
99
atf_check cc -shared -Wl,-soname=libfoo.so.1 empty.c -o libfoo.so.1
100
atf_check cc -shared -Wl,-soname=libfoo.so.2 empty.c -o libfoo.so.2
101
atf_check cc -shared -Wl,-soname=libbar.so.1 empty.c -o libbar.so.1
102
atf_check cc -shared -Wl,-soname=libbar.so.2 empty.c -o libbar.so.2
103
104
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "1"
105
cat << EOF >> foo.ucl
106
files: {
107
${TMPDIR}/a: "",
108
${TMPDIR}/libfoo.so.1: "",
109
}
110
EOF
111
atf_check pkg create -M foo.ucl
112
113
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "2"
114
cat << EOF >> foo.ucl
115
files: {
116
${TMPDIR}/b: "",
117
${TMPDIR}/libfoo.so.2: "",
118
}
119
EOF
120
atf_check pkg create -M foo.ucl
121
122
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "1"
123
cat << EOF >> bar.ucl
124
files: {
125
${TMPDIR}/b: "",
126
${TMPDIR}/libbar.so.1: "",
127
}
128
EOF
129
atf_check pkg create -M bar.ucl
130
131
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "2"
132
cat << EOF >> bar.ucl
133
files: {
134
${TMPDIR}/a: "",
135
${TMPDIR}/libbar.so.2: "",
136
}
137
EOF
138
atf_check pkg create -M bar.ucl
139
140
atf_check mkdir ${TMPDIR}/target ${TMPDIR}/reposconf
141
atf_check -o ignore pkg repo .
142
cat <<EOF > ${TMPDIR}/reposconf/repo.conf
143
local: {
144
url: file://${TMPDIR},
145
enabled: true
146
}
147
EOF
148
149
# Install the base version packages, foo-1 and bar-1.
150
atf_check \
151
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target \
152
install -qfy ${TMPDIR}/foo-1.pkg
153
atf_check \
154
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target \
155
install -qfy ${TMPDIR}/bar-1.pkg
156
157
# Now upgrade foo and bar to version 2. Since the files a and b
158
# move between the two packages, a split upgrade is necessary.
159
atf_check -o ignore \
160
pkg -o BACKUP_LIBRARY_PATH=/back/ -o BACKUP_LIBRARIES=true \
161
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
162
upgrade -y
163
164
atf_check test -f ${TMPDIR}/target/back/libfoo.so.1
165
atf_check test -f ${TMPDIR}/target/back/libbar.so.1
166
atf_check -o inline:"libbar.so.1\n" \
167
pkg -r ${TMPDIR}/target query "%b" bar-backup-libraries
168
atf_check -o inline:"libfoo.so.1\n" \
169
pkg -r ${TMPDIR}/target query "%b" foo-backup-libraries
170
}
171
172
# If a package foo provides libfoo.so.1 and a different package bar
173
# depends on it, and libfoo.so is upgraded to version 2, and
174
# BACKUP_LIBRARIES is configured, then upgrading should not result in
175
# removal of bar.
176
#
177
# XXX-MJ check the case where bar is not upgraded
178
# XXX-MJ check the case where foo and bar come from different repositories
179
depends_body()
180
{
181
atf_skip_on Darwin The macOS linker uses different flags
182
183
atf_check touch empty.c
184
atf_check cc -shared -Wl,-soname=libfoo.so.1 empty.c -o libfoo.so.1
185
atf_check ln -s libfoo.so.1 libfoo.so
186
atf_check cc -shared -Wl,-soname=libbar.so.1 empty.c -o libbar.so.1 -lfoo -L.
187
atf_check cc -shared -Wl,-soname=libbar.so.2 empty.c -o libbar.so.2 -lfoo -L.
188
atf_check cc -shared -Wl,-soname=libfoo.so.2 empty.c -o libfoo.so.2
189
190
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "1"
191
cat << EOF >> foo.ucl
192
files: {
193
${TMPDIR}/libfoo.so.1: "",
194
}
195
EOF
196
atf_check pkg create -M foo.ucl
197
198
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "2"
199
cat << EOF >> foo.ucl
200
files: {
201
${TMPDIR}/libfoo.so.2: "",
202
}
203
EOF
204
atf_check pkg create -M foo.ucl
205
206
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "1"
207
cat << EOF >> bar.ucl
208
files: {
209
${TMPDIR}/libbar.so.1: "",
210
}
211
EOF
212
atf_check pkg create -M bar.ucl
213
214
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "2"
215
cat << EOF >> bar.ucl
216
files: {
217
${TMPDIR}/libbar.so.2: "",
218
}
219
EOF
220
atf_check pkg create -M bar.ucl
221
222
atf_check mkdir ${TMPDIR}/target ${TMPDIR}/reposconf
223
atf_check -o ignore pkg repo .
224
cat <<EOF > ${TMPDIR}/reposconf/repo.conf
225
local: {
226
url: file://${TMPDIR},
227
enabled: true
228
}
229
EOF
230
231
# Install the base version packages, foo-1 and bar-1.
232
atf_check \
233
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target \
234
install -qfy ${TMPDIR}/foo-1.pkg
235
atf_check \
236
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target \
237
install -qfy ${TMPDIR}/bar-1.pkg
238
239
# Upgrade foo to version 2. This will remove libfoo.so.1, but
240
# we shouldn't remove the bar package because libfoo.so.1 is
241
# still available via the backup libraries mechanism.
242
atf_check -o ignore \
243
pkg \
244
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
245
-o BACKUP_LIBRARIES=yes \
246
upgrade -y foo bar
247
248
atf_check test -f ${TMPDIR}/target/${TMPDIR}/libfoo.so.2
249
atf_check test -f ${TMPDIR}/target/${TMPDIR}/libbar.so.2
250
}
251
252
# A regression test for a scenario where the same shlib version is backed up
253
# multiple times. This would result in a registration failure of the
254
# backup package, which in turn could result in a sqlite error if this
255
# happened during a pkg uninstall during a split upgrade.
256
multiple_upgrade_body()
257
{
258
atf_skip_on Darwin The macOS linker uses different flags
259
260
atf_check touch a b c d
261
atf_check touch empty.c
262
atf_check cc -shared -Wl,-soname=libfoo.so.1 empty.c -o libfoo.so.1
263
atf_check ln -s libfoo.so.1 libfoo.so
264
atf_check cc -shared -Wl,-soname=libbar.so.1 empty.c -o libbar.so.1
265
atf_check ln -s libbar.so.1 libbar.so
266
267
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "1"
268
cat << EOF >> foo.ucl
269
files: {
270
${TMPDIR}/a: "",
271
${TMPDIR}/libfoo.so.1: "",
272
${TMPDIR}/libbar.so.1: "",
273
}
274
EOF
275
atf_check pkg create -M foo.ucl
276
277
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "1"
278
cat << EOF >> bar.ucl
279
files: {
280
${TMPDIR}/b: "",
281
}
282
EOF
283
atf_check pkg create -M bar.ucl
284
285
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "baz" "baz" "1"
286
cat << EOF >> baz.ucl
287
files: {
288
${TMPDIR}/c: "",
289
}
290
EOF
291
atf_check pkg create -M baz.ucl
292
293
atf_check mkdir ${TMPDIR}/target ${TMPDIR}/reposconf
294
atf_check -o ignore \
295
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy \
296
${TMPDIR}/foo-1.pkg ${TMPDIR}/bar-1.pkg ${TMPDIR}/baz-1.pkg
297
298
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "2"
299
cat << EOF >> foo.ucl
300
files: {
301
${TMPDIR}/a: "",
302
}
303
EOF
304
atf_check pkg create -M foo.ucl
305
306
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "2"
307
cat << EOF >> bar.ucl
308
files: {
309
${TMPDIR}/b: "",
310
${TMPDIR}/libfoo.so.1: "",
311
${TMPDIR}/libbar.so.1: "",
312
}
313
EOF
314
atf_check pkg create -M bar.ucl
315
316
cat <<EOF > ${TMPDIR}/reposconf/repo.conf
317
local: {
318
url: file://${TMPDIR}/repo,
319
enabled: true
320
}
321
EOF
322
atf_check mkdir repo
323
atf_check mv foo-2.pkg bar-2.pkg repo
324
atf_check -o ignore pkg repo repo
325
326
# Upgrade the packages. Moving the libraries between packages will
327
# cause them to be backed up.
328
atf_check -o ignore \
329
pkg \
330
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
331
-o BACKUP_LIBRARIES=yes \
332
-o BACKUP_LIBRARY_PATH=/back/ \
333
upgrade -y
334
335
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "foo" "foo" "3"
336
cat << EOF >> foo.ucl
337
files: {
338
${TMPDIR}/a: "",
339
${TMPDIR}/libfoo.so.1: "",
340
${TMPDIR}/libbar.so.1: "",
341
}
342
EOF
343
atf_check pkg create -M foo.ucl
344
345
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "bar" "bar" "3"
346
cat << EOF >> bar.ucl
347
files: {
348
${TMPDIR}/b: "",
349
${TMPDIR}/c: "",
350
}
351
EOF
352
atf_check pkg create -M bar.ucl
353
354
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "baz" "baz" "3"
355
cat << EOF >> baz.ucl
356
files: {
357
${TMPDIR}/d: "",
358
},
359
deps: {
360
"foo": {
361
version: "3",
362
origin: "foo",
363
},
364
}
365
EOF
366
atf_check pkg create -M baz.ucl
367
368
atf_check rm -rf repo
369
atf_check mkdir repo
370
atf_check mv foo-3.pkg bar-3.pkg baz-3.pkg repo
371
atf_check -o ignore pkg repo repo
372
373
# Make sure pkg fetches a new catalogue.
374
atf_check -o ignore \
375
pkg \
376
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
377
update -f
378
379
# Upgrade the three packages to version 3. The shlibs move from bar-2
380
# to foo-3, and the library backup logic infers that it must therefore
381
# back up libfoo.so and libbar.so. (This is really a bug in itself
382
# since those libraries aren't actually going away, but that's because
383
# library backup mechanism is plumbed in at the wrong layer. One step
384
# at a time.)
385
#
386
# Then, we use a conflict between bar-3 and baz-2 to split the
387
# bar-2->bar-3 upgrade. baz-3 depends on foo-3 to try and provoke the
388
# split, otherwise pkg would first upgrade baz-1->baz-3 and then there
389
# would be no need to split the bar upgrade.
390
atf_check -o ignore \
391
-e match:"bar-backup-libraries-.* conflicts with foo-backup-libraries-.*" \
392
pkg \
393
-o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
394
-o BACKUP_LIBRARIES=yes \
395
-o BACKUP_LIBRARY_PATH=/back/ \
396
upgrade -y
397
}
398
399