From: Petr Machata <petrm@nvidia.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>,
<edumazet@google.com>, <pabeni@redhat.com>, <shuah@kernel.org>,
<sdf@google.com>, <donald.hunter@gmail.com>,
<linux-kselftest@vger.kernel.org>, <petrm@nvidia.com>
Subject: Re: [PATCH net-next 7/7] testing: net-drv: add a driver test for stats reporting
Date: Tue, 2 Apr 2024 18:37:44 +0200 [thread overview]
Message-ID: <87bk6rit8f.fsf@nvidia.com> (raw)
In-Reply-To: <20240402010520.1209517-8-kuba@kernel.org>
Jakub Kicinski <kuba@kernel.org> writes:
> Add a very simple test to make sure drivers report expected
> stats. Drivers which implement FEC or pause configuration
> should report relevant stats. Qstats must be reported,
> at least packet and byte counts, and they must match
> total device stats.
>
> Tested with netdevsim, bnxt, in-tree and installed.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> tools/testing/selftests/drivers/net/stats.py | 85 ++++++++++++++++++++
> 1 file changed, 85 insertions(+)
> create mode 100755 tools/testing/selftests/drivers/net/stats.py
>
> diff --git a/tools/testing/selftests/drivers/net/stats.py b/tools/testing/selftests/drivers/net/stats.py
> new file mode 100755
> index 000000000000..751cca2869b8
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/stats.py
> @@ -0,0 +1,85 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: GPL-2.0
> +
> +from lib.py import ksft_run, ksft_in, ksft_true, KsftSkipEx, KsftXfailEx
> +from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
> +from lib.py import NetDrvEnv
> +
> +cfg = None
> +ethnl = EthtoolFamily()
> +netfam = NetdevFamily()
> +rtnl = RtnlFamily()
> +
> +
> +def check_pause() -> None:
> + global cfg, ethnl
> +
> + try:
> + ethnl.pause_get({"header": {"dev-index": cfg.ifindex}})
> + except NlError as e:
> + if e.error == 95:
> + raise KsftXfailEx("pause not supported by the device")
> + raise
> +
> + data = ethnl.pause_get({"header": {"dev-index": cfg.ifindex,
> + "flags": {'stats'}}})
> + ksft_true(data['stats'], "driver does not report stats")
> +
> +
> +def check_fec() -> None:
> + global ethnl
> +
> + try:
> + ethnl.fec_get({"header": {"dev-index": cfg.ifindex}})
> + except NlError as e:
> + if e.error == 95:
> + raise KsftXfailEx("FEC not supported by the device")
> + raise
> +
> + data = ethnl.fec_get({"header": {"dev-index": cfg.ifindex,
> + "flags": {'stats'}}})
> + ksft_true(data['stats'], "driver does not report stats")
> +
> +
> +def pkt_byte_sum() -> None:
> + global cfg, netfam, rtnl
> +
> + def get_qstat(test):
> + global netfam
> + stats = netfam.qstats_get({}, dump=True)
> + if stats:
> + for qs in stats:
> + if qs["ifindex"]== test.ifindex:
> + return qs
> +
> + qstat = get_qstat(cfg)
> + if qstat is None:
> + raise KsftSkipEx("qstats not supported by the device")
> +
> + for key in ['tx-packets', 'tx-bytes', 'rx-packets', 'rx-bytes']:
> + ksft_in(key, qstat, "Drivers should always report basic keys")
> +
> + # Compare stats, rtnl stats and qstats must match,
> + # but the interface may be up, so do a series of dumps
> + # each time the more "recent" stats must be higher or same.
> + def stat_cmp(rstat, qstat):
> + for key in ['tx-packets', 'tx-bytes', 'rx-packets', 'rx-bytes']:
> + if rstat[key] != qstat[key]:
> + return rstat[key] - qstat[key]
> + return 0
> +
> + for _ in range(10):
> + rtstat = rtnl.getlink({"ifi-index": cfg.ifindex})['stats']
> + if stat_cmp(rtstat, qstat) < 0:
> + raise Exception("RTNL stats are lower, fetched later")
> + qstat = get_qstat(cfg)
> + if stat_cmp(rtstat, qstat) > 0:
> + raise Exception("Qstats are lower, fetched later")
> +
> +
> +if __name__ == "__main__":
> + cfg = NetDrvEnv(__file__)
> + try:
> + ksft_run([check_pause, check_fec, pkt_byte_sum])
> + finally:
> + del cfg
Yeah, this would be usually done through context managers, as I mention
in the other e-mail. But then cfg would be lexically scoped, which IMHO
is a good thing, but then it needs to be passed around as an argument,
and that makes the ksft_run() invocation a bit messy:
with NetDrvEnv(__file__) as cfg:
ksft_run([lambda: check_pause(cfg),
lambda: check_fec(cfg),
lambda: pkt_byte_sum(cfg)])
Dunno, maybe it could forward *args **kwargs to the cases? But then it
loses some of the readability again.
next prev parent reply other threads:[~2024-04-02 17:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 1:05 [PATCH net-next 0/7] selftests: net: groundwork for YNL-based tests Jakub Kicinski
2024-04-02 1:05 ` [PATCH net-next 1/7] netlink: specs: define ethtool header flags Jakub Kicinski
2024-04-02 1:05 ` [PATCH net-next 2/7] tools: ynl: copy netlink error to NlError Jakub Kicinski
2024-04-02 1:05 ` [PATCH net-next 3/7] selftests: net: add scaffolding for Netlink tests in Python Jakub Kicinski
2024-04-02 15:53 ` Petr Machata
2024-04-02 17:26 ` Jakub Kicinski
2024-04-03 0:09 ` David Wei
2024-04-02 1:05 ` [PATCH net-next 4/7] selftests: nl_netdev: add a trivial Netlink netdev test Jakub Kicinski
2024-04-03 0:15 ` David Wei
2024-04-02 1:05 ` [PATCH net-next 5/7] netdevsim: report stats by default, like a real device Jakub Kicinski
2024-04-03 2:51 ` David Wei
2024-04-02 1:05 ` [PATCH net-next 6/7] selftests: drivers: add scaffolding for Netlink tests in Python Jakub Kicinski
2024-04-03 3:06 ` David Wei
2024-04-02 1:05 ` [PATCH net-next 7/7] testing: net-drv: add a driver test for stats reporting Jakub Kicinski
2024-04-02 16:37 ` Petr Machata [this message]
2024-04-02 17:31 ` Jakub Kicinski
2024-04-02 17:44 ` Jakub Kicinski
2024-04-02 22:02 ` Petr Machata
2024-04-02 22:04 ` Petr Machata
2024-04-02 23:36 ` Jakub Kicinski
2024-04-03 8:58 ` Petr Machata
2024-04-03 13:55 ` Jakub Kicinski
2024-04-03 16:52 ` Petr Machata
2024-04-03 21:48 ` Jakub Kicinski
2024-04-03 3:15 ` David Wei
2024-04-03 3:09 ` David Wei
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=87bk6rit8f.fsf@nvidia.com \
--to=petrm@nvidia.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=shuah@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).