Skip to content

Commit c2706b6

Browse files
committed
tests: only setup cdfe for requested descriptor version
The setUp method was enabling all cross-namespace cdfe bits (CDF2E | CDF3E = 12) for every test, including format 0 and 1. Only enable support necessary descriptor version used in the test. Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 20f6c6f commit c2706b6

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

tests/nvme_copy_test.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,6 @@ def setUp(self):
3939
self.mcl = to_decimal(self.get_id_ns_field_value("mcl"))
4040
self.mssrl = to_decimal(self.get_id_ns_field_value("mssrl"))
4141
self.msrc = to_decimal(self.get_id_ns_field_value("msrc"))
42-
cross_namespace_copy = self.ocfs & 0xc
43-
if cross_namespace_copy:
44-
get_features_cmd = f"{self.nvme_bin} feat host-behavior-support " + \
45-
f"{self.ctrl} --output-format=json"
46-
result = self.run_cmd(get_features_cmd)
47-
self.assertEqual(result.returncode, 0,
48-
"ERROR : nvme feat host-behavior-support failed")
49-
data = json.loads(result.stdout)
50-
fields = data.get("Feature: 0x16", [{}])[0]
51-
current_cdfe = (
52-
(0x4 if fields.get("Copy Descriptor Format 2h Enable (CDF2E)") == "True" else 0) |
53-
(0x8 if fields.get("Copy Descriptor Format 3h Enable (CDF3E)") == "True" else 0) |
54-
(0x10 if fields.get("Copy Descriptor Format 4h Enable (CDF4E)") == "True" else 0)
55-
)
56-
if current_cdfe & cross_namespace_copy:
57-
print("Cross-namespace copy already enabled, skipping set-features")
58-
else:
59-
self.original_cdfe = current_cdfe
60-
new_cdfe = current_cdfe | cross_namespace_copy
61-
set_features_cmd = f"{self.nvme_bin} feat host-behavior-support " + \
62-
f"{self.ctrl} --cdfe={new_cdfe}"
63-
result = self.run_cmd(set_features_cmd)
64-
self.assertEqual(result.returncode, 0,
65-
"Failed to enable cross-namespace copy formats")
6642
get_ns_id_cmd = f"{self.nvme_bin} get-ns-id {self.ns1}"
6743
result = self.run_cmd(get_ns_id_cmd)
6844
err = result.returncode
@@ -92,6 +68,35 @@ def _check_ns_copy_limits(self):
9268
if missing:
9369
self.skipTest(f"{', '.join(missing)} are 0, copy not supported on this namespace")
9470

71+
def _enable_cdfe_for_format(self, desc_format):
72+
""" Enable the host-behavior-support cdfe bit for the given cross-namespace format.
73+
Only the bit corresponding to desc_format is enabled; other bits are left unchanged.
74+
The original value is saved in self.original_cdfe for tearDown to restore.
75+
"""
76+
cdfe_bit = 1 << desc_format
77+
get_features_cmd = f"{self.nvme_bin} feat host-behavior-support " + \
78+
f"{self.ctrl} --output-format=json"
79+
result = self.run_cmd(get_features_cmd)
80+
self.assertEqual(result.returncode, 0,
81+
"ERROR : nvme feat host-behavior-support failed")
82+
data = json.loads(result.stdout)
83+
fields = data.get("Feature: 0x16", [{}])[0]
84+
current_cdfe = (
85+
(0x4 if fields.get("Copy Descriptor Format 2h Enable (CDF2E)") == "True" else 0) |
86+
(0x8 if fields.get("Copy Descriptor Format 3h Enable (CDF3E)") == "True" else 0) |
87+
(0x10 if fields.get("Copy Descriptor Format 4h Enable (CDF4E)") == "True" else 0)
88+
)
89+
if current_cdfe & cdfe_bit:
90+
return
91+
if self.original_cdfe is None:
92+
self.original_cdfe = current_cdfe
93+
new_cdfe = current_cdfe | cdfe_bit
94+
set_features_cmd = f"{self.nvme_bin} feat host-behavior-support " + \
95+
f"{self.ctrl} --cdfe={new_cdfe}"
96+
result = self.run_cmd(set_features_cmd)
97+
self.assertEqual(result.returncode, 0,
98+
f"Failed to enable cdfe bit {cdfe_bit:#x} for format {desc_format}")
99+
95100
def copy(self, sdlba, blocks, slbs, **kwargs):
96101
""" Wrapper for nvme copy
97102
- Args:
@@ -132,22 +137,26 @@ def test_copy_format_2(self):
132137
""" Test copy with descriptor format 2 """
133138
self._check_format_supported(2)
134139
self._check_ns_copy_limits()
140+
self._enable_cdfe_for_format(2)
135141
self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid)
136142

137143
def test_copy_format_2_sopts(self):
138144
""" Test copy with descriptor format 2 and source options """
139145
self._check_format_supported(2)
140146
self._check_ns_copy_limits()
147+
self._enable_cdfe_for_format(2)
141148
self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid, sopts=0)
142149

143150
def test_copy_format_3(self):
144151
""" Test copy with descriptor format 3 """
145152
self._check_format_supported(3)
146153
self._check_ns_copy_limits()
154+
self._enable_cdfe_for_format(3)
147155
self.copy(0, 1, 2, descriptor_format=3, snsids=self.ns1_nsid)
148156

149157
def test_copy_format_3_sopts(self):
150158
""" Test copy with descriptor format 3 and source options """
151159
self._check_format_supported(3)
152160
self._check_ns_copy_limits()
161+
self._enable_cdfe_for_format(3)
153162
self.copy(0, 1, 2, descriptor_format=3, snsids=self.ns1_nsid, sopts=0)

0 commit comments

Comments
 (0)