Skip to content

Commit

Permalink
Merge branch 'net-selftests-unique-namespace-last-part'
Browse files Browse the repository at this point in the history
Hangbin Liu says:

====================
Convert net selftests to run in unique namespace (last part)

Here is the last part of converting net selftests to run in unique namespace.
This part converts all left tests. After the conversion, we can run the net
sleftests in parallel. e.g.

 # ./run_kselftest.sh -n -t net:reuseport_bpf
 TAP version 13
 1..1
 # selftests: net: reuseport_bpf
 ok 1 selftests: net: reuseport_bpf
  mod 10...
 # Socket 0: 0
 # Socket 1: 1
 ...
 # Socket 4: 19
 # Testing filter add without bind...
 # SUCCESS

 # ./run_kselftest.sh -p -n -t net:cmsg_so_mark.sh -t net:cmsg_time.sh -t net:cmsg_ipv6.sh
 TAP version 13
 1..3
 # selftests: net: cmsg_so_mark.sh
 ok 1 selftests: net: cmsg_so_mark.sh
 # selftests: net: cmsg_time.sh
 ok 2 selftests: net: cmsg_time.sh
 # selftests: net: cmsg_ipv6.sh
 ok 3 selftests: net: cmsg_ipv6.sh

 # ./run_kselftest.sh -p -n -c net
 TAP version 13
 1..95
 # selftests: net: reuseport_bpf_numa
 ok 3 selftests: net: reuseport_bpf_numa
 # selftests: net: reuseport_bpf_cpu
 ok 2 selftests: net: reuseport_bpf_cpu
 # selftests: net: sk_bind_sendto_listen
 ok 9 selftests: net: sk_bind_sendto_listen
 # selftests: net: reuseaddr_conflict
 ok 5 selftests: net: reuseaddr_conflict
 ...

Here is the part 1 link:
https://lore.kernel.org/netdev/20231202020110.362433-1-liuhangbin@gmail.com
part 2 link:
https://lore.kernel.org/netdev/20231206070801.1691247-1-liuhangbin@gmail.com
part 3 link:
https://lore.kernel.org/netdev/20231213060856.4030084-1-liuhangbin@gmail.com
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Dec 23, 2023
2 parents 6530b29 + 9d0b4ad commit 2437c0f
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 157 deletions.
38 changes: 36 additions & 2 deletions tools/testing/selftests/kselftest/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export skip_rc=4
export timeout_rc=124
export logfile=/dev/stdout
export per_test_logging=
export RUN_IN_NETNS=

# Defaults for "settings" file fields:
# "timeout" how many seconds to let each test run before running
Expand Down Expand Up @@ -47,7 +48,7 @@ run_one()
{
DIR="$1"
TEST="$2"
NUM="$3"
local test_num="$3"

BASENAME_TEST=$(basename $TEST)

Expand Down Expand Up @@ -141,6 +142,33 @@ run_one()
fi
}

in_netns()
{
local name=$1
ip netns exec $name bash <<-EOF
BASE_DIR=$BASE_DIR
source $BASE_DIR/kselftest/runner.sh
logfile=$logfile
run_one $DIR $TEST $test_num
EOF
}

run_in_netns()
{
local netns=$(mktemp -u ${BASENAME_TEST}-XXXXXX)
local tmplog="/tmp/$(mktemp -u ${BASENAME_TEST}-XXXXXX)"
ip netns add $netns
if [ $? -ne 0 ]; then
echo "# Warning: Create namespace failed for $BASENAME_TEST"
echo "not ok $test_num selftests: $DIR: $BASENAME_TEST # Create NS failed"
fi
ip -n $netns link set lo up
in_netns $netns &> $tmplog
ip netns del $netns &> /dev/null
cat $tmplog
rm -f $tmplog
}

