Skip to content

Commit e7ddd62

Browse files
ararslanKristofferC
authored andcommitted
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 (cherry picked from commit 8a7e23d)
1 parent bab4ef1 commit e7ddd62

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/threads.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ end
344344

345345
@testset "jl_*affinity" begin
346346
cpumasksize = @ccall uv_cpumask_size()::Cint
347-
if !Sys.iswindows() && cpumasksize > 0 # otherwise affinities are not supported on the platform (UV_ENOTSUP)
348-
mask = zeros(Cchar, cpumasksize);
347+
if cpumasksize > 0 # otherwise affinities are not supported on the platform (UV_ENOTSUP)
349348
jl_getaffinity = (tid, mask, cpumasksize) -> ccall(:jl_getaffinity, Int32, (Int16, Ptr{Cchar}, Int32), tid, mask, cpumasksize)
350349
jl_setaffinity = (tid, mask, cpumasksize) -> ccall(:jl_setaffinity, Int32, (Int16, Ptr{Cchar}, Int32), tid, mask, cpumasksize)
351-
@test jl_getaffinity(1, mask, cpumasksize) == 0
352-
fill!(mask, 1)
353-
@test jl_setaffinity(1, mask, cpumasksize) == 0
350+
mask = zeros(Cchar, cpumasksize)
351+
@test jl_getaffinity(0, mask, cpumasksize) == 0
352+
@test !all(iszero, mask)
353+
@test jl_setaffinity(0, mask, cpumasksize) == 0
354354
end
355355
end

0 commit comments

Comments
 (0)