tools/testing/selftests/drivers/net/shaper.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/shaper.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/shaper.py- Extension
.py- Size
- 20210 bytes
- Lines
- 482
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
import errno
from lib.py import ksft_run, ksft_exit
from lib.py import ksft_eq, ksft_raises, ksft_true, KsftSkipEx
from lib.py import EthtoolFamily, NetshaperFamily
from lib.py import NetDrvEnv
from lib.py import NlError
from lib.py import cmd
def get_shapers(cfg, nl_shaper) -> None:
try:
shapers = nl_shaper.get({'ifindex': cfg.ifindex}, dump=True)
except NlError as e:
if e.error == 95:
raise KsftSkipEx("shapers not supported by the device")
raise
# Default configuration: no shapers configured.
ksft_eq(len(shapers), 0)
def get_caps(cfg, nl_shaper) -> None:
try:
caps = nl_shaper.cap_get({'ifindex': cfg.ifindex}, dump=True)
except NlError as e:
if e.error == 95:
raise KsftSkipEx("shapers not supported by the device")
raise
# Each device implementing shaper support must support some
# features in at least a scope.
ksft_true(len(caps)> 0)
def set_qshapers(cfg, nl_shaper) -> None:
try:
caps = nl_shaper.cap_get({'ifindex': cfg.ifindex,
'scope':'queue'})
except NlError as e:
if e.error == 95:
raise KsftSkipEx("shapers not supported by the device")
raise
if not 'support-bw-max' in caps or not 'support-metric-bps' in caps:
raise KsftSkipEx("device does not support queue scope shapers with bw_max and metric bps")
cfg.queues = True;
netnl = EthtoolFamily()
channels = netnl.channels_get({'header': {'dev-index': cfg.ifindex}})
if channels['combined-count'] == 0:
cfg.rx_type = 'rx'
cfg.nr_queues = channels['rx-count']
else:
cfg.rx_type = 'combined'
cfg.nr_queues = channels['combined-count']
if cfg.nr_queues < 3:
raise KsftSkipEx(f"device does not support enough queues min 3 found {cfg.nr_queues}")
nl_shaper.set({'ifindex': cfg.ifindex,
'handle': {'scope': 'queue', 'id': 1},
'metric': 'bps',
'bw-max': 10000})
nl_shaper.set({'ifindex': cfg.ifindex,
'handle': {'scope': 'queue', 'id': 2},
'metric': 'bps',
'bw-max': 20000})
# Querying a specific shaper not yet configured must fail.
raised = False
try:
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.