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

selftests/net: convert drop_monitor_tests.sh to run it in unique namespace

Here is the test result after conversion.

]# ./drop_monitor_tests.sh

Software drops test
TEST: Capturing active software drops [ OK ]
TEST: Capturing inactive software drops [ OK ]

Hardware drops test
TEST: Capturing active hardware drops [ OK ]
TEST: Capturing inactive hardware drops [ OK ]

Tests passed: 4
Tests failed: 0

Acked-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Hangbin Liu and committed by
Paolo Abeni
0d8b4887 7c16d485

+11 -10
+11 -10
tools/testing/selftests/net/drop_monitor_tests.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 # This test is for checking drop monitor functionality. 5 - 5 + source lib.sh 6 6 ret=0 7 - # Kselftest framework requirement - SKIP code is 4. 8 - ksft_skip=4 9 7 10 8 # all tests in this script. Can be overridden with -t option 11 9 TESTS=" ··· 11 13 hw_drops 12 14 " 13 15 14 - IP="ip -netns ns1" 15 - TC="tc -netns ns1" 16 - DEVLINK="devlink -N ns1" 17 - NS_EXEC="ip netns exec ns1" 18 16 NETDEVSIM_PATH=/sys/bus/netdevsim/ 19 17 DEV_ADDR=1337 20 18 DEV=netdevsim${DEV_ADDR} ··· 37 43 modprobe netdevsim &> /dev/null 38 44 39 45 set -e 40 - ip netns add ns1 46 + setup_ns NS1 41 47 $IP link add dummy10 up type dummy 42 48 43 49 $NS_EXEC echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device ··· 51 57 cleanup() 52 58 { 53 59 $NS_EXEC echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device 54 - ip netns del ns1 60 + cleanup_ns ${NS1} 55 61 } 56 62 57 63 sw_drops_test() ··· 188 194 exit $ksft_skip 189 195 fi 190 196 191 - # start clean 197 + # create netns first so we can get the namespace name 198 + setup_ns NS1 192 199 cleanup &> /dev/null 200 + trap cleanup EXIT 201 + 202 + IP="ip -netns ${NS1}" 203 + TC="tc -netns ${NS1}" 204 + DEVLINK="devlink -N ${NS1}" 205 + NS_EXEC="ip netns exec ${NS1}" 193 206 194 207 for t in $TESTS 195 208 do