Path: blob/master/tools/testing/selftests/drivers/net/netcons_basic.sh
48888 views
#!/usr/bin/env bash1# SPDX-License-Identifier: GPL-2.023# This test creates two netdevsim virtual interfaces, assigns one of them (the4# "destination interface") to a new namespace, and assigns IP addresses to both5# interfaces.6#7# It listens on the destination interface using socat and configures a dynamic8# target on netconsole, pointing to the destination IP address.9#10# Finally, it checks whether the message was received properly on the11# destination interface. Note that this test may pollute the kernel log buffer12# (dmesg) and relies on dynamic configuration and namespaces being configured.13#14# Author: Breno Leitao <[email protected]>1516set -euo pipefail1718SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")1920source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh2122modprobe netdevsim 2> /dev/null || true23modprobe netconsole 2> /dev/null || true2425# The content of kmsg will be save to the following file26OUTPUT_FILE="/tmp/${TARGET}"2728# Check for basic system dependency and exit if not found29check_for_dependencies30# Remove the namespace, interfaces and netconsole target on exit31trap cleanup EXIT3233# Run the test twice, with different format modes34for FORMAT in "basic" "extended"35do36for IP_VERSION in "ipv6" "ipv4"37do38echo "Running with target mode: ${FORMAT} (${IP_VERSION})"39# Set current loglevel to KERN_INFO(6), and default to40# KERN_NOTICE(5)41echo "6 5" > /proc/sys/kernel/printk42# Create one namespace and two interfaces43set_network "${IP_VERSION}"44# Create a dynamic target for netconsole45create_dynamic_target "${FORMAT}"46# Only set userdata for extended format47if [ "$FORMAT" == "extended" ]48then49# Set userdata "key" with the "value" value50set_user_data51fi52# Listed for netconsole port inside the namespace and53# destination interface54listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" &55# Wait for socat to start and listen to the port.56wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}"57# Send the message58echo "${MSG}: ${TARGET}" > /dev/kmsg59# Wait until socat saves the file to disk60busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"6162# Make sure the message was received in the dst part63# and exit64validate_result "${OUTPUT_FILE}" "${FORMAT}"65# kill socat in case it is still running66pkill_socat67cleanup68echo "${FORMAT} : ${IP_VERSION} : Test passed" >&269done70done7172trap - EXIT73exit "${ksft_pass}"747576