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

150 lines
5.5 KiB
Python

# Copyright (c) Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
"""
Regression tests for the shared tool_runner used by rocprof-sys-run and
rocprof-sys-sample. Each test pins behavior that previously broke or that the
unification refactor consolidated; failures here indicate a regression in
tool_runner, argparse env-update semantics, or the conflict-detection path.
"""
from __future__ import annotations
import pytest
from conftest import RocprofsysTest
pytestmark = [pytest.mark.presets]
TARGETS = [
pytest.param("rocprof-sys-run", marks=pytest.mark.sys_run, id="run"),
pytest.param("rocprof-sys-sample", marks=pytest.mark.sampling, id="sample"),
]
# ============================================================================
# update_env(REPLACE) must not leave duplicate KEY= entries
# ----------------------------------------------------------------------------
# Regression for the bug fixed in this refactor: a shell-exported value plus a
# preset that REPLACEs the same key used to produce "KEY=preset_value:shell_value"
# after consolidate_env_entries joined the two surviving entries. The original
# reproducer was ROCPROFSYS_TRACE=true + --preset=profile-only, which silently
# turned tracing back on under "profile only".
# ============================================================================
@pytest.mark.timeout(30)
@pytest.mark.class_name("tool-runner-replace-env")
class TestReplaceEnvNoDuplicates(RocprofsysTest):
@pytest.mark.parametrize("target", TARGETS)
def test_preset_replaces_shell_env(self, target):
result = self.run_test(
"baseline",
target=target,
env={"ROCPROFSYS_TRACE": "true"},
run_args=["--preset=profile-only", "-v", "2", "--", "ls"],
fail_on_not_found=True,
)
self.assert_regex(
result,
pass_regex=[r"ROCPROFSYS_TRACE=false(?![^\n]*:)"],
fail_regex=[r"ROCPROFSYS_TRACE=\S*:\S*"],
)
# ============================================================================
# --profile and --flat-profile must not be accepted together
# ----------------------------------------------------------------------------
# argparse declares the conflict via .conflicts({"flat-profile"}); tool_runner's
# apply_post_parse keeps a defensive throw as a second line of defense. Either
# layer must reject the combination with a non-zero exit code and a message
# mentioning the conflict.
# ============================================================================
@pytest.mark.timeout(30)
@pytest.mark.class_name("tool-runner-profile-conflict")
class TestProfileFlatProfileConflict(RocprofsysTest):
@pytest.mark.parametrize("target", TARGETS)
def test_profile_and_flat_profile_rejected(self, target):
result = self.run_test(
"baseline",
target=target,
run_args=["--profile", "--flat-profile", "--", "ls"],
fail_on_not_found=True,
fail_on_pass=True,
)
self.assert_regex(
result,
pass_regex=[r"--profile.*conflicts.*--flat-profile"],
)
# ============================================================================
# --output-format selects backends authoritatively
# ----------------------------------------------------------------------------
# --output-format names the exact set of outputs to produce: listed formats are
# enabled and every unlisted backend is explicitly disabled. A lone "rocpd" must
# not leave tracing on through the perfetto/profile default derivation, where
# ROCPROFSYS_TRACE otherwise defaults to the negation of ROCPROFSYS_PROFILE.
# ============================================================================
@pytest.mark.timeout(30)
@pytest.mark.class_name("tool-runner-output-format")
class TestOutputFormatSelection(RocprofsysTest):
@pytest.mark.parametrize("target", TARGETS)
def test_proto_rocpd_enables_both(self, target):
result = self.run_test(
"baseline",
target=target,
run_args=["--output-format", "proto", "rocpd", "-v", "2", "--", "ls"],
fail_on_not_found=True,
)
self.assert_regex(
result,
pass_regex=[
r"ROCPROFSYS_TRACE=true",
r"ROCPROFSYS_USE_ROCPD=true",
r"ROCPROFSYS_PROFILE=false",
],
)
@pytest.mark.parametrize("target", TARGETS)
def test_rocpd_only_disables_perfetto(self, target):
result = self.run_test(
"baseline",
target=target,
run_args=["--output-format", "rocpd", "-v", "2", "--", "ls"],
fail_on_not_found=True,
)
self.assert_regex(
result,
pass_regex=[
r"ROCPROFSYS_USE_ROCPD=true",
r"ROCPROFSYS_TRACE=false",
r"ROCPROFSYS_PROFILE=false",
],
)
@pytest.mark.parametrize(
"legacy_args",
[
["--trace"],
["--profile"],
["--flat-profile"],
["--profile-format", "text"],
],
)
@pytest.mark.parametrize("target", TARGETS)
def test_conflicts_with_legacy_flags(self, target, legacy_args):
result = self.run_test(
"baseline",
target=target,
run_args=["--output-format", "rocpd", *legacy_args, "--", "ls"],
fail_on_not_found=True,
fail_on_pass=True,
)
self.assert_regex(
result,
pass_regex=[r"--output-format.*conflicts.*"],
)