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