| 57 |
95
|
|
"the installer reinstalls whatever is already on disk"
|
| 58 |
96
|
|
end
|
| 59 |
97
|
|
|
|
98
|
+ |
describe "libc detection" do
|
|
99
|
+ |
# `linux_libc` is extracted from the served script and run against fixture
|
|
100
|
+ |
# roots, so these assert the code readers actually receive rather than a
|
|
101
|
+ |
# copy of it. The choice matters more than most: a glibc binary on a musl
|
|
102
|
+ |
# system fails at exec with "no such file or directory" naming a file that
|
|
103
|
+ |
# is plainly there, and nothing in that message points at the installer.
|
|
104
|
+ |
setup do
|
|
105
|
+ |
script = File.read!(@script)
|
|
106
|
+ |
|
|
107
|
+ |
[function] = Regex.run(~r/^linux_libc\(\).*?^\}/ms, script)
|
|
108
|
+ |
|
|
109
|
+ |
dir = Path.join(System.tmp_dir!(), "install-libc-#{System.unique_integer([:positive])}")
|
|
110
|
+ |
File.mkdir_p!(dir)
|
|
111
|
+ |
on_exit(fn -> File.rm_rf(dir) end)
|
|
112
|
+ |
|
|
113
|
+ |
source = Path.join(dir, "linux_libc.sh")
|
|
114
|
+ |
File.write!(source, function)
|
|
115
|
+ |
|
|
116
|
+ |
{:ok, source: source, dir: dir}
|
|
117
|
+ |
end
|
|
118
|
+ |
|
|
119
|
+ |
test "a present glibc loader means the dynamically linked build runs", context do
|
|
120
|
+ |
root = fixture(context.dir, "glibc", ["lib64/ld-linux-x86-64.so.2"])
|
|
121
|
+ |
|
|
122
|
+ |
assert libc(context.source, "x86_64", root) == "gnu"
|
|
123
|
+ |
end
|
|
124
|
+ |
|
|
125
|
+ |
test "a multiarch glibc loader counts too", context do
|
|
126
|
+ |
root = fixture(context.dir, "multiarch", ["lib/x86_64-linux-gnu/ld-linux-x86-64.so.2"])
|
|
127
|
+ |
|
|
128
|
+ |
assert libc(context.source, "x86_64", root) == "gnu"
|
|
129
|
+ |
end
|
|
130
|
+ |
|
|
131
|
+ |
test "no glibc loader means only the static build runs", context do
|
|
132
|
+ |
root = fixture(context.dir, "alpine", ["lib/ld-musl-x86_64.so.1"])
|
|
133
|
+ |
|
|
134
|
+ |
assert libc(context.source, "x86_64", root) == "musl"
|
|
135
|
+ |
end
|
|
136
|
+ |
|
|
137
|
+ |
test "an image carrying no libc at all still resolves to the static build", context do
|
|
138
|
+ |
root = fixture(context.dir, "bare", [])
|
|
139
|
+ |
|
|
140
|
+ |
assert libc(context.source, "x86_64", root) == "musl"
|
|
141
|
+ |
assert libc(context.source, "aarch64", root) == "musl"
|
|
142
|
+ |
end
|
|
143
|
+ |
|
|
144
|
+ |
test "a glibc host with the musl package installed is still glibc", context do
|
|
145
|
+ |
# Debian's `musl` package drops a musl loader onto a glibc system. The
|
|
146
|
+ |
# question is which artifact runs, not which loaders exist, and both do.
|
|
147
|
+ |
root =
|
|
148
|
+ |
fixture(context.dir, "both", [
|
|
149
|
+ |
"lib64/ld-linux-x86-64.so.2",
|
|
150
|
+ |
"lib/ld-musl-x86_64.so.1"
|
|
151
|
+ |
])
|
|
152
|
+ |
|
|
153
|
+ |
assert libc(context.source, "x86_64", root) == "gnu"
|
|
154
|
+ |
end
|
|
155
|
+ |
|
|
156
|
+ |
test "each architecture is judged by its own loader", context do
|
|
157
|
+ |
root = fixture(context.dir, "arm", ["lib/ld-linux-aarch64.so.1"])
|
|
158
|
+ |
|
|
159
|
+ |
assert libc(context.source, "aarch64", root) == "gnu"
|
|
160
|
+ |
|
|
161
|
+ |
# The x86_64 loader is absent from this root, and an architecture's
|
|
162
|
+ |
# verdict must not be borrowed from another's.
|
|
163
|
+ |
assert libc(context.source, "x86_64", root) == "musl"
|
|
164
|
+ |
end
|
|
165
|
+ |
|
|
166
|
+ |
test "an architecture with no musl build asks for the glibc one", context do
|
|
167
|
+ |
root = fixture(context.dir, "riscv", [])
|
|
168
|
+ |
|
|
169
|
+ |
assert libc(context.source, "riscv64", root) == "gnu"
|
|
170
|
+ |
end
|
|
171
|
+ |
end
|
|
172
|
+ |
|
|
173
|
+ |
test "the musl platform is named the way the release publishes it" do
|
|
174
|
+ |
script = File.read!(@script)
|
|
175
|
+ |
|
|
176
|
+ |
assert script =~ ~s(platform="${platform}-musl"),
|
|
177
|
+ |
"the installer detects musl and then asks for the same artifact anyway"
|
|
178
|
+ |
|
|
179
|
+ |
refute script =~ ~s(platform="${os}-${arch}-${libc}"),
|
|
180
|
+ |
"the glibc artifact is renamed, which breaks every installer already in circulation"
|
|
181
|
+ |
end
|
|
182
|
+ |
|
| 60 |
183
|
|
test "the channel resolves a version rather than hardcoding one" do
|
| 61 |
184
|
|
script = File.read!(@script)
|
| 62 |
185
|
|
|