Files
TheRock/rocm-systems/projects/rocprofiler-compute/tests/test_native_tool_finder.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

86 lines
3.2 KiB
Python

# Copyright (c) Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
from pathlib import Path
from unittest.mock import patch
import pytest
from utils.native_tool_finder import NativeToolFinder
class TestNativeToolFinder:
def test_when_no_installed_collector_and_no_src_dir__throws(
self,
) -> None:
with pytest.raises(RuntimeError):
NativeToolFinder(Path("incorrect_src")).get_collector_library_path()
def test_when_run_from_install_dir__finds_prebuilt_native_collector(
self, rocm_install_dir: tuple[Path, Path]
) -> None:
root_path, installed_lib_path = rocm_install_dir
lib_path = NativeToolFinder(root_path).get_collector_library_path()
assert lib_path == installed_lib_path
def test_when_run_from_source_dir__builds_and_returns_collector(self, sources_dir):
root_path, built_lib_path = sources_dir
def mock_build_collector(_: Path) -> None:
self.__create_file(built_lib_path)
with patch.object(NativeToolFinder, "_generate_cmake", return_value=None):
with patch.object(
NativeToolFinder,
"_build_cmake",
side_effect=mock_build_collector,
):
lib_path = NativeToolFinder(root_path).get_collector_library_path()
assert lib_path == built_lib_path
def test_when_run_from_source_dir_and_collector_not_found_after_build__throws(
self, sources_dir: tuple[Path, Path]
):
root_path, built_lib_path = sources_dir
built_lib_path.unlink()
with patch.object(NativeToolFinder, "_generate_cmake", return_value=None):
with patch.object(NativeToolFinder, "_build_cmake", return_value=None):
with pytest.raises(RuntimeError):
NativeToolFinder(root_path).get_collector_library_path()
def test_when_run_from_source_dir_and_generation_fails__throws(
self, sources_dir: tuple[Path, Path]
):
root_path, _ = sources_dir
lib_path = None
with pytest.raises(RuntimeError):
lib_path = NativeToolFinder(root_path).get_collector_library_path()
assert lib_path == None
@pytest.fixture(params=["lib", "lib32", "lib64"])
def rocm_install_dir(
self, tmp_path: Path, request: pytest.FixtureRequest
) -> tuple[Path, Path]:
rocm_path = tmp_path / "opt" / "rocm"
compute_root_path = rocm_path / "libexec" / "rocprofiler-compute"
compute_root_path.mkdir(parents=True, exist_ok=True)
lib_path = (
rocm_path
/ f"{request.param}/rocprofiler-compute/{NativeToolFinder.lib_name}"
)
self.__create_file(lib_path)
return compute_root_path, lib_path
@pytest.fixture
def sources_dir(self, tmp_path: Path) -> tuple[Path, Path]:
sources_path = tmp_path / "src"
sources_path.mkdir(parents=True, exist_ok=True)
lib_path = sources_path / Path(NativeToolFinder.lib_relative_path)
self.__create_file(lib_path)
return sources_path, lib_path
def __create_file(self, file_path: Path):
file_path.parent.mkdir(parents=True, exist_ok=True)
file_path.write_text("#!/bin/bash\n")
return file_path