Skip to content

Commit 266b835

Browse files
Daniel Zahkakuba-moo
authored andcommitted
selftests: drv-net: tso: enable test cases based on hw_features
tso.py uses the active features at the time of test execution as the set of available gso features to test. This means if a gso feature is supported but toggled off at test start, the test will be skipped with a "Device does not support {feature}" message. Instead, we can enumerate the set of toggleable features by capturing the driver's hw_features bitmap. To avoid configuration side-effects from running the test, we also snapshot the wanted_features flag set before making any feature changes, and then attempt to restore the same set of wanted_features before test exit. Fixes: 0d0f417 ("selftests: drv-net: add a simple TSO test") Signed-off-by: Daniel Zahka <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 407c114 commit 266b835

File tree

1 file changed

+40
-12
lines changed
  • tools/testing/selftests/drivers/net/hw

1 file changed

+40
-12
lines changed

tools/testing/selftests/drivers/net/hw/tso.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,30 @@ def build_tunnel(cfg, outer_ipver, tun_info):
119119
return remote_v4, remote_v6
120120

121121

122+
def restore_wanted_features(cfg):
123+
features_cmd = ""
124+
for feature in cfg.hw_features:
125+
setting = "on" if feature in cfg.wanted_features else "off"
126+
features_cmd += f" {feature} {setting}"
127+
try:
128+
ethtool(f"-K {cfg.ifname} {features_cmd}")
129+
except Exception as e:
130+
ksft_pr(f"WARNING: failure restoring wanted features: {e}")
131+
132+
122133
def test_builder(name, cfg, outer_ipver, feature, tun=None, inner_ipver=None):
123134
"""Construct specific tests from the common template."""
124135
def f(cfg):
125136
cfg.require_ipver(outer_ipver)
137+
defer(restore_wanted_features, cfg)
126138

127139
if not cfg.have_stat_super_count and \
128140
not cfg.have_stat_wire_count:
129141
raise KsftSkipEx(f"Device does not support LSO queue stats")
130142

143+
if feature not in cfg.hw_features:
144+
raise KsftSkipEx(f"Device does not support {feature}")
145+
131146
ipver = outer_ipver
132147
if tun:
133148
remote_v4, remote_v6 = build_tunnel(cfg, ipver, tun)
@@ -138,12 +153,12 @@ def f(cfg):
138153

139154
tun_partial = tun and tun[1]
140155
# Tunnel which can silently fall back to gso-partial
141-
has_gso_partial = tun and 'tx-gso-partial' in cfg.features
156+
has_gso_partial = tun and 'tx-gso-partial' in cfg.hw_features
142157

143158
# For TSO4 via partial we need mangleid
144159
if ipver == "4" and feature in cfg.partial_features:
145160
ksft_pr("Testing with mangleid enabled")
146-
if 'tx-tcp-mangleid-segmentation' not in cfg.features:
161+
if 'tx-tcp-mangleid-segmentation' not in cfg.hw_features:
147162
ethtool(f"-K {cfg.ifname} tx-tcp-mangleid-segmentation on")
148163
defer(ethtool, f"-K {cfg.ifname} tx-tcp-mangleid-segmentation off")
149164

@@ -161,11 +176,8 @@ def f(cfg):
161176
should_lso=tun_partial)
162177

163178
# Full feature enabled.
164-
if feature in cfg.features:
165-
ethtool(f"-K {cfg.ifname} {feature} on")
166-
run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso=True)
167-
else:
168-
raise KsftXfailEx(f"Device does not support {feature}")
179+
ethtool(f"-K {cfg.ifname} {feature} on")
180+
run_one_stream(cfg, ipver, remote_v4, remote_v6, should_lso=True)
169181

170182
f.__name__ = name + ((outer_ipver + "_") if tun else "") + "ipv" + inner_ipver
171183
return f
@@ -176,23 +188,39 @@ def query_nic_features(cfg) -> None:
176188
cfg.have_stat_super_count = False
177189
cfg.have_stat_wire_count = False
178190

179-
cfg.features = set()
180191
features = cfg.ethnl.features_get({"header": {"dev-index": cfg.ifindex}})
181-
for f in features["active"]["bits"]["bit"]:
182-
cfg.features.add(f["name"])
192+
193+
cfg.wanted_features = set()
194+
for f in features["wanted"]["bits"]["bit"]:
195+
cfg.wanted_features.add(f["name"])
196+
197+
cfg.hw_features = set()
198+
hw_all_features_cmd = ""
199+
for f in features["hw"]["bits"]["bit"]:
200+
if f.get("value", False):
201+
feature = f["name"]
202+
cfg.hw_features.add(feature)
203+
hw_all_features_cmd += f" {feature} on"
204+
try:
205+
ethtool(f"-K {cfg.ifname} {hw_all_features_cmd}")
206+
except Exception as e:
207+
ksft_pr(f"WARNING: failure enabling all hw features: {e}")
208+
ksft_pr("partial gso feature detection may be impacted")
183209

184210
# Check which features are supported via GSO partial
185211
cfg.partial_features = set()
186-
if 'tx-gso-partial' in cfg.features:
212+
if 'tx-gso-partial' in cfg.hw_features:
187213
ethtool(f"-K {cfg.ifname} tx-gso-partial off")
188214

189215
no_partial = set()
190216
features = cfg.ethnl.features_get({"header": {"dev-index": cfg.ifindex}})
191217
for f in features["active"]["bits"]["bit"]:
192218
no_partial.add(f["name"])
193-
cfg.partial_features = cfg.features - no_partial
219+
cfg.partial_features = cfg.hw_features - no_partial
194220
ethtool(f"-K {cfg.ifname} tx-gso-partial on")
195221

222+
restore_wanted_features(cfg)
223+
196224
stats = cfg.netnl.qstats_get({"ifindex": cfg.ifindex}, dump=True)
197225
if stats:
198226
if 'tx-hw-gso-packets' in stats[0]:

0 commit comments

Comments
 (0)