Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com,
	amcohen@nvidia.com, danieller@nvidia.com, mlxsw@nvidia.com,
	roopa@nvidia.com, dsahern@gmail.com, andrew@lunn.ch,
	f.fainelli@gmail.com, vivien.didelot@gmail.com,
	saeedm@nvidia.com, tariqt@nvidia.com, ayal@nvidia.com,
	eranbe@nvidia.com, mkubecek@suse.cz,
	Ido Schimmel <idosch@nvidia.com>
Subject: [RFC PATCH net-next 3/6] selftests: netdevsim: Add devlink metric tests
Date: Mon, 17 Aug 2020 15:50:56 +0300	[thread overview]
Message-ID: <20200817125059.193242-4-idosch@idosch.org> (raw)
In-Reply-To: <20200817125059.193242-1-idosch@idosch.org>

From: Ido Schimmel <idosch@nvidia.com>

Test the existing functionality of the devlink metric infrastructure.
Tests will be added for any new functionality.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 .../networking/devlink/devlink-metric.rst     | 11 +++++
 .../drivers/net/netdevsim/devlink.sh          | 49 ++++++++++++++++++-
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/Documentation/networking/devlink/devlink-metric.rst b/Documentation/networking/devlink/devlink-metric.rst
index cf5c5b4e4077..8a4515df1bc0 100644
--- a/Documentation/networking/devlink/devlink-metric.rst
+++ b/Documentation/networking/devlink/devlink-metric.rst
@@ -24,3 +24,14 @@ driver-specific ``devlink`` documentation under
 
 When possible, a selftest (under ``tools/testing/selftests/drivers/``) should
 also be provided to ensure the metrics are updated under the right conditions.
+
+Testing
+=======
+
+See ``tools/testing/selftests/drivers/net/netdevsim/devlink.sh`` for a
+test covering the core infrastructure. Test cases should be added for any new
+functionality.
+
+Device drivers should focus their tests on device-specific functionality, such
+as making sure the exposed metrics are correctly incremented and read from the
+device.
diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
index de4b32fc4223..4ca345e227bc 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
@@ -5,7 +5,8 @@ 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 \
+	   metric_counter_test"
 NUM_NETIFS=0
 source $lib_dir/lib.sh
 
@@ -486,6 +487,52 @@ dummy_reporter_test()
 	log_test "dummy reporter test"
 }
 
+metric_counter_value_get()
+{
+	local metric=$1; shift
+
+	cmd_jq "devlink -jps dev metric show $DL_HANDLE metric $metric" \
+		'.[][][]["value"]'
+}
+
+metric_group_get()
+{
+	local metric=$1; shift
+
+	cmd_jq "devlink -jp dev metric show $DL_HANDLE metric $metric" \
+		'.[][][]["group"]'
+}
+
+metric_counter_test()
+{
+	RET=0
+
+	local val_t0=$(metric_counter_value_get dummy_counter)
+	local val_t1=$(metric_counter_value_get dummy_counter)
+	(( val_t0 < val_t1 ))
+	check_err $? "Expected to read a higher value in second read"
+
+	echo "y" > $DEBUGFS_DIR/metric/fail_counter_get
+	metric_counter_value_get dummy_counter
+	check_fail $? "Unexpected success of counter get"
+	echo "n" > $DEBUGFS_DIR/metric/fail_counter_get
+
+	devlink dev metric set $DL_HANDLE metric dummy_counter group 10
+
+	(( 10 == $(metric_group_get dummy_counter) ))
+	check_err $? "Expected \"dummy_counter\" to be in group 10"
+
+	devlink dev metric show group 10 | grep -q "dummy_counter"
+	check_err $? "Expected \"dummy_counter\" to be dumped"
+
+	devlink dev metric show group 20 | grep -q "dummy_counter"
+	check_fail $? "Did not expect to see \"dummy_counter\" in group 20"
+
+	devlink dev metric set $DL_HANDLE metric dummy_counter group 0
+
+	log_test "metric counter test"
+}
+
 setup_prepare()
 {
 	modprobe netdevsim
-- 
2.26.2


  parent reply	other threads:[~2020-08-17 12:52 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17 12:50 [RFC PATCH net-next 0/6] devlink: Add device metric support Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 1/6] devlink: Add device metric infrastructure Ido Schimmel
2020-08-17 14:12   ` Andrew Lunn
2020-08-17 12:50 ` [RFC PATCH net-next 2/6] netdevsim: Add devlink metric support Ido Schimmel
2020-08-17 12:50 ` Ido Schimmel [this message]
2020-08-17 12:50 ` [RFC PATCH net-next 4/6] mlxsw: reg: Add Tunneling NVE Counters Register Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 5/6] mlxsw: reg: Add Tunneling NVE Counters Register Version 2 Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 6/6] mlxsw: spectrum_nve: Expose VXLAN counters via devlink-metric Ido Schimmel
2020-08-17 14:29   ` Andrew Lunn
2020-08-18  6:59     ` Ido Schimmel
2020-08-19  0:24 ` [RFC PATCH net-next 0/6] devlink: Add device metric support Jakub Kicinski
2020-08-19  2:43   ` David Ahern
2020-08-19  3:35     ` Jakub Kicinski
2020-08-19  4:30       ` Florian Fainelli
2020-08-19 16:18         ` Jakub Kicinski
2020-08-19 17:20           ` Florian Fainelli
2020-08-19 18:07             ` Jakub Kicinski
2020-08-20 14:35               ` David Ahern
2020-08-20 16:09                 ` Jakub Kicinski
2020-08-21 10:30                   ` Ido Schimmel
2020-08-21 16:53                     ` Jakub Kicinski
2020-08-21 19:12                       ` David Ahern
2020-08-21 23:50                         ` Jakub Kicinski
2020-08-21 23:59                           ` David Ahern
2020-08-22  0:37                             ` Jakub Kicinski
2020-08-22  1:18                               ` David Ahern
2020-08-22 16:27                                 ` Jakub Kicinski
2020-08-23  7:04                                   ` Ido Schimmel
2020-08-24 19:11                                     ` 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=20200817125059.193242-4-idosch@idosch.org \
    --to=idosch@idosch.org \
    --cc=amcohen@nvidia.com \
    --cc=andrew@lunn.ch \
    --cc=ayal@nvidia.com \
    --cc=danieller@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=eranbe@nvidia.com \
    --cc=f.fainelli@gmail.com \
    --cc=idosch@nvidia.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=vivien.didelot@gmail.com \
    --subject='Re: [RFC PATCH net-next 3/6] selftests: netdevsim: Add devlink metric tests' \
    /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

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).