Skip to content

Commit 20f6c6f

Browse files
committed
tests: add mcl/mssrl/msrc limit checks to nvme_copy_test
The copy test can only run with valid mcl, mssrl, and msrc values. Therefore, check that they are non-zero. QEMU’s default namespace settings set these values to 0. The user must set them explicitly, e.g -device nvme-ns,drive=ns0,nsid=1,mcl=1024,mssrl=1024,msrc=63 Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 3ed661a commit 20f6c6f

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

tests/nvme_copy_test.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import json
2020

21-
from nvme_test import TestNVMe
21+
from nvme_test import TestNVMe, to_decimal
2222

2323

2424
class TestNVMeCopy(TestNVMe):
@@ -36,6 +36,9 @@ def setUp(self):
3636
super().setUp()
3737
self.ocfs = self.get_ocfs()
3838
self.original_cdfe = None
39+
self.mcl = to_decimal(self.get_id_ns_field_value("mcl"))
40+
self.mssrl = to_decimal(self.get_id_ns_field_value("mssrl"))
41+
self.msrc = to_decimal(self.get_id_ns_field_value("msrc"))
3942
cross_namespace_copy = self.ocfs & 0xc
4043
if cross_namespace_copy:
4144
get_features_cmd = f"{self.nvme_bin} feat host-behavior-support " + \
@@ -81,6 +84,14 @@ def _check_format_supported(self, desc_format):
8184
if not self.ocfs & (1 << desc_format):
8285
self.skipTest(f"descriptor format {desc_format} is not supported")
8386

87+
def _check_ns_copy_limits(self):
88+
""" Skip test if namespace copy limits (mcl, mssrl, msrc) are not set """
89+
missing = [name for name, val in
90+
[("mcl", self.mcl), ("mssrl", self.mssrl), ("msrc", self.msrc)]
91+
if val == 0]
92+
if missing:
93+
self.skipTest(f"{', '.join(missing)} are 0, copy not supported on this namespace")
94+
8495
def copy(self, sdlba, blocks, slbs, **kwargs):
8596
""" Wrapper for nvme copy
8697
- Args:
@@ -108,29 +119,35 @@ def copy(self, sdlba, blocks, slbs, **kwargs):
108119
def test_copy_format_0(self):
109120
""" Test copy with descriptor format 0 """
110121
self._check_format_supported(0)
122+
self._check_ns_copy_limits()
111123
self.copy(0, 1, 2, descriptor_format=0)
112124

113125
def test_copy_format_1(self):
114126
""" Test copy with descriptor format 1 """
115127
self._check_format_supported(1)
128+
self._check_ns_copy_limits()
116129
self.copy(0, 1, 2, descriptor_format=1)
117130

118131
def test_copy_format_2(self):
119132
""" Test copy with descriptor format 2 """
120133
self._check_format_supported(2)
134+
self._check_ns_copy_limits()
121135
self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid)
122136

123137
def test_copy_format_2_sopts(self):
124138
""" Test copy with descriptor format 2 and source options """
125139
self._check_format_supported(2)
140+
self._check_ns_copy_limits()
126141
self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid, sopts=0)
127142

128143
def test_copy_format_3(self):
129144
""" Test copy with descriptor format 3 """
130145
self._check_format_supported(3)
146+
self._check_ns_copy_limits()
131147
self.copy(0, 1, 2, descriptor_format=3, snsids=self.ns1_nsid)
132148

133149
def test_copy_format_3_sopts(self):
134150
""" Test copy with descriptor format 3 and source options """
135151
self._check_format_supported(3)
152+
self._check_ns_copy_limits()
136153
self.copy(0, 1, 2, descriptor_format=3, snsids=self.ns1_nsid, sopts=0)

tests/nvme_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,22 @@ def get_id_ctrl_field_value(self, field):
345345
f"ERROR : reading field '{field}' failed")
346346
return str(json_output[field])
347347

348+
def get_id_ns_field_value(self, field):
349+
""" Wrapper for extracting id-ns field values
350+
- Args:
351+
- field : field name to extract
352+
- Returns:
353+
- Field value of the given field as a string
354+
"""
355+
id_ns_cmd = f"{self.nvme_bin} id-ns {self.ns1} " + \
356+
"--output-format=json"
357+
result = self.run_cmd(id_ns_cmd)
358+
self.assertEqual(result.returncode, 0, "ERROR : reading id-ns failed")
359+
json_output = json.loads(result.stdout)
360+
self.assertTrue(field in json_output,
361+
f"ERROR : reading field '{field}' failed")
362+
return str(json_output[field])
363+
348364
def get_ocfs(self):
349365
""" Wrapper for extracting optional copy formats supported
350366
- Args:

0 commit comments

Comments
 (0)