From: Ido Schimmel <idosch@idosch.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, amitc@mellanox.com, mlxsw@mellanox.com,
Ido Schimmel <idosch@mellanox.com>
Subject: [PATCH net-next 1/3] selftests: mlxsw: Add ethtool_lib.sh
Date: Mon, 10 Jun 2019 11:40:43 +0300 [thread overview]
Message-ID: <20190610084045.6029-2-idosch@idosch.org> (raw)
In-Reply-To: <20190610084045.6029-1-idosch@idosch.org>
From: Amit Cohen <amitc@mellanox.com>
Functions:
1. ethtool_set:
params: cmd
The function runs ethtool by cmd (ethtool -s cmd) and checks if there
was an error in configuration
2. speeds_get:
params: dev, with_mode (0 or 1)
return value: Array of supported link modes with/without mode.
* Example 1:
speeds_get swp1 0
return: 1000 10000 40000
* Example 2:
speeds_get swp1 1
return: 1000baseKX/Full 10000baseKR/Full 40000baseCR4/Full 40000baseSR4/Full
3. common_speeds_get:
params: dev1, dev2, with_mode (0 or 1)
return value: Array of common speeds of dev1 and dev2.
* Example:
common_speeds_get swp1 swp2 0
return: 1000 10000
(assume that swp1 supports 1000 10000 40000 and swp2 supports 1000 10000)
Signed-off-by: Amit Cohen <amitc@mellanox.com>
Reviewed-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
.../selftests/net/forwarding/ethtool_lib.sh | 91 +++++++++++++++++++
1 file changed, 91 insertions(+)
create mode 100755 tools/testing/selftests/net/forwarding/ethtool_lib.sh
diff --git a/tools/testing/selftests/net/forwarding/ethtool_lib.sh b/tools/testing/selftests/net/forwarding/ethtool_lib.sh
new file mode 100755
index 000000000000..6dcbbd228047
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/ethtool_lib.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+declare -A speed_values
+
+speed_values=( [10baseT/Half]=0x001
+ [10baseT/Full]=0x002
+ [100baseT/Half]=0x004
+ [100baseT/Full]=0x008
+ [1000baseT/Half]=0x010
+ [1000baseT/Full]=0x020
+ [1000baseKX/Full]=0x20000
+ [1000baseX/Full]=0x20000000000
+ [2500baseT/Full]=0x800000000000
+ [2500baseX/Full]=0x8000
+ [5000baseT/Full]=0x1000000000000
+ [10000baseT/Full]=0x1000
+ [10000baseKX4/Full]=0x40000
+ [10000baseKR/Full]=0x80000
+ [10000baseCR/Full]=0x40000000000
+ [10000baseSR/Full]=0x80000000000
+ [10000baseLR/Full]=0x100000000000
+ [10000baseLRM/Full]=0x200000000000
+ [10000baseER/Full]=0x400000000000
+ [20000baseMLD2/Full]=0x200000
+ [20000baseKR2/Full]=0x400000
+ [25000baseCR/Full]=0x80000000
+ [25000baseKR/Full]=0x100000000
+ [25000baseSR/Full]=0x200000000
+ [40000baseKR4/Full]=0x800000
+ [40000baseCR4/Full]=0x1000000
+ [40000baseSR4/Full]=0x2000000
+ [40000baseLR4/Full]=0x4000000
+ [50000baseCR2/Full]=0x400000000
+ [40000baseSR4/Full]=0x2000000
+ [40000baseLR4/Full]=0x4000000
+ [50000baseCR2/Full]=0x400000000
+ [50000baseKR2/Full]=0x800000000
+ [50000baseSR2/Full]=0x10000000000
+ [56000baseKR4/Full]=0x8000000
+ [56000baseCR4/Full]=0x10000000
+ [56000baseSR4/Full]=0x20000000
+ [56000baseLR4/Full]=0x40000000
+ [100000baseKR4/Full]=0x1000000000
+ [100000baseSR4/Full]=0x2000000000
+ [100000baseCR4/Full]=0x4000000000
+ [100000baseLR4_ER4/Full]=0x8000000000)
+
+ethtool_set()
+{
+ local cmd="$@"
+ local out=$(ethtool -s $cmd 2>&1 | wc -l)
+ check_err $out "error in configuration. $cmd"
+}
+
+speeds_get()
+{
+ local dev=$1; shift
+ local with_mode=$1; shift
+
+ local speeds_str=$(ethtool "$dev" | \
+ # Snip everything before the link modes section.
+ sed -n '/Supported link modes:/,$p' | \
+ # Quit processing the rest at the start of the next section.
+ # When checking, skip the header of this section (hence the 2,).
+ sed -n '2,${/^[\t][^ \t]/q};p' | \
+ # Drop the section header of the current section.
+ cut -d':' -f2)
+
+ local -a speeds_arr=($speeds_str)
+ if [[ $with_mode -eq 0 ]]; then
+ for ((i=0; i<${#speeds_arr[@]}; i++)); do
+ speeds_arr[$i]=${speeds_arr[$i]%base*}
+ done
+ fi
+ echo ${speeds_arr[@]}
+}
+
+common_speeds_get()
+{
+ dev1=$1; shift
+ dev2=$1; shift
+ with_mode=$1; shift
+
+ local -a dev1_speeds=($(speeds_get $dev1 $with_mode))
+ local -a dev2_speeds=($(speeds_get $dev2 $with_mode))
+
+ comm -12 \
+ <(printf '%s\n' "${dev1_speeds[@]}" | sort -u) \
+ <(printf '%s\n' "${dev2_speeds[@]}" | sort -u)
+}
--
2.20.1
next prev parent reply other threads:[~2019-06-10 8:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-10 8:40 [PATCH net-next 0/3] mlxsw: Add speed and auto-negotiation test Ido Schimmel
2019-06-10 8:40 ` Ido Schimmel [this message]
2019-06-10 13:35 ` [PATCH net-next 1/3] selftests: mlxsw: Add ethtool_lib.sh Andrew Lunn
2019-06-10 13:56 ` Ido Schimmel
2019-06-10 15:29 ` Florian Fainelli
2019-06-11 6:51 ` Ido Schimmel
2019-06-10 13:59 ` Andrew Lunn
2019-06-10 14:31 ` Ido Schimmel
2019-06-10 14:51 ` Andrew Lunn
2019-06-10 8:40 ` [PATCH net-next 2/3] selftests: mlxsw: lib.sh: Add wait for dev with timeout Ido Schimmel
2019-06-10 8:40 ` [PATCH net-next 3/3] selftests: mlxsw: Add speed and auto-negotiation test Ido Schimmel
2019-06-10 13:48 ` Andrew Lunn
2019-06-10 13:58 ` Ido Schimmel
2019-06-10 14:06 ` Andrew Lunn
2019-06-11 6:35 ` Ido Schimmel
2019-06-11 12:22 ` Andrew Lunn
2019-06-11 13:06 ` Ido Schimmel
2019-06-11 13:30 ` Andrew Lunn
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=20190610084045.6029-2-idosch@idosch.org \
--to=idosch@idosch.org \
--cc=amitc@mellanox.com \
--cc=davem@davemloft.net \
--cc=idosch@mellanox.com \
--cc=mlxsw@mellanox.com \
--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).