Files
TheRock/build_tools/github_actions/tests/expand_amdgpu_families_test.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

104 lines
3.5 KiB
Python

# Copyright Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
import io
import os
import sys
import unittest
from contextlib import redirect_stdout
from pathlib import Path
sys.path.insert(0, os.fspath(Path(__file__).parent.parent))
sys.path.insert(0, os.fspath(Path(__file__).parent.parent.parent))
import expand_amdgpu_families
from _therock_utils.cmake_amdgpu_targets import expand_families
_SAMPLE_MAP: dict[str, list[str]] = {
"gfx942": ["gfx942"],
"gfx1100": ["gfx1100"],
"gfx1101": ["gfx1101"],
"gfx94X-dcgpu": ["gfx942"],
"gfx110X-all": ["gfx1100", "gfx1101"],
"dcgpu-all": ["gfx942"],
}
class ExpandFamiliesTest(unittest.TestCase):
def test_single_family_expands(self):
self.assertEqual(expand_families(["gfx94X-dcgpu"], _SAMPLE_MAP), ["gfx942"])
def test_multiple_families_preserve_order(self):
self.assertEqual(
expand_families(["gfx110X-all", "gfx94X-dcgpu"], _SAMPLE_MAP),
["gfx1100", "gfx1101", "gfx942"],
)
def test_overlap_deduplicates_keeping_first_occurrence(self):
# Both dcgpu-all and gfx94X-dcgpu expand to gfx942; the second occurrence
# is dropped.
self.assertEqual(
expand_families(["dcgpu-all", "gfx94X-dcgpu"], _SAMPLE_MAP),
["gfx942"],
)
def test_empty_input_returns_empty_list(self):
self.assertEqual(expand_families([], _SAMPLE_MAP), [])
def test_unknown_family_raises_by_default(self):
with self.assertRaisesRegex(ValueError, "Unknown AMD GPU families"):
expand_families(["gfx94X-dcgpu", "gfxNOPE"], _SAMPLE_MAP)
def test_unknown_family_silently_skipped_when_not_strict(self):
self.assertEqual(
expand_families(
["gfx94X-dcgpu", "gfxNOPE", "gfx110X-all"],
_SAMPLE_MAP,
strict=False,
),
["gfx942", "gfx1100", "gfx1101"],
)
class ExpandAmdgpuFamiliesMainTest(unittest.TestCase):
"""End-to-end test of the script's main() against the real CMake file."""
def _run_and_capture(self, *argv: str) -> str:
buf = io.StringIO()
with redirect_stdout(buf):
rc = expand_amdgpu_families.main(list(argv))
self.assertEqual(rc, 0)
return buf.getvalue().strip()
def test_main_expands_single_known_family(self):
# gfx94X-dcgpu should always contain gfx942.
out = self._run_and_capture("--amdgpu-families", "gfx94X-dcgpu")
self.assertIn("gfx942", out.split(","))
def test_main_empty_input_prints_empty(self):
out = self._run_and_capture("--amdgpu-families", "")
self.assertEqual(out, "")
def test_main_unknown_family_raises(self):
with self.assertRaises(ValueError):
expand_amdgpu_families.main(["--amdgpu-families", "gfxNOPE"])
def test_main_device_extras_mode(self):
out = self._run_and_capture(
"--amdgpu-families", "gfx94X-dcgpu", "--output-mode", "device-extras"
)
# gha_set_output logs extra lines to stdout; the result is the first line.
first_line = out.split("\n")[0]
self.assertIn("device-gfx942", first_line.split(","))
for token in first_line.split(","):
self.assertTrue(token.startswith("device-"), token)
def test_main_targets_mode_is_default(self):
out = self._run_and_capture("--amdgpu-families", "gfx94X-dcgpu")
self.assertIn("gfx942", out.split(","))
self.assertNotIn("device-", out)
if __name__ == "__main__":
unittest.main()