Skip to content

Commit

Permalink
add unit tests for unit tests generator functions
Browse files Browse the repository at this point in the history
- fix small bug in add_unit_test_verify_job_yaml!() if stage entry did not already exist
- fix small bug in _get_nightly_unit_test(), which avoids setting custom base image
  • Loading branch information
SimeonEhrig committed Nov 25, 2024
1 parent 647eca1 commit 3c5b15d
Show file tree
Hide file tree
Showing 12 changed files with 555 additions and 21 deletions.
1 change: 1 addition & 0 deletions .ci/CI/src/CI.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

module CI
include("./modules/Utils.jl")
include("./modules/UnitTest.jl")
include("./modules/IntegTest.jl")
include("./modules/GitLabTargetBranch.jl")
include("./SetupDevEnv.jl")
Expand Down
5 changes: 3 additions & 2 deletions .ci/CI/src/modules/UnitTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ function add_unit_test_verify_job_yaml!(
)
# verification script that no custom URLs are used in unit tests
if target_branch != "main"
if !haskey(job_dict, "stages")
job_dict["stages"] = []
end
push!(job_dict["stages"], "verify-unit-test-deps")
job_dict["verify-unit-test-deps"] = Dict(
"image" => "julia:1.10",
Expand Down Expand Up @@ -270,8 +273,6 @@ fi",
"cp -r \$JULIA_EXTRACT_FOLDER/* /usr",
]

job_yaml["image"] = "debian:bookworm-slim"

job_yaml["allow_failure"] = true
return job_yaml
end
Expand Down
74 changes: 74 additions & 0 deletions .ci/CI/test/UnitTest/amdgpu_unit_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@testset "test _get_amdgpu_unit_test" begin
test_package = CI.TestPackage("QEDfoo", "/path/to/project", "42.0")
git_url = "http://github.com/name/repo"
git_branch = "branch"

expected_job = get_generic_unit_job("1.11", test_package)

expected_job["script"] = get_main_unit_job_script_section(git_url, git_branch)

expected_job["image"] = "rocm/dev-ubuntu-24.04:6.2.4-complete"
expected_job["before_script"] = get_amdgpu_before_script("1.11")
expected_job["variables"]["TEST_AMDGPU"] = "1"
expected_job["tags"] = ["rocm", "x86_64"]

job_yaml = CI._get_amdgpu_unit_test(
"1.11", test_package, "main", CI.ToolsGitRepo(git_url, git_branch)
)

@test keys(expected_job) == keys(job_yaml)

for k in keys(expected_job)
@test (
@assert job_yaml[k] == expected_job[k] (
"\nkey: \"$(k)\"\n:" * yaml_diff(job_yaml[k], expected_job[k])
);
true
)
end

@test (@assert job_yaml == expected_job yaml_diff(job_yaml, expected_job);
true)

@testset "test public interface" begin
julia_versions = Vector{String}(["1.9", "1.10", "1.11"])

job_dict = Dict()
CI.add_unit_test_job_yaml!(
job_dict,
test_package,
julia_versions,
"main",
CI.AMDGPU,
CI.ToolsGitRepo(git_url, git_branch),
)

for julia_version in julia_versions
job_name = "unit_test_julia_amdgpu_$(replace(julia_version, "." => "_"))"
expected_job["before_script"] = get_amdgpu_before_script(julia_version)

@test haskey(job_dict, job_name)
@test job_dict["stages"] == ["unit-test"]

unit_test_job = job_dict[job_name]

@test keys(expected_job) == keys(unit_test_job)

for k in keys(expected_job)
@test (
@assert unit_test_job[k] == expected_job[k] (
"\nkey: \"$(k)\"\n:" * yaml_diff(unit_test_job[k], expected_job[k])
);
true
)
end

@test (
@assert unit_test_job == expected_job yaml_diff(
unit_test_job, expected_job
);
true
)
end
end
end
72 changes: 72 additions & 0 deletions .ci/CI/test/UnitTest/cuda_unit_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@testset "test _get_normal_unit_test CUDA platform" begin
julia_version = "1.10"
test_package = CI.TestPackage("QEDfoo", "/path/to/project", "42.0")
git_url = "http://github.com/name/repo"
git_branch = "branch"

expected_job = get_generic_unit_job(julia_version, test_package)

expected_job["script"] = get_main_unit_job_script_section(git_url, git_branch)

expected_job["variables"]["TEST_CUDA"] = "1"
expected_job["tags"] = ["cuda", "x86_64"]

job_yaml = CI._get_normal_unit_test(
julia_version, test_package, "main", CI.CUDA, CI.ToolsGitRepo(git_url, git_branch)
)

@test keys(expected_job) == keys(job_yaml)

for k in keys(expected_job)
@test (
@assert job_yaml[k] == expected_job[k] (
"\nkey: \"$(k)\"\n:" * yaml_diff(job_yaml[k], expected_job[k])
);
true
)
end

