Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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# Check for basic system dependency and exit if not found
23# check_for_dependencies
24# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)
25echo "6 5" > /proc/sys/kernel/printk
26# Remove the namespace and network interfaces
27trap do_cleanup EXIT
28# Create one namespace and two interfaces
29set_network
30
31# Run the test twice, with different cmdline parameters
32for BINDMODE in "ifname" "mac"
33do
34 echo "Running with bind mode: ${BINDMODE}" >&2
35 # Create the command line for netconsole, with the configuration from
36 # the function above
37 CMDLINE=$(create_cmdline_str "${BINDMODE}")
38
39 # The content of kmsg will be save to the following file
40 OUTPUT_FILE="/tmp/${TARGET}-${BINDMODE}"
41
42 # Load the module, with the cmdline set
43 modprobe netconsole "${CMDLINE}"
44
45 # Listed for netconsole port inside the namespace and destination
46 # interface
47 listen_port_and_save_to "${OUTPUT_FILE}" &
48 # Wait for socat to start and listen to the port.
49 wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
50 # Send the message
51 echo "${MSG}: ${TARGET}" > /dev/kmsg
52 # Wait until socat saves the file to disk
53 busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
54 # Make sure the message was received in the dst part
55 # and exit
56 validate_msg "${OUTPUT_FILE}"
57
58 # kill socat in case it is still running
59 pkill_socat
60 # Unload the module
61 rmmod netconsole
62 echo "${BINDMODE} : Test passed" >&2
63done
64
65exit "${ksft_pass}"