run_many()
{
echo "TAP version 13"
Expand All @@ -155,6 +183,12 @@ run_many()
logfile="/tmp/$BASENAME_TEST"
cat /dev/null > "$logfile"
fi
run_one "$DIR" "$TEST" "$test_num"
if [ -n "$RUN_IN_NETNS" ]; then
run_in_netns &
else
run_one "$DIR" "$TEST" "$test_num"
fi
done

wait
}
18 changes: 7 additions & 11 deletions tools/testing/selftests/net/gre_gso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
# SPDX-License-Identifier: GPL-2.0

# This test is for checking GRE GSO.

source lib.sh
ret=0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4

# all tests in this script. Can be overridden with -t option
TESTS="gre_gso"

VERBOSE=0
PAUSE_ON_FAIL=no
PAUSE=no
IP="ip -netns ns1"
NS_EXEC="ip netns exec ns1"
TMPFILE=`mktemp`
PID=

Expand Down Expand Up @@ -50,13 +46,13 @@ log_test()
setup()
{
set -e
ip netns add ns1
ip netns set ns1 auto
$IP link set dev lo up
setup_ns ns1
IP="ip -netns $ns1"
NS_EXEC="ip netns exec $ns1"

ip link add veth0 type veth peer name veth1
ip link set veth0 up
ip link set veth1 netns ns1
ip link set veth1 netns $ns1
$IP link set veth1 name veth0
$IP link set veth0 up

Expand All @@ -70,7 +66,7 @@ cleanup()
[ -n "$PID" ] && kill $PID
ip link del dev gre1 &> /dev/null
ip link del dev veth0 &> /dev/null
ip netns del ns1
cleanup_ns $ns1
}

get_linklocal()
Expand Down Expand Up @@ -145,7 +141,7 @@ gre6_gso_test()
setup

a1=$(get_linklocal veth0)
a2=$(get_linklocal veth0 ns1)
a2=$(get_linklocal veth0 $ns1)

