Files
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

145 lines
4.5 KiB
Python

# Copyright (c) Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
"""
Unit tests for rocprof-compute general CLI options.
"""
import argparse
from pathlib import Path
from unittest.mock import patch
import pytest
from common import SUPPORTED_ARCHS
from argparser import omniarg_parser
HOME = Path.cwd()
VERSION = {"ver_pretty": "rocprof-compute (unit test)"}
def build_args(argv, experimental=False):
"""Construct the argument parser."""
parser = argparse.ArgumentParser(
prog="tool", usage="rocprof-compute [mode] [options]"
)
omniarg_parser(parser, HOME, SUPPORTED_ARCHS, VERSION, experimental)
return parser.parse_args(argv)
# =============================================================================
# -v / --version
# =============================================================================
@pytest.mark.parametrize("flag", ["-v", "--version"])
def test_version_success_exits_zero(flag, capsys):
with pytest.raises(SystemExit) as exc:
build_args([flag])
assert exc.value.code == 0
assert "unit test" in capsys.readouterr().out
# =============================================================================
# -h / --help
# =============================================================================
@pytest.mark.parametrize("flag", ["-h", "--help"])
def test_help_success_exits_zero(flag, capsys):
with pytest.raises(SystemExit) as exc:
build_args([flag])
assert exc.value.code == 0
assert "usage" in capsys.readouterr().out.lower()
@pytest.mark.parametrize("flag", ["-h", "--help"])
def test_help_rejects_explicit_value(flag, capsys):
with pytest.raises(SystemExit) as exc:
build_args([f"{flag}=now"])
assert exc.value.code == 2
assert "--help" in capsys.readouterr().err
# =============================================================================
# -V / --verbose
# =============================================================================
@pytest.mark.parametrize("flag", ["-V", "--verbose"])
def test_verbose_success_counts(flag):
assert build_args([]).verbose == 0
assert build_args([flag]).verbose == 1
assert build_args([flag, flag, flag]).verbose == 3
@pytest.mark.parametrize("flag", ["-V", "--verbose"])
def test_verbose_rejects_explicit_value(flag, capsys):
with pytest.raises(SystemExit) as exc:
build_args([f"{flag}=2"])
assert exc.value.code == 2
assert "--verbose" in capsys.readouterr().err
# =============================================================================
# -q / --quiet
# =============================================================================
@pytest.mark.parametrize("flag", ["-q", "--quiet"])
def test_quiet_success_sets_flag(flag):
assert build_args([]).quiet is False
assert build_args([flag]).quiet is True
@pytest.mark.parametrize("flag", ["-q", "--quiet"])
def test_quiet_rejects_explicit_value(flag, capsys):
with pytest.raises(SystemExit) as exc:
build_args([f"{flag}=loud"])
assert exc.value.code == 2
assert "--quiet" in capsys.readouterr().err
# =============================================================================
# --config-dir
# =============================================================================
def test_config_dir_success_stores_value():
assert build_args(["--config-dir", "/tmp/cfg"]).config_dir == "/tmp/cfg"
def test_config_dir_requires_value(capsys):
with pytest.raises(SystemExit) as exc:
build_args(["--config-dir"])
assert exc.value.code == 2
assert "--config-dir" in capsys.readouterr().err
def test_pc_sampling_analyze_options():
"""Defaults, overrides, and validation for the analyze PC sampling options."""
defaults = build_args(["analyze"])
assert defaults.pc_sampling_sorting_type == "count"
assert defaults.pc_sampling_rows == 10
overrides = build_args([
"analyze",
"--pc-sampling-sorting-type",
"offset",
"--pc-sampling-rows",
"25",
])
assert overrides.pc_sampling_sorting_type == "offset"
assert overrides.pc_sampling_rows == 25
# 0 is allowed and means "show all rows".
assert build_args(["analyze", "--pc-sampling-rows", "0"]).pc_sampling_rows == 0
# Negative row counts trigger an argparse error.
with patch.object(
argparse.ArgumentParser, "error", side_effect=SystemExit(2)
) as mock_error:
with pytest.raises(SystemExit):
build_args(["analyze", "--pc-sampling-rows", "-1"])
mock_error.assert_called_once()