|
1 | 1 | @testset "No-op" begin |
2 | | - kernel() = 0 |
| 2 | + mod = @eval module $(gensym()) |
| 3 | + kernel() = 0 |
| 4 | + end |
3 | 5 |
|
4 | | - output = sprint(io->BPF.code_native(io, kernel, ())) |
5 | | - @test occursin("\tr0 = 0\n\texit", output) |
| 6 | + @test @filecheck begin |
| 7 | + check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:" |
| 8 | + check"CHECK: r0 = 0" |
| 9 | + check"CHECK-NEXT: exit" |
| 10 | + BPF.code_native(mod.kernel, ()) |
| 11 | + end |
6 | 12 | end |
7 | 13 | @testset "Return argument" begin |
8 | | - kernel(x) = x |
| 14 | + mod = @eval module $(gensym()) |
| 15 | + kernel(x) = x |
| 16 | + end |
9 | 17 |
|
10 | | - output = sprint(io->BPF.code_native(io, kernel, (UInt64,))) |
11 | | - @test occursin("\tr0 = r1\n\texit", output) |
| 18 | + @test @filecheck begin |
| 19 | + check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:" |
| 20 | + check"CHECK: r0 = r1" |
| 21 | + check"CHECK-NEXT: exit" |
| 22 | + BPF.code_native(mod.kernel, (UInt64,)) |
| 23 | + end |
12 | 24 | end |
13 | 25 | @testset "Addition" begin |
14 | | - kernel(x) = x+1 |
| 26 | + mod = @eval module $(gensym()) |
| 27 | + kernel(x) = x+1 |
| 28 | + end |
15 | 29 |
|
16 | | - output = sprint(io->BPF.code_native(io, kernel, (UInt64,))) |
17 | | - @test occursin("\tr0 = r1\n\tr0 += 1\n\texit", output) |
| 30 | + @test @filecheck begin |
| 31 | + check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:" |
| 32 | + check"CHECK: r0 = r1" |
| 33 | + check"CHECK-NEXT: r0 += 1" |
| 34 | + check"CHECK-NEXT: exit" |
| 35 | + BPF.code_native(mod.kernel, (UInt64,)) |
| 36 | + end |
18 | 37 | end |
19 | 38 | @testset "Errors" begin |
20 | | - kernel(x) = fakefunc(x) |
| 39 | + mod = @eval module $(gensym()) |
| 40 | + kernel(x) = fakefunc(x) |
| 41 | + end |
21 | 42 |
|
22 | | - @test_throws GPUCompiler.InvalidIRError BPF.code_execution(kernel, (UInt64,)) |
| 43 | + @test_throws GPUCompiler.InvalidIRError BPF.code_execution(mod.kernel, (UInt64,)) |
23 | 44 | end |
24 | 45 | @testset "Function Pointers" begin |
25 | 46 | @testset "valid" begin |
26 | | - goodcall(x) = Base.llvmcall("%2 = call i64 inttoptr (i64 3 to i64 (i64)*)(i64 %0)\nret i64 %2", Int, Tuple{Int}, x) |
27 | | - kernel(x) = goodcall(x) |
| 47 | + mod = @eval module $(gensym()) |
| 48 | + goodcall(x) = Base.llvmcall("%2 = call i64 inttoptr (i64 3 to i64 (i64)*)(i64 %0)\nret i64 %2", Int, Tuple{Int}, x) |
| 49 | + kernel(x) = goodcall(x) |
| 50 | + end |
28 | 51 |
|
29 | | - output = sprint(io->BPF.code_native(io, kernel, (Int,))) |
30 | | - @test occursin(r"\tcall .*\n\texit", output) |
| 52 | + @test @filecheck begin |
| 53 | + check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:" |
| 54 | + check"CHECK: call" |
| 55 | + check"CHECK-NEXT: exit" |
| 56 | + BPF.code_native(mod.kernel, (Int,)) |
| 57 | + end |
31 | 58 | end |
| 59 | + |
32 | 60 | @testset "invalid" begin |
33 | | - badcall(x) = Base.llvmcall("%2 = call i64 inttoptr (i64 3000 to i64 (i64)*)(i64 %0)\nret i64 %2", Int, Tuple{Int}, x) |
34 | | - kernel(x) = badcall(x) |
| 61 | + mod = @eval module $(gensym()) |
| 62 | + badcall(x) = Base.llvmcall("%2 = call i64 inttoptr (i64 3000 to i64 (i64)*)(i64 %0)\nret i64 %2", Int, Tuple{Int}, x) |
| 63 | + kernel(x) = badcall(x) |
| 64 | + end |
35 | 65 |
|
36 | | - @test_throws GPUCompiler.InvalidIRError BPF.code_execution(kernel, (Int,)) |
| 66 | + @test_throws GPUCompiler.InvalidIRError BPF.code_execution(mod.kernel, (Int,)) |
37 | 67 | end |
38 | 68 | end |
0 commit comments