Path: blob/master/tools/testing/selftests/drivers/net/netcons_cmdline.sh
29270 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# Check for basic system dependency and exit if not found22# check_for_dependencies23# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)24echo "6 5" > /proc/sys/kernel/printk25# Remove the namespace and network interfaces26trap do_cleanup EXIT27# Create one namespace and two interfaces28set_network2930# Run the test twice, with different cmdline parameters31for BINDMODE in "ifname" "mac"32do33echo "Running with bind mode: ${BINDMODE}" >&234# Create the command line for netconsole, with the configuration from35# the function above36CMDLINE=$(create_cmdline_str "${BINDMODE}")3738# The content of kmsg will be save to the following file39OUTPUT_FILE="/tmp/${TARGET}-${BINDMODE}"4041# Load the module, with the cmdline set42modprobe netconsole "${CMDLINE}"4344# Listed for netconsole port inside the namespace and destination45# interface46listen_port_and_save_to "${OUTPUT_FILE}" &47# Wait for socat to start and listen to the port.48wait_local_port_listen "${NAMESPACE}" "${PORT}" udp49# Send the message50echo "${MSG}: ${TARGET}" > /dev/kmsg51# Wait until socat saves the file to disk52busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"53# Make sure the message was received in the dst part54# and exit55validate_msg "${OUTPUT_FILE}"5657# kill socat in case it is still running58pkill_socat59# Unload the module60rmmod netconsole61echo "${BINDMODE} : Test passed" >&262done6364exit "${ksft_pass}"656667