Skip to content

Commit

Permalink
Switch to ReTestItems.jl (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Sep 6, 2023
1 parent f3f2c5e commit 06e4288
Show file tree
Hide file tree
Showing 23 changed files with 505 additions and 472 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ jobs:
- branch: 'master'
os: 'windows-latest'
arch: 'x64'
# hangs
# hangs during compilation
- branch: 'release-1.10'
os: 'macOS-latest'
arch: 'x64'
- branch: 'master'
os: 'macOS-latest'
arch: 'x64'
# compilation failure
- branch: 'release-1.8'
os: 'windows-latest'
arch: 'x64'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
Expand All @@ -80,20 +87,21 @@ jobs:
# compile Julia
- name: Compile Julia
run: |
sed -i.bak 's/exit 2/exit 0/g' julia/deps/tools/jlchecksum
make -C julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/julia/usr/bin >> $GITHUB_PATH
mv julia ../ # move julia checkout out of the way, for ReTestItems.jl
sed -i.bak 's/exit 2/exit 0/g' ../julia/deps/tools/jlchecksum
make -C ../julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/../julia/usr/bin >> $GITHUB_PATH
if: runner.os != 'Windows'
- name: Compile Julia (in msys2)
shell: msys2 {0}
run: |
echo $PWD
sed -i.bak 's/exit 2/exit 0/g' julia/deps/tools/jlchecksum
mv julia ../ # move julia checkout out of the way, for ReTestItems.jl
sed -i.bak 's/exit 2/exit 0/g' ../julia/deps/tools/jlchecksum
# XXX: workaround for JuliaLang/julia#48081
make -C julia/deps install-csl && \
cp ${MINGW_PREFIX}/lib/libmsvcrt.a ./julia/usr/lib/libmsvcrt.a && \
make -C julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/julia/usr/bin >> $GITHUB_PATH
make -C ../julia/deps install-csl && \
cp ${MINGW_PREFIX}/lib/libmsvcrt.a ../julia/usr/lib/libmsvcrt.a && \
make -C ../julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/../julia/usr/bin >> $GITHUB_PATH
if: runner.os == 'Windows'

# set-up packages
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
Metal_LLVM_Tools_jll = "0418c028-ff8c-56b8-a53e-0f9676ed36fc"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
SPIRV_LLVM_Translator_unified_jll = "85f0d8ed-5b39-5caa-b1ae-7472de402361"
SPIRV_Tools_jll = "6ac6d60f-d740-5983-97d7-a4482c0689f4"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
16 changes: 7 additions & 9 deletions test/bpf.jl → test/bpf_tests.jl
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
@testset "eBPF" begin

include("definitions/bpf.jl")
@testitem "BPF" setup=[BPF, Helpers] begin

############################################################################################

@testset "No-op" begin
kernel() = 0

output = sprint(io->bpf_code_native(io, kernel, ()))
output = sprint(io->BPF.code_native(io, kernel, ()))
@test occursin("\tr0 = 0\n\texit", output)
end
@testset "Return argument" begin
kernel(x) = x

output = sprint(io->bpf_code_native(io, kernel, (UInt64,)))
output = sprint(io->BPF.code_native(io, kernel, (UInt64,)))
@test occursin("\tr0 = r1\n\texit", output)
end
@testset "Addition" begin
kernel(x) = x+1

output = sprint(io->bpf_code_native(io, kernel, (UInt64,)))
output = sprint(io->BPF.code_native(io, kernel, (UInt64,)))
@test occursin("\tr0 = r1\n\tr0 += 1\n\texit", output)
end
@testset "Errors" begin
kernel(x) = fakefunc(x)

@test_throws GPUCompiler.InvalidIRError bpf_code_execution(kernel, (UInt64,))
@test_throws GPUCompiler.InvalidIRError BPF.code_execution(kernel, (UInt64,))
end
@testset "Function Pointers" begin
@testset "valid" begin
goodcall(x) = Base.llvmcall("%2 = call i64 inttoptr (i64 3 to i64 (i64)*)(i64 %0)\nret i64 %2", Int, Tuple{Int}, x)
kernel(x) = goodcall(x)

output = sprint(io->bpf_code_native(io, kernel, (Int,)))
output = sprint(io->BPF.code_native(io, kernel, (Int,)))
@test occursin("\tcall 3\n\texit", output)
end
@testset "invalid" begin
badcall(x) = Base.llvmcall("%2 = call i64 inttoptr (i64 3000 to i64 (i64)*)(i64 %0)\nret i64 %2", Int, Tuple{Int}, x)
kernel(x) = badcall(x)

@test_throws GPUCompiler.InvalidIRError bpf_code_execution(kernel, (Int,))
@test_throws GPUCompiler.InvalidIRError BPF.code_execution(kernel, (Int,))
end
end

Expand Down
39 changes: 39 additions & 0 deletions test/bpf_testsetup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@testsetup module BPF

using GPUCompiler


# create a native test compiler, and generate reflection methods for it

include("runtime.jl")
struct CompilerParams <: AbstractCompilerParams end
GPUCompiler.runtime_module(::CompilerJob{<:Any,CompilerParams}) = TestRuntime

function create_job(@nospecialize(func), @nospecialize(types);
kernel::Bool=false, always_inline=false, kwargs...)
source = methodinstance(typeof(func), Base.to_tuple_type(types), Base.get_world_counter())
target = BPFCompilerTarget()
params = CompilerParams()
config = CompilerConfig(target, params; kernel, always_inline)
CompilerJob(source, config), kwargs
end

function code_llvm(io::IO, @nospecialize(func), @nospecialize(types); kwargs...)
job, kwargs = create_job(func, types; kwargs...)
GPUCompiler.code_llvm(io, job; kwargs...)
end

function code_native(io::IO, @nospecialize(func), @nospecialize(types); kwargs...)
job, kwargs = create_job(func, types; kwargs...)
GPUCompiler.code_native(io, job; kwargs...)
end

# simulates codegen for a kernel function: validates by default
function code_execution(@nospecialize(func), @nospecialize(types); kwargs...)
job, kwargs = create_job(func, types; kwargs...)
JuliaContext() do ctx
GPUCompiler.compile(:asm, job; kwargs...)
end
end

end
35 changes: 0 additions & 35 deletions test/definitions/bpf.jl

This file was deleted.

45 changes: 0 additions & 45 deletions test/definitions/gcn.jl

This file was deleted.

45 changes: 0 additions & 45 deletions test/definitions/metal.jl

This file was deleted.

46 changes: 0 additions & 46 deletions test/definitions/spirv.jl

This file was deleted.

14 changes: 7 additions & 7 deletions test/examples.jl → test/examples_tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "examples" begin
@testitem "examples" begin

function find_sources(path::String, sources=String[])
if isdir(path)
Expand All @@ -11,13 +11,13 @@ function find_sources(path::String, sources=String[])
sources
end

examples_dir = joinpath(@__DIR__, "..", "examples")
examples = find_sources(examples_dir)
filter!(file -> readline(file) != "# EXCLUDE FROM TESTING", examples)
filter!(file -> !occursin("Kaleidoscope", file), examples)
dir = joinpath(@__DIR__, "..", "examples")
files = find_sources(dir)
filter!(file -> readline(file) != "# EXCLUDE FROM TESTING", files)
filter!(file -> !occursin("Kaleidoscope", file), files)

cd(examples_dir) do
examples = relpath.(examples, Ref(examples_dir))
cd(dir) do
examples = relpath.(files, Ref(dir))
@testset for example in examples
cmd = `$(Base.julia_cmd()) --project=$(Base.active_project())`
@test success(pipeline(`$cmd $example`, stderr=stderr))
Expand Down
Loading

0 comments on commit 06e4288

Please sign in to comment.