|
24 | 24 | from __future__ import annotations # Remove when switching to Python 3.10+. |
25 | 25 |
|
26 | 26 | from pathlib import Path |
| 27 | +import shutil |
27 | 28 |
|
| 29 | +import pytest |
28 | 30 | from tests import common |
29 | 31 | from pepclibs import TPMI |
| 32 | +from pepclibs.helperlibs.Exceptions import Error |
30 | 33 |
|
31 | 34 | def _get_tpmi_instance() -> TPMI.TPMI: |
32 | 35 | """ |
@@ -197,3 +200,35 @@ def test_read_bitfield(): |
197 | 200 | # instance 2. |
198 | 201 | value = tpmi.read_register("ufs", "0000:00:02.1", 2, "UFS_STATUS", bfname="AGENT_TYPE_IO") |
199 | 202 | assert value == 0x1, f"Unexpected AGENT_TYPE_IO bitfield value: {value:#x}" |
| 203 | + |
| 204 | +def test_no_tpmi_info(tmp_path: Path): |
| 205 | + """ |
| 206 | + Test the special case: no 'tpmi_info' feature is present in the TPMI debugfs dump. |
| 207 | +
|
| 208 | + Args: |
| 209 | + tmp_path: A temporary directory path for testing (provided by the pytest framework). |
| 210 | + """ |
| 211 | + |
| 212 | + # Create a copy of the debugfs dump without the 'tpmi_info' feature. |
| 213 | + debugfs_dump_path = common.get_test_data_path(__file__) / Path("debugfs-dump") |
| 214 | + test_dump_path = tmp_path / Path("debugfs-dump-no-tpmi_info") |
| 215 | + |
| 216 | + shutil.copytree(debugfs_dump_path, test_dump_path) |
| 217 | + shutil.rmtree(test_dump_path / Path("tpmi-0000:00:02.1/tpmi-id-81")) |
| 218 | + shutil.rmtree(test_dump_path / Path("tpmi-0001:00:02.1/tpmi-id-81")) |
| 219 | + |
| 220 | + tpmi = TPMI.TPMI(base=test_dump_path) |
| 221 | + sdicts = tpmi.get_known_features() |
| 222 | + |
| 223 | + expected_fnames = {"ufs", "rapl", "tpmi_info"} |
| 224 | + assert set(sdicts) == expected_fnames, \ |
| 225 | + f"Unexpected known feature names: {list(sdicts)}" |
| 226 | + |
| 227 | + # Check that reading a register from existing features still works. |
| 228 | + value = tpmi.read_register("ufs", "0000:00:02.1", 2, "UFS_STATUS") |
| 229 | + assert value == 0xa52fc5f04092008, \ |
| 230 | + f"Unexpected UFS_STATUS register value: {value:#x}" |
| 231 | + |
| 232 | + # Check that readint 'tpmi_info' feature raises an exception. |
| 233 | + with pytest.raises(Error): |
| 234 | + tpmi.read_register("tpmi_info", "0000:00:02.1", 0, "TPMI_INFO_HEADER") |
0 commit comments