diff --git a/test/Kaleidoscope.jl b/test/Kaleidoscope_tests.jl similarity index 97% rename from test/Kaleidoscope.jl rename to test/Kaleidoscope_tests.jl index 9d2170a3..a344117e 100644 --- a/test/Kaleidoscope.jl +++ b/test/Kaleidoscope_tests.jl @@ -1,4 +1,4 @@ -@testset "Kaleidoscope" begin +@testitem "Kaleidoscope" begin include(joinpath(@__DIR__, "..", "examples", "Kaleidoscope", "Kaleidoscope.jl")) diff --git a/test/Project.toml b/test/Project.toml index 6dd5450d..17352403 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,6 @@ [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LLVMExtra_jll = "dad2f222-ce93-54a1-a47d-0025e8a3acab" +ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/test/analysis.jl b/test/analysis_tests.jl similarity index 96% rename from test/analysis.jl rename to test/analysis_tests.jl index 5be9baf7..4fbbca16 100644 --- a/test/analysis.jl +++ b/test/analysis_tests.jl @@ -1,4 +1,4 @@ -@testset "analysis" begin +@testitem "analysis" begin @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("SomeModule") begin ft = LLVM.FunctionType(LLVM.Int32Type()) diff --git a/test/bitcode.jl b/test/bitcode_tests.jl similarity index 97% rename from test/bitcode.jl rename to test/bitcode_tests.jl index 1c4c93c9..dbb52fb2 100644 --- a/test/bitcode.jl +++ b/test/bitcode_tests.jl @@ -1,4 +1,4 @@ -@testset "bitcode" begin +@testitem "bitcode" begin @dispose ctx=Context() begin invalid_bitcode = "invalid" diff --git a/test/buffer.jl b/test/buffer_tests.jl similarity index 96% rename from test/buffer.jl rename to test/buffer_tests.jl index 966eb2ef..c3a353f8 100644 --- a/test/buffer.jl +++ b/test/buffer_tests.jl @@ -1,4 +1,4 @@ -@testset "buffer" begin +@testitem "buffer" begin data = rand(UInt8, 8) diff --git a/test/core.jl b/test/core_tests.jl similarity index 99% rename from test/core.jl rename to test/core_tests.jl index 6f5158c9..46e8c126 100644 --- a/test/core.jl +++ b/test/core_tests.jl @@ -1,3 +1,5 @@ +@testitem "core" setup=[TestHelpers] begin + struct TestStruct x::Bool y::Int64 @@ -11,8 +13,6 @@ end struct TestSingleton end -@testset "core" begin - @testset "context" begin @test context(; throw_error=false) === nothing diff --git a/test/datalayout.jl b/test/datalayout_tests.jl similarity index 97% rename from test/datalayout.jl rename to test/datalayout_tests.jl index 4111406c..112209e0 100644 --- a/test/datalayout.jl +++ b/test/datalayout_tests.jl @@ -1,4 +1,4 @@ -@testset "datalayout" begin +@testitem "datalayout" begin dlstr = "E-p:32:32-f128:128:128" diff --git a/test/debuginfo.jl b/test/debuginfo_tests.jl similarity index 98% rename from test/debuginfo.jl rename to test/debuginfo_tests.jl index 3a381973..b976804c 100644 --- a/test/debuginfo.jl +++ b/test/debuginfo_tests.jl @@ -1,6 +1,4 @@ -using LLVM,Test - -@testset "debuginfo" begin +@testitem "debuginfo" begin DEBUG_METADATA_VERSION() diff --git a/test/essential_tests.jl b/test/essential_tests.jl new file mode 100644 index 00000000..b7ab8702 --- /dev/null +++ b/test/essential_tests.jl @@ -0,0 +1,38 @@ +@testitem "essentials" begin + +@testset "types" begin + @test convert(Bool, LLVM.True) == true + @test convert(Bool, LLVM.False) == false + + @test_throws ArgumentError LLVM.convert(Bool, LLVM.API.LLVMBool(2)) + + @test convert(LLVM.Bool, true) == LLVM.True + @test convert(LLVM.Bool, false) == LLVM.False +end + +@testset "pass registry" begin + passreg = GlobalPassRegistry() + + @test version() isa VersionNumber + @test ismultithreaded() isa Bool + + InitializeCore(passreg) + InitializeTransformUtils(passreg) + InitializeScalarOpts(passreg) + InitializeObjCARCOpts(passreg) + InitializeVectorization(passreg) + InitializeInstCombine(passreg) + InitializeIPO(passreg) + InitializeInstrumentation(passreg) + InitializeAnalysis(passreg) + InitializeIPA(passreg) + InitializeCodeGen(passreg) + InitializeTarget(passreg) + + InitializeNativeTarget() + InitializeAllTargetInfos() + InitializeAllTargetMCs() + InitializeNativeAsmPrinter() +end + +end diff --git a/test/examples.jl b/test/examples_tests.jl similarity index 96% rename from test/examples.jl rename to test/examples_tests.jl index 181a05db..37afd7bd 100644 --- a/test/examples.jl +++ b/test/examples_tests.jl @@ -1,4 +1,4 @@ -@testset "examples" begin +@testitem "examples" begin function find_sources(path::String, sources=String[]) if isdir(path) diff --git a/test/execution.jl b/test/execution_tests.jl similarity index 99% rename from test/execution.jl rename to test/execution_tests.jl index d1372ae5..6d9e3c5a 100644 --- a/test/execution.jl +++ b/test/execution_tests.jl @@ -1,4 +1,4 @@ -@testset "execution" begin +@testitem "execution" begin @testset "generic values" begin diff --git a/test/helpers.jl b/test/helpers_testsetup.jl similarity index 64% rename from test/helpers.jl rename to test/helpers_testsetup.jl index bf5b1ef6..1ee4da1d 100644 --- a/test/helpers.jl +++ b/test/helpers_testsetup.jl @@ -1,6 +1,14 @@ +@testsetup module TestHelpers + +using Test + +export @check_ir + macro check_ir(inst, str) quote inst = string($(esc(inst))) @test occursin($(str), inst) end end + +end diff --git a/test/instructions.jl b/test/instructions_tests.jl similarity index 99% rename from test/instructions.jl rename to test/instructions_tests.jl index f0e4aae4..74366403 100644 --- a/test/instructions.jl +++ b/test/instructions_tests.jl @@ -1,3 +1,5 @@ +@testitem "instructions" setup=[TestHelpers] begin + @testset "irbuilder" begin @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("SomeModule") begin @@ -501,3 +503,5 @@ end end end end + +end diff --git a/test/interop.jl b/test/interop_tests.jl similarity index 99% rename from test/interop.jl rename to test/interop_tests.jl index 6765803c..9e7e7b22 100644 --- a/test/interop.jl +++ b/test/interop_tests.jl @@ -1,8 +1,8 @@ +@testitem "interop" begin + using LLVM.Interop using InteractiveUtils -@testset "interop" begin - # many of these tests don't use explicit contexts, as they rely on high-level functionality. # that functionality should be using default context options, so query those here. supports_typed_ptrs = @dispose ctx=Context() begin @@ -120,7 +120,6 @@ end @testset "passes" begin - @dispose ctx=Context() mod=LLVM.Module("SomeModule") pm=ModulePassManager() begin demote_float16!(pm) @@ -143,6 +142,8 @@ cpu_features!(pm) end +@test "we didn't crash!" != "" + end diff --git a/test/ir.jl b/test/ir_tests.jl similarity index 97% rename from test/ir.jl rename to test/ir_tests.jl index 2a988e48..ac207e46 100644 --- a/test/ir.jl +++ b/test/ir_tests.jl @@ -1,4 +1,4 @@ -@testset "ir" begin +@testitem "ir" begin @dispose ctx=Context() begin invalid_ir = "invalid" diff --git a/test/jljit.jl b/test/jljit_tests.jl similarity index 99% rename from test/jljit.jl rename to test/jljit_tests.jl index 4059d0d7..f2d5c993 100644 --- a/test/jljit.jl +++ b/test/jljit_tests.jl @@ -1,4 +1,5 @@ -@testset "jljit" begin +@static if LLVM.has_julia_ojit() +@testitem "jljit" begin let jljit=JuliaOJIT() dispose(jljit) @@ -265,3 +266,4 @@ end end end +end diff --git a/test/linker.jl b/test/linker_tests.jl similarity index 96% rename from test/linker.jl rename to test/linker_tests.jl index 12056b26..a4cd4066 100644 --- a/test/linker.jl +++ b/test/linker_tests.jl @@ -1,4 +1,4 @@ -@testset "linker" begin +@testitem "linker" begin @dispose ctx=Context() builder=IRBuilder() begin mod1 = let diff --git a/test/moduleprovider.jl b/test/moduleprovider_tests.jl similarity index 71% rename from test/moduleprovider.jl rename to test/moduleprovider_tests.jl index 23ad5187..37684a1b 100644 --- a/test/moduleprovider.jl +++ b/test/moduleprovider_tests.jl @@ -1,22 +1,27 @@ -@testset "moduleprovider" begin +@testitem "moduleprovider" begin @dispose ctx=Context() begin mod = LLVM.Module("SomeModule") mp = ModuleProvider(mod) dispose(mp) + + @test "we didn't crash!" != "" end @dispose ctx=Context() begin mod = LLVM.Module("SomeModule") ModuleProvider(mod) do md end + + @test "we didn't crash!" != "" end @dispose ctx=Context() begin mod = LLVM.Module("SomeModule") @dispose mp=ModuleProvider(mod) begin - end + + @test "we didn't crash!" != "" end end diff --git a/test/newpm.jl b/test/newpm_tests.jl similarity index 97% rename from test/newpm.jl rename to test/newpm_tests.jl index 7d86d2c2..9dc35213 100644 --- a/test/newpm.jl +++ b/test/newpm_tests.jl @@ -1,3 +1,8 @@ +@static if LLVM.has_newpm() +@testitem "newpm" begin + +using InteractiveUtils # for subtypes + @testset "newpm pass managers" begin let mpm = NewPMModulePassManager() @@ -197,22 +202,22 @@ host_t = Target(triple=host_triple) end @test "Successfully added custom module and function passes!" != "" - + @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("test") begin pa = run!(mpm, mod, mam) @test observed_modules == 1 @test observed_functions == 0 @test are_all_preserved(pa) - - + + ft = LLVM.FunctionType(LLVM.VoidType()) fn = LLVM.Function(mod, "SomeFunction", ft) - + entry = BasicBlock(fn, "entry") position!(builder, entry) - + ret!(builder) - + pa = run!(mpm, mod, mam) @test observed_modules == 2 @test observed_functions == 1 @@ -222,4 +227,7 @@ host_t = Target(triple=host_triple) end end -end # testset "newpm custom passes" +end # testset "newpm passes" + +end +end diff --git a/test/orc.jl b/test/orc_tests.jl similarity index 98% rename from test/orc.jl rename to test/orc_tests.jl index c83d9799..a277251d 100644 --- a/test/orc.jl +++ b/test/orc_tests.jl @@ -1,4 +1,5 @@ -@testset "orc" begin +@static if LLVM.has_orc_v1() && !LLVM.is_asserts() # XXX: dangling references abort +@testitem "orc" begin let tm = JITTargetMachine() let orc = OrcJIT(tm) @@ -328,3 +329,4 @@ end end end +end diff --git a/test/orcv2.jl b/test/orcv2_tests.jl similarity index 99% rename from test/orcv2.jl rename to test/orcv2_tests.jl index cde8661b..4c47c884 100644 --- a/test/orcv2.jl +++ b/test/orcv2_tests.jl @@ -1,4 +1,5 @@ -@testset "orcv2" begin +@static if LLVM.has_orc_v2() +@testitem "orcv2" begin let lljit=LLJIT() dispose(lljit) @@ -302,3 +303,4 @@ end end end +end diff --git a/test/pass.jl b/test/pass_tests.jl similarity index 98% rename from test/pass.jl rename to test/pass_tests.jl index 9d0f1645..ca313a76 100644 --- a/test/pass.jl +++ b/test/pass_tests.jl @@ -1,4 +1,4 @@ -@testset "pass" begin +@testitem "pass" begin @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("SomeModule") begin ft = LLVM.FunctionType(LLVM.VoidType()) diff --git a/test/passmanager.jl b/test/passmanager_tests.jl similarity index 93% rename from test/passmanager.jl rename to test/passmanager_tests.jl index 47ef2b5f..334933e6 100644 --- a/test/passmanager.jl +++ b/test/passmanager_tests.jl @@ -1,4 +1,4 @@ -@testset "passmanager" begin +@testitem "passmanager" begin let mpm = ModulePassManager() diff --git a/test/runtests.jl b/test/runtests.jl index 135788fa..1d635fef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,7 +9,6 @@ if VERSION < v"1.8-" end using LLVM -using Test if Base.JLOptions().debug_level < 2 @warn "It is recommended to run the LLVM.jl test suite with -g2" @@ -18,86 +17,14 @@ end using InteractiveUtils @info "System information:\n" * sprint(io->versioninfo(io)) -@testset "LLVM" begin +worker_init_expr = quote + using LLVM -# HACK: if a test throws within a Context() do block, displaying the LLVM value may crash -# because the context has been disposed already. avoid that by disabling `dispose`, -# and only have it pop the context off the stack (but not destroy it). -LLVM.dispose(ctx::Context) = LLVM.deactivate(ctx) - -include("helpers.jl") - -@testset "types" begin - @test convert(Bool, LLVM.True) == true - @test convert(Bool, LLVM.False) == false - - @test_throws ArgumentError LLVM.convert(Bool, LLVM.API.LLVMBool(2)) - - @test convert(LLVM.Bool, true) == LLVM.True - @test convert(LLVM.Bool, false) == LLVM.False -end - -@testset "pass registry" begin - passreg = GlobalPassRegistry() - - version() - ismultithreaded() - InitializeCore(passreg) - InitializeTransformUtils(passreg) - InitializeScalarOpts(passreg) - InitializeObjCARCOpts(passreg) - InitializeVectorization(passreg) - InitializeInstCombine(passreg) - InitializeIPO(passreg) - InitializeInstrumentation(passreg) - InitializeAnalysis(passreg) - InitializeIPA(passreg) - InitializeCodeGen(passreg) - InitializeTarget(passreg) - - InitializeNativeTarget() - InitializeAllTargetInfos() - InitializeAllTargetMCs() - InitializeNativeAsmPrinter() -end - -include("support.jl") -include("core.jl") -include("linker.jl") -include("instructions.jl") -include("buffer.jl") -include("bitcode.jl") -include("ir.jl") -include("analysis.jl") -include("moduleprovider.jl") -include("passmanager.jl") -include("pass.jl") -include("execution.jl") -include("transform.jl") -include("target.jl") -include("targetmachine.jl") -include("datalayout.jl") -include("debuginfo.jl") -include("utils.jl") - -if LLVM.has_orc_v1() && !LLVM.is_asserts() - # XXX: dangling references abort - include("orc.jl") -end -if LLVM.has_orc_v2() - include("orcv2.jl") -end -if LLVM.has_newpm() - include("newpm.jl") + # HACK: if a test throws within a Context() do block, displaying the LLVM value may + # crash because the context has been disposed already. avoid that by disabling + # `dispose`, and only have it pop the context off the stack (but not destroy it). + LLVM.dispose(ctx::Context) = LLVM.deactivate(ctx) end -if LLVM.has_julia_ojit() - include("jljit.jl") -end -include("Kaleidoscope.jl") - -include("examples.jl") - -include("interop.jl") - -end +using ReTestItems +runtests(LLVM; worker_init_expr, nworkers=min(Sys.CPU_THREADS,4), nworker_threads=1) diff --git a/test/support.jl b/test/support_tests.jl similarity index 92% rename from test/support.jl rename to test/support_tests.jl index 81aedf24..be7a6305 100644 --- a/test/support.jl +++ b/test/support_tests.jl @@ -1,4 +1,4 @@ -@testset "support" begin +@testitem "support" begin @testset "command-line options" begin diff --git a/test/target.jl b/test/target_tests.jl similarity index 95% rename from test/target.jl rename to test/target_tests.jl index f755d790..1f477a94 100644 --- a/test/target.jl +++ b/test/target_tests.jl @@ -1,4 +1,4 @@ -@testset "target" begin +@testitem "target" begin @test_throws ArgumentError Target(triple="invalid") @test_throws ArgumentError Target(name="invalid") diff --git a/test/targetmachine.jl b/test/targetmachine_tests.jl similarity index 97% rename from test/targetmachine.jl rename to test/targetmachine_tests.jl index aa8b707e..7ea0b924 100644 --- a/test/targetmachine.jl +++ b/test/targetmachine_tests.jl @@ -1,4 +1,4 @@ -@testset "targetmachine" begin +@testitem "targetmachine" begin host_triple = triple() host_t = Target(triple=host_triple) diff --git a/test/transform.jl b/test/transform_tests.jl similarity index 97% rename from test/transform.jl rename to test/transform_tests.jl index 07719a4d..36da139f 100644 --- a/test/transform.jl +++ b/test/transform_tests.jl @@ -1,4 +1,4 @@ -@testset "transform" begin +@testitem "transform" begin let pmb = PassManagerBuilder() @@ -109,4 +109,6 @@ end internalize!(pm, ["SomeFunction", "SomeOtherFunction"]) end +@test "we didn't crash!" != "" + end diff --git a/test/utils.jl b/test/util_tests.jl similarity index 99% rename from test/utils.jl rename to test/util_tests.jl index d19aebcf..089f29ae 100644 --- a/test/utils.jl +++ b/test/util_tests.jl @@ -1,4 +1,4 @@ -@testset "utils" begin +@testitem "utils" begin @testset "function cloning" begin @dispose ctx=Context() begin