Skip to content

Commit 5005fae

Browse files
staticfloattkf
authored andcommitted
More flexible test affinity setting (#44677)
* More flexibly test affinity setting When running on a machine with `cpusets` applied, we are unable to assign CPU affinity to CPUs 1 and 2; we may be locked to CPUs 9-16, for example. So we must inspect what our current cpumask is, and from that select CPUs that we can safely assign affinity to in our tests. * Import `uv_thread_getaffinity` from `print_process_affinity.jl` * Call `uv_thread_getaffinity` only if `AFFINITY_SUPPORTED` * Fix a syntax error Co-authored-by: Takafumi Arakaki <[email protected]> (cherry picked from commit 32b1305)
1 parent c004dcc commit 5005fae

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/threads.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ using Test
44

55
using Base.Threads
66

7+
include("print_process_affinity.jl") # import `uv_thread_getaffinity`
8+
79
# simple sanity tests for locks under cooperative concurrent access
810
let lk = ReentrantLock()
911
c1 = Event()
@@ -93,10 +95,13 @@ else
9395
end
9496
# Note also that libuv does not support affinity in macOS and it is known to
9597
# hang in FreeBSD. So, it's tested only in Linux and Windows:
96-
if Sys.islinux() || Sys.iswindows()
97-
if Sys.CPU_THREADS > 1 && !running_under_rr()
98-
@test run_with_affinity([2]) == "2"
99-
@test run_with_affinity([1, 2]) == "1,2"
98+
const AFFINITY_SUPPORTED = (Sys.islinux() || Sys.iswindows()) && !running_under_rr()
99+
100+
if AFFINITY_SUPPORTED
101+
allowed_cpus = findall(uv_thread_getaffinity())
102+
if length(allowed_cpus) 2
103+
@test run_with_affinity(allowed_cpus[1:1]) == "$(allowed_cpus[1])"
104+
@test run_with_affinity(allowed_cpus[1:2]) == "$(allowed_cpus[1]),$(allowed_cpus[2])"
100105
end
101106
end
102107

0 commit comments

Comments
 (0)