xref: /linux/tools/testing/selftests/drivers/net/netconsole/netcons_cmdline.sh (revision 37a93dd5c49b5fda807fd204edf2547c3493319c)
1*b3827c91SAndre Carvalho#!/usr/bin/env bash
2*b3827c91SAndre Carvalho# SPDX-License-Identifier: GPL-2.0
3*b3827c91SAndre Carvalho
4*b3827c91SAndre Carvalho# This is a selftest to test cmdline arguments on netconsole.
5*b3827c91SAndre Carvalho# It exercises loading of netconsole from cmdline instead of the dynamic
6*b3827c91SAndre Carvalho# reconfiguration. This includes parsing the long netconsole= line and all the
7*b3827c91SAndre Carvalho# flow through init_netconsole().
8*b3827c91SAndre Carvalho#
9*b3827c91SAndre Carvalho# Author: Breno Leitao <leitao@debian.org>
10*b3827c91SAndre Carvalho
11*b3827c91SAndre Carvalhoset -euo pipefail
12*b3827c91SAndre Carvalho
13*b3827c91SAndre CarvalhoSCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
14*b3827c91SAndre Carvalho
15*b3827c91SAndre Carvalhosource "${SCRIPTDIR}"/../lib/sh/lib_netcons.sh
16*b3827c91SAndre Carvalho
17*b3827c91SAndre Carvalhocheck_netconsole_module
18*b3827c91SAndre Carvalho
19*b3827c91SAndre Carvalhomodprobe netdevsim 2> /dev/null || true
20*b3827c91SAndre Carvalhormmod netconsole 2> /dev/null || true
21*b3827c91SAndre Carvalho
22*b3827c91SAndre Carvalho# Check for basic system dependency and exit if not found
23*b3827c91SAndre Carvalho# check_for_dependencies
24*b3827c91SAndre Carvalho# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)
25*b3827c91SAndre Carvalhoecho "6 5" > /proc/sys/kernel/printk
26*b3827c91SAndre Carvalho# Remove the namespace and network interfaces
27*b3827c91SAndre Carvalhotrap do_cleanup EXIT
28*b3827c91SAndre Carvalho# Create one namespace and two interfaces
29*b3827c91SAndre Carvalhoset_network
30*b3827c91SAndre Carvalho
31*b3827c91SAndre Carvalho# Run the test twice, with different cmdline parameters
32*b3827c91SAndre Carvalhofor BINDMODE in "ifname" "mac"
33*b3827c91SAndre Carvalhodo
34*b3827c91SAndre Carvalho	echo "Running with bind mode: ${BINDMODE}" >&2
35*b3827c91SAndre Carvalho	# Create the command line for netconsole, with the configuration from
36*b3827c91SAndre Carvalho	# the function above
37*b3827c91SAndre Carvalho	CMDLINE=$(create_cmdline_str "${BINDMODE}")
38*b3827c91SAndre Carvalho
39*b3827c91SAndre Carvalho	# The content of kmsg will be save to the following file
40*b3827c91SAndre Carvalho	OUTPUT_FILE="/tmp/${TARGET}-${BINDMODE}"
41*b3827c91SAndre Carvalho
42*b3827c91SAndre Carvalho	# Load the module, with the cmdline set
43*b3827c91SAndre Carvalho	modprobe netconsole "${CMDLINE}"
44*b3827c91SAndre Carvalho
45*b3827c91SAndre Carvalho	# Listed for netconsole port inside the namespace and destination
46*b3827c91SAndre Carvalho	# interface
47*b3827c91SAndre Carvalho	listen_port_and_save_to "${OUTPUT_FILE}" &
48*b3827c91SAndre Carvalho	# Wait for socat to start and listen to the port.
49*b3827c91SAndre Carvalho	wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
50*b3827c91SAndre Carvalho	# Send the message
51*b3827c91SAndre Carvalho	echo "${MSG}: ${TARGET}" > /dev/kmsg
52*b3827c91SAndre Carvalho	# Wait until socat saves the file to disk
53*b3827c91SAndre Carvalho	busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
54*b3827c91SAndre Carvalho	# Make sure the message was received in the dst part
55*b3827c91SAndre Carvalho	# and exit
56*b3827c91SAndre Carvalho	validate_msg "${OUTPUT_FILE}"
57*b3827c91SAndre Carvalho
58*b3827c91SAndre Carvalho	# kill socat in case it is still running
59*b3827c91SAndre Carvalho	pkill_socat
60*b3827c91SAndre Carvalho	# Unload the module
61*b3827c91SAndre Carvalho	rmmod netconsole
62*b3827c91SAndre Carvalho	echo "${BINDMODE} : Test passed" >&2
63*b3827c91SAndre Carvalhodone
64*b3827c91SAndre Carvalho
65*b3827c91SAndre Carvalhoexit "${ksft_pass}"
66