Skip to content

Commit a0cd812

Browse files
committed
Add a check_cuda macro for unit tests
Added @/check_cuda, a macro that checks CUDA.functional() before running CUDA-related unit tests. If CUDA is not detected on the system, it emits a warning before continuing with other unit tests.
1 parent cefb434 commit a0cd812

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using ChaChaCiphers, Documenter, Test
22

3+
include("utils.jl")
4+
35
include("test_core.jl")
46
include("test_chacha.jl")
57
include("test_keystream.jl")

test/test_chacha.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ using Test
173173
end
174174

175175
@testset "CUDA ChaCha tests" begin
176-
if CUDA.functional()
176+
@check_cuda begin
177177
@testset "Test quarter-round function" begin
178178
# Ref: IETF RFC 8439, Sec. 2.1.1
179179
# https://datatracker.ietf.org/doc/html/rfc8439#section-2.1.1

test/test_cuda_keystream.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using Statistics
88
using Test
99

1010
@testset "CUDAChaChaStream tests" begin
11-
if CUDA.functional()
11+
@check_cuda begin
1212
@testset "Construct CUDAChaChaStream" begin
1313
rng = CUDAChaCha12Stream()
1414
@test rng.doublerounds == 6
@@ -85,7 +85,5 @@ using Test
8585

8686
@test rand_gpu == rand_cpu
8787
end
88-
else
89-
@warn "CUDA.functional() = false; skipping tests"
9088
end
9189
end

test/utils.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Testing utilities
2+
3+
macro check_cuda(expr)
4+
quote
5+
import CUDA
6+
7+
if CUDA.functional()
8+
$(esc(expr))
9+
else
10+
@warn "CUDA.functional() = false; skipping tests"
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)