[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210122094648.1631078-11-jiri@resnulli.us>
Date: Fri, 22 Jan 2021 10:46:48 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, kuba@...nel.org, jacob.e.keller@...el.com,
roopa@...dia.com, andrew@...n.ch, dsahern@...il.com,
mlxsw@...dia.com
Subject: [patch net-next RFCv2 10/10] selftests: add netdevsim devlink lc test
From: Jiri Pirko <jiri@...dia.com>
Add test to verify netdevsim driver line card functionality.
Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
RFC->RFCv2:
- adjusted to "active"->"insert_type" activation conversion
---
.../drivers/net/netdevsim/devlink.sh | 62 ++++++++++++++++++-
1 file changed, 60 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
index 40909c254365..212fe3d5b1c6 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
@@ -5,12 +5,13 @@ lib_dir=$(dirname $0)/../../../net/forwarding
ALL_TESTS="fw_flash_test params_test regions_test reload_test \
netns_reload_test resource_test dev_info_test \
- empty_reporter_test dummy_reporter_test"
+ empty_reporter_test dummy_reporter_test linecard_test"
NUM_NETIFS=0
source $lib_dir/lib.sh
BUS_ADDR=10
PORT_COUNT=4
+LINECARD_COUNT=2
DEV_NAME=netdevsim$BUS_ADDR
SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
@@ -507,10 +508,67 @@ dummy_reporter_test()
log_test "dummy reporter test"
}
+check_linecards_state()
+{
+ local expected_state_0=$1
+ local expected_state_1=$2
+
+ local state=$(devlink lc show $DL_HANDLE lc 0 -j | jq -e -r ".[][][].state")
+ check_err $? "Failed to get linecard 0 state"
+
+ [ "$state" == "$expected_state_0" ]
+ check_err $? "Unexpected linecard 0 state (got $state, expected $expected_state_0)"
+
+ local state=$(devlink lc show $DL_HANDLE lc 1 -j | jq -e -r ".[][][].state")
+ check_err $? "Failed to get linecard 1 state"
+
+ [ "$state" == "$expected_state_1" ]
+ check_err $? "Unexpected linecard 1 state (got $state, expected $expected_state_1)"
+}
+
+linecard_test()
+{
+ RET=0
+
+ check_linecards_state "unprovisioned" "unprovisioned"
+
+ devlink lc set $DL_HANDLE lc 0 type card2ports
+ check_err $? "Failed to provision linecard 0 with card2ports"
+
+ check_linecards_state "provisioned" "unprovisioned"
+
+ devlink lc set $DL_HANDLE lc 1 type card4ports
+ check_err $? "Failed to provision linecard 0 with card4ports"
+
+ check_linecards_state "provisioned" "provisioned"
+
+ echo "card2ports"> $DEBUGFS_DIR/linecards/0/inserted_type
+ check_err $? "Failed to insert linecard 0"
+
+ check_linecards_state "active" "provisioned"
+
+ echo "card4ports"> $DEBUGFS_DIR/linecards/1/inserted_type
+ check_err $? "Failed to insert linecard 1"
+
+ check_linecards_state "active" "active"
+
+ devlink lc set $DL_HANDLE lc 0 notype
+ check_err $? "Failed to unprovision linecard 0"
+
+ check_linecards_state "unprovisioned" "active"
+
+ devlink lc set $DL_HANDLE lc 1 notype
+ check_err $? "Failed to unprovision linecard 1"
+
+ check_linecards_state "unprovisioned" "unprovisioned"
+
+ log_test "linecard test"
+}
+
setup_prepare()
{
modprobe netdevsim
- echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device
+ echo "$BUS_ADDR $PORT_COUNT $LINECARD_COUNT" > /sys/bus/netdevsim/new_device
while [ ! -d $SYSFS_NET_DIR ] ; do :; done
}
--
2.26.2
Powered by blists - more mailing lists