WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / netdevsim / devlink_in_netns.sh
blob7effd35369e1ae15d564824446dfd125aebcbc11
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 lib_dir=$(dirname $0)/../../../net/forwarding
6 ALL_TESTS="check_devlink_test check_ports_test"
7 NUM_NETIFS=0
8 source $lib_dir/lib.sh
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
17 port_netdev_get()
19 local port_index=$1
21 cmd_jq "devlink -N $NETNS_NAME port show -j" \
22 ".[][\"$DL_HANDLE/$port_index\"].netdev" "-e"
25 check_ports_test()
27 RET=0
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
36 log_test "check ports test"
39 check_devlink_test()
41 RET=0
43 devlink -N $NETNS_NAME dev show $DL_HANDLE &> /dev/null
44 check_err $? "Failed to show devlink instance"
46 log_test "check devlink test"
49 setup_prepare()
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
58 cleanup()
60 pre_cleanup
61 echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device
62 ip netns del $NETNS_NAME
63 modprobe -r netdevsim
66 trap cleanup EXIT
68 setup_prepare
70 tests_run
72 exit $EXIT_STATUS