Skip to content

Commit 8a7e23d

Browse files
authored
Make jl_*affinity tests more portable (#55261)
Changes made: - Use 0 for the thread ID to ensure it's always valid. The function expects `0 <= tid < jl_n_threads` so 1 is incorrect if `jl_n_threads` is 1. - After retrieving the affinity mask with `jl_getaffinity`, pass that same mask back to `jl_setaffinity`. This ensures that the mask is always valid. Using a mask of all ones results in `EINVAL` on FreeBSD. Based on the discussion in #53402, this change may also fix Windows, so I've tried reenabling it here. - To check whether `jl_getaffinity` actually did something, we can check that the mask is no longer all zeros after the call. Fixes #54817
1 parent cdd599c commit 8a7e23d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/threads.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,12 @@ end
357357

358358
@testset "jl_*affinity" begin
359359
cpumasksize = @ccall uv_cpumask_size()::Cint
360-
if !Sys.iswindows() && cpumasksize > 0 # otherwise affinities are not supported on the platform (UV_ENOTSUP)
361-
mask = zeros(Cchar, cpumasksize);
360+
if cpumasksize > 0 # otherwise affinities are not supported on the platform (UV_ENOTSUP)
362361
jl_getaffinity = (tid, mask, cpumasksize) -> ccall(:jl_getaffinity, Int32, (Int16, Ptr{Cchar}, Int32), tid, mask, cpumasksize)
363362
jl_setaffinity = (tid, mask, cpumasksize) -> ccall(:jl_setaffinity, Int32, (Int16, Ptr{Cchar}, Int32), tid, mask, cpumasksize)
364-
@test jl_getaffinity(1, mask, cpumasksize) == 0
365-
fill!(mask, 1)
366-
@test jl_setaffinity(1, mask, cpumasksize) == 0
363+
mask = zeros(Cchar, cpumasksize)
364+
@test jl_getaffinity(0, mask, cpumasksize) == 0
365+
@test !all(iszero, mask)
366+
@test jl_setaffinity(0, mask, cpumasksize) == 0
367367
end
368368
end

0 commit comments

Comments
 (0)