gre_create_tun $a1 $a2

Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/net/gro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ run_test() {
# on every try.
for tries in {1..3}; do
# Actual test starts here
ip netns exec server_ns ./gro "${ARGS[@]}" "--rx" "--iface" "server" \
ip netns exec $server_ns ./gro "${ARGS[@]}" "--rx" "--iface" "server" \
1>>log.txt &
server_pid=$!
sleep 0.5 # to allow for socket init
ip netns exec client_ns ./gro "${ARGS[@]}" "--iface" "client" \
ip netns exec $client_ns ./gro "${ARGS[@]}" "--iface" "client" \
1>>log.txt
wait "${server_pid}"
exit_code=$?
Expand Down
44 changes: 22 additions & 22 deletions tools/testing/selftests/net/netns-name.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

source lib.sh
set -o pipefail

NS=netns-name-test
DEV=dummy-dev0
DEV2=dummy-dev1
ALT_NAME=some-alt-name

RET_CODE=0

cleanup() {
ip netns del $NS
cleanup_ns $NS $test_ns
}

trap cleanup EXIT
Expand All @@ -21,62 +21,62 @@ fail() {
RET_CODE=1
}

ip netns add $NS
setup_ns NS test_ns

#
# Test basic move without a rename
#
ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link set dev $DEV netns 1 ||
ip -netns $NS link set dev $DEV netns $test_ns ||
fail "Can't perform a netns move"
ip link show dev $DEV >> /dev/null || fail "Device not found after move"
ip link del $DEV || fail
ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move"
ip -netns $test_ns link del $DEV || fail

#
# Test move with a conflict
#
ip link add name $DEV type dummy
ip -netns $test_ns link add name $DEV type dummy
ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link set dev $DEV netns 1 2> /dev/null &&
ip -netns $NS link set dev $DEV netns $test_ns 2> /dev/null &&
fail "Performed a netns move with a name conflict"
ip link show dev $DEV >> /dev/null || fail "Device not found after move"
ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move"
ip -netns $NS link del $DEV || fail
ip link del $DEV || fail
ip -netns $test_ns link del $DEV || fail

#
# Test move with a conflict and rename
#
ip link add name $DEV type dummy
ip -netns $test_ns link add name $DEV type dummy
ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link set dev $DEV netns 1 name $DEV2 ||
ip -netns $NS link set dev $DEV netns $test_ns name $DEV2 ||
fail "Can't perform a netns move with rename"
ip link del $DEV2 || fail
ip link del $DEV || fail
ip -netns $test_ns link del $DEV2 || fail
ip -netns $test_ns link del $DEV || fail

#
# Test dup alt-name with netns move
#
ip link add name $DEV type dummy || fail
ip link property add dev $DEV altname $ALT_NAME || fail
ip -netns $test_ns link add name $DEV type dummy || fail
ip -netns $test_ns link property add dev $DEV altname $ALT_NAME || fail
ip -netns $NS link add name $DEV2 type dummy || fail
ip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail

ip -netns $NS link set dev $DEV2 netns 1 2> /dev/null &&
ip -netns $NS link set dev $DEV2 netns $test_ns 2> /dev/null &&
fail "Moved with alt-name dup"

ip link del $DEV || fail
ip -netns $test_ns link del $DEV || fail
ip -netns $NS link del $DEV2 || fail

#
# Test creating alt-name in one net-ns and using in another
#
ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link property add dev $DEV altname $ALT_NAME || fail
ip -netns $NS link set dev $DEV netns 1 || fail
ip link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move"
ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
ip -netns $NS link set dev $DEV netns $test_ns || fail
ip -netns $test_ns link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move"
ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
fail "Can still find alt-name after move"
ip link del $DEV || fail
ip -netns $test_ns link del $DEV || fail

echo -ne "$(basename $0) \t\t\t\t"
if [ $RET_CODE -eq 0 ]; then
Expand Down
27 changes: 9 additions & 18 deletions tools/testing/selftests/net/pmtu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@
# - pmtu_ipv6_route_change
# Same as above but with IPv6

# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
source ./lib.sh

PAUSE_ON_FAIL=no
VERBOSE=0
Expand Down Expand Up @@ -268,16 +267,6 @@ tests="
pmtu_ipv4_route_change ipv4: PMTU exception w/route replace 1
pmtu_ipv6_route_change ipv6: PMTU exception w/route replace 1"

NS_A="ns-A"
NS_B="ns-B"
NS_C="ns-C"
NS_R1="ns-R1"
NS_R2="ns-R2"
ns_a="ip netns exec ${NS_A}"
ns_b="ip netns exec ${NS_B}"
ns_c="ip netns exec ${NS_C}"
ns_r1="ip netns exec ${NS_R1}"
ns_r2="ip netns exec ${NS_R2}"
# Addressing and routing for tests with routers: four network segments, with
# index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an
# identifier ID, which is 1 for hosts (A and B), 2 for routers (R1 and R2).
Expand Down Expand Up @@ -543,13 +532,17 @@ setup_ip6ip6() {
}

setup_namespaces() {
setup_ns NS_A NS_B NS_C NS_R1 NS_R2
for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do
ip netns add ${n} || return 1

# Disable DAD, so that we don't have to wait to use the
# configured IPv6 addresses
ip netns exec ${n} sysctl -q net/ipv6/conf/default/accept_dad=0
done
ns_a="ip netns exec ${NS_A}"
ns_b="ip netns exec ${NS_B}"
ns_c="ip netns exec ${NS_C}"
ns_r1="ip netns exec ${NS_R1}"
ns_r2="ip netns exec ${NS_R2}"
}

setup_veth() {
Expand Down Expand Up @@ -839,7 +832,7 @@ setup_bridge() {
run_cmd ${ns_a} ip link set br0 up

run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
run_cmd ${ns_c} ip link set veth_A-C netns ns-A
run_cmd ${ns_c} ip link set veth_A-C netns ${NS_A}

run_cmd ${ns_a} ip link set veth_A-C up
run_cmd ${ns_c} ip link set veth_C-A up
Expand Down Expand Up @@ -944,9 +937,7 @@ cleanup() {
done
socat_pids=

for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do
ip netns del ${n} 2> /dev/null
done
cleanup_all_ns

ip link del veth_A-C 2>/dev/null
ip link del veth_A-R1 2>/dev/null
Expand Down
Loading

0 comments on commit 2437c0f

Please sign in to comment.