@test (@assert job_yaml == expected_job yaml_diff(job_yaml, expected_job);
true)

@testset "test public interface" begin
julia_versions = Vector{String}(["1.9", "1.10", "1.11"])

job_dict = Dict()
CI.add_unit_test_job_yaml!(
job_dict,
test_package,
julia_versions,
"main",
CI.CUDA,
CI.ToolsGitRepo(git_url, git_branch),
)

for julia_version in julia_versions
job_name = "unit_test_julia_cuda_$(replace(julia_version, "." => "_"))"
expected_job["image"] = "julia:$(julia_version)"
@test haskey(job_dict, job_name)
@test job_dict["stages"] == ["unit-test"]

unit_test_job = job_dict[job_name]

@test keys(expected_job) == keys(unit_test_job)

for k in keys(expected_job)
@test (
@assert unit_test_job[k] == expected_job[k] (
"\nkey: \"$(k)\"\n:" * yaml_diff(unit_test_job[k], expected_job[k])
);
true
)
end

@test (
@assert unit_test_job == expected_job yaml_diff(
unit_test_job, expected_job
);
true
)
end
end
end
94 changes: 94 additions & 0 deletions .ci/CI/test/UnitTest/nightly_unit_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@testset "test _get_nightly_unit_test" begin
for nightly_image in ["debian:bookworm-slim", "custom_image:latest"]
julia_version = "a"
test_package = CI.TestPackage("QEDfoo", "/path/to/project", "42.0")
git_url = "http://github.com/name/repo"
git_branch = "branch"

expected_job = get_generic_unit_job(julia_version, test_package)

expected_job["script"] = get_dev_unit_job_script_section(git_url, git_branch)

expected_job["variables"]["TEST_CPU"] = "1"
expected_job["variables"]["JULIA_DOWNLOAD"] = "/julia/download"
expected_job["variables"]["JULIA_EXTRACT"] = "/julia/extract"
expected_job["tags"] = ["cpuonly"]
expected_job["image"] = nightly_image

expected_job["before_script"] = [
"apt update && apt install -y wget",
"mkdir -p \$JULIA_DOWNLOAD",
"mkdir -p \$JULIA_EXTRACT",
"if [[ \$CI_RUNNER_EXECUTABLE_ARCH == \"linux/arm64\" ]]; then
wget https://julialangnightlies-s3.julialang.org/bin/linux/aarch64/julia-latest-linux-aarch64.tar.gz -O \$JULIA_DOWNLOAD/julia-nightly.tar.gz
elif [[ \$CI_RUNNER_EXECUTABLE_ARCH == \"linux/amd64\" ]]; then
wget https://julialangnightlies-s3.julialang.org/bin/linux/x86_64/julia-latest-linux-x86_64.tar.gz -O \$JULIA_DOWNLOAD/julia-nightly.tar.gz
else
echo \"unknown runner architecture -> \$CI_RUNNER_EXECUTABLE_ARCH\"
exit 1
fi",
"tar -xf \$JULIA_DOWNLOAD/julia-nightly.tar.gz -C \$JULIA_EXTRACT",
"JULIA_EXTRACT_FOLDER=\${JULIA_EXTRACT}/\$(ls \$JULIA_EXTRACT | grep -m1 julia)",
"cp -r \$JULIA_EXTRACT_FOLDER/* /usr",
]
expected_job["allow_failure"] = true

job_yaml = CI._get_nightly_unit_test(
test_package, "dev", CI.CPU, CI.ToolsGitRepo(git_url, git_branch), nightly_image
)

@test keys(expected_job) == keys(job_yaml)

for k in keys(expected_job)
@test (
@assert job_yaml[k] == expected_job[k] (
"\nkey: \"$(k)\"\n:" * yaml_diff(job_yaml[k], expected_job[k])
);
true
)
end

@test (@assert job_yaml == expected_job yaml_diff(job_yaml, expected_job);
true)

@testset "test public interface" begin
julia_versions = Vector{String}(["nightly"])

job_dict = Dict()
CI.add_unit_test_job_yaml!(
job_dict,
test_package,
julia_versions,
"dev",
CI.CPU,
CI.ToolsGitRepo(git_url, git_branch),
)

job_name = "unit_test_julia_cpu_nightly"
# default image
expected_job["image"] = "debian:bookworm-slim"
@test haskey(job_dict, job_name)
@test job_dict["stages"] == ["unit-test"]

unit_test_job = job_dict[job_name]

@test keys(expected_job) == keys(unit_test_job)

for k in keys(expected_job)
@test (
@assert unit_test_job[k] == expected_job[k] (
"\nkey: \"$(k)\"\n:" * yaml_diff(unit_test_job[k], expected_job[k])
);
true
)
end

@test (
@assert unit_test_job == expected_job yaml_diff(
unit_test_job, expected_job
);
true
)
end
end
end
Loading

0 comments on commit 3c5b15d

Please sign in to comment.