Path: blob/master/tools/testing/selftests/drivers/net/netcons_torture.sh
38226 views
#!/usr/bin/env bash1# SPDX-License-Identifier: GPL-2.023# Repeatedly send kernel messages, toggles netconsole targets on and off,4# creates and deletes targets in parallel, and toggles the source interface to5# simulate stress conditions.6#7# This test aims to verify the robustness of netconsole under dynamic8# configurations and concurrent operations.9#10# The major goal is to run this test with LOCKDEP, Kmemleak and KASAN to make11# sure no issues is reported.12#13# Author: Breno Leitao <[email protected]>1415set -euo pipefail1617SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")1819source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh2021# Number of times the main loop run22ITERATIONS=${1:-150}2324# Only test extended format25FORMAT="extended"26# And ipv6 only27IP_VERSION="ipv6"2829# Create, enable and delete some targets.30create_and_delete_random_target() {31COUNT=232RND_PREFIX=$(mktemp -u netcons_rnd_XXXX_)3334if [ -d "${NETCONS_CONFIGFS}/${RND_PREFIX}${COUNT}" ] || \35[ -d "${NETCONS_CONFIGFS}/${RND_PREFIX}0" ]; then36echo "Function didn't finish yet, skipping it." >&237return38fi3940# enable COUNT targets41for i in $(seq ${COUNT})42do43RND_TARGET="${RND_PREFIX}"${i}44RND_TARGET_PATH="${NETCONS_CONFIGFS}"/"${RND_TARGET}"4546# Basic population so the target can come up47_create_dynamic_target "${FORMAT}" "${RND_TARGET_PATH}"48done4950echo "netconsole selftest: ${COUNT} additional targets were created" > /dev/kmsg51# disable them all52for i in $(seq ${COUNT})53do54RND_TARGET="${RND_PREFIX}"${i}55RND_TARGET_PATH="${NETCONS_CONFIGFS}"/"${RND_TARGET}"56if [[ $(cat "${RND_TARGET_PATH}/enabled") -eq 1 ]]57then58echo 0 > "${RND_TARGET_PATH}"/enabled59fi60rmdir "${RND_TARGET_PATH}"61done62}6364# Disable and enable the target mid-air, while messages65# are being transmitted.66toggle_netcons_target() {67for i in $(seq 2)68do69if [ ! -d "${NETCONS_PATH}" ]70then71break72fi73echo 0 > "${NETCONS_PATH}"/enabled 2> /dev/null || true74# Try to enable a bit harder, given it might fail to enable75# Write to `enabled` might fail depending on the lock, which is76# highly contentious here77for _ in $(seq 5)78do79echo 1 > "${NETCONS_PATH}"/enabled 2> /dev/null || true80done81done82}8384toggle_iface(){85ip link set "${SRCIF}" down86ip link set "${SRCIF}" up87}8889# Start here9091modprobe netdevsim 2> /dev/null || true92modprobe netconsole 2> /dev/null || true9394# Check for basic system dependency and exit if not found95check_for_dependencies96# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)97echo "6 5" > /proc/sys/kernel/printk98# Remove the namespace, interfaces and netconsole target on exit99trap cleanup EXIT100# Create one namespace and two interfaces101set_network "${IP_VERSION}"102# Create a dynamic target for netconsole103create_dynamic_target "${FORMAT}"104105for i in $(seq "$ITERATIONS")106do107for _ in $(seq 10)108do109echo "${MSG}: ${TARGET} ${i}" > /dev/kmsg110done111wait112113if (( i % 30 == 0 )); then114toggle_netcons_target &115fi116117if (( i % 50 == 0 )); then118# create some targets, enable them, send msg and disable119# all in a parallel thread120create_and_delete_random_target &121fi122123if (( i % 70 == 0 )); then124toggle_iface &125fi126done127wait128129exit "${EXIT_STATUS}"130131132