tools/testing/selftests/drivers/net/hw/nic_timestamp.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/hw/nic_timestamp.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/hw/nic_timestamp.py- Extension
.py- Size
- 7126 bytes
- Lines
- 226
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
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
# pylint: disable=locally-disabled, invalid-name, attribute-defined-outside-init, too-few-public-methods
"""
Tests related to configuration of HW timestamping
"""
import errno
import ctypes
import fcntl
import socket
from lib.py import ksft_run, ksft_exit, ksft_ge, ksft_eq, KsftSkipEx
from lib.py import NetDrvEnv, EthtoolFamily, NlError
SIOCSHWTSTAMP = 0x89b0
SIOCGHWTSTAMP = 0x89b1
class hwtstamp_config(ctypes.Structure):
""" Python copy of struct hwtstamp_config """
_fields_ = [
("flags", ctypes.c_int),
("tx_type", ctypes.c_int),
("rx_filter", ctypes.c_int),
]
class ifreq(ctypes.Structure):
""" Python copy of struct ifreq """
_fields_ = [
("ifr_name", ctypes.c_char * 16),
("ifr_data", ctypes.POINTER(hwtstamp_config)),
]
def __get_hwtimestamp_support(cfg):
""" Retrieve supported configuration information """
try:
tsinfo = cfg.ethnl.tsinfo_get({'header': {'dev-name': cfg.ifname}})
except NlError as e:
if e.error == errno.EOPNOTSUPP:
raise KsftSkipEx("timestamping configuration is not supported") from e
raise
ctx = {}
tx = tsinfo.get('tx-types', {})
rx = tsinfo.get('rx-filters', {})
bits = tx.get('bits', {})
ctx['tx'] = bits.get('bit', [])
bits = rx.get('bits', {})
ctx['rx'] = bits.get('bit', [])
return ctx
def __get_hwtimestamp_config_ioctl(cfg):
""" Retrieve current TS configuration information (via ioctl) """
config = hwtstamp_config()
req = ifreq()
req.ifr_name = cfg.ifname.encode()
req.ifr_data = ctypes.pointer(config)
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
fcntl.ioctl(sock.fileno(), SIOCGHWTSTAMP, req)
sock.close()
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.