tools/testing/selftests/drivers/net/netconsole/netcons_basic.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/netconsole/netcons_basic.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/netconsole/netcons_basic.sh- Extension
.sh- Size
- 2552 bytes
- Lines
- 79
- 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 bash
# SPDX-License-Identifier: GPL-2.0
# This test creates two netdevsim virtual interfaces, assigns one of them (the
# "destination interface") to a new namespace, and assigns IP addresses to both
# interfaces.
#
# It listens on the destination interface using socat and configures a dynamic
# target on netconsole, pointing to the destination IP address.
#
# Finally, it checks whether the message was received properly on the
# destination interface. Note that this test may pollute the kernel log buffer
# (dmesg) and relies on dynamic configuration and namespaces being configured.
#
# Author: Breno Leitao <leitao@debian.org>
set -euo pipefail
SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
source "${SCRIPTDIR}"/../lib/sh/lib_netcons.sh
modprobe netdevsim 2> /dev/null || true
modprobe netconsole 2> /dev/null || true
# The content of kmsg will be save to the following file
OUTPUT_FILE="/tmp/${TARGET}"
# Check for basic system dependency and exit if not found
check_for_dependencies
# Remove the namespace, interfaces and netconsole target on exit
trap cleanup EXIT
# Run the test twice, with different format modes
for FORMAT in "basic" "extended"
do
for IP_VERSION in "ipv6" "ipv4"
do
echo "Running with target mode: ${FORMAT} (${IP_VERSION})"
# Set current loglevel to KERN_INFO(6), and default to
# KERN_NOTICE(5)
echo "6 5" > /proc/sys/kernel/printk
# Create one namespace and two interfaces
set_network "${IP_VERSION}"
# Create a dynamic target for netconsole
create_dynamic_target "${FORMAT}"
# Only set userdata for extended format
if [ "$FORMAT" == "extended" ]
then
# Set userdata "key" with the "value" value
set_user_data
fi
# Listed for netconsole port inside the namespace and
# destination interface
listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" &
# Wait for socat to start and listen to the port.
wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}"
# Send the message
echo "${MSG}: ${TARGET}" > /dev/kmsg
# Wait until socat saves the file to disk
if ! busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
then
echo "FAIL: Timed out waiting (${BUSYWAIT_TIMEOUT} ms) for netconsole message in ${OUTPUT_FILE}" >&2
exit "${ksft_fail}"
fi
# Make sure the message was received in the dst part
# and exit
validate_result "${OUTPUT_FILE}" "${FORMAT}"
# kill socat in case it is still running
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.