1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 3 4 lib_dir=$(dirname $0)/../../../net/forwarding 5 6 ALL_TESTS="check_devlink_test check_ports_test" 7 NUM_NETIFS=0 8 source $lib_dir/lib.sh 9 10 BUS_ADDR=10 11 PORT_COUNT=4 12 DEV_NAME=netdevsim$BUS_ADDR 13 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/ 14 DL_HANDLE=netdevsim/$DEV_NAME 15 NETNS_NAME=testns1 16 17 port_netdev_get() 18 { 19 local port_index=$1 20 21 cmd_jq "devlink -N $NETNS_NAME port show -j" \ 22 ".[][\"$DL_HANDLE/$port_index\"].netdev" "-e" 23 } 24 25 check_ports_test() 26 { 27 RET=0 28 29 for i in $(seq 0 $(expr $PORT_COUNT - 1)); do 30 netdev_name=$(port_netdev_get $i) 31 check_err $? "Failed to get netdev name for port $DL_HANDLE/$i" 32 ip -n $NETNS_NAME link show $netdev_name &> /dev/null 33 check_err $? "Failed to find netdev $netdev_name" 34 done 35 36 log_test "check ports test" 37 } 38 39 check_devlink_test() 40 { 41 RET=0 42 43 devlink -N $NETNS_NAME dev show $DL_HANDLE &> /dev/null 44 check_err $? "Failed to show devlink instance" 45 46 log_test "check devlink test" 47 } 48 49 setup_prepare() 50 { 51 modprobe netdevsim 52 ip netns add $NETNS_NAME 53 ip netns exec $NETNS_NAME \ 54 echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device 55 while [ ! -d $SYSFS_NET_DIR ] ; do :; done 56 } 57 58 cleanup() 59 { 60 pre_cleanup 61 echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device 62 ip netns del $NETNS_NAME 63 modprobe -r netdevsim 64 } 65 66 trap cleanup EXIT 67 68 setup_prepare 69 70 tests_run 71 72 exit $EXIT_STATUS
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.