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 06/10] tools: ynl: add netdevsim wrapper library for YNL tests
Date: Thu, 5 Mar 2026 18:08:57 -0800 [thread overview]
Message-ID: <20260306020901.524105-7-kuba@kernel.org> (raw)
In-Reply-To: <20260306020901.524105-1-kuba@kernel.org>
Some tests need netdevsim setup which is painful to do from C.
Add ynl_nsim_lib.sh, a shared library providing nsim_setup and
nsim_cleanup functions for tests that need a netdevsim device.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/tests/Makefile | 5 +++++
tools/net/ynl/tests/ynl_nsim_lib.sh | 35 +++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
create mode 100644 tools/net/ynl/tests/ynl_nsim_lib.sh
diff --git a/tools/net/ynl/tests/Makefile b/tools/net/ynl/tests/Makefile
index 524092a8de7e..a329de031add 100644
--- a/tools/net/ynl/tests/Makefile
+++ b/tools/net/ynl/tests/Makefile
@@ -32,6 +32,8 @@ BINS := \
rt-route \
# end of BINS
+TEST_FILES := ynl_nsim_lib.sh
+
CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link)
CFLAGS_ovs:=$(CFLAGS_ovs_datapath)
@@ -68,6 +70,9 @@ install: $(TEST_GEN_PROGS) $(BINS)
$$test > $(INSTALL_PATH)/ynl/$$name; \
chmod +x $(INSTALL_PATH)/ynl/$$name; \
done
+ @for file in $(TEST_FILES); do \
+ cp $$file $(INSTALL_PATH)/ynl/$$file; \
+ done
@for bin in $(TEST_GEN_PROGS) $(BINS); do \
cp $$bin $(INSTALL_PATH)/ynl/$$bin; \
done
diff --git a/tools/net/ynl/tests/ynl_nsim_lib.sh b/tools/net/ynl/tests/ynl_nsim_lib.sh
new file mode 100644
index 000000000000..98cdce44a69c
--- /dev/null
+++ b/tools/net/ynl/tests/ynl_nsim_lib.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Shared netdevsim setup/cleanup for YNL C test wrappers
+
+NSIM_ID="1337"
+NSIM_DEV=""
+KSFT_SKIP=4
+
+nsim_cleanup() {
+ echo "$NSIM_ID" > /sys/bus/netdevsim/del_device 2>/dev/null || true
+}
+
+nsim_setup() {
+ modprobe netdevsim 2>/dev/null
+ if ! [ -f /sys/bus/netdevsim/new_device ]; then
+ echo "netdevsim module not available, skipping" >&2
+ exit "$KSFT_SKIP"
+ fi
+
+ trap nsim_cleanup EXIT
+
+ echo "$NSIM_ID 1" > /sys/bus/netdevsim/new_device
+ udevadm settle
+
+ NSIM_DEV=$(ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net 2>/dev/null | head -1)
+ if [ -z "$NSIM_DEV" ]; then
+ echo "failed to find netdevsim device" >&2
+ exit 1
+ fi
+
+ ip link set dev "$NSIM_DEV" name nsim0
+ ip link set dev nsim0 up
+ ip addr add 192.168.1.1/24 dev nsim0
+ ip addr add 2001:db8::1/64 dev nsim0 nodad
+}
--
2.53.0
next prev parent reply other threads:[~2026-03-06 2:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 2:08 [PATCH net-next 00/10] tools: ynl: convert samples into selftests Jakub Kicinski
2026-03-06 2:08 ` [PATCH net-next 01/10] tools: ynl: move samples to tests Jakub Kicinski
2026-03-06 12:07 ` Donald Hunter
2026-03-06 2:08 ` [PATCH net-next 02/10] tools: ynl: convert netdev sample to selftest Jakub Kicinski
2026-03-06 13:45 ` Donald Hunter
2026-03-06 2:08 ` [PATCH net-next 03/10] tools: ynl: convert ovs " Jakub Kicinski
2026-03-06 2:08 ` [PATCH net-next 04/10] tools: ynl: convert rt-link " Jakub Kicinski
2026-03-06 14:29 ` Donald Hunter
2026-03-07 0:09 ` Jakub Kicinski
2026-03-06 2:08 ` [PATCH net-next 05/10] tools: ynl: convert tc and tc-filter-add samples " Jakub Kicinski
2026-03-06 2:08 ` Jakub Kicinski [this message]
2026-03-06 12:23 ` [PATCH net-next 06/10] tools: ynl: add netdevsim wrapper library for YNL tests Donald Hunter
2026-03-06 2:08 ` [PATCH net-next 07/10] tools: ynl: convert devlink sample to selftest Jakub Kicinski
2026-03-06 11:53 ` Donald Hunter
2026-03-07 0:11 ` Jakub Kicinski
2026-03-06 2:08 ` [PATCH net-next 08/10] tools: ynl: convert ethtool " Jakub Kicinski
2026-03-06 2:09 ` [PATCH net-next 09/10] tools: ynl: convert rt-addr " Jakub Kicinski
2026-03-06 2:09 ` [PATCH net-next 10/10] tools: ynl: convert rt-route " Jakub Kicinski
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=20260306020901.524105-7-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.