Skip to content

Commit 8f05136

Browse files
committed
Add test for Zero-sized types
1 parent 0aaaa37 commit 8f05136

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ function check_default_ordering(T::Type)
1010
xs = T[rand(T), rand(T)]
1111
x1 = rand(T)
1212
x2 = rand(T)
13+
check_default_ordering(xs, x1, x2)
14+
end
15+
16+
function check_default_ordering(xs::AbstractArray{T}, x1::T, x2::T,) where T
1317
@debug "xs=$(repr(xs)) x1=$(repr(x1)) x2=$(repr(x2))"
1418

1519
ptr = llvmptr(xs, 1)
1620
GC.@preserve xs begin
1721
@test UnsafeAtomics.load(ptr) === xs[1]
1822
UnsafeAtomics.store!(ptr, x1)
1923
@test xs[1] === x1
24+
sizeof(T) == 0 && return # CAS hangs on zero sized data...
2025
desired = (old = x1, success = true)
2126
@test UnsafeAtomics.cas!(ptr, x1, x2) === (old = x1, success = true)
2227
@test xs[1] === x2
@@ -37,6 +42,10 @@ function test_explicit_ordering(T::Type = UInt)
3742
xs = T[rand(T), rand(T)]
3843
x1 = rand(T)
3944
x2 = rand(T)
45+
test_explicit_ordering(xs, x1, x2)
46+
end
47+
48+
function test_explicit_ordering(xs::AbstractArray{T}, x1::T, x2::T,) where T
4049
@debug "xs=$(repr(xs)) x1=$(repr(x1)) x2=$(repr(x2))"
4150

4251
ptr = llvmptr(xs, 1)
@@ -45,6 +54,7 @@ function test_explicit_ordering(T::Type = UInt)
4554
@test UnsafeAtomics.load(ptr, acquire) === xs[1]
4655
UnsafeAtomics.store!(ptr, x1, release)
4756
@test xs[1] === x1
57+
sizeof(T) == 0 && return # CAS hangs on zero sized data...
4858
desired = (old = x1, success = true)
4959
@test UnsafeAtomics.cas!(ptr, x1, x2, acq_rel, acquire) === desired
5060
@test xs[1] === x2
@@ -79,4 +89,10 @@ end
7989
check_default_ordering(T)
8090
test_explicit_ordering(T)
8191
end
92+
93+
@testset "Zero-sized types" begin
94+
@test sizeof(Nothing) == 0
95+
check_default_ordering([nothing, nothing], nothing, nothing)
96+
test_explicit_ordering([nothing, nothing], nothing, nothing)
97+
end
8298
end

0 commit comments

Comments
 (0)