Skip to content

Commit 6da085b

Browse files
committed
Switch to FileCheck.jl.
1 parent d762273 commit 6da085b

File tree

10 files changed

+210
-340
lines changed

10 files changed

+210
-340
lines changed

test/Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3-
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
3+
FileCheck = "4e644321-382b-4b05-b0b6-5d23c3d944fb"
44
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
55
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
66
LLVM_jll = "86de99a1-58d6-5da7-8064-bd56ce2e322c"
@@ -18,4 +18,6 @@ demumble_jll = "1e29f10c-031c-5a83-9565-69cddfc27673"
1818
[compat]
1919
Aqua = "0.8"
2020
ParallelTestRunner = "1"
21-
LLVM_jll = "15,16,18,20"
21+
22+
[sources]
23+
FileCheck = {url = "https://github.com/JuliaLLVM/FileCheck.jl", rev="main"}

test/bpf.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
end
55

66
@test @filecheck begin
7-
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
8-
check"CHECK: r0 = 0"
9-
check"CHECK-NEXT: exit"
7+
@check_label "julia_kernel_{{[0-9_]*}}:"
8+
@check "r0 = 0"
9+
@check_next "exit"
1010
BPF.code_native(mod.kernel, ())
1111
end
1212
end
@@ -16,9 +16,9 @@ end
1616
end
1717

1818
@test @filecheck begin
19-
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
20-
check"CHECK: r0 = r1"
21-
check"CHECK-NEXT: exit"
19+
@check_label "julia_kernel_{{[0-9_]*}}:"
20+
@check "r0 = r1"
21+
@check_next "exit"
2222
BPF.code_native(mod.kernel, (UInt64,))
2323
end
2424
end
@@ -28,10 +28,10 @@ end
2828
end
2929

3030
@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"
31+
@check_label "julia_kernel_{{[0-9_]*}}:"
32+
@check "r0 = r1"
33+
@check_next "r0 += 1"
34+
@check_next "exit"
3535
BPF.code_native(mod.kernel, (UInt64,))
3636
end
3737
end
@@ -50,9 +50,9 @@ end
5050
end
5151

5252
@test @filecheck begin
53-
check"CHECK-LABEL: julia_kernel_{{[0-9_]*}}:"
54-
check"CHECK: call"
55-
check"CHECK-NEXT: exit"
53+
@check_label "julia_kernel_{{[0-9_]*}}:"
54+
@check "call"
55+
@check_next "exit"
5656
BPF.code_native(mod.kernel, (Int,))
5757
end
5858
end

test/gcn.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ sink_gcn(i) = sink(i, Val(5))
1111
end
1212

1313
@test @filecheck begin
14-
check"CHECK-NOT: amdgpu_kernel"
14+
@check_not "amdgpu_kernel"
1515
GCN.code_llvm(mod.kernel, Tuple{}; dump_module=true)
1616
end
1717

1818
@test @filecheck begin
19-
check"CHECK: amdgpu_kernel"
19+
@check "amdgpu_kernel"
2020
GCN.code_llvm(mod.kernel, Tuple{}; dump_module=true, kernel=true)
2121
end
2222
end
@@ -30,9 +30,9 @@ end
3030
end
3131

3232
@test @filecheck begin
33-
check"CHECK-NOT: {{julia_throw_boundserror_[0-9]+}}"
34-
check"CHECK: @gpu_report_exception"
35-
check"CHECK: @gpu_signal_exception"
33+
@check_not "{{julia_throw_boundserror_[0-9]+}}"
34+
@check "@gpu_report_exception"
35+
@check "@gpu_signal_exception"
3636
GCN.code_llvm(mod.kernel, Tuple{})
3737
end
3838
end
@@ -63,9 +63,9 @@ end
6363
end
6464

6565
@test @filecheck begin
66-
check"CHECK-LABEL: {{(julia|j)_kernel_[0-9]+}}:"
67-
check"CHECK: s_cbranch_exec"
68-
check"CHECK: s_trap 2"
66+
@check_label "{{(julia|j)_kernel_[0-9]+}}:"
67+
@check "s_cbranch_exec"
68+
@check "s_trap 2"
6969
GCN.code_native(mod.kernel, Tuple{})
7070
end
7171
end
@@ -83,9 +83,9 @@ end
8383
end
8484

8585
@test @filecheck begin
86-
check"CHECK-LABEL: {{(julia|j)_parent_[0-9]+}}:"
87-
check"CHECK: s_add_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
88-
check"CHECK: s_addc_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
86+
@check_label "{{(julia|j)_parent_[0-9]+}}:"
87+
@check "s_add_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
88+
@check "s_addc_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
8989
GCN.code_native(mod.parent, Tuple{Int64}; dump_module=true)
9090
end
9191
end
@@ -101,9 +101,9 @@ end
101101
end
102102

