Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/selftests/drivers/net/netcons_cmdline.sh
26292 views
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 <[email protected]>
10
11
set -euo pipefail
12
13
SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
14
15
source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh
16
17
check_netconsole_module
18
19
modprobe netdevsim 2> /dev/null || true
20
rmmod netconsole 2> /dev/null || true
21
22
# The content of kmsg will be save to the following file
23
OUTPUT_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)
28
echo "6 5" > /proc/sys/kernel/printk
29
# Remove the namespace and network interfaces
30
trap do_cleanup EXIT
31
# Create one namespace and two interfaces
32
set_network
33
# Create the command line for netconsole, with the configuration from the
34
# function above
35
CMDLINE="$(create_cmdline_str)"
36
37
# Load the module, with the cmdline set
38
modprobe netconsole "${CMDLINE}"
39
40
# Listed for netconsole port inside the namespace and destination interface
41
listen_port_and_save_to "${OUTPUT_FILE}" &
42
# Wait for socat to start and listen to the port.
43
wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
44
# Send the message
45
echo "${MSG}: ${TARGET}" > /dev/kmsg
46
# Wait until socat saves the file to disk
47
busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
48
# Make sure the message was received in the dst part
49
# and exit
50
validate_msg "${OUTPUT_FILE}"
51
52
exit "${ksft_pass}"
53
54