tools/testing/selftests/net/nl_nlctrl.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/nl_nlctrl.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/nl_nlctrl.py- Extension
.py- Size
- 4625 bytes
- Lines
- 132
- 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
"""
Tests for the nlctrl genetlink family (family info and policy dumps).
"""
from lib.py import ksft_run, ksft_exit
from lib.py import ksft_eq, ksft_ge, ksft_true, ksft_in, ksft_not_in
from lib.py import NetdevFamily, EthtoolFamily, NlctrlFamily
def getfamily_do(ctrl) -> None:
"""Query a single family by name and validate its ops."""
fam = ctrl.getfamily({'family-name': 'netdev'})
ksft_eq(fam['family-name'], 'netdev')
ksft_true(fam['family-id'] > 0)
# The format of ops is quite odd, [{$idx: {"id"...}}, {$idx: {"id"...}}]
# Discard the indices and re-key by command id.
ops_by_id = {v['id']: v for op in fam['ops'] for v in op.values()}
ksft_eq(len(ops_by_id), len(fam['ops']))
# All ops should have a policy (either do or dump has one)
for op in ops_by_id.values():
ksft_in('cmd-cap-haspol', op['flags'],
comment=f"op {op['id']} missing haspol")
# dev-get (id 1) should support both do and dump
ksft_in('cmd-cap-do', ops_by_id[1]['flags'])
ksft_in('cmd-cap-dump', ops_by_id[1]['flags'])
# qstats-get (id 12) is dump-only
ksft_not_in('cmd-cap-do', ops_by_id[12]['flags'])
ksft_in('cmd-cap-dump', ops_by_id[12]['flags'])
# napi-set (id 14) is do-only and requires admin
ksft_in('cmd-cap-do', ops_by_id[14]['flags'])
ksft_not_in('cmd-cap-dump', ops_by_id[14]['flags'])
ksft_in('admin-perm', ops_by_id[14]['flags'])
# Notification-only commands (dev-add/del/change-ntf etc.) must
# not appear in the ops list since they have no do/dump handlers.
for ntf_id in [2, 3, 4, 6, 7, 8]:
ksft_not_in(ntf_id, ops_by_id,
comment=f"ntf-only cmd {ntf_id} should not be in ops")
def getfamily_dump(ctrl) -> None:
"""Dump all families and verify expected entries."""
families = ctrl.getfamily({}, dump=True)
ksft_ge(len(families), 2)
names = [f['family-name'] for f in families]
ksft_in('nlctrl', names, comment="nlctrl not found in family dump")
ksft_in('netdev', names, comment="netdev not found in family dump")
def getpolicy_dump(_ctrl) -> None:
"""Dump policies for ops using get_policy() and validate results.
Test with netdev (split ops) where do and dump can have different
policies, and with ethtool (full ops) where they always share one.
"""
# -- netdev (split ops) --
ndev = NetdevFamily()
# dev-get: do has a real policy with ifindex, dump has no policy
# (only the reject-all policy with maxattr=0)
pol = ndev.get_policy('dev-get', 'do')
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.