Skip to content

Commit d5e06a7

Browse files
committed
tests/test_tpmi_nohost: Cover no 'tpmi_info' case
And fix a found bug. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent 5406b9d commit d5e06a7

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

pepclibs/TPMI.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,10 @@ def _validate_instance_offset(self,
12791279
raise Error(f"Bad instance number '{instance}' for TPMI feature '{fname}' and "
12801280
f"device '{addr}', available instances: {available}")
12811281

1282+
if not mdmap[instance]:
1283+
raise Error(f"TPMI feature '{fname}', device '{addr}', instance '{instance}' is not "
1284+
f"implemented")
1285+
12821286
if offset < 0 or offset % 4 != 0 or offset not in mdmap[instance]:
12831287
max_offset = max(mdmap[instance])
12841288
raise Error(f"Bad offset '{offset:#x}' for register '{regname}' of TPMI feature "

tests/test_tpmi_nohost.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
from __future__ import annotations # Remove when switching to Python 3.10+.
2525

2626
from pathlib import Path
27+
import shutil
2728

29+
import pytest
2830
from tests import common
2931
from pepclibs import TPMI
32+
from pepclibs.helperlibs.Exceptions import Error
3033

3134
def _get_tpmi_instance() -> TPMI.TPMI:
3235
"""
@@ -197,3 +200,35 @@ def test_read_bitfield():
197200
# instance 2.
198201
value = tpmi.read_register("ufs", "0000:00:02.1", 2, "UFS_STATUS", bfname="AGENT_TYPE_IO")
199202
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

Comments
 (0)