103103
@test @filecheck begin
104-
check"CHECK-NOT: .amdhsa_kernel {{(julia|j)_nonentry_[0-9]+}}"
105-
check"CHECK: .type {{(julia|j)_nonentry_[0-9]+}},@function"
106-
check"CHECK: .amdhsa_kernel _Z5entry5Int64"
104+
@check_not ".amdhsa_kernel {{(julia|j)_nonentry_[0-9]+}}"
105+
@check ".type {{(julia|j)_nonentry_[0-9]+}},@function"
106+
@check ".amdhsa_kernel _Z5entry5Int64"
107107
GCN.code_native(mod.entry, Tuple{Int64}; dump_module=true, kernel=true)
108108
end
109109
end
@@ -126,12 +126,12 @@ end
126126
end
127127

128128
@test @filecheck begin
129-
check"CHECK: .type {{(julia|j)_child_[0-9]+}},@function"
129+
@check ".type {{(julia|j)_child_[0-9]+}},@function"
130130
GCN.code_native(mod.parent1, Tuple{Int}; dump_module=true)
131131
end
132132

133133
@test @filecheck begin
134-
check"CHECK: .type {{(julia|j)_child_[0-9]+}},@function"
134+
@check ".type {{(julia|j)_child_[0-9]+}},@function"
135135
GCN.code_native(mod.parent2, Tuple{Int}; dump_module=true)
136136
end
137137
end
@@ -155,14 +155,14 @@ end
155155
end
156156

157157
@test @filecheck begin
158-
check"CHECK-DAG: .type {{(julia|j)_child1_[0-9]+}},@function"
159-
check"CHECK-DAG: .type {{(julia|j)_child2_[0-9]+}},@function"
158+
@check_dag ".type {{(julia|j)_child1_[0-9]+}},@function"
159+
@check_dag ".type {{(julia|j)_child2_[0-9]+}},@function"
160160
GCN.code_native(mod.parent1, Tuple{Int}; dump_module=true)
161161
end
162162

163163
@test @filecheck begin
164-
check"CHECK-DAG: .type {{(julia|j)_child1_[0-9]+}},@function"
165-
check"CHECK-DAG: .type {{(julia|j)_child2_[0-9]+}},@function"
164+
@check_dag ".type {{(julia|j)_child1_[0-9]+}},@function"
165+
@check_dag ".type {{(julia|j)_child2_[0-9]+}},@function"
166166
GCN.code_native(mod.parent2, Tuple{Int}; dump_module=true)
167167
end
168168
end
@@ -182,9 +182,9 @@ end
182182
end
183183

184184
@test @filecheck begin
185-
check"CHECK-LABEL: {{(julia|j)_kernel_[0-9]+}}:"
186-
check"CHECK-NOT: jl_throw"
187-
check"CHECK-NOT: jl_invoke"
185+
@check_label "{{(julia|j)_kernel_[0-9]+}}:"
186+
@check_not "jl_throw"
187+
@check_not "jl_invoke"
188188
GCN.code_native(mod.kernel, Tuple{Ptr{Int32}})
189189
end
190190
end
@@ -234,11 +234,11 @@ false && @testset "GC and TLS lowering" begin
234234
end
235235

236236
@test @filecheck begin
237-
check"CHECK-NOT: jl_push_gc_frame"
238-
check"CHECK-NOT: jl_pop_gc_frame"
239-
check"CHECK-NOT: jl_get_gc_frame_slot"
240-
check"CHECK-NOT: jl_new_gc_frame"
241-
check"CHECK: gpu_gc_pool_alloc"
237+
@check_not "jl_push_gc_frame"
238+
@check_not "jl_pop_gc_frame"
239+
@check_not "jl_get_gc_frame_slot"
240+
@check_not "jl_new_gc_frame"
241+
@check "gpu_gc_pool_alloc"
242242
GCN.code_native(mod.kernel, Tuple{Int})
243243
end
244244

@@ -256,7 +256,7 @@ false && @testset "GC and TLS lowering" begin
256256
end
257257

258258
@test @filecheck begin
259-
check"CHECK-NOT: gpu_gc_pool_alloc"
259+
@check_not "gpu_gc_pool_alloc"
260260
GCN.code_native(ref_kernel, Tuple{Ptr{Int64}, Int})
261261
end
262262
end
@@ -275,8 +275,8 @@ end
275275
end
276276

