Add a test which creates two targets whose names start with the same seven characters, so that netcons_ is cut to the same console name for both, and checks that /proc/consoles lists a different console for each of them. It fails without the previous patch: # ./netcons_console_name.sh FAIL: targets 9gqXFYF_alpha 9gqXFYF_beta share a console name in /proc/consoles: netcons_9gqXFYF0 netcons_9gqXFYF0 Signed-off-by: Chris Down --- .../selftests/drivers/net/netconsole/Makefile | 1 + .../net/netconsole/netcons_console_name.sh | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/netconsole/netcons_console_name.sh diff --git a/tools/testing/selftests/drivers/net/netconsole/Makefile b/tools/testing/selftests/drivers/net/netconsole/Makefile index c7972a40babf..0a689d75aed4 100644 --- a/tools/testing/selftests/drivers/net/netconsole/Makefile +++ b/tools/testing/selftests/drivers/net/netconsole/Makefile @@ -9,6 +9,7 @@ TEST_INCLUDES := \ TEST_PROGS := \ netcons_basic.sh \ netcons_cmdline.sh \ + netcons_console_name.sh \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ netcons_resume.sh \ diff --git a/tools/testing/selftests/drivers/net/netconsole/netcons_console_name.sh b/tools/testing/selftests/drivers/net/netconsole/netcons_console_name.sh new file mode 100755 index 000000000000..28a3f17f560d --- /dev/null +++ b/tools/testing/selftests/drivers/net/netconsole/netcons_console_name.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This test creates two netconsole targets whose names start with the same +# seven characters. The console of a target is called netcons_, +# cut to the 15 characters that fit in the name of a console, so the consoles +# of these two targets get the same name and only the index that follows it +# can tell them apart. +# +# The test checks that /proc/consoles lists a different console for each of +# the two targets. +# +# Author: Chris Down + +set -euo pipefail + +SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/../lib/sh/lib_netcons.sh + +# The seven characters that both target names start with +PREFIX=$(mktemp -u XXXXXXX) +CONSOLE="netcons_${PREFIX}" +TARGETS=("${PREFIX}_alpha" "${PREFIX}_beta") + +function cleanup() { + local T + + for T in "${TARGETS[@]}" + do + cleanup_netcons "${NETCONS_CONFIGFS}/${T}" + done + do_cleanup +} + +modprobe netdevsim 2> /dev/null || true +modprobe netconsole 2> /dev/null || true + +# Check for basic system dependency and exit if not found +check_for_dependencies +# Remove the namespace, interfaces and netconsole targets on exit +trap cleanup EXIT +# Create one namespace and two interfaces +set_network + +for T in "${TARGETS[@]}" +do + create_dynamic_target "extended" "${NETCONS_CONFIGFS}/${T}" +done + +# /proc/consoles starts each line with the name and the index of a console +NAMES=$(awk -v con="${CONSOLE}" 'index($1, con) == 1 { print $1 }' \ + /proc/consoles) +NR_CONSOLES=$(echo "${NAMES}" | grep -c . || true) +NR_NAMES=$(echo "${NAMES}" | sort -u | grep -c . || true) + +if [ "${NR_CONSOLES}" -ne "${#TARGETS[@]}" ] +then + echo "FAIL: found ${NR_CONSOLES} consoles called ${CONSOLE}, not ${#TARGETS[@]}" >&2 + exit "${ksft_fail}" +fi + +if [ "${NR_NAMES}" -ne "${NR_CONSOLES}" ] +then + echo "FAIL: targets ${TARGETS[*]} share a console name in /proc/consoles:" >&2 + echo "${NAMES}" >&2 + exit "${ksft_fail}" +fi + +exit "${ksft_pass}" -- 2.56.1