Skip to content

Commit

Permalink
Use TestFunctionRunner (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Jan 30, 2022
1 parent 0c6632b commit 83d6fab
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 111 deletions.
1 change: 1 addition & 0 deletions test/FoldsCUDATests/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
112 changes: 19 additions & 93 deletions test/FoldsCUDATests/src/FoldsCUDATests.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 12 additions & 0 deletions test/FoldsCUDATests/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 18 additions & 1 deletion test/environments/jl16/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/environments/jl16/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 18 additions & 1 deletion test/environments/jl17/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/environments/jl17/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 0 additions & 14 deletions test/load.jl

This file was deleted.

5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

0 comments on commit 83d6fab

Please sign in to comment.