netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 v2 6/7] selftests: drivers: add scaffolding for Netlink tests in Python
Date: Thu, 4 Apr 2024 12:42:24 +0200	[thread overview]
Message-ID: <87zfu9fk2v.fsf@nvidia.com> (raw)
In-Reply-To: <20240403023426.1762996-7-kuba@kernel.org>


Jakub Kicinski <kuba@kernel.org> writes:

> Add drivers/net as a target for mixed-use tests.
> The setup is expected to work similarly to the forwarding tests.
> Since we only need one interface (unlike forwarding tests)
> read the target device name from NETIF. If not present we'll
> try to run the test against netdevsim.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Petr Machata <petrm@nvidia.com>

However:

> diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py
> new file mode 100644
> index 000000000000..25ae0d081788
> --- /dev/null
> +++ b/tools/testing/selftests/net/lib/py/nsim.py
> @@ -0,0 +1,118 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +import json
> +import os
> +import random
> +import re
> +import time
> +from .utils import cmd, ip
> +
> +
> +class NetdevSim:
> +    """
> +    Class for netdevsim netdevice and its attributes.
> +    """
> +
> +    def __init__(self, nsimdev, port_index, ifname, ns=None):
> +        # In case udev renamed the netdev to according to new schema,
> +        # check if the name matches the port_index.
> +        nsimnamere = re.compile(r"eni\d+np(\d+)")
> +        match = nsimnamere.match(ifname)
> +        if match and int(match.groups()[0]) != port_index + 1:
> +            raise Exception("netdevice name mismatches the expected one")
> +
> +        self.ifname = ifname
> +        self.nsimdev = nsimdev
> +        self.port_index = port_index
> +        self.ns = ns
> +        self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index)
> +        ret = ip("-j link show dev %s" % ifname, ns=ns)
> +        self.dev = json.loads(ret.stdout)[0]

I don't think self.ifname, .ns, .dfs_dir, .dev are actually used outside
of this function.

> +
> +    def dfs_write(self, path, val):
> +        self.nsimdev.dfs_write(f'ports/{self.port_index}/' + path, val)
> +
> +
> +class NetdevSimDev:
> +    """
> +    Class for netdevsim bus device and its attributes.
> +    """
> +    @staticmethod
> +    def ctrl_write(path, val):
> +        fullpath = os.path.join("/sys/bus/netdevsim/", path)
> +        with open(fullpath, "w") as f:
> +            f.write(val)
> +
> +    def dfs_write(self, path, val):
> +        fullpath = os.path.join(f"/sys/kernel/debug/netdevsim/netdevsim{self.addr}/", path)
> +        with open(fullpath, "w") as f:
> +            f.write(val)
> +
> +    def __init__(self, port_count=1, ns=None):
> +        # nsim will spawn in init_net, we'll set to actual ns once we switch it the.sre

the.sre?

  reply	other threads:[~2024-04-04 11:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03  2:34 [PATCH net-next v2 0/7] selftests: net: groundwork for YNL-based tests Jakub Kicinski
2024-04-03  2:34 ` [PATCH net-next v2 1/7] netlink: specs: define ethtool header flags Jakub Kicinski
2024-04-04 10:38   ` Petr Machata
2024-04-03  2:34 ` [PATCH net-next v2 2/7] tools: ynl: copy netlink error to NlError Jakub Kicinski
2024-04-04 10:39   ` Petr Machata
2024-04-03  2:34 ` [PATCH net-next v2 3/7] selftests: net: add scaffolding for Netlink tests in Python Jakub Kicinski
2024-04-04  9:11   ` Petr Machata
2024-04-03  2:34 ` [PATCH net-next v2 4/7] selftests: nl_netdev: add a trivial Netlink netdev test Jakub Kicinski
2024-04-04 10:39   ` Petr Machata
2024-04-03  2:34 ` [PATCH net-next v2 5/7] netdevsim: report stats by default, like a real device Jakub Kicinski
2024-04-04 10:40   ` Petr Machata
2024-04-04 13:52     ` Jakub Kicinski
2024-04-04 13:40   ` Paolo Abeni
2024-04-04 13:53     ` Jakub Kicinski
2024-04-03  2:34 ` [PATCH net-next v2 6/7] selftests: drivers: add scaffolding for Netlink tests in Python Jakub Kicinski
2024-04-04 10:42   ` Petr Machata [this message]
2024-04-05  1:58     ` Jakub Kicinski
2024-04-03  2:34 ` [PATCH net-next v2 7/7] testing: net-drv: add a driver test for stats reporting Jakub Kicinski
2024-04-04 17:40 ` [PATCH net-next v2 0/7] selftests: net: groundwork for YNL-based tests patchwork-bot+netdevbpf

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=87zfu9fk2v.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).