Skip to content

Commit 012a527

Browse files
committed
tests: handle data size based on dsp and ms settings
The read, write and compare use case have hard coded dependencies on data size. Use dsp and ms from the namespace and set the data size correctly. Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 39694c7 commit 012a527

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

tests/nvme_compare_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def setUp(self):
6060
super().setUp()
6161
if not self.compare_cmd_supported():
6262
self.skipTest("because: Optional NVM Command 'Compare' (NVMCMPS) not supported")
63-
self.data_size = 1024
6463
self.start_block = 1023
6564
self.setup_log_dir(self.__class__.__name__)
6665
self.compare_file = self.test_log_dir + "/" + "compare_file.txt"
@@ -83,6 +82,8 @@ def nvme_compare(self, cmp_file):
8382
f"--start-block={str(self.start_block)} " + \
8483
f"--block-count={str(self.block_count)} " + \
8584
f"--data-size={str(self.data_size)} --data={cmp_file}"
85+
if self.prinfo:
86+
compare_cmd += f" --prinfo={self.prinfo}"
8687
return self.exec_cmd(compare_cmd)
8788

8889
def test_nvme_compare(self):

tests/nvme_test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def setUp(self):
8080
self.do_validate_pci_device = True
8181
self.default_nsid = 0x1
8282
self.flbas = 0
83+
self.ns_dps = 0
8384
self.config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
8485

8586
self.load_config()
@@ -88,6 +89,13 @@ def setUp(self):
8889
self.ns_mgmt_supported = self.get_ns_mgmt_support()
8990
if self.ns_mgmt_supported:
9091
self.create_and_attach_default_ns()
92+
else:
93+
# Namespace is managed externally (e.g. by QEMU). Discover the
94+
# active lbaf so that get_lba_format_size() returns the correct
95+
# ds and ms values for the format actually in use. Also read
96+
# the DPS field so IO tests can enable PRACT when PI is active.
97+
self.flbas = self._get_active_lbaf_index()
98+
self.ns_dps = self._get_ns_dps()
9199
logger.debug("setup: ctrl: %s, ns1: %s, default_nsid: %s, flbas: %s",
92100
self.ctrl, self.ns1, self.default_nsid, self.flbas)
93101

@@ -300,6 +308,38 @@ def get_lba_status_supported(self):
300308
"""
301309
return to_decimal(self.get_id_ctrl_field_value("oacs")) & (1 << 9)
302310

311+
def _get_active_lbaf_index(self):
312+
""" Return the index of the currently active LBA format for ns1.
313+
- Args:
314+
- None
315+
- Returns:
316+
- lbaf index (int) of the format whose in_use flag is set,
317+
or 0 if no in_use entry is found.
318+
"""
319+
nvme_id_ns_cmd = f"{self.nvme_bin} id-ns {self.ns1} " + \
320+
"--output-format=json"
321+
result = self.run_cmd(nvme_id_ns_cmd)
322+
self.assertEqual(result.returncode, 0, "ERROR : reading id-ns")
323+
json_output = json.loads(result.stdout)
324+
for lbaf in json_output.get('lbafs', []):
325+
if lbaf.get('in_use') == 1:
326+
return int(lbaf['lbaf'])
327+
return 0
328+
329+
def _get_ns_dps(self):
330+
""" Return the Data Protection Settings (DPS) field for ns1.
331+
- Args:
332+
- None
333+
- Returns:
334+
- dps value (int); non-zero means end-to-end PI is enabled.
335+
"""
336+
nvme_id_ns_cmd = f"{self.nvme_bin} id-ns {self.ns1} " + \
337+
"--output-format=json"
338+
result = self.run_cmd(nvme_id_ns_cmd)
339+
self.assertEqual(result.returncode, 0, "ERROR : reading id-ns")
340+
json_output = json.loads(result.stdout)
341+
return int(json_output.get('dps', 0))
342+
303343
def get_lba_format_size(self):
304344
""" Wrapper for extracting lba format size of the given flbas
305345
- Args:

tests/nvme_test_io.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ def setUp(self):
4343
""" Pre Section for TestNVMeIO """
4444
super().setUp()
4545
# common code used in various testcases.
46-
(self.data_size, _) = self.get_lba_format_size()
46+
(ds, ms) = self.get_lba_format_size()
47+
if self.ns_dps != 0 and ms != 0:
48+
# End-to-end protection information (PI) is active. Use PRACT=1
49+
# (--prinfo=8) so the controller inserts and strips PI
50+
# automatically. With PRACT=1 the PI bytes are not transferred
51+
# over the host interface, so data_size equals the logical block
52+
# data size only (ds), not ds+ms.
53+
self.prinfo = 8
54+
self.data_size = ds
55+
else:
56+
# No PI. Include the full LBA (user data + metadata) in the
57+
# buffer so the read file size matches the write file size and
58+
# so that uninitialized trailing metadata bytes are consistent
59+
# across write and compare operations.
60+
self.prinfo = 0
61+
self.data_size = ds + ms
4762
self.start_block = 0
4863
self.block_count = 0
4964
self.write_file = "write_file.txt"
@@ -81,6 +96,8 @@ def nvme_write(self):
8196
f"--start-block={str(self.start_block)} " + \
8297
f"--block-count={str(self.block_count)} " + \
8398
f"--data-size={str(self.data_size)} --data={self.write_file}"
99+
if self.prinfo:
100+
write_cmd += f" --prinfo={self.prinfo}"
84101
return self.exec_cmd(write_cmd)
85102

86103
def nvme_read(self):
@@ -94,4 +111,6 @@ def nvme_read(self):
94111
f"--start-block={str(self.start_block)} " + \
95112
f"--block-count={str(self.block_count)} " + \
96113
f"--data-size={str(self.data_size)} --data={self.read_file}"
114+
if self.prinfo:
115+
read_cmd += f" --prinfo={self.prinfo}"
97116
return self.exec_cmd(read_cmd)

0 commit comments

Comments
 (0)