forked from JuliaPackaging/BinaryBuilderBase.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunners.jl
More file actions
317 lines (293 loc) · 14.6 KB
/
runners.jl
File metadata and controls
317 lines (293 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
using Test
using BinaryBuilderBase
using BinaryBuilderBase: platform_dlext, platform_exeext
using Pkg
@testset "Wrappers utilities" begin
@test nbits(Platform("i686", "linux")) == 32
@test nbits(Platform("x86_64", "linux"; march="avx")) == 64
@test nbits(Platform("armv7l", "linux")) == 32
@test nbits(Platform("aarch64", "linux"; cuda="10.1")) == 64
@test nbits(Platform("powerpc64le", "linux")) == 64
@test nbits(AnyPlatform()) == 64
@test proc_family(Platform("i686", "linux")) == "intel"
@test proc_family(Platform("x86_64", "linux"; march="avx")) == "intel"
@test proc_family(Platform("armv7l", "linux")) == "arm"
@test proc_family(Platform("aarch64", "linux"; cuda="10.1")) == "arm"
@test proc_family(Platform("powerpc64le", "linux")) == "power"
@test proc_family(AnyPlatform()) == "any"
@test platform_exeext(Platform("i686", "linux")) == ""
@test platform_exeext(Platform("x86_64", "freebsd")) == ""
@test platform_exeext(Platform("x86_64", "macos")) == ""
@test platform_exeext(Platform("i686", "windows")) == ".exe"
@test platform_exeext(Platform("x86_64", "linux"; march="avx512")) == ""
@test aatriplet(Platform("x86_64", "linux"; libc="glibc", libgfortran_version=v"4.0.0", march="avx", cuda="9.2")) == "x86_64-linux-gnu"
end
# Are we using docker? If so, test that the docker runner works...
@testset "Runner utilities" begin
# Test that is_ecryptfs works for something we're certain isn't encrypted
if isdir("/proc")
isecfs = (false, "/proc/")
@test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == isecfs
@test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == isecfs
@test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == isecfs
else
@test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == (false, "/proc")
@test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == (false, "/proc/")
@test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == (false, "/proc/not_a_file")
end
if isa(preferred_runner(), BinaryBuilderBase.DockerRunner)
@testset "Docker image importing" begin
# First, delete the docker image, in case it already existed
BinaryBuilderBase.delete_docker_image()
# Next, import it and ensure that doesn't throw
rootfs = first(BinaryBuilderBase.choose_shards(platform))
mktempdir() do dir
@test BinaryBuilderBase.import_docker_image(rootfs, dir; verbose=true) === nothing
end
# Test that deleting the docker image suceeds, now that we know
# it exists
@test BinaryBuilderBase.delete_docker_image()
end
end
@testset "hello world" begin
mktempdir() do dir
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl"))
iobuff = IOBuffer()
@test run(ur, `/bin/bash -c "echo test"`, iobuff)
seek(iobuff, 0)
# Test that we get the output we expect (e.g. the second line is `test`)
@test readlines(iobuff)[2] == "test"
end
end
if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true"
@info("Beginning full shard test... (this can take a while)")
platforms = supported_platforms()
else
platforms = (Platform("x86_64", "linux"; libc="musl"),)
end
# Checks that the wrappers provide the correct C++ string ABI
@testset "Compilation - C++ string ABI" begin
mktempdir() do dir
# Host is x86_64-linux-musl-cxx11 and target is x86_64-linux-musl-cxx03
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03"), preferred_gcc_version=v"5")
iobuff = IOBuffer()
test_script = raw"""
set -e
# Building for the target uses C++03 string ABI
echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${CC} -x c - 2>&1 | grep -- "-D_GLIBCXX_USE_CXX11_ABI=0"
# Building for the host uses C++11 string ABI
echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${HOSTCC} -x c - 2>&1 | grep -v -- "-D_GLIBCXX_USE_CXX11_ABI=0"
"""
@test run(ur, `/bin/bash -c "$(test_script)"`, iobuff; tee_stream=devnull)
end
end
# This tests only that compilers for all platforms can build a simple C program
# TODO: for the time being we only test `cc`, eventually we want to run `gcc` and `clang` separately
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc",)
mktempdir() do dir
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
@test run(ur, `/bin/bash -c "echo 'int main() {return 0;}' | $(compiler) -x c -"`, iobuff; tee_stream=devnull)
seekstart(iobuff)
@test split(String(read(iobuff)), "\n")[2] == ""
end
end
# This tests that compilers for all Intel Linux platforms can build simple
# C, C++, Fortran programs that we can also run
@testset "Compilation and running" begin
platforms = filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms())
@testset "C - $(platform)" for platform in platforms
mktempdir() do dir
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_c = """
#include <stdio.h>
int main() {
printf("Hello World!\\n");
return 0;
}
"""
cmd = `/bin/bash -c "echo '$(test_c)' > test.c && cc -o test test.c && ./test"`
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
# Test that we get the output we expect
@test endswith(readchomp(iobuff), "Hello World!")
end
end
@testset "C and link to quadmath - $(platform)" for platform in platforms
mktempdir() do dir
# Use a recent GCC with libgfortran5
options = (preferred_gcc_version=v"9", compilers=[:c])
shards = choose_shards(platform; options...)
concrete_platform = get_concrete_platform(platform, shards)
prefix = setup_workspace(
dir,
[],
concrete_platform,
default_host_platform;
)
# Install `MPICH_jll` in the `${prefix}` to make sure we can link to
# libquadmath without problems, see
# https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/157#issuecomment-879263820
artifact_paths =
setup_dependencies(prefix,
[PackageSpec(; name="MPICH_jll", version="3.4.2")],
concrete_platform, verbose=false)
ur = preferred_runner()(prefix.path;
platform=concrete_platform,
shards = shards,
options...)
iobuff = IOBuffer()
test_c = """
#include <stdio.h>
int main() {
printf("Hello World!\\n");
return 0;
}
"""
test_script = """
set -e
echo '$(test_c)' > test.c
# Make sure we can compile successfully also when linking to libmpifort
cc -o test test.c -L\${libdir} -lmpifort -lquadmath
./test
"""
cmd = `/bin/bash -c "$(test_script)"`
if arch(platform) == "i686" && libc(platform) == "musl"
# We can't run this program for this platform
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
else
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
# Test that we get the output we expect
@test endswith(readchomp(iobuff), "Hello World!")
end
cleanup_dependencies(prefix, artifact_paths, concrete_platform)
end
end
@testset "C++ - $(platform)" for platform in platforms
mktempdir() do dir
# Use an old GCC with libgfortran3
options = (preferred_gcc_version=v"4", compilers=[:c])
shards = choose_shards(platform; options...)
concrete_platform = get_concrete_platform(platform, shards)
prefix = setup_workspace(
dir,
[],
concrete_platform,
default_host_platform;
)
# Install `CompilerSupportLibraries_jll` v0.5.0 in the `${prefix}` to make
# sure it doesn't break compilation of the program for i686-linux-gnu, see
# https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/163
artifact_paths =
setup_dependencies(prefix,
[PackageSpec(; name="CompilerSupportLibraries_jll", version="0.5.0")],
concrete_platform, verbose=false)
ur = preferred_runner()(prefix.path;
platform=concrete_platform,
shards = shards,
options...)
iobuff = IOBuffer()
test_cpp = """
#include <iostream>
class breakCCompiler; // Courtesy of Meson
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
"""
test_script = """
set -e
echo '$(test_cpp)' > test.cpp
# Make sure we can compile successfully also when `\${libdir}` is in the
# linker search path
c++ -o test test.cpp -L\${libdir}
./test
"""
cmd = `/bin/bash -c "$(test_script)"`
if arch(platform) == "i686" && libc(platform) == "musl"
# We can't run C++ programs for this platform
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
else
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
# Test that we get the output we expect
@test endswith(readchomp(iobuff), "Hello World!")
end
cleanup_dependencies(prefix, artifact_paths, concrete_platform)
end
end
# This tests that compilers for all Intel Linux platforms can build a simple
# Fortran program that we can also run
@testset "Fortran - $(platform)" for platform in platforms
mktempdir() do dir
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_f = """
program hello
print *, "Hello World!"
end program
"""
cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"`
if arch(platform) == "i686" && libc(platform) == "musl"
# We can't run Fortran programs for this platform
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
else
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
# Test that we get the output we expect
@test endswith(readchomp(iobuff), "Hello World!")
end
end
end
end
@testset "Locking microarchitecture" begin
mktempdir() do dir
platform = Platform("x86_64", "linux"; libc="musl")
cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -march=native -"`
ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=true)
iobuff = IOBuffer()
@test !run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
@test readlines(iobuff)[2] == "Cannot force an architecture"
ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=false)
iobuff = IOBuffer()
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
@test split(String(read(iobuff)), "\n")[2] == ""
end
end
@testset "Unsafe flags" begin
mktempdir() do dir
platform = Platform("x86_64", "linux"; libc="musl")
cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -Ofast -"`
ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false)
iobuff = IOBuffer()
@test !run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
lines = readlines(iobuff)
@test lines[2] == "You used one or more of the unsafe flags: -Ofast, -ffast-math, -funsafe-math-optimizations"
@test lines[3] == "Please repent."
ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=true)
iobuff = IOBuffer()
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
@test split(String(read(iobuff)), "\n")[2] == ""
end
end
end
@testset "Shards" begin
# Run the testsuite as sanity check
@testset "testsuite" begin
mktempdir() do dir
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers=[:c, :rust, :go])
iobuff = IOBuffer()
test_script = raw"""
set -e
make -j${nproc} -sC /usr/share/testsuite install
"""
@test run(ur, `/bin/bash -c "$(test_script)"`, iobuff; tee_stream=devnull)
end
end
end