From: Antonio Cardace <acardace@redhat.com>
To: netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Michal Kubecek <mkubecek@suse.cz>
Subject: [PATCH net-next v6 4/6] selftests: extract common functions in ethtool-common.sh
Date: Wed, 18 Nov 2020 21:45:20 +0100 [thread overview]
Message-ID: <20201118204522.5660-5-acardace@redhat.com> (raw)
In-Reply-To: <20201118204522.5660-1-acardace@redhat.com>
Factor out some useful functions so that they can be reused
by other ethtool-netdevsim scripts.
Signed-off-by: Antonio Cardace <acardace@redhat.com>
---
.../drivers/net/netdevsim/ethtool-common.sh | 69 +++++++++++++++++++
.../drivers/net/netdevsim/ethtool-pause.sh | 63 +----------------
2 files changed, 71 insertions(+), 61 deletions(-)
create mode 100644 tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
new file mode 100644
index 000000000000..fa44cf6e732c
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+NSIM_ID=$((RANDOM % 1024))
+NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID
+NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0
+NSIM_NETDEV=
+num_passes=0
+num_errors=0
+
+function cleanup_nsim {
+ if [ -e $NSIM_DEV_SYS ]; then
+ echo $NSIM_ID > /sys/bus/netdevsim/del_device
+ fi
+}
+
+function cleanup {
+ cleanup_nsim
+}
+
+trap cleanup EXIT
+
+function get_netdev_name {
+ local -n old=$1
+
+ new=$(ls /sys/class/net)
+
+ for netdev in $new; do
+ for check in $old; do
+ [ $netdev == $check ] && break
+ done
+
+ if [ $netdev != $check ]; then
+ echo $netdev
+ break
+ fi
+ done
+}
+
+function check {
+ local code=$1
+ local str=$2
+ local exp_str=$3
+
+ if [ $code -ne 0 ]; then
+ ((num_errors++))
+ return
+ fi
+
+ if [ "$str" != "$exp_str" ]; then
+ echo -e "Expected: '$exp_str', got '$str'"
+ ((num_errors++))
+ return
+ fi
+
+ ((num_passes++))
+}
+
+function make_netdev {
+ # Make a netdevsim
+ old_netdevs=$(ls /sys/class/net)
+
+ if ! $(lsmod | grep -q netdevsim); then
+ modprobe netdevsim
+ fi
+
+ echo $NSIM_ID > /sys/bus/netdevsim/new_device
+ echo `get_netdev_name old_netdevs`
+}
diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh
index 25c896b9e2eb..b4a7abfe5454 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-pause.sh
@@ -1,60 +1,7 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
-NSIM_ID=$((RANDOM % 1024))
-NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID
-NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0
-NSIM_NETDEV=
-num_passes=0
-num_errors=0
-
-function cleanup_nsim {
- if [ -e $NSIM_DEV_SYS ]; then
- echo $NSIM_ID > /sys/bus/netdevsim/del_device
- fi
-}
-
-function cleanup {
- cleanup_nsim
-}
-
-trap cleanup EXIT
-
-function get_netdev_name {
- local -n old=$1
-
- new=$(ls /sys/class/net)
-
- for netdev in $new; do
- for check in $old; do
- [ $netdev == $check ] && break
- done
-
- if [ $netdev != $check ]; then
- echo $netdev
- break
- fi
- done
-}
-
-function check {
- local code=$1
- local str=$2
- local exp_str=$3
-
- if [ $code -ne 0 ]; then
- ((num_errors++))
- return
- fi
-
- if [ "$str" != "$exp_str" ]; then
- echo -e "Expected: '$exp_str', got '$str'"
- ((num_errors++))
- return
- fi
-
- ((num_passes++))
-}
+source ethtool-common.sh
# Bail if ethtool is too old
if ! ethtool -h | grep include-stat 2>&1 >/dev/null; then
@@ -62,13 +9,7 @@ if ! ethtool -h | grep include-stat 2>&1 >/dev/null; then
exit 4
fi
-# Make a netdevsim
-old_netdevs=$(ls /sys/class/net)
-
-modprobe netdevsim
-echo $NSIM_ID > /sys/bus/netdevsim/new_device
-
-NSIM_NETDEV=`get_netdev_name old_netdevs`
+NSIM_NETDEV=$(make_netdev)
set -o pipefail
--
2.28.0
next prev parent reply other threads:[~2020-11-18 20:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 20:45 [PATCH net-next v6 0/6] netdevsim: add ethtool coalesce and ring settings Antonio Cardace
2020-11-18 20:45 ` [PATCH net-next v6 1/6] ethtool: add ETHTOOL_COALESCE_ALL_PARAMS define Antonio Cardace
2020-11-18 20:45 ` [PATCH net-next v6 2/6] netdevsim: move ethtool pause params in separate struct Antonio Cardace
2020-11-18 20:45 ` [PATCH net-next v6 3/6] netdevsim: support ethtool ring and coalesce settings Antonio Cardace
2020-11-18 20:45 ` Antonio Cardace [this message]
2020-11-18 20:45 ` [PATCH net-next v6 5/6] selftests: refactor get_netdev_name function Antonio Cardace
2020-11-18 20:45 ` [PATCH net-next v6 6/6] selftests: add ring and coalesce selftests Antonio Cardace
2020-11-20 22:22 ` [PATCH net-next v6 0/6] netdevsim: add ethtool coalesce and ring settings Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201118204522.5660-5-acardace@redhat.com \
--to=acardace@redhat.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).