additional-code-coverage-compute (#763)

* added additional functions to test_utils.py

* added code coverage for db_connector.py

* Update test_profile_general.py

Added additional roofline test cases

Signed-off-by: jamessiddeley-amd <James.Siddeley@amd.com>

* updated coverage mi_gpu_spec.py 73% -> 94%

* added parser.py coverage

* removed redundant comments

* added test_utils and test_db_connector

---------

Signed-off-by: jamessiddeley-amd <James.Siddeley@amd.com>

[ROCm/rocprofiler-compute commit: a6463f5e98]
This commit is contained in:
jamessiddeley-amd
2025-07-02 13:29:10 -04:00
committed by GitHub
parent e085f3cc54
commit 94ea0fbf2f
6 changed files with 2662 additions and 110 deletions
@@ -25,8 +25,13 @@
import re
import subprocess
import sys
import pytest
import yaml
import tempfile
import os
from importlib.machinery import SourceFileLoader
from unittest.mock import patch
from unittest.mock import patch, mock_open, MagicMock
from pathlib import Path
import pandas as pd
import pytest
@@ -195,3 +200,186 @@ def test_num_xcds_cli_output():
assert compute_partition_actual is not None
assert int(num_xcd_actual) == num_xcds.get(compute_partition_actual.lower(), -1)
@pytest.mark.misc
def test_load_yaml_file_not_found():
"""Test _load_yaml with non-existent file - covers lines 104-105"""
from src.utils.mi_gpu_spec import MIGPUSpecs
non_existent_path = "/path/that/does/not/exist/file.yaml"
with pytest.raises(SystemExit):
MIGPUSpecs._load_yaml(non_existent_path)
@pytest.mark.misc
def test_load_yaml_invalid_yaml():
"""Test _load_yaml with corrupted YAML - covers lines 106-107"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:
f.write('invalid: yaml: content: [\nunclosed bracket')
temp_path = f.name
try:
with pytest.raises(SystemExit):
MIGPUSpecs._load_yaml(temp_path)
finally:
os.unlink(temp_path)
@pytest.mark.misc
def test_load_yaml_generic_exception():
"""Test _load_yaml generic exception handling - covers lines 108-111"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch('builtins.open', side_effect=PermissionError("Access denied")):
with pytest.raises(SystemExit):
MIGPUSpecs._load_yaml("some_file.yaml")
@pytest.mark.misc
def test_get_gpu_series_dict_uninitialized():
"""Test get_gpu_series_dict when dict not populated - covers lines 182-185"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_gpu_series_dict', {}):
with pytest.raises(SystemExit):
MIGPUSpecs.get_gpu_series_dict()
@pytest.mark.misc
def test_get_gpu_series_uninitialized():
"""Test get_gpu_series when dict not populated - covers lines 191-194"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_gpu_series_dict', {}):
with pytest.raises(SystemExit):
result = MIGPUSpecs.get_gpu_series("gfx942")
@pytest.mark.misc
def test_get_perfmon_config_uninitialized():
"""Test get_perfmon_config when dict not populated - covers lines 210-213"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_perfmon_config', {}):
with pytest.raises(SystemExit):
MIGPUSpecs.get_perfmon_config("gfx942")
@pytest.mark.misc
def test_get_gpu_model_uninitialized():
"""Test get_gpu_model when dict not populated - covers lines 223-226"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_gpu_model_dict', {}):
with pytest.raises(SystemExit):
MIGPUSpecs.get_gpu_model("gfx942", "29857")
@pytest.mark.misc
def test_get_gpu_model_invalid_chip_id():
"""Test get_gpu_model with invalid chip_id - covers lines 235-236"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_gpu_model("gfx942", "99999")
assert result is None
@pytest.mark.misc
def test_get_gpu_model_invalid_arch():
"""Test get_gpu_model with invalid architecture - covers lines 243-244"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_gpu_model("gfx999", "12345")
assert result is None
@pytest.mark.misc
def test_get_gpu_model_none_result():
"""Test get_gpu_model when result is None - covers lines 246-248"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_chip_id_dict', {999: None}):
result = MIGPUSpecs.get_gpu_model("gfx942", "999")
assert result is None
@pytest.mark.misc
def test_get_num_xcds_no_compute_partition_data():
"""Test get_num_xcds when no compute partition data found - covers lines 307-309"""
from src.utils.mi_gpu_spec import MIGPUSpecs
mock_dict = {"gfx942": None}
with patch.object(MIGPUSpecs, '_gpu_arch_to_compute_partition_dict', mock_dict):
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx942")
@pytest.mark.misc
def test_get_num_xcds_uninitialized_dict():
"""Test get_num_xcds when XCD dict not populated - covers lines 315-317"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_num_xcds_dict', {}):
with pytest.raises(SystemExit):
MIGPUSpecs.get_num_xcds(gpu_arch="gfx950", gpu_model="MI350")
@pytest.mark.misc
def test_get_num_xcds_unknown_gpu_model():
"""Test get_num_xcds with unknown gpu model - covers lines 319-321"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx950", gpu_model="UNKNOWN_MODEL")
@pytest.mark.misc
def test_get_num_xcds_no_compute_partition():
"""Test get_num_xcds with no compute partition - covers lines 325-327"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx950", gpu_model="MI350", compute_partition="")
@pytest.mark.misc
def test_get_num_xcds_unknown_compute_partition():
"""Test get_num_xcds with unknown compute partition - covers lines 329-332"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx950", gpu_model="MI350", compute_partition="UNKNOWN")
@pytest.mark.misc
def test_get_num_xcds_none_partition_value():
"""Test get_num_xcds when partition value is None - covers lines 338-340"""
from src.utils.mi_gpu_spec import MIGPUSpecs
mock_dict = {"mi350": {"spx": None}}
with patch.object(MIGPUSpecs, '_num_xcds_dict', mock_dict):
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx950", gpu_model="MI350", compute_partition="spx")
@pytest.mark.misc
def test_get_num_xcds_no_gpu_model():
"""Test get_num_xcds with no gpu model - covers line 342"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx950", gpu_model="", compute_partition="spx")
@pytest.mark.misc
def test_get_chip_id_dict_empty():
"""Test get_chip_id_dict when dict is empty - covers line 352"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_chip_id_dict', {}):
with patch('src.utils.mi_gpu_spec.console_error') as mock_error:
result = MIGPUSpecs.get_chip_id_dict()
mock_error.assert_called_once()
@pytest.mark.misc
def test_get_num_xcds_dict_empty():
"""Test get_num_xcds_dict when dict is empty - covers line 359"""
from src.utils.mi_gpu_spec import MIGPUSpecs
with patch.object(MIGPUSpecs, '_num_xcds_dict', {}):
with patch('src.utils.mi_gpu_spec.console_error') as mock_error:
result = MIGPUSpecs.get_num_xcds_dict()
mock_error.assert_called_once()
@pytest.mark.misc
def test_normal_functionality_still_works():
"""Ensure that normal paths still work after adding error handling tests"""
from src.utils.mi_gpu_spec import MIGPUSpecs
result = MIGPUSpecs.get_gpu_model("gfx906", None)
assert result is not None
result = MIGPUSpecs.get_gpu_series("gfx906")
assert result is not None
result = MIGPUSpecs.get_num_xcds(gpu_arch="gfx906")
assert result == 1