Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest: netcons: refactor target creation

Extract the netconsole target creation from create_dynamic_target(), by
moving it from create_dynamic_target() into a new helper function. This
enables other tests to use the creation of netconsole targets with
arbitrary parameters and no sleep.

The new helper will be utilized by forthcoming torture-type selftests
that require dynamic target management.

Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20251107-netconsole_torture-v10-2-749227b55f63@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Breno Leitao and committed by
Jakub Kicinski
39acc6a9 49c8d2c1

+19 -11
+19 -11
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh
··· 113 113 configure_ip 114 114 } 115 115 116 - function create_dynamic_target() { 117 - local FORMAT=${1:-"extended"} 116 + function _create_dynamic_target() { 117 + local FORMAT="${1:?FORMAT parameter required}" 118 + local NCPATH="${2:?NCPATH parameter required}" 118 119 119 120 DSTMAC=$(ip netns exec "${NAMESPACE}" \ 120 121 ip link show "${DSTIF}" | awk '/ether/ {print $2}') 121 122 122 123 # Create a dynamic target 123 - mkdir "${NETCONS_PATH}" 124 + mkdir "${NCPATH}" 124 125 125 - echo "${DSTIP}" > "${NETCONS_PATH}"/remote_ip 126 - echo "${SRCIP}" > "${NETCONS_PATH}"/local_ip 127 - echo "${DSTMAC}" > "${NETCONS_PATH}"/remote_mac 128 - echo "${SRCIF}" > "${NETCONS_PATH}"/dev_name 126 + echo "${DSTIP}" > "${NCPATH}"/remote_ip 127 + echo "${SRCIP}" > "${NCPATH}"/local_ip 128 + echo "${DSTMAC}" > "${NCPATH}"/remote_mac 129 + echo "${SRCIF}" > "${NCPATH}"/dev_name 129 130 130 131 if [ "${FORMAT}" == "basic" ] 131 132 then 132 133 # Basic target does not support release 133 - echo 0 > "${NETCONS_PATH}"/release 134 - echo 0 > "${NETCONS_PATH}"/extended 134 + echo 0 > "${NCPATH}"/release 135 + echo 0 > "${NCPATH}"/extended 135 136 elif [ "${FORMAT}" == "extended" ] 136 137 then 137 - echo 1 > "${NETCONS_PATH}"/extended 138 + echo 1 > "${NCPATH}"/extended 138 139 fi 139 140 140 - echo 1 > "${NETCONS_PATH}"/enabled 141 + echo 1 > "${NCPATH}"/enabled 142 + 143 + } 144 + 145 + function create_dynamic_target() { 146 + local FORMAT=${1:-"extended"} 147 + local NCPATH=${2:-"$NETCONS_PATH"} 148 + _create_dynamic_target "${FORMAT}" "${NCPATH}" 141 149 142 150 # This will make sure that the kernel was able to 143 151 # load the netconsole driver configuration. The console message