277277
@test @filecheck begin
278-
check"CHECK-LABEL: define void @{{(julia|j)_kernel_[0-9]+}}"
279-
check"CHECK: jl_box_float32"
278+
@check_label "define void @{{(julia|j)_kernel_[0-9]+}}"
279+
@check "jl_box_float32"
280280
GCN.code_llvm(mod.kernel, Tuple{Float32,Ptr{Float32}})
281281
end
282282
GCN.code_native(devnull, mod.kernel, Tuple{Float32,Ptr{Float32}})

test/helpers/test.jl

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -36,120 +36,10 @@ end
3636
return :(Base.llvmcall($llvmcall_str, T, Tuple{T}, i))
3737
end
3838

39-
# filecheck utils
39+
# typed/opaque pointer detection for conditional FileCheck checks
4040

41-
module FileCheck
42-
import LLVM_jll
43-
import IOCapture
44-
using GPUCompiler, LLVM
45-
46-
export filecheck, @filecheck, @check_str
47-
48-
global filecheck_path::String
49-
function __init__()
50-
global filecheck_path = joinpath(LLVM_jll.artifact_dir, "tools", "FileCheck")
51-
end
52-
53-
function filecheck_exe(; adjust_PATH::Bool=true, adjust_LIBPATH::Bool=true)
54-
env = Base.invokelatest(
55-
LLVM_jll.JLLWrappers.adjust_ENV!,
56-
copy(ENV),
57-
LLVM_jll.PATH[],
58-
LLVM_jll.LIBPATH[],
59-
adjust_PATH,
60-
adjust_LIBPATH
61-
)
62-
63-
return Cmd(Cmd([filecheck_path]); env)
64-
end
65-
66-
const julia_typed_pointers = JuliaContext() do ctx
67-
supports_typed_pointers(ctx)
68-
end
69-
70-
function filecheck(f, input)
71-
# FileCheck assumes that the input is available as a file
72-
mktemp() do path, input_io
73-
write(input_io, input)
74-
close(input_io)
75-
76-
# capture the output of `f` and write it into a temporary buffer
77-
result = IOCapture.capture(rethrow=Union{}) do
78-
f(input)
79-
end
80-
output_io = IOBuffer()
81-
write(output_io, result.output)
82-
println(output_io)
83-
84-
if result.error
85-
# if the function errored, also render the exception and backtrace
86-
showerror(output_io, result.value, result.backtrace)
87-
elseif result.value !== nothing
88-
# also show the returned value; some APIs don't print
89-
write(output_io, string(result.value))
90-
end
91-
92-
# determine some useful prefixes for FileCheck
93-
prefixes = ["CHECK",
94-
"JULIA$(VERSION.major)_$(VERSION.minor)",
95-
"LLVM$(Base.libllvm_version.major)"]
96-
## whether we use typed pointers or opaque pointers
97-
if julia_typed_pointers
98-
push!(prefixes, "TYPED")
99-
else
100-
push!(prefixes, "OPAQUE")
101-
end
102-
## whether we pass pointers as integers or as actual pointers
103-
if VERSION >= v"1.12.0-DEV.225"
104-
push!(prefixes, "PTR_ABI")
105-
else
106-
push!(prefixes, "INTPTR_ABI")
107-
end
108-
109-
# now pass the collected output to FileCheck
110-
seekstart(output_io)
111-
filecheck_io = Pipe()
112-
cmd = ```$(filecheck_exe())
113-
--color
114-
--allow-unused-prefixes
115-
--check-prefixes $(join(prefixes, ','))
116-
$path```
117-
proc = run(pipeline(ignorestatus(cmd); stdin=output_io, stdout=filecheck_io, stderr=filecheck_io); wait=false)
118-
close(filecheck_io.in)
119-
120-
# collect the output of FileCheck
121-
reader = Threads.@spawn String(read(filecheck_io))
122-
Base.wait(proc)
123-
log = strip(fetch(reader))
124-
125-
# error out if FileCheck did not succeed.
126-
# otherwise, return true so that `@test @filecheck` works as expected.
127-
if !success(proc)
128-
error(log)
129-
end
130-
return true
131-
end
132-
end
133-
134-
# collect checks used in the @filecheck block by piggybacking on macro expansion
135-
const checks = String[]
136-
macro check_str(str)
137-
push!(checks, str)
138-
nothing
139-
end
140-
141-
macro filecheck(ex)
142-
ex = Base.macroexpand(__module__, ex)
143-
if isempty(checks)
144-
error("No checks provided within the @filecheck macro block")
145-
end
146-
check_str = join(checks, "\n")
147-
empty!(checks)
148-
149-
esc(quote
150-
filecheck($check_str) do _
151-
$ex
152-
end
153-
end)
154-
end
41+
using LLVM
42+
const typed_ptrs = JuliaContext() do ctx
43+
supports_typed_pointers(ctx)
15544
end
45+
const opaque_ptrs = !typed_ptrs

0 commit comments

Comments
 (0)