Skip to content

Commit 5e1300e

Browse files
KristofferCclaude
andcommitted
Run test files in parallel with ParallelTestRunner (#739)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent b2fed21 commit 5e1300e

3 files changed

Lines changed: 59 additions & 60 deletions

File tree

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Dates = "<0.0.1, 1"
1515
InteractiveUtils = "<0.0.1, 1"
1616
Libdl = "<0.0.1, 1"
1717
LinearAlgebra = "<0.0.1, 1"
18+
ParallelTestRunner = "2"
1819
Pkg = "<0.0.1, 1"
1920
Printf = "<0.0.1, 1"
2021
Random = "<0.0.1, 1"
@@ -27,9 +28,10 @@ julia = "1.11"
2728
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2829
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
2930
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
31+
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
3032
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
3133
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
3234
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3335

3436
[targets]
35-
test = ["Aqua", "Dates", "InteractiveUtils", "Pkg", "Printf", "Test"]
37+
test = ["Aqua", "Dates", "InteractiveUtils", "ParallelTestRunner", "Pkg", "Printf", "Test"]

test/runtests.jl

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,32 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
23
using Test, LinearAlgebra, SparseArrays
34

45
include("util/gha.jl")
56

6-
include("allowscalar.jl")
7-
include("fixed.jl")
8-
include("higherorderfns.jl")
9-
include("sparsematrix_constructors_indexing.jl")
10-
include("sparsematrix_ops.jl")
11-
include("sparsevector.jl")
12-
include("issues.jl")
7+
testfiles = ["allowscalar.jl", "fixed.jl", "higherorderfns.jl",
8+
"sparsematrix_constructors_indexing.jl", "sparsematrix_ops.jl",
9+
"sparsevector.jl", "issues.jl"]
1310

1411
if Base.USE_GPL_LIBS
15-
16-
include("cholmod.jl")
17-
include("umfpack.jl")
18-
include("spqr.jl")
19-
include("linalg.jl")
20-
include("linalg_solvers.jl")
21-
22-
nt = @static if isdefined(Threads, :maxthreadid)
23-
Threads.maxthreadid()
24-
else
25-
Threads.nthreads()
26-
end
27-
28-
# 1. If the OS is Windows and we are in GitHub Actions CI, we do NOT run
29-
# the `threads` tests.
30-
# 2. If the OS is Windows and we are NOT in GitHub Actions CI, we DO run
31-
# the `threads` tests.
32-
# - So, just as an example, if the OS is Windows and we are in
33-
# Buildkite CI, we DO run the `threads` tests.
34-
# 3. If the OS is NOT Windows, we DO run the `threads` tests.
12+
append!(testfiles, ["cholmod.jl", "umfpack.jl", "spqr.jl", "linalg.jl",
13+
"linalg_solvers.jl"])
3514
if Sys.iswindows() && is_github_actions_ci()
3615
@warn "Skipping `threads` tests on Windows on GitHub Actions CI"
37-
@test_skip false
3816
else
39-
@debug "Beginning the `threads` tests..."
40-
41-
# Test multithreaded execution
42-
@testset "threaded SuiteSparse tests" verbose = true begin
43-
@testset "threads = $nt" begin
44-
include("threads.jl")
45-
end
46-
# test both nthreads==1 and nthreads>1. spawn a process to test whichever
47-
# case we are not running currently.
48-
other_nthreads = nt == 1 ? 4 : 1
49-
@testset "threads = $other_nthreads" begin
50-
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads.jl`
51-
p = run(
52-
pipeline(
53-
setenv(
54-
cmd,
55-
"JULIA_NUM_THREADS" => other_nthreads,
56-
dir=@__DIR__()),
57-
stdout = stdout,
58-
stderr = stderr),
59-
wait = false)
60-
if !success(p)
61-
error("SuiteSparse threads test failed with nthreads == $other_nthreads")
62-
else
63-
@test true # mimic the one @test in threads.jl
64-
end
65-
end
66-
end
67-
end
68-
69-
@debug "Finished the `threads` tests..."
17+
push!(testfiles, "threads_suite.jl")
7018
end
7119
end
20+
21+
# ParallelTestRunner comes from the Pkg.test target; Julia base CI runs this
22+
# file without it and falls back to the serial path.
23+
if Base.find_package("ParallelTestRunner") !== nothing
24+
using ParallelTestRunner
25+
# Auto CPU thread count detection in ParallelTestRunner is bad
26+
push!(ARGS, "--jobs=$(Sys.CPU_THREADS)")
27+
testsuite = Dict{String,Expr}(splitext(f)[1] => :(include($(joinpath(@__DIR__, f))))
28+
for f in testfiles)
29+
runtests(SparseArrays, ARGS; testsuite)
30+
else
31+
foreach(include, testfiles)
32+
end

test/threads_suite.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
using Test, SparseArrays
4+
5+
nt = @static if isdefined(Threads, :maxthreadid)
6+
Threads.maxthreadid()
7+
else
8+
Threads.nthreads()
9+
end
10+
11+
@testset "threaded SuiteSparse tests" verbose = true begin
12+
@testset "threads = $nt" begin
13+
include("threads.jl")
14+
end
15+
# test both nthreads==1 and nthreads>1. spawn a process to test whichever
16+
# case we are not running currently.
17+
other_nthreads = nt == 1 ? 4 : 1
18+
@testset "threads = $other_nthreads" begin
19+
let p, cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads.jl`
20+
p = run(
21+
pipeline(
22+
setenv(
23+
cmd,
24+
"JULIA_NUM_THREADS" => other_nthreads,
25+
dir=@__DIR__()),
26+
stdout = stdout,
27+
stderr = stderr),
28+
wait = false)
29+
if !success(p)
30+
error("SuiteSparse threads test failed with nthreads == $other_nthreads")
31+
else
32+
@test true # mimic the one @test in threads.jl
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)