Skip to content

Commit 5cc1bdd

Browse files
cjubrankuba-moo
authored andcommitted
selftests: drv-net: Fix tolerance calculation in devlink_rate_tc_bw.py
Currently, tolerance is computed against the TC’s expected percentage, making TC3 (20%) validation overly strict and TC4 (80%) overly loose. Update BandwidthValidator to take a dict of shares and compute bounds relative to the overall total, so that all shares are validated consistently. Signed-off-by: Carolina Jubran <cjubran@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Reviewed-by: Nimrod Oren <noren@nvidia.com> Link: https://patch.msgid.link/20251130091938.4109055-7-cjubran@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 9ecd05a commit 5cc1bdd

File tree

1 file changed

+30
-44
lines changed

1 file changed

+30
-44
lines changed

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

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -69,39 +69,35 @@
6969

7070
class BandwidthValidator:
7171
"""
72-
Validates bandwidth totals and per-TC shares against expected values
73-
with a tolerance.
72+
Validates total bandwidth and individual shares with tolerance
73+
relative to the overall total.
7474
"""
7575

76-
def __init__(self):
76+
def __init__(self, shares):
7777
self.tolerance_percent = 12
78-
self.expected_total_gbps = 1.0
79-
self.total_min_expected = self.min_expected(self.expected_total_gbps)
80-
self.total_max_expected = self.max_expected(self.expected_total_gbps)
81-
self.tc_expected_percent = {
82-
3: 20.0,
83-
4: 80.0,
84-
}
78+
self.expected_total = sum(shares.values())
79+
self.bounds = {}
80+
81+
for name, exp in shares.items():
82+
self.bounds[name] = (self.min_expected(exp), self.max_expected(exp))
8583

8684
def min_expected(self, value):
8785
"""Calculates the minimum acceptable value based on tolerance."""
88-
return value - (value * self.tolerance_percent / 100)
86+
return value - (self.expected_total * self.tolerance_percent / 100)
8987

9088
def max_expected(self, value):
9189
"""Calculates the maximum acceptable value based on tolerance."""
92-
return value + (value * self.tolerance_percent / 100)
93-
94-
def bound(self, expected, value):
95-
"""Returns True if value is within expected tolerance."""
96-
return self.min_expected(expected) <= value <= self.max_expected(expected)
90+
return value + (self.expected_total * self.tolerance_percent / 100)
9791

98-
def tc_bandwidth_bound(self, value, tc_ix):
92+
def bound(self, values):
9993
"""
100-
Returns True if the given bandwidth value is within tolerance
101-
for the TC's expected bandwidth.
94+
Return True if all given values fall within tolerance.
10295
"""
103-
expected = self.tc_expected_percent[tc_ix]
104-
return self.bound(expected, value)
96+
for name, value in values.items():
97+
low, high = self.bounds[name]
98+
if not low <= value <= high:
99+
return False
100+
return True
105101

106102

107103
def setup_vf(cfg, set_tc_mapping=True):
@@ -353,38 +349,26 @@ def verify_total_bandwidth(bw_data, validator):
353349
"""
354350
total = bw_data['total_bw']
355351

356-
if validator.bound(validator.expected_total_gbps, total):
352+
if validator.bound({"total": total}):
357353
return
358354

359-
if total < validator.total_min_expected:
355+
low, high = validator.bounds["total"]
356+
357+
if total < low:
360358
raise KsftSkipEx(
361359
f"Total bandwidth {total:.2f} Gbps < minimum "
362-
f"{validator.total_min_expected:.2f} Gbps; "
363-
f"parent tx_max ({validator.expected_total_gbps:.1f} G) "
360+
f"{low:.2f} Gbps; "
361+
f"parent tx_max ({validator.expected_total:.1f} G) "
364362
f"not reached, cannot validate share"
365363
)
366364

367365
raise KsftFailEx(
368366
f"Total bandwidth {total:.2f} Gbps exceeds allowed ceiling "
369-
f"{validator.total_max_expected:.2f} Gbps "
370-
f"(VF tx_max set to {validator.expected_total_gbps:.1f} G)"
367+
f"{high:.2f} Gbps "
368+
f"(VF tx_max set to {validator.expected_total:.1f} G)"
371369
)
372370

373371

374-
def check_bandwidth_distribution(bw_data, validator):
375-
"""
376-
Checks whether the measured TC3 and TC4 bandwidth percentages
377-
fall within their expected tolerance ranges.
378-
379-
Returns:
380-
bool: True if both TC3 and TC4 percentages are within bounds.
381-
"""
382-
tc3_valid = validator.tc_bandwidth_bound(bw_data['tc3_percentage'], 3)
383-
tc4_valid = validator.tc_bandwidth_bound(bw_data['tc4_percentage'], 4)
384-
385-
return tc3_valid and tc4_valid
386-
387-
388372
def run_bandwidth_distribution_test(cfg, set_tc_mapping):
389373
"""
390374
Runs parallel bandwidth measurements for both TCs and collects results.
@@ -395,9 +379,10 @@ def run_bandwidth_distribution_test(cfg, set_tc_mapping):
395379
test_name = "with TC mapping" if set_tc_mapping else "without TC mapping"
396380
print_bandwidth_results(bw_data, test_name)
397381

398-
verify_total_bandwidth(bw_data, cfg.bw_validator)
382+
verify_total_bandwidth(bw_data, cfg.traffic_bw_validator)
399383

400-
return check_bandwidth_distribution(bw_data, cfg.bw_validator)
384+
return cfg.tc_bw_validator.bound({"tc3": bw_data['tc3_percentage'],
385+
"tc4": bw_data['tc4_percentage']})
401386

402387

403388
def test_no_tc_mapping_bandwidth(cfg):
@@ -441,7 +426,8 @@ def main() -> None:
441426
if not cfg.pci:
442427
raise KsftSkipEx("Could not get PCI address of the interface")
443428

444-
cfg.bw_validator = BandwidthValidator()
429+
cfg.traffic_bw_validator = BandwidthValidator({"total": 1})
430+
cfg.tc_bw_validator = BandwidthValidator({"tc3": 20, "tc4": 80})
445431

446432
cases = [test_no_tc_mapping_bandwidth, test_tc_mapping_bandwidth]
447433

0 commit comments

Comments
 (0)