selftests: net: move wait_local_port_listen to lib.sh

The function wait_local_port_listen() is the only function defined in
net_helper.sh. Since some tests source both lib.sh and net_helper.sh,
we can simplify the setup by moving wait_local_port_listen() to lib.sh.

With this change, net_helper.sh becomes redundant and can be removed.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250526014600.9128-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Hangbin Liu 2025-05-26 01:46:00 +00:00 committed by Jakub Kicinski
parent 08f8bad025
commit d9d836bfa5
15 changed files with 29 additions and 38 deletions

View File

@ -3,7 +3,6 @@ CFLAGS += $(KHDR_INCLUDES)
TEST_INCLUDES := $(wildcard lib/py/*.py) \
$(wildcard lib/sh/*.sh) \
../../net/net_helper.sh \
../../net/lib.sh \
TEST_GEN_FILES := \

View File

@ -33,7 +33,6 @@ NSIM_DEV_SYS_NEW="/sys/bus/netdevsim/new_device"
# Used to create and delete namespaces
source "${LIBDIR}"/../../../../net/lib.sh
source "${LIBDIR}"/../../../../net/net_helper.sh
# Create netdevsim interfaces
create_ifaces() {

View File

@ -1,7 +1,7 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
source ../../../net/net_helper.sh
source ../../../net/lib.sh
NSIM_DEV_1_ID=$((256 + RANDOM % 256))
NSIM_DEV_1_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_DEV_1_ID

View File

@ -115,7 +115,7 @@ YNL_GEN_FILES := busy_poller netlink-dumps
TEST_GEN_FILES += $(YNL_GEN_FILES)
TEST_FILES := settings
TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh
TEST_FILES += in_netns.sh lib.sh setup_loopback.sh setup_veth.sh
TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c))

View File

@ -1,6 +1,6 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
source net_helper.sh
source lib.sh
NSIM_SV_ID=$((256 + RANDOM % 256))
NSIM_SV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_SV_ID

View File

@ -69,7 +69,6 @@
# which can affect the conditions needed to trigger a soft lockup.
source lib.sh
source net_helper.sh
TEST_DURATION=300
ROUTING_TABLE_REFRESH_PERIOD=0.01

View File

@ -595,3 +595,24 @@ bridge_vlan_add()
bridge vlan add "$@"
defer bridge vlan del "$@"
}
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"
local protocol="${3}"
local pattern
local i
pattern=":$(printf "%04X" "${port}") "
# for tcp protocol additionally check the socket state
[ ${protocol} = "tcp" ] && pattern="${pattern}0A"
for i in $(seq 10); do
if ip netns exec "${listener_ns}" awk '{print $2" "$4}' \
/proc/net/"${protocol}"* | grep -q "${pattern}"; then
break
fi
sleep 0.1
done
}

View File

@ -11,7 +11,7 @@ TEST_GEN_FILES = mptcp_connect pm_nl_ctl mptcp_sockopt mptcp_inq mptcp_diag
TEST_FILES := mptcp_lib.sh settings
TEST_INCLUDES := ../lib.sh $(wildcard ../lib/sh/*.sh) ../net_helper.sh
TEST_INCLUDES := ../lib.sh $(wildcard ../lib/sh/*.sh)
EXTRA_CLEAN := *.pcap

View File

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-2.0
. "$(dirname "${0}")/../lib.sh"
. "$(dirname "${0}")/../net_helper.sh"
readonly KSFT_PASS=0
readonly KSFT_FAIL=1

View File

@ -1,25 +0,0 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Helper functions
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"
local protocol="${3}"
local pattern
local i
pattern=":$(printf "%04X" "${port}") "
# for tcp protocol additionally check the socket state
[ ${protocol} = "tcp" ] && pattern="${pattern}0A"
for i in $(seq 10); do
if ip netns exec "${listener_ns}" awk '{print $2" "$4}' \
/proc/net/"${protocol}"* | grep -q "${pattern}"; then
break
fi
sleep 0.1
done
}

View File

@ -205,7 +205,6 @@
# Check that PMTU exceptions are created for both paths.
source lib.sh
source net_helper.sh
PAUSE_ON_FAIL=no
VERBOSE=0

View File

@ -3,7 +3,7 @@
#
# Run a series of udpgro functional tests.
source net_helper.sh
source lib.sh
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"

View File

@ -3,7 +3,7 @@
#
# Run a series of udpgro benchmarks
source net_helper.sh
source lib.sh
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"

View File

@ -3,7 +3,7 @@
#
# Run a series of udpgro benchmarks
source net_helper.sh
source lib.sh
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
source net_helper.sh
source lib.sh
BPF_FILE="lib/xdp_dummy.bpf.o"
readonly BASE="ns-$(mktemp -u XXXXXX)"