Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/abi.sh
2065 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
10
native_body() {
11
OS=$(uname -s)
12
thisarch=$(uname -p)
13
if [ "$thisarch" = "unknown" -o "${OS}" = "Darwin" ]; then
14
thisarch=$(uname -m)
15
fi
16
thisabi=$thisarch
17
case "${OS}" in
18
Linux)
19
version=$(readelf -n /bin/uname | awk '/ABI: / { split($NF, a, "."); print a[1]"."a[2] }')
20
;;
21
Darwin)
22
# without a hint, the first arch is selected, which happens to be consistently x86_64
23
thisarch="x86_64"
24
thisabi="x86_64"
25
version=$(uname -r | cut -d. -f1)
26
;;
27
FreeBSD)
28
version=$(uname -r | cut -d. -f1)
29
thisarch=$(echo "${thisarch}" | sed s/x86_64/amd64/)
30
thisabi=$(echo "${thisarch}" | sed s/amd64/x86:64/)
31
;;
32
*)
33
version=$(uname -r | cut -d. -f1)
34
;;
35
esac
36
_expected="${OS}:${version}:${thisarch}\n"
37
atf_check \
38
-o inline:"${_expected}" \
39
pkg config abi
40
41
_expected="$(uname -s | tr '[:upper:]' '[:lower:]'):${version}:${thisabi}\n"
42
atf_check \
43
-o inline:"${_expected}" \
44
pkg config altabi
45
}
46
47
override_body() {
48
_expected="FreeBSD:12:powerpc\n"
49
atf_check \
50
-o inline:"${_expected}" \
51
-e ignore \
52
pkg -o ABI=FreeBSD:12:powerpc -o OSVERSION=1201000 config abi
53
54
_expected="freebsd:12:powerpc:32:eb\n"
55
atf_check \
56
-o inline:"${_expected}" \
57
-e ignore \
58
pkg -o ABI=FreeBSD:12:powerpc -o OSVERSION=1201000 config altabi
59
}
60
61
elfparse_body() {
62
# ELF parsing now works across platforms
63
64
for bin in \
65
freebsd-aarch64.bin freebsd-amd64.bin freebsd-armv6.bin freebsd-armv7.bin \
66
freebsd-i386.bin freebsd-powerpc.bin freebsd-powerpc64.bin freebsd-powerpc64le.bin \
67
freebsd-riscv64.bin dfly.bin linux.bin
68
do
69
bin_meta ${bin}
70
71
_expected="${XABI}\n"
72
atf_check \
73
-o inline:"${_expected}" \
74
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config abi
75
76
_expected="${XALTABI}\n"
77
atf_check \
78
-o inline:"${_expected}" \
79
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config altabi
80
done
81
}
82
83
machoparse_body() {
84
# Macho-O parsing now works across platforms
85
86
for bin in \
87
macos.bin macos106.bin macos150.bin \
88
macosfat.bin "macosfat.bin#x86_64" "macosfat.bin#aarch64" \
89
macosfatlib.bin "macosfatlib.bin#x86_64" "macosfatlib.bin#aarch64"
90
do
91
bin_meta ${bin}
92
93
_expected="${XABI}\n"
94
atf_check \
95
-o inline:"${_expected}" \
96
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config abi
97
98
_expected="${XALTABI}\n"
99
atf_check \
100
-o inline:"${_expected}" \
101
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/${bin} config altabi
102
done
103
104
# explicitely select a fat entry that is not in the ABI_FILE
105
_expected="Scanned 2 entries, found none matching selector i386\n"
106
atf_check \
107
-s exit:1 \
108
-o inline:"${_expected}" \
109
-e match:"Unable to determine ABI" \
110
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#i386 config abi
111
112
atf_check \
113
-s exit:1 \
114
-o inline:"${_expected}" \
115
-e match:"Unable to determine ABI" \
116
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#i386 config altabi
117
118
# explicitely select a fat entry that is not a valid architecture, hence not in the ABI_FILE
119
_expected=""
120
atf_check \
121
-s exit:1 \
122
-o inline:"${_expected}" \
123
-e match:"Invalid ABI_FILE architecture hint abc" \
124
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#abc config abi
125
126
atf_check \
127
-s exit:1 \
128
-o inline:"${_expected}" \
129
-e match:"Invalid ABI_FILE architecture hint abc" \
130
pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin#abc config altabi
131
132
# if the binary is not universal, selecting the first entry is not commentable
133
_expected="Darwin:24:aarch64\n"
134
atf_check \
135
-o inline:"${_expected}" \
136
-e not-match:"picking first" \
137
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin config abi
138
139
_expected="darwin:24:aarch64:64\n"
140
atf_check \
141
-o inline:"${_expected}" \
142
-e not-match:"picking first" \
143
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin config altabi
144
145
_expected="Scanned 1 entry, found none matching selector i386\n"
146
atf_check \
147
-s exit:1 \
148
-o inline:"${_expected}" \
149
-e match:"Unable to determine ABI" \
150
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin#i386 config abi
151
152
atf_check \
153
-s exit:1 \
154
-o inline:"${_expected}" \
155
-e match:"Unable to determine ABI" \
156
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macos.bin#i386 config altabi
157
158
# if the binary is universal, selecting the first entry is to be commented
159
_expected="Darwin:17:x86_64\n"
160
atf_check \
161
-o inline:"${_expected}" \
162
-e match:"picking first" \
163
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin config abi
164
165
_expected="darwin:17:x86_64\n"
166
atf_check \
167
-o inline:"${_expected}" \
168
-e match:"picking first" \
169
pkg -d -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/macosfat.bin config altabi
170
}
171
172