From: Joe Damato <joe@dama.to>
To: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: andrew+netdev@lunn.ch, linux-kernel@vger.kernel.org,
willemb@google.com, Joe Damato <joe@dama.to>,
linux-kselftest@vger.kernel.org
Subject: [net-next v2 1/3] selftests/net: Test PACKET_STATISTICS
Date: Fri, 3 Apr 2026 16:32:36 -0700 [thread overview]
Message-ID: <20260403233240.178948-2-joe@dama.to> (raw)
In-Reply-To: <20260403233240.178948-1-joe@dama.to>
Update the existing packet socket test to include a test for the sockopt
PACKET_STATISTICS.
Signed-off-by: Joe Damato <joe@dama.to>
---
tools/testing/selftests/net/psock_snd.c | 32 ++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/psock_snd.c b/tools/testing/selftests/net/psock_snd.c
index edf1e6f80d41..5be481a3d2bd 100644
--- a/tools/testing/selftests/net/psock_snd.c
+++ b/tools/testing/selftests/net/psock_snd.c
@@ -359,6 +359,34 @@ static void parse_opts(int argc, char **argv)
error(1, 0, "option gso (-g) requires csum offload (-c)");
}
+static void check_packet_stats(int fd)
+{
+ struct tpacket_stats st = {};
+ socklen_t len = sizeof(st);
+
+ if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &len))
+ error(1, errno, "getsockopt packet statistics");
+
+ if (st.tp_packets != 1)
+ error(1, 0, "stats: tp_packets %u != 1", st.tp_packets);
+
+ if (st.tp_drops != 0)
+ error(1, 0, "stats: tp_drops %u != 0", st.tp_drops);
+
+ /* verify clear on read */
+ memset(&st, 0xff, sizeof(st));
+ len = sizeof(st);
+
+ if (getsockopt(fd, SOL_PACKET, PACKET_STATISTICS, &st, &len))
+ error(1, errno, "getsockopt packet statistics");
+
+ if (st.tp_packets != 0)
+ error(1, 0, "stats: tp_packets %u != 0 after clear", st.tp_packets);
+
+ if (st.tp_drops != 0)
+ error(1, 0, "stats: tp_drops %u != 0 after clear", st.tp_drops);
+}
+
static void run_test(void)
{
int fdr, fds, total_len;
@@ -369,9 +397,11 @@ static void run_test(void)
total_len = do_tx();
/* BPF filter accepts only this length, vlan changes MAC */
- if (cfg_payload_len == DATA_LEN && !cfg_use_vlan)
+ if (cfg_payload_len == DATA_LEN && !cfg_use_vlan) {
do_rx(fds, total_len - sizeof(struct virtio_net_hdr),
tbuf + sizeof(struct virtio_net_hdr));
+ check_packet_stats(fds);
+ }
do_rx(fdr, cfg_payload_len, tbuf + total_len - cfg_payload_len);
--
2.52.0
next prev parent reply other threads:[~2026-04-03 23:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 23:32 [net-next 0/3] Extend packet socket selftests Joe Damato
2026-04-03 23:32 ` Joe Damato [this message]
2026-04-03 23:32 ` [net-next v2 2/3] selftests/net: Test PACKET_STATISTICS drops Joe Damato
2026-04-04 15:08 ` Willem de Bruijn
2026-04-06 16:29 ` Joe Damato
2026-04-06 18:37 ` Jakub Kicinski
2026-04-06 21:20 ` Willem de Bruijn
2026-04-03 23:32 ` [net-next v2 3/3] selftests/net: Test PACKET_AUXDATA Joe Damato
2026-04-04 15:10 ` Willem de Bruijn
2026-04-06 16:36 ` Joe Damato
2026-04-05 3:04 ` Willem de Bruijn
2026-04-05 3:30 ` Willem de Bruijn
2026-04-06 17:01 ` Joe Damato
2026-04-06 20:56 ` Willem de Bruijn
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=20260403233240.178948-2-joe@dama.to \
--to=joe@dama.to \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=willemb@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.