tools/testing/selftests/drivers/net/xdp.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/xdp.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/xdp.py- Extension
.py- Size
- 26598 bytes
- Lines
- 757
- 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
"""
This file contains tests to verify native XDP support in network drivers.
The tests utilize the BPF program `xdp_native.bpf.o` from the `selftests.net.lib`
directory, with each test focusing on a specific aspect of XDP functionality.
"""
import random
import string
from dataclasses import dataclass
from enum import Enum
from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_ge, ksft_ne, ksft_pr
from lib.py import KsftNamedVariant, ksft_variants
from lib.py import KsftFailEx, KsftSkipEx, NetDrvEpEnv
from lib.py import EthtoolFamily, NetdevFamily, NlError
from lib.py import bkg, cmd, rand_port, wait_port_listen
from lib.py import ip, defer
from lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
class TestConfig(Enum):
"""Enum for XDP configuration options."""
MODE = 0 # Configures the BPF program for a specific test
PORT = 1 # Port configuration to communicate with the remote host
ADJST_OFFSET = 2 # Tail/Head adjustment offset for extension/shrinking
ADJST_TAG = 3 # Adjustment tag to annotate the start and end of extension
class XDPAction(Enum):
"""Enum for XDP actions."""
PASS = 0 # Pass the packet up to the stack
DROP = 1 # Drop the packet
TX = 2 # Route the packet to the remote host
TAIL_ADJST = 3 # Adjust the tail of the packet
HEAD_ADJST = 4 # Adjust the head of the packet
class XDPStats(Enum):
"""Enum for XDP statistics."""
RX = 0 # Count of valid packets received for testing
PASS = 1 # Count of packets passed up to the stack
DROP = 2 # Count of packets dropped
TX = 3 # Count of incoming packets routed to the remote host
ABORT = 4 # Count of packets that were aborted
@dataclass
class BPFProgInfo:
"""Data class to store information about a BPF program."""
name: str # Name of the BPF program
file: str # BPF program object file
xdp_sec: str = "xdp" # XDP section name (e.g., "xdp" or "xdp.frags")
mtu: int = 1500 # Maximum Transmission Unit, default is 1500
def _exchg_udp(cfg, port, test_string):
"""
Exchanges UDP packets between a local and remote host using the socat tool.
Args:
cfg: Configuration object containing network settings.
port: Port number to use for the UDP communication.
test_string: String that the remote host will send.
Returns:
The string received by the test host.
"""
cfg.require_cmd("socat", remote=True)
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.