Skip to content

Commit

Permalink
testing: net-drv: add basic shaper test
Browse files Browse the repository at this point in the history
Leverage a basic/dummy netdevsim implementation to do functional
coverage for NL interface.

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Link: https://patch.msgid.link/43092afbf38365c796088bf8fc155e523ab434ae.1728460186.git.pabeni@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Paolo Abeni authored and Jakub Kicinski committed Oct 10, 2024
1 parent ecd82cf commit b3ea416
Show file tree
Hide file tree
Showing 7 changed files with 510 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ config NETDEVSIM
depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
select NET_DEVLINK
select PAGE_POOL
select NET_SHAPER
help
This driver is a developer testing tool and software model that can
be used to test various control path networking APIs, especially
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/netdevsim/ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ nsim_set_channels(struct net_device *dev, struct ethtool_channels *ch)
struct netdevsim *ns = netdev_priv(dev);
int err;

mutex_lock(&dev->lock);
err = netif_set_real_num_queues(dev, ch->combined_count,
ch->combined_count);
mutex_unlock(&dev->lock);
if (err)
return err;

Expand Down
39 changes: 39 additions & 0 deletions drivers/net/netdevsim/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <net/netdev_queues.h>
#include <net/page_pool/helpers.h>
#include <net/netlink.h>
#include <net/net_shaper.h>
#include <net/pkt_cls.h>
#include <net/rtnetlink.h>
#include <net/udp_tunnel.h>
Expand Down Expand Up @@ -475,6 +476,43 @@ static int nsim_stop(struct net_device *dev)
return 0;
}

static int nsim_shaper_set(struct net_shaper_binding *binding,
const struct net_shaper *shaper,
struct netlink_ext_ack *extack)
{
return 0;
}

static int nsim_shaper_del(struct net_shaper_binding *binding,
const struct net_shaper_handle *handle,
struct netlink_ext_ack *extack)
{
return 0;
}

static int nsim_shaper_group(struct net_shaper_binding *binding,
int leaves_count,
const struct net_shaper *leaves,
const struct net_shaper *root,
struct netlink_ext_ack *extack)
{
return 0;
}

static void nsim_shaper_cap(struct net_shaper_binding *binding,
enum net_shaper_scope scope,
unsigned long *flags)
{
*flags = ULONG_MAX;
}

static const struct net_shaper_ops nsim_shaper_ops = {
.set = nsim_shaper_set,
.delete = nsim_shaper_del,
.group = nsim_shaper_group,
.capabilities = nsim_shaper_cap,
};

static const struct net_device_ops nsim_netdev_ops = {
.ndo_start_xmit = nsim_start_xmit,
.ndo_set_rx_mode = nsim_set_rx_mode,
Expand All @@ -496,6 +534,7 @@ static const struct net_device_ops nsim_netdev_ops = {
.ndo_bpf = nsim_bpf,
.ndo_open = nsim_open,
.ndo_stop = nsim_stop,
.net_shaper_ops = &nsim_shaper_ops,
};

static const struct net_device_ops nsim_vf_netdev_ops = {
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/drivers/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TEST_PROGS := \
ping.py \
queues.py \
stats.py \
shaper.py
# end of TEST_PROGS

include ../../lib.mk
Loading

0 comments on commit b3ea416

Please sign in to comment.