Path: blob/master/tools/testing/selftests/drivers/net/netcons_cmdline.sh
26292 views
#!/usr/bin/env bash1# SPDX-License-Identifier: GPL-2.023# This is a selftest to test cmdline arguments on netconsole.4# It exercises loading of netconsole from cmdline instead of the dynamic5# reconfiguration. This includes parsing the long netconsole= line and all the6# flow through init_netconsole().7#8# Author: Breno Leitao <[email protected]>910set -euo pipefail1112SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")1314source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh1516check_netconsole_module1718modprobe netdevsim 2> /dev/null || true19rmmod netconsole 2> /dev/null || true2021# The content of kmsg will be save to the following file22OUTPUT_FILE="/tmp/${TARGET}"2324# Check for basic system dependency and exit if not found25# check_for_dependencies26# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)27echo "6 5" > /proc/sys/kernel/printk28# Remove the namespace and network interfaces29trap do_cleanup EXIT30# Create one namespace and two interfaces31set_network32# Create the command line for netconsole, with the configuration from the33# function above34CMDLINE="$(create_cmdline_str)"3536# Load the module, with the cmdline set37modprobe netconsole "${CMDLINE}"3839# Listed for netconsole port inside the namespace and destination interface40listen_port_and_save_to "${OUTPUT_FILE}" &41# Wait for socat to start and listen to the port.42wait_local_port_listen "${NAMESPACE}" "${PORT}" udp43# Send the message44echo "${MSG}: ${TARGET}" > /dev/kmsg45# Wait until socat saves the file to disk46busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"47# Make sure the message was received in the dst part48# and exit49validate_msg "${OUTPUT_FILE}"5051exit "${ksft_pass}"525354