Skip to content

Commit 03a1803

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 <[email protected]>
1 parent 8f90d58 commit 03a1803

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 " + \
@@ -85,6 +88,14 @@ def _check_format_supported(self, desc_format):
8588
if not self.ocfs & (1 << desc_format):
8689
self.skipTest(f"descriptor format {desc_format} is not supported")
8790

91+
def _check_ns_copy_limits(self):
92+
""" Skip test if namespace copy limits (mcl, mssrl, msrc) are not set """
93+
missing = [name for name, val in
94+
[("mcl", self.mcl), ("mssrl", self.mssrl), ("msrc", self.msrc)]
95+
if val == 0]
96+
if missing:
97+
self.skipTest(f"{', '.join(missing)} are 0, copy not supported on this namespace")
98+
8899
def copy(self, sdlba, blocks, slbs, **kwargs):
89100
""" Wrapper for nvme copy
90101
- Args:
@@ -112,29 +123,35 @@ def copy(self, sdlba, blocks, slbs, **kwargs):
112123
def test_copy_format_0(self):
113124
""" Test copy with descriptor format 0 """
114125
self._check_format_supported(0)
126+
self._check_ns_copy_limits()
115127
self.copy(0, 1, 2, descriptor_format=0)
116128

117129
def test_copy_format_1(self):
118130
""" Test copy with descriptor format 1 """
119131
self._check_format_supported(1)
132+
self._check_ns_copy_limits()
120133
self.copy(0, 1, 2, descriptor_format=1)
121134

122135
def test_copy_format_2(self):
123136
""" Test copy with descriptor format 2 """
124137
self._check_format_supported(2)
138+
self._check_ns_copy_limits()
125139
self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid)
126140

127141
def test_copy_format_2_sopts(self):
128142
""" Test copy with descriptor format 2 and source options """
129143
self._check_format_supported(2)
144+
self._check_ns_copy_limits()
130145
self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid, sopts=0)
131146

132147
def test_copy_format_3(self):
133148
""" Test copy with descriptor format 3 """
134149
self._check_format_supported(3)
150+
self._check_ns_copy_limits()
135151
self.copy(0, 1, 2, descriptor_format=3, snsids=self.ns1_nsid)
136152

137153
def test_copy_format_3_sopts(self):
138154
""" Test copy with descriptor format 3 and source options """
139155
self._check_format_supported(3)
156+
self._check_ns_copy_limits()
140157
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
@@ -350,6 +350,22 @@ def get_id_ctrl_field_value(self, field):
350350
f"ERROR : reading field '{field}' failed")
351351
return str(json_output[field])
352352

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

0 commit comments

Comments
 (0)