diff --git a/test/FoldsCUDATests/Project.toml b/test/FoldsCUDATests/Project.toml index 5b3c6c0..e78ac7a 100644 --- a/test/FoldsCUDATests/Project.toml +++ b/test/FoldsCUDATests/Project.toml @@ -21,6 +21,7 @@ Referenceables = "42d2dcc6-99eb-4e98-b66c-637b7d73030e" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SplittablesBase = "171d559e-b47b-412a-8079-5efa626c420e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999" [compat] diff --git a/test/FoldsCUDATests/src/FoldsCUDATests.jl b/test/FoldsCUDATests/src/FoldsCUDATests.jl index 9b16ad7..a934a95 100644 --- a/test/FoldsCUDATests/src/FoldsCUDATests.jl +++ b/test/FoldsCUDATests/src/FoldsCUDATests.jl @@ -1,115 +1,41 @@ module FoldsCUDATests +import CUDA using GPUArrays using Test +using TestFunctionRunner include("utils.jl") -function include_tests(m = @__MODULE__, dir = @__DIR__) - for file in readdir(dir) - if match(r"^test_.*\.jl$", file) !== nothing - Base.include(m, joinpath(dir, file)) - end - end -end - -include_tests() - -module Generic -using ..FoldsCUDATests: include_tests +module TestGeneric +using ..Utils: include_tests include_tests(@__MODULE__, joinpath(@__DIR__, "generic")) end -should_test_gpu() = - lowercase(get(ENV, "JULIA_PKGEVAL", "false")) != "true" && - lowercase(get(ENV, "CUDAFOLDS_JL_TEST_GPU", "true")) == "true" - -requires_gpu(m::Module) = parentmodule(m) === @__MODULE__ - -function collect_modules(root::Module) - modules = Module[] - for n in names(root, all = true) - m = getproperty(root, n) - m isa Module || continue - m === root && continue - startswith(string(nameof(m)), "Test") || continue - push!(modules, m) - end - return modules -end - -function collect_modules() - modules = collect_modules(@__MODULE__) - append!(modules, collect_modules(Generic)) - return modules +module TestGPU +using ..Utils: include_tests, should_test_gpu +include_tests(@__MODULE__) +should_test_module() = should_test_gpu() end -this_project() = joinpath(dirname(@__DIR__), "Project.toml") - -function is_in_path() - project = this_project() - paths = Base.load_path() - project in paths && return true - realproject = realpath(project) - realproject in paths && return true - matches(path) = path == project || path == realproject - return any(paths) do path - matches(path) || matches(realpath(path)) - end -end +""" A list of tests to be run from UnionArrays.jl """ +const UNIONARRAYS_TESTS = [TestGPU.TestTypeChangingAccumulators] -function with_project(f) - is_in_path() && return f() - load_path = copy(LOAD_PATH) - push!(LOAD_PATH, this_project()) - try - f() - finally - append!(empty!(LOAD_PATH), load_path) - end +function runtests_unionarrays(; kwargs...) + TestFunctionRunner.run(UNIONARRAYS_TESTS; kwargs...) end -function runtests(modules = collect_modules()) - with_project() do - runtests_impl(modules) +function before_test_module() + if !CUDA.functional() + @info "CUDA.jl not functional" + return end -end -function runtests_impl(modules) GPUArrays.allowscalar(false) - test_gpu = should_test_gpu() - @testset "$(nameof(m))" for m in modules - if !test_gpu && requires_gpu(m) - continue # branch inside `for` loop for printing skipped tests - end - if m in ( - Generic.TestReducePartitionBy, - TestCoalescedCUDAEx, - TestTypeChangingAccumulators, - ) - VERSION < v"1.6-" && continue - end - tests = map(names(m, all = true)) do n - n == :test || startswith(string(n), "test_") || return nothing - f = getproperty(m, n) - f !== m || return nothing - parentmodule(f) === m || return nothing - applicable(f) || return nothing # removed by Revise? - return f - end - filter!(!isnothing, tests) - @testset "$f" for f in tests - f() - end - end -end - -""" A list of tests to be run from UnionArrays.jl """ -const UNIONARRAYS_TESTS = [TestTypeChangingAccumulators] -function runtests_unionarrays() - with_project() do - runtests_impl(UNIONARRAYS_TESTS) + if lowercase(get(ENV, "CI", "false")) == "true" + CUDA.versioninfo() + println() end end diff --git a/test/FoldsCUDATests/src/utils.jl b/test/FoldsCUDATests/src/utils.jl index a9dfdc1..c1280e8 100644 --- a/test/FoldsCUDATests/src/utils.jl +++ b/test/FoldsCUDATests/src/utils.jl @@ -2,6 +2,18 @@ module Utils using CUDA +function include_tests(m, dir = @__DIR__) + for file in readdir(dir) + if match(r"^test_.*\.jl$", file) !== nothing + Base.include(m, joinpath(dir, file)) + end + end +end + +should_test_gpu() = + lowercase(get(ENV, "JULIA_PKGEVAL", "false")) != "true" && + lowercase(get(ENV, "CUDAFOLDS_JL_TEST_GPU", "true")) == "true" + """ unsafe_free_all!(namespace::Module) diff --git a/test/Project.toml b/test/Project.toml index 6e2a597..173997f 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -16,8 +16,10 @@ Referenceables = "42d2dcc6-99eb-4e98-b66c-637b7d73030e" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SplittablesBase = "171d559e-b47b-412a-8079-5efa626c420e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999" [compat] Aqua = "0.5" Random123 = "~1.3" +TestFunctionRunner = "0.1.3" diff --git a/test/environments/jl16/Manifest.toml b/test/environments/jl16/Manifest.toml index 8d31fd9..e7a5dc0 100644 --- a/test/environments/jl16/Manifest.toml +++ b/test/environments/jl16/Manifest.toml @@ -195,7 +195,7 @@ uuid = "1457febb-a09b-4652-98c9-46b8ccd8ff53" version = "0.1.0" [[FoldsCUDATests]] -deps = ["Adapt", "Aqua", "CUDA", "Documenter", "FLoops", "Folds", "FoldsCUDA", "FoldsCUDABenchmarks", "GPUArrays", "InitialValues", "LiterateTest", "Random", "Random123", "Referenceables", "Setfield", "SplittablesBase", "Test", "Transducers"] +deps = ["Adapt", "Aqua", "CUDA", "Documenter", "FLoops", "Folds", "FoldsCUDA", "FoldsCUDABenchmarks", "GPUArrays", "InitialValues", "LiterateTest", "Random", "Random123", "Referenceables", "Setfield", "SplittablesBase", "Test", "TestFunctionRunner", "Transducers"] path = "../../FoldsCUDATests" uuid = "d11caea5-3c98-4cd5-8a56-9589fe6662ee" version = "0.1.0" @@ -310,6 +310,12 @@ git-tree-sha1 = "f10e6f4d46da26a33e9cea7a5aed3476b592bbfb" uuid = "d77d25b0-90d3-4a16-b10a-412a9d48f625" version = "0.1.4" +[[LoadAllPackages]] +deps = ["Pkg"] +git-tree-sha1 = "de9eababca8fdc9b6b207ed05f99693faa608230" +uuid = "b37bcd2d-1570-475d-a8c6-9b4fae6d0ba9" +version = "0.1.0" + [[LogExpFunctions]] deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] git-tree-sha1 = "e5718a00af0ab9756305a0392832c8952c7426c1" @@ -494,10 +500,21 @@ version = "1.6.1" deps = ["ArgTools", "SHA"] uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +[[Terminators]] +git-tree-sha1 = "e72e157c08773595052733e8b39944a49b0109d9" +uuid = "b0858c3f-a9bf-4cba-a0e3-6aaeea5477ac" +version = "0.1.1" + [[Test]] deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[[TestFunctionRunner]] +deps = ["Distributed", "LoadAllPackages", "Pkg", "Terminators", "Test"] +git-tree-sha1 = "5e58b00d31869b4972aad04e6b34558653b2831f" +uuid = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" +version = "0.1.3" + [[TimerOutputs]] deps = ["ExprTools", "Printf"] git-tree-sha1 = "97e999be94a7147d0609d0b9fc9feca4bf24d76b" diff --git a/test/environments/jl16/Project.toml b/test/environments/jl16/Project.toml index 34e50bf..8cca63a 100644 --- a/test/environments/jl16/Project.toml +++ b/test/environments/jl16/Project.toml @@ -2,3 +2,4 @@ FoldsCUDA = "6cd66ae4-5932-4b96-926d-e73e578e42cc" FoldsCUDABenchmarks = "1457febb-a09b-4652-98c9-46b8ccd8ff53" FoldsCUDATests = "d11caea5-3c98-4cd5-8a56-9589fe6662ee" +TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" diff --git a/test/environments/jl17/Manifest.toml b/test/environments/jl17/Manifest.toml index d250a28..a9b86de 100644 --- a/test/environments/jl17/Manifest.toml +++ b/test/environments/jl17/Manifest.toml @@ -198,7 +198,7 @@ uuid = "1457febb-a09b-4652-98c9-46b8ccd8ff53" version = "0.1.0" [[deps.FoldsCUDATests]] -deps = ["Adapt", "Aqua", "CUDA", "Documenter", "FLoops", "Folds", "FoldsCUDA", "FoldsCUDABenchmarks", "GPUArrays", "InitialValues", "LiterateTest", "Random", "Random123", "Referenceables", "Setfield", "SplittablesBase", "Test", "Transducers"] +deps = ["Adapt", "Aqua", "CUDA", "Documenter", "FLoops", "Folds", "FoldsCUDA", "FoldsCUDABenchmarks", "GPUArrays", "InitialValues", "LiterateTest", "Random", "Random123", "Referenceables", "Setfield", "SplittablesBase", "Test", "TestFunctionRunner", "Transducers"] path = "../../FoldsCUDATests" uuid = "d11caea5-3c98-4cd5-8a56-9589fe6662ee" version = "0.1.0" @@ -313,6 +313,12 @@ git-tree-sha1 = "f10e6f4d46da26a33e9cea7a5aed3476b592bbfb" uuid = "d77d25b0-90d3-4a16-b10a-412a9d48f625" version = "0.1.4" +[[deps.LoadAllPackages]] +deps = ["Pkg"] +git-tree-sha1 = "de9eababca8fdc9b6b207ed05f99693faa608230" +uuid = "b37bcd2d-1570-475d-a8c6-9b4fae6d0ba9" +version = "0.1.0" + [[deps.LogExpFunctions]] deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] git-tree-sha1 = "e5718a00af0ab9756305a0392832c8952c7426c1" @@ -501,10 +507,21 @@ version = "1.6.1" deps = ["ArgTools", "SHA"] uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +[[deps.Terminators]] +git-tree-sha1 = "e72e157c08773595052733e8b39944a49b0109d9" +uuid = "b0858c3f-a9bf-4cba-a0e3-6aaeea5477ac" +version = "0.1.1" + [[deps.Test]] deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[[deps.TestFunctionRunner]] +deps = ["Distributed", "LoadAllPackages", "Pkg", "Terminators", "Test"] +git-tree-sha1 = "9b4dc94c31f85a386e7e7793d78dd4c237f8cfdc" +uuid = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" +version = "0.1.4" + [[deps.TimerOutputs]] deps = ["ExprTools", "Printf"] git-tree-sha1 = "97e999be94a7147d0609d0b9fc9feca4bf24d76b" diff --git a/test/environments/jl17/Project.toml b/test/environments/jl17/Project.toml index 34e50bf..8cca63a 100644 --- a/test/environments/jl17/Project.toml +++ b/test/environments/jl17/Project.toml @@ -2,3 +2,4 @@ FoldsCUDA = "6cd66ae4-5932-4b96-926d-e73e578e42cc" FoldsCUDABenchmarks = "1457febb-a09b-4652-98c9-46b8ccd8ff53" FoldsCUDATests = "d11caea5-3c98-4cd5-8a56-9589fe6662ee" +TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" diff --git a/test/load.jl b/test/load.jl deleted file mode 100644 index 409a626..0000000 --- a/test/load.jl +++ /dev/null @@ -1,14 +0,0 @@ -try - using FoldsCUDATests - true -catch - false -end || begin - let path = joinpath(@__DIR__, "FoldsCUDATests") - path in LOAD_PATH || push!(LOAD_PATH, path) - end - let path = joinpath(@__DIR__, "../benchmark/FoldsCUDABenchmarks") - path in LOAD_PATH || push!(LOAD_PATH, path) - end - using FoldsCUDATests -end diff --git a/test/runtests.jl b/test/runtests.jl index 00b6ffd..1f4ebec 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,5 +7,6 @@ if VERSION ≥ v"1.6-" push!(LOAD_PATH, "@stdlib") end end -include("load.jl") -FoldsCUDATests.runtests() + +using TestFunctionRunner +TestFunctionRunner.@run(paths = ["../benchmark/FoldsCUDABenchmarks"])