selftests: netconsole: Validate interface selection by MAC address
authorAndre Carvalho <asantostc@gmail.com>
Tue, 12 Aug 2025 19:38:23 +0000 (20:38 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 14 Aug 2025 00:28:27 +0000 (17:28 -0700)
Extend the existing netconsole cmdline selftest to also validate that
interface selection can be performed via MAC address.

The test now validates that netconsole works with both interface name
and MAC address, improving test coverage.

Suggested-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Andre Carvalho <asantostc@gmail.com>
Link: https://patch.msgid.link/20250812-netcons-cmdline-selftest-v2-1-8099fb7afa9e@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh
tools/testing/selftests/drivers/net/netcons_cmdline.sh

index b6071e8..8e1085e 100644 (file)
@@ -148,12 +148,20 @@ function create_dynamic_target() {
 # Generate the command line argument for netconsole following:
 #  netconsole=[+][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
 function create_cmdline_str() {
+       local BINDMODE=${1:-"ifname"}
+       if [ "${BINDMODE}" == "ifname" ]
+       then
+               SRCDEV=${SRCIF}
+       else
+               SRCDEV=$(mac_get "${SRCIF}")
+       fi
+
        DSTMAC=$(ip netns exec "${NAMESPACE}" \
                 ip link show "${DSTIF}" | awk '/ether/ {print $2}')
        SRCPORT="1514"
        TGTPORT="6666"
 
-       echo "netconsole=\"+${SRCPORT}@${SRCIP}/${SRCIF},${TGTPORT}@${DSTIP}/${DSTMAC}\""
+       echo "netconsole=\"+${SRCPORT}@${SRCIP}/${SRCDEV},${TGTPORT}@${DSTIP}/${DSTMAC}\""
 }
 
 # Do not append the release to the header of the message
index ad2fb8b..d1d23dc 100755 (executable)
@@ -19,9 +19,6 @@ check_netconsole_module
 modprobe netdevsim 2> /dev/null || true
 rmmod netconsole 2> /dev/null || true
 
-# The content of kmsg will be save to the following file
-OUTPUT_FILE="/tmp/${TARGET}"
-
 # Check for basic system dependency and exit if not found
 # check_for_dependencies
 # Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)
@@ -30,23 +27,39 @@ echo "6 5" > /proc/sys/kernel/printk
 trap do_cleanup EXIT
 # Create one namespace and two interfaces
 set_network
-# Create the command line for netconsole, with the configuration from the
-# function above
-CMDLINE="$(create_cmdline_str)"
-
-# Load the module, with the cmdline set
-modprobe netconsole "${CMDLINE}"
-
-# Listed for netconsole port inside the namespace and destination interface
-listen_port_and_save_to "${OUTPUT_FILE}" &
-# Wait for socat to start and listen to the port.
-wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
-# Send the message
-echo "${MSG}: ${TARGET}" > /dev/kmsg
-# Wait until socat saves the file to disk
-busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
-# Make sure the message was received in the dst part
-# and exit
-validate_msg "${OUTPUT_FILE}"
+
+# Run the test twice, with different cmdline parameters
+for BINDMODE in "ifname" "mac"
+do
+       echo "Running with bind mode: ${BINDMODE}" >&2
+       # Create the command line for netconsole, with the configuration from
+       # the function above
+       CMDLINE=$(create_cmdline_str "${BINDMODE}")
+
+       # The content of kmsg will be save to the following file
+       OUTPUT_FILE="/tmp/${TARGET}-${BINDMODE}"
+
+       # Load the module, with the cmdline set
+       modprobe netconsole "${CMDLINE}"
+
+       # Listed for netconsole port inside the namespace and destination
+       # interface
+       listen_port_and_save_to "${OUTPUT_FILE}" &
+       # Wait for socat to start and listen to the port.
+       wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
+       # Send the message
+       echo "${MSG}: ${TARGET}" > /dev/kmsg
+       # Wait until socat saves the file to disk
+       busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
+       # Make sure the message was received in the dst part
+       # and exit
+       validate_msg "${OUTPUT_FILE}"
+
+       # kill socat in case it is still running
+       pkill_socat
+       # Unload the module
+       rmmod netconsole
+       echo "${BINDMODE} : Test passed" >&2
+done
 
 exit "${ksft_pass}"