Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/abi.sh
2649 views
1
#! /usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
tests_init \
5
elfparse \
6
machoparse \
7
native \
8
override \
9
shlib
10
11
native_body() {
12
OS=$(uname -s)
13
thisarch=$(uname -p)
14
if [ "$thisarch" = "unknown" -o "${OS}" = "Darwin" ]; then
15
thisarch=$(uname -m)
16
fi
17
thisabi=$thisarch
18
case "${OS}" in
19
Linux)
20
version=$(readelf -n /bin/uname | awk '/ABI: / { split($NF, a, "."); print a[1]"."a[2] }')
21
;;
22
Darwin)
23
# without a hint, the first arch is selected, which happens to be consistently x86_64
24
thisarch="x86_64"
25
thisabi="x86_64"
26
version=$(uname -r | cut -d. -f1)
27
;;
28
FreeBSD)
29
version=$(freebsd-version -u | cut -d. -f1)
30
thisarch=$(echo "${thisarch}" | sed s/x86_64/amd64/)
31
thisabi=$(echo "${thisarch}" | sed 's/amd64/x86:64/; s/aarch64/aarch64:64/')
32
;;
33
*)
34
version=$(uname -r | cut -d. -f1)
35
;;
36
esac
37
_expected="${OS}:${version}:${thisarch}\n"
38
atf_check \
39
-o inline:"${_expected}" \
40
pkg config abi
41
42
_expected="$(uname -s | tr '[:upper:]' '[:lower:]'):${version}:${thisabi}\n"
43
atf_check \
44
-o inline:"${_expected}" \
45
pkg config altabi
46
}
47
48
override_body() {
49
_expected="FreeBSD:12:powerpc\n"
50
atf_check \
51
-o inline:"${_expected}" \
52
-e ignore \
53
pkg -o ABI=FreeBSD:12:powerpc -o OSVERSION=1201000 config abi
54
55
_expected="freebsd:12:powerpc:32:eb\n"
56
atf_check \
57
-o inline:"${_expected}" \
58
-e ignore \
59
pkg -o ABI=FreeBSD:12:powerpc -o OSVERSION=1201000 config altabi
60
}
61
62
elfparse_body() {
63
# ELF parsing now works across platforms
64
65
for bin in \
66
freebsd-aarch64.bin freebsd-amd64.bin freebsd-armv6.bin freebsd-armv7.bin \
67
freebsd-i386.bin freebsd-powerpc.bin freebsd-powerpc64.bin freebsd-powerpc64le.bin \
68
freebsd-riscv64.bin dfly.bin linux.bin
69
do
70
bin_meta ${bin}
71
72
_expected="${XABI}\n"
73
atf_check \
74
-o inline:"${_expected}" \
75
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config abi
76
77
_expected="${XALTABI}\n"
78
atf_check \
79
-o inline:"${_expected}" \
80
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config altabi
81
done
82
}
83
84
machoparse_body() {
85
# Macho-O parsing now works across platforms
86
87
for bin in \
88
macos.bin macos106.bin macos150.bin \
89
macosfat.bin "macosfat.bin#x86_64" "macosfat.bin#aarch64" \
90
macosfatlib.bin "macosfatlib.bin#x86_64" "macosfatlib.bin#aarch64"
91
do
92
bin_meta ${bin}
93
94
_expected="${XABI}\n"
95
atf_check \
96
-o inline:"${_expected}" \
97
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config abi
98
99
_expected="${XALTABI}\n"
100
atf_check \
101
-o inline:"${_expected}" \
102
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config altabi
103
done
104
105
# explicitely select a fat entry that is not in the ABI_FILE
106
_expected="Scanned 2 entries, found none matching selector i386\n"
107
atf_check \
108
-s exit:1 \
109
-o inline:"${_expected}" \
110
-e match:"Unable to determine ABI" \
111
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#i386 config abi
112
113
atf_check \
114
-s exit:1 \
115
-o inline:"${_expected}" \
116
-e match:"Unable to determine ABI" \
117
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#i386 config altabi
118
119
# explicitely select a fat entry that is not a valid architecture, hence not in the ABI_FILE
120
_expected=""
121
atf_check \
122
-s exit:1 \
123
-o inline:"${_expected}" \
124
-e match:"Invalid ABI_FILE architecture hint abc" \
125
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#abc config abi
126
127
atf_check \
128
-s exit:1 \
129
-o inline:"${_expected}" \
130
-e match:"Invalid ABI_FILE architecture hint abc" \
131
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#abc config altabi
132
133
# if the binary is not universal, selecting the first entry is not commentable
134
_expected="Darwin:24:aarch64\n"
135
atf_check \
136
-o inline:"${_expected}" \
137
-e not-match:"picking first" \
138
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin config abi
139
140
_expected="darwin:24:aarch64:64\n"
141
atf_check \
142
-o inline:"${_expected}" \
143
-e not-match:"picking first" \
144
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin config altabi
145
146
_expected="Scanned 1 entry, found none matching selector i386\n"
147
atf_check \
148
-s exit:1 \
149
-o inline:"${_expected}" \
150
-e match:"Unable to determine ABI" \
151
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin#i386 config abi
152
153
atf_check \
154
-s exit:1 \
155
-o inline:"${_expected}" \
156
-e match:"Unable to determine ABI" \
157
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin#i386 config altabi
158
159
# if the binary is universal, selecting the first entry is to be commented
160
_expected="Darwin:17:x86_64\n"
161
atf_check \
162
-o inline:"${_expected}" \
163
-e match:"picking first" \
164
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin config abi
165
166
_expected="darwin:17:x86_64\n"
167
atf_check \
168
-o inline:"${_expected}" \
169
-e match:"picking first" \
170
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin config altabi
171
}
172
173
# Helper for the test below. Create a package with the specified name, version
174
# and ABI, containing a single shared library of the same name.
175
make_onelib_pkg()
176
{
177
local name version abi
178
179
name=$1
180
version=$2
181
abi=$3
182
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg $name $name $version / $abi
183
cat <<__EOF__ >> ${name}.ucl
184
files: {
185
${TMPDIR}/lib${name}.so.1: "",
186
}
187
__EOF__
188
atf_check pkg create -M ${name}.ucl
189
}
190
191
# Try to verify ABI mixing in shared library dependencies. It's ok for a shlib
192
# to depend on a shlib from a newer ABI, at least on FreeBSD. In this case,
193
# bar-* can be satisfied by foo-*, but baz-2 cannot be satisfied by foo-1. We
194
# check that the solver enforces this.
195
shlib_body()
196
{
197
atf_skip_on Darwin Not sure how to test this there
198
atf_skip_on Linux Not sure how to test this there
199
200
atf_check touch empty.c
201
atf_check cc -shared -Wl,-soname=libfoo.so.1 empty.c -o libfoo.so.1
202
atf_check ln -s libfoo.so.1 libfoo.so
203
atf_check cc -shared -Wl,-soname=libbar.so.1 empty.c -o libbar.so.1 -lfoo -L.
204
atf_check ln -s libbar.so.1 libbar.so
205
atf_check cc -shared -Wl,-soname=libbaz.so.1 empty.c -o libbaz.so.1 -lbar -L.
206
207
make_onelib_pkg foo 1 FreeBSD:15:amd64
208
make_onelib_pkg bar 1 FreeBSD:15:amd64
209
make_onelib_pkg baz 1 FreeBSD:15:amd64
210
211
make_onelib_pkg foo 2 FreeBSD:16:amd64
212
make_onelib_pkg bar 2 FreeBSD:15:amd64
213
make_onelib_pkg baz 2 FreeBSD:16:amd64
214
215
atf_check mkdir target reposconf
216
217
# Install the base version packages, foo-1, bar-1, baz-1.
218
for pkg in foo bar baz; do
219
atf_check \
220
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target \
221
install -qfy ${TMPDIR}/${pkg}-1.pkg
222
done
223
224
# Set up our repos. foo and baz go in one, bar in another.
225
atf_check mkdir repo1 repo2
226
atf_check cp ${TMPDIR}/foo-2.pkg ${TMPDIR}/repo1
227
atf_check cp ${TMPDIR}/baz-2.pkg ${TMPDIR}/repo1
228
atf_check cp ${TMPDIR}/bar-2.pkg ${TMPDIR}/repo2
229
230
for repo in repo1 repo2; do
231
atf_check -o ignore pkg repo ${repo}
232
cat <<__EOF__ > ${TMPDIR}/reposconf/${repo}.conf
233
${repo}: {
234
url: file://${TMPDIR}/${repo},
235
enabled: true
236
}
237
__EOF__
238
239
done
240
241
# Override the ABI for each repo update, otherwise pkg
242
# refuses to proceed.
243
atf_check -o ignore -e ignore \
244
pkg -o REPOS_DIR=${TMPDIR}/reposconf \
245
-r ${TMPDIR}/target -o ABI=FreeBSD:16:amd64 update -r repo1
246
atf_check -o ignore -e ignore \
247
pkg -o REPOS_DIR=${TMPDIR}/reposconf \
248
-r ${TMPDIR}/target -o ABI=FreeBSD:15:amd64 update -r repo2
249
250
atf_check -o ignore -e empty \
251
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target \
252
-o IGNORE_OSMAJOR=yes \
253
-o OSVERSION=1600000 \
254
-o ABI=FreeBSD:16:amd64 upgrade -y -r repo1
255
256
# We should end up with foo-2, bar-1 and baz-2 installed. This
257
# is not quite right since baz-2 depends on libbar.so.1, which
258
# has an older OS version. But this is a pre-existing behaviour
259
# of the solver: pkg_solve_add_require_rule() will ignore the
260
# dependency if it cannot be satisfied. If that behaviour
261
# changes, this test will need an update.
262
#
263
# However, we shouldn't uninstall bar-1 since foo-2's
264
# libfoo.so.1 should still be compatible even though its OS
265
# version is newer.
266
atf_check test -f ${TMPDIR}/target/${TMPDIR}/libfoo.so.1
267
atf_check test -f ${TMPDIR}/target/${TMPDIR}/libbar.so.1
268
atf_check test -f ${TMPDIR}/target/${TMPDIR}/libbaz.so.1
269
}
270
271