Skip to content

Commit b3ea416

Browse files
Paolo Abenikuba-moo
authored andcommitted
testing: net-drv: add basic shaper test
Leverage a basic/dummy netdevsim implementation to do functional coverage for NL interface. Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Link: https://patch.msgid.link/43092afbf38365c796088bf8fc155e523ab434ae.1728460186.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ecd82cf commit b3ea416

File tree

7 files changed

+510
-0
lines changed

7 files changed

+510
-0
lines changed

drivers/net/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ config NETDEVSIM
641641
depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
642642
select NET_DEVLINK
643643
select PAGE_POOL
644+
select NET_SHAPER
644645
help
645646
This driver is a developer testing tool and software model that can
646647
be used to test various control path networking APIs, especially

drivers/net/netdevsim/ethtool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ nsim_set_channels(struct net_device *dev, struct ethtool_channels *ch)
103103
struct netdevsim *ns = netdev_priv(dev);
104104
int err;
105105

106+
mutex_lock(&dev->lock);
106107
err = netif_set_real_num_queues(dev, ch->combined_count,
107108
ch->combined_count);
109+
mutex_unlock(&dev->lock);
108110
if (err)
109111
return err;
110112

drivers/net/netdevsim/netdev.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <net/netdev_queues.h>
2323
#include <net/page_pool/helpers.h>
2424
#include <net/netlink.h>
25+
#include <net/net_shaper.h>
2526
#include <net/pkt_cls.h>
2627
#include <net/rtnetlink.h>
2728
#include <net/udp_tunnel.h>
@@ -475,6 +476,43 @@ static int nsim_stop(struct net_device *dev)
475476
return 0;
476477
}
477478

479+
static int nsim_shaper_set(struct net_shaper_binding *binding,
480+
const struct net_shaper *shaper,
481+
struct netlink_ext_ack *extack)
482+
{
483+
return 0;
484+
}
485+
486+
static int nsim_shaper_del(struct net_shaper_binding *binding,
487+
const struct net_shaper_handle *handle,
488+
struct netlink_ext_ack *extack)
489+
{
490+
return 0;
491+
}
492+
493+
static int nsim_shaper_group(struct net_shaper_binding *binding,
494+
int leaves_count,
495+
const struct net_shaper *leaves,
496+
const struct net_shaper *root,
497+
struct netlink_ext_ack *extack)
498+
{
499+
return 0;
500+
}
501+
502+
static void nsim_shaper_cap(struct net_shaper_binding *binding,
503+
enum net_shaper_scope scope,
504+
unsigned long *flags)
505+
{
506+
*flags = ULONG_MAX;
507+
}
508+
509+
static const struct net_shaper_ops nsim_shaper_ops = {
510+
.set = nsim_shaper_set,
511+
.delete = nsim_shaper_del,
512+
.group = nsim_shaper_group,
513+
.capabilities = nsim_shaper_cap,
514+
};
515+
478516
static const struct net_device_ops nsim_netdev_ops = {
479517
.ndo_start_xmit = nsim_start_xmit,
480518
.ndo_set_rx_mode = nsim_set_rx_mode,
@@ -496,6 +534,7 @@ static const struct net_device_ops nsim_netdev_ops = {
496534
.ndo_bpf = nsim_bpf,
497535
.ndo_open = nsim_open,
498536
.ndo_stop = nsim_stop,
537+
.net_shaper_ops = &nsim_shaper_ops,
499538
};
500539

501540
static const struct net_device_ops nsim_vf_netdev_ops = {

tools/testing/selftests/drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ TEST_PROGS := \
99
ping.py \
1010
queues.py \
1111
stats.py \
12+
shaper.py
1213
# end of TEST_PROGS
1314

1415
include ../../lib.mk

0 commit comments

Comments
 (0)