From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, donald.hunter@gmail.com,
liuhangbin@gmail.com, matttbe@kernel.org,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 08/10] tools: ynl: convert ethtool sample to selftest
Date: Fri, 6 Mar 2026 19:36:28 -0800 [thread overview]
Message-ID: <20260307033630.1396085-9-kuba@kernel.org> (raw)
In-Reply-To: <20260307033630.1396085-1-kuba@kernel.org>
Convert ethtool.c to use kselftest_harness.h with FIXTURE/TEST_F.
Move ethtool from BINS to TEST_GEN_FILES and add ethtool.sh wrapper
which sets up a netdevsim device before running the test binary.
Output:
TAP version 13
1..2
# Starting 2 tests from 1 test cases.
# RUN ethtool.channels ...
# nsim0: combined 1
# OK ethtool.channels
ok 1 ethtool.channels
# RUN ethtool.rings ...
# nsim0: rx 512 tx 512
# OK ethtool.rings
ok 2 ethtool.rings
# PASSED: 2 / 2 tests passed.
# Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/tests/Makefile | 3 +-
tools/net/ynl/tests/ethtool.c | 83 ++++++++++++++++++++++------------
tools/net/ynl/tests/ethtool.sh | 5 ++
3 files changed, 62 insertions(+), 29 deletions(-)
create mode 100755 tools/net/ynl/tests/ethtool.sh
diff --git a/tools/net/ynl/tests/Makefile b/tools/net/ynl/tests/Makefile
index 14d399a70f10..c380e9f331a3 100644
--- a/tools/net/ynl/tests/Makefile
+++ b/tools/net/ynl/tests/Makefile
@@ -15,6 +15,7 @@ LDLIBS=../lib/ynl.a ../generated/protos.a
TEST_PROGS := \
devlink.sh \
+ ethtool.sh \
test_ynl_cli.sh \
test_ynl_ethtool.sh \
# end of TEST_PROGS
@@ -28,10 +29,10 @@ TEST_GEN_PROGS := \
TEST_GEN_FILES := \
devlink \
+ ethtool \
# end of TEST_GEN_FILES
BINS := \
- ethtool \
rt-addr \
rt-route \
# end of BINS
diff --git a/tools/net/ynl/tests/ethtool.c b/tools/net/ynl/tests/ethtool.c
index a7ebbd1b98db..926a75d23c9b 100644
--- a/tools/net/ynl/tests/ethtool.c
+++ b/tools/net/ynl/tests/ethtool.c
@@ -6,28 +6,49 @@
#include <net/if.h>
+#include <kselftest_harness.h>
+
#include "ethtool-user.h"
-int main(int argc, char **argv)
+FIXTURE(ethtool)
+{
+ struct ynl_sock *ys;
+};
+
+FIXTURE_SETUP(ethtool)
+{
+ self->ys = ynl_sock_create(&ynl_ethtool_family, NULL);
+ ASSERT_NE(NULL, self->ys)
+ TH_LOG("failed to create ethtool socket");
+}
+
+FIXTURE_TEARDOWN(ethtool)
+{
+ ynl_sock_destroy(self->ys);
+}
+
+TEST_F(ethtool, channels)
{
struct ethtool_channels_get_req_dump creq = {};
- struct ethtool_rings_get_req_dump rreq = {};
struct ethtool_channels_get_list *channels;
- struct ethtool_rings_get_list *rings;
- struct ynl_sock *ys;
- ys = ynl_sock_create(&ynl_ethtool_family, NULL);
- if (!ys)
- return 1;
+ creq._present.header = 1; /* ethtool needs an empty nest */
+ channels = ethtool_channels_get_dump(self->ys, &creq);
+ ASSERT_NE(NULL, channels) {
+ TH_LOG("channels dump failed: %s", self->ys->err.msg);
+ }
- creq._present.header = 1; /* ethtool needs an empty nest, sigh */
- channels = ethtool_channels_get_dump(ys, &creq);
- if (!channels)
- goto err_close;
+ if (ynl_dump_empty(channels)) {
+ ethtool_channels_get_list_free(channels);
+ SKIP(return, "no entries in channels dump");
+ }
- printf("Channels:\n");
ynl_dump_foreach(channels, dev) {
- printf(" %8s: ", dev->header.dev_name);
+ EXPECT_TRUE((bool)dev->header._len.dev_name);
+ ksft_print_msg("%8s: ", dev->header.dev_name);
+ EXPECT_TRUE(dev->_present.rx_count ||
+ dev->_present.tx_count ||
+ dev->_present.combined_count);
if (dev->_present.rx_count)
printf("rx %d ", dev->rx_count);
if (dev->_present.tx_count)
@@ -37,15 +58,28 @@ int main(int argc, char **argv)
printf("\n");
}
ethtool_channels_get_list_free(channels);
+}
- rreq._present.header = 1; /* ethtool needs an empty nest.. */
- rings = ethtool_rings_get_dump(ys, &rreq);
- if (!rings)
- goto err_close;
+TEST_F(ethtool, rings)
+{
+ struct ethtool_rings_get_req_dump rreq = {};
+ struct ethtool_rings_get_list *rings;
+
+ rreq._present.header = 1; /* ethtool needs an empty nest */
+ rings = ethtool_rings_get_dump(self->ys, &rreq);
+ ASSERT_NE(NULL, rings) {
+ TH_LOG("rings dump failed: %s", self->ys->err.msg);
+ }
+
+ if (ynl_dump_empty(rings)) {
+ ethtool_rings_get_list_free(rings);
+ SKIP(return, "no entries in rings dump");
+ }
- printf("Rings:\n");
ynl_dump_foreach(rings, dev) {
- printf(" %8s: ", dev->header.dev_name);
+ EXPECT_TRUE((bool)dev->header._len.dev_name);
+ ksft_print_msg("%8s: ", dev->header.dev_name);
+ EXPECT_TRUE(dev->_present.rx || dev->_present.tx);
if (dev->_present.rx)
printf("rx %d ", dev->rx);
if (dev->_present.tx)
@@ -53,13 +87,6 @@ int main(int argc, char **argv)
printf("\n");
}
ethtool_rings_get_list_free(rings);
-
- ynl_sock_destroy(ys);
-
- return 0;
-
-err_close:
- fprintf(stderr, "YNL (%d): %s\n", ys->err.code, ys->err.msg);
- ynl_sock_destroy(ys);
- return 2;
}
+
+TEST_HARNESS_MAIN
diff --git a/tools/net/ynl/tests/ethtool.sh b/tools/net/ynl/tests/ethtool.sh
new file mode 100755
index 000000000000..0859ddd697e8
--- /dev/null
+++ b/tools/net/ynl/tests/ethtool.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh"
+nsim_setup
+"$(dirname "$(realpath "$0")")/ethtool"
--
2.53.0
next prev parent reply other threads:[~2026-03-07 3:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 3:36 [PATCH net-next v2 00/10] tools: ynl: convert samples into selftests Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 01/10] tools: ynl: move samples to tests Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 02/10] tools: ynl: convert netdev sample to selftest Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 03/10] tools: ynl: convert ovs " Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 04/10] tools: ynl: convert rt-link " Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 05/10] tools: ynl: convert tc and tc-filter-add samples " Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 06/10] tools: ynl: add netdevsim wrapper library for YNL tests Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 07/10] tools: ynl: convert devlink sample to selftest Jakub Kicinski
2026-03-07 3:36 ` Jakub Kicinski [this message]
2026-03-07 3:36 ` [PATCH net-next v2 09/10] tools: ynl: convert rt-addr " Jakub Kicinski
2026-03-07 3:36 ` [PATCH net-next v2 10/10] tools: ynl: convert rt-route " Jakub Kicinski
2026-03-08 17:23 ` [PATCH net-next v2 00/10] tools: ynl: convert samples into selftests Donald Hunter
2026-03-10 0:10 ` 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=20260307033630.1396085-9-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=liuhangbin@gmail.com \
--cc=matttbe@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox