All of lore.kernel.org
 help / color / mirror / Atom feed
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 03/10] tools: ynl: convert ovs sample to selftest
Date: Fri,  6 Mar 2026 19:36:23 -0800	[thread overview]
Message-ID: <20260307033630.1396085-4-kuba@kernel.org> (raw)
In-Reply-To: <20260307033630.1396085-1-kuba@kernel.org>

Convert ovs.c to produce KTAP output with kselftest_harness.
The single "crud" test creates a new OVS datapath, fetches it back
by name, then dumps all datapaths verifying the new one appears.

IIRC I added this test because ovs is a genetlink family but
has a family-specific fixed header.

  TAP version 13
  1..1
  # Starting 1 tests from 1 test cases.
  #  RUN           ovs.crud ...
  # get:
  # ynl-test(3): pid:0 cache:256
  # dump:
  # ynl-test(3): pid:0 cache:256
  #            OK  ovs.crud
  ok 1 ovs.crud
  # PASSED: 1 / 1 tests passed.
  # Totals: pass:1 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/ovs.c    | 128 ++++++++++++++++++++++++-----------
 tools/net/ynl/tests/config   |   1 +
 3 files changed, 91 insertions(+), 41 deletions(-)

diff --git a/tools/net/ynl/tests/Makefile b/tools/net/ynl/tests/Makefile
index 1d77d3662f46..df9d37c8b2a4 100644
--- a/tools/net/ynl/tests/Makefile
+++ b/tools/net/ynl/tests/Makefile
@@ -20,12 +20,12 @@ TEST_PROGS := \
 
 TEST_GEN_PROGS := \
 	netdev \
+	ovs \
 # end of TEST_GEN_PROGS
 
 BINS := \
 	devlink \
 	ethtool \
-	ovs \
 	rt-addr \
 	rt-link \
 	rt-route \
@@ -34,6 +34,7 @@ BINS := \
 # end of BINS
 
 CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link)
+CFLAGS_ovs:=$(CFLAGS_ovs_datapath)
 CFLAGS_tc-filter-add:=$(CFLAGS_tc)
 
 include $(wildcard *.d)
diff --git a/tools/net/ynl/tests/ovs.c b/tools/net/ynl/tests/ovs.c
index 3e975c003d77..d49f5a8e647e 100644
--- a/tools/net/ynl/tests/ovs.c
+++ b/tools/net/ynl/tests/ovs.c
@@ -4,57 +4,105 @@
 
 #include <ynl.h>
 
+#include <kselftest_harness.h>
+
 #include "ovs_datapath-user.h"
 
-int main(int argc, char **argv)
+static void ovs_print_datapath(struct __test_metadata *_metadata,
+			       struct ovs_datapath_get_rsp *dp)
+{
+	EXPECT_TRUE((bool)dp->_len.name);
+	if (!dp->_len.name)
+		return;
+
+	EXPECT_TRUE((bool)dp->_hdr.dp_ifindex);
+	ksft_print_msg("%s(%d): pid:%u cache:%u\n",
+		       dp->name, dp->_hdr.dp_ifindex,
+		       dp->upcall_pid, dp->masks_cache_size);
+}
+
+FIXTURE(ovs)
 {
 	struct ynl_sock *ys;
+	char *dp_name;
+};
+
+FIXTURE_SETUP(ovs)
+{
+	self->ys = ynl_sock_create(&ynl_ovs_datapath_family, NULL);
+	ASSERT_NE(NULL, self->ys)
+		TH_LOG("failed to create OVS datapath socket");
+}
+
+FIXTURE_TEARDOWN(ovs)
+{
+	if (self->dp_name) {
+		struct ovs_datapath_del_req *req;
+
+		req = ovs_datapath_del_req_alloc();
+		if (req) {
+			ovs_datapath_del_req_set_name(req, self->dp_name);
+			ovs_datapath_del(self->ys, req);
+			ovs_datapath_del_req_free(req);
+		}
+	}
+	ynl_sock_destroy(self->ys);
+}
+
+TEST_F(ovs, crud)
+{
+	struct ovs_datapath_get_req_dump *dreq;
+	struct ovs_datapath_new_req *new_req;
+	struct ovs_datapath_get_list *dps;
+	struct ovs_datapath_get_rsp *dp;
+	struct ovs_datapath_get_req *req;
+	bool found = false;
 	int err;
 
-	ys = ynl_sock_create(&ynl_ovs_datapath_family, NULL);
-	if (!ys)
-		return 1;
+	new_req = ovs_datapath_new_req_alloc();
+	ASSERT_NE(NULL, new_req);
+	ovs_datapath_new_req_set_upcall_pid(new_req, 1);
+	ovs_datapath_new_req_set_name(new_req, "ynl-test");
 
-	if (argc > 1) {
-		struct ovs_datapath_new_req *req;
+	err = ovs_datapath_new(self->ys, new_req);
+	ovs_datapath_new_req_free(new_req);
+	ASSERT_EQ(0, err) {
+		TH_LOG("new failed: %s", self->ys->err.msg);
+	}
+	self->dp_name = "ynl-test";
 
-		req = ovs_datapath_new_req_alloc();
-		if (!req)
-			goto err_close;
+	ksft_print_msg("get:\n");
+	req = ovs_datapath_get_req_alloc();
+	ASSERT_NE(NULL, req);
+	ovs_datapath_get_req_set_name(req, "ynl-test");
 
-		ovs_datapath_new_req_set_upcall_pid(req, 1);
-		ovs_datapath_new_req_set_name(req, argv[1]);
-
-		err = ovs_datapath_new(ys, req);
-		ovs_datapath_new_req_free(req);
-		if (err)
-			goto err_close;
-	} else {
-		struct ovs_datapath_get_req_dump *req;
-		struct ovs_datapath_get_list *dps;
-
-		printf("Dump:\n");
-		req = ovs_datapath_get_req_dump_alloc();
-
-		dps = ovs_datapath_get_dump(ys, req);
-		ovs_datapath_get_req_dump_free(req);
-		if (!dps)
-			goto err_close;
-
-		ynl_dump_foreach(dps, dp) {
-			printf("  %s(%d): pid:%u cache:%u\n",
-			       dp->name, dp->_hdr.dp_ifindex,
-			       dp->upcall_pid, dp->masks_cache_size);
-		}
-		ovs_datapath_get_list_free(dps);
+	dp = ovs_datapath_get(self->ys, req);
+	ovs_datapath_get_req_free(req);
+	ASSERT_NE(NULL, dp) {
+		TH_LOG("get failed: %s", self->ys->err.msg);
 	}
 
-	ynl_sock_destroy(ys);
+	ovs_print_datapath(_metadata, dp);
+	EXPECT_STREQ("ynl-test", dp->name);
+	ovs_datapath_get_rsp_free(dp);
 
-	return 0;
+	ksft_print_msg("dump:\n");
+	dreq = ovs_datapath_get_req_dump_alloc();
+	ASSERT_NE(NULL, dreq);
 
-err_close:
-	fprintf(stderr, "YNL (%d): %s\n", ys->err.code, ys->err.msg);
-	ynl_sock_destroy(ys);
-	return 2;
+	dps = ovs_datapath_get_dump(self->ys, dreq);
+	ovs_datapath_get_req_dump_free(dreq);
+	ASSERT_NE(NULL, dps) {
+		TH_LOG("dump failed: %s", self->ys->err.msg);
+	}
+
+	ynl_dump_foreach(dps, d) {
+		ovs_print_datapath(_metadata, d);
+		if (d->name && !strcmp(d->name, "ynl-test"))
+			found = true;
+	}
+	ovs_datapath_get_list_free(dps);
+	EXPECT_TRUE(found);
 }
+
+TEST_HARNESS_MAIN
diff --git a/tools/net/ynl/tests/config b/tools/net/ynl/tests/config
index 339f1309c03f..357b34611da4 100644
--- a/tools/net/ynl/tests/config
+++ b/tools/net/ynl/tests/config
@@ -3,4 +3,5 @@ CONFIG_INET_DIAG=y
 CONFIG_IPV6=y
 CONFIG_NET_NS=y
 CONFIG_NETDEVSIM=m
+CONFIG_OPENVSWITCH=m
 CONFIG_VETH=m
-- 
2.53.0


  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 ` Jakub Kicinski [this message]
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 ` [PATCH net-next v2 08/10] tools: ynl: convert ethtool " Jakub Kicinski
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-4-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 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.