From: Isaac Boukris <iboukris@gmail.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
Chenbo Xia <chenbox@nvidia.com>
Cc: dev@dpdk.org, David Marchand <david.marchand@redhat.com>,
Aman Singh <aman.deep.singh@intel.com>,
Luca Vizzarro <luca.vizzarro@arm.com>,
Patrick Robb <patrickrobb1997@gmail.com>,
Isaac Boukris <iboukris@gmail.com>
Subject: [PATCH v4 4/8] test/virtio_user: add unit test of unused queue pairs
Date: Wed, 18 Nov 2026 10:27:48 +0200 [thread overview]
Message-ID: <20261118082752.1043794-5-iboukris@gmail.com> (raw)
In-Reply-To: <20261118082752.1043794-1-iboukris@gmail.com>
Add a test suite for the virtio PMD on a virtio-user port with
vhost-net, modeled on the TAP PMD's. It needs no VM and no PCI
device. It is skipped where the port cannot be created (no root, no
/dev/vhost-net).
The port has two queue pairs and the test configures one Rx queue.
The kernel sends frames of 16 flows through a packet socket on the
TAP interface, and all must arrive. Without the fix of the unused
queue pairs, about half of them go to the TAP queue of the second
queue pair and are lost.
DPDK_TEST=virtio_user_pmd_autotest ./build/app/dpdk-test --no-huge
Signed-off-by: Isaac Boukris <iboukris@gmail.com>
---
v4: ignore a flow number that is out of range. Shorter comments.
v3: new patch. It has the test suite and the kernel socket that patch 2 of v2 added.
MAINTAINERS | 1 +
app/test/meson.build | 1 +
app/test/test_pmd_virtio_user.c | 264 ++++++++++++++++++++++++++++++++
3 files changed, 266 insertions(+)
create mode 100644 app/test/test_pmd_virtio_user.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 8fcb4ef5fa..36dd253f36 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1106,6 +1106,7 @@ T: git://dpdk.org/next/dpdk-next-virtio
F: drivers/net/virtio/
F: doc/guides/nics/virtio.rst
F: doc/guides/nics/features/virtio*.ini
+F: app/test/test_pmd_virtio_user.c
Wind River AVP
M: Steven Webster <steven.webster@windriver.com>
diff --git a/app/test/meson.build b/app/test/meson.build
index 2f1cd817cd..e480353885 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -155,6 +155,7 @@ source_file_deps = {
'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'],
'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'],
'test_pmd_tap.c': ['ethdev', 'net_tap', 'bus_vdev'],
+ 'test_pmd_virtio_user.c': ['ethdev', 'net_virtio', 'bus_vdev'],
'test_pmu.c': ['pmu'],
'test_power.c': ['power', 'power_acpi', 'power_kvm_vm', 'power_intel_pstate',
'power_amd_pstate', 'power_cppc'],
diff --git a/app/test/test_pmd_virtio_user.c b/app/test/test_pmd_virtio_user.c
new file mode 100644
index 0000000000..c47d5a833b
--- /dev/null
+++ b/app/test/test_pmd_virtio_user.c
@@ -0,0 +1,264 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Isaac Boukris
+ */
+
+/*
+ * Tests of the virtio PMD on a virtio-user port backed by vhost-net and a TAP
+ * interface. They need no VM and no PCI device. The kernel's end is a packet
+ * socket on the TAP interface.
+ */
+
+#include "test.h"
+
+#include <stdio.h>
+
+#ifndef RTE_EXEC_ENV_LINUX
+
+static int
+test_pmd_virtio_user(void)
+{
+ printf("virtio-user with vhost-net is only available on Linux, skipping test\n");
+ return TEST_SKIPPED;
+}
+
+#else /* RTE_EXEC_ENV_LINUX */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/if_packet.h>
+#include <linux/virtio_net.h>
+
+#include <rte_bus_vdev.h>
+#include <rte_cycles.h>
+#include <rte_ethdev.h>
+#include <rte_ether.h>
+#include <rte_ip.h>
+#include <rte_mbuf.h>
+
+#define VDEV_NAME "net_virtio_user_test"
+#define TAP_NAME "dtap_vu_test"
+#define RING_SIZE 256
+#define NB_MBUF 1024
+#define BURST 32
+#define WAIT_MS 1000
+/* The test frames' IP protocol (experimental, RFC 3692) */
+#define TEST_IP_PROTO 253
+#define NB_FLOWS 16
+
+static struct rte_mempool *mp;
+static uint16_t port_id = RTE_MAX_ETHPORTS;
+static int ksock = -1; /* the kernel's end, each frame follows a virtio_net_hdr */
+static bool started;
+
+static int
+port_stop(void)
+{
+ int ret;
+
+ if (!started)
+ return TEST_SUCCESS;
+ started = false;
+ ret = rte_eth_dev_stop(port_id);
+ TEST_ASSERT_SUCCESS(ret, "stop failed: %s", rte_strerror(-ret));
+
+ return TEST_SUCCESS;
+}
+
+/* Configure the port and start it. A failed case may have left it started. */
+static int
+port_start(const struct rte_eth_conf *conf)
+{
+ int ret;
+
+ TEST_ASSERT_SUCCESS(port_stop(), "port stop failed");
+ ret = rte_eth_dev_configure(port_id, 1, 1, conf);
+ TEST_ASSERT_SUCCESS(ret, "configure failed: %s", rte_strerror(-ret));
+ ret = rte_eth_rx_queue_setup(port_id, 0, RING_SIZE, SOCKET_ID_ANY, NULL, mp);
+ TEST_ASSERT_SUCCESS(ret, "Rx queue setup failed: %s", rte_strerror(-ret));
+ ret = rte_eth_tx_queue_setup(port_id, 0, RING_SIZE, SOCKET_ID_ANY, NULL);
+ TEST_ASSERT_SUCCESS(ret, "Tx queue setup failed: %s", rte_strerror(-ret));
+ ret = rte_eth_dev_start(port_id);
+ TEST_ASSERT_SUCCESS(ret, "start failed: %s", rte_strerror(-ret));
+ started = true;
+
+ return TEST_SUCCESS;
+}
+
+/*
+ * Send a frame from the kernel's end. The kernel picks the TAP queue by a hash
+ * of the frame's addresses, so the source address makes the flow.
+ */
+static int
+kernel_send(uint8_t flow)
+{
+ struct {
+ struct virtio_net_hdr vnet; /* no offload */
+ struct rte_ether_hdr eth;
+ struct rte_ipv4_hdr ip;
+ uint8_t payload[RTE_ETHER_MIN_LEN];
+ } frame;
+ ssize_t n;
+
+ memset(&frame, 0, sizeof(frame));
+ memset(&frame.eth.dst_addr, 0xff, RTE_ETHER_ADDR_LEN);
+ frame.eth.src_addr.addr_bytes[0] = RTE_ETHER_LOCAL_ADMIN_ADDR;
+ frame.eth.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
+ frame.ip.version_ihl = RTE_IPV4_VHL_DEF;
+ frame.ip.total_length = rte_cpu_to_be_16(sizeof(frame.ip) + sizeof(frame.payload));
+ frame.ip.time_to_live = 64;
+ frame.ip.next_proto_id = TEST_IP_PROTO;
+ frame.ip.src_addr = rte_cpu_to_be_32(RTE_IPV4(192, 0, 2, flow));
+ frame.ip.dst_addr = rte_cpu_to_be_32(RTE_IPV4(198, 51, 100, 1));
+ frame.ip.hdr_checksum = rte_ipv4_cksum(&frame.ip);
+ n = send(ksock, &frame, sizeof(frame), 0);
+ TEST_ASSERT(n == (ssize_t)sizeof(frame), "send on %s failed: %s", TAP_NAME,
+ strerror(errno));
+
+ return TEST_SUCCESS;
+}
+
+/* Receive what the queue holds. Return the flows of the frames of kernel_send(), a bit each. */
+static uint32_t
+port_receive(void)
+{
+ struct rte_mbuf *pkts[BURST];
+ uint32_t flows = 0;
+ uint16_t i, n;
+
+ while ((n = rte_eth_rx_burst(port_id, 0, pkts, BURST)) != 0) {
+ for (i = 0; i < n; i++) {
+ const struct rte_ether_hdr *eth =
+ rte_pktmbuf_mtod(pkts[i], const struct rte_ether_hdr *);
+ const struct rte_ipv4_hdr *ip = (const struct rte_ipv4_hdr *)(eth + 1);
+ uint8_t flow = NB_FLOWS;
+
+ if (rte_pktmbuf_data_len(pkts[i]) >= sizeof(*eth) + sizeof(*ip) &&
+ eth->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4) &&
+ ip->next_proto_id == TEST_IP_PROTO)
+ flow = rte_be_to_cpu_32(ip->src_addr) & 0xff;
+ if (flow < NB_FLOWS)
+ flows |= UINT32_C(1) << flow;
+ }
+ rte_pktmbuf_free_bulk(pkts, n);
+ }
+
+ return flows;
+}
+
+/*
+ * The port has two queue pairs and one Rx queue. The frames of all the flows
+ * that the kernel sends must arrive on it.
+ */
+static int
+test_virtio_user_rx_flows(void)
+{
+ const uint32_t all = RTE_LEN2MASK(NB_FLOWS, uint32_t);
+ struct rte_eth_conf conf = { 0 };
+ uint32_t flows = 0;
+ uint64_t deadline;
+ uint8_t flow;
+
+ TEST_ASSERT_SUCCESS(port_start(&conf), "port start failed");
+ for (flow = 0; flow < NB_FLOWS; flow++)
+ TEST_ASSERT_SUCCESS(kernel_send(flow), "kernel send failed");
+ deadline = rte_get_timer_cycles() + rte_get_timer_hz() * WAIT_MS / 1000;
+ while (flows != all && rte_get_timer_cycles() < deadline)
+ flows |= port_receive();
+ TEST_ASSERT(flows == all, "received the flows 0x%x of 0x%x", flows, all);
+ TEST_ASSERT_SUCCESS(port_stop(), "port stop failed");
+
+ return TEST_SUCCESS;
+}
+
+static void
+test_virtio_user_cleanup(void)
+{
+ if (ksock >= 0)
+ close(ksock);
+ ksock = -1;
+ if (port_id != RTE_MAX_ETHPORTS) {
+ port_stop();
+ rte_eth_dev_close(port_id);
+ rte_vdev_uninit(VDEV_NAME);
+ }
+ port_id = RTE_MAX_ETHPORTS;
+ rte_mempool_free(mp);
+ mp = NULL;
+}
+
+/* Set the TAP interface up and bind a packet socket to it. */
+static int
+kernel_open(void)
+{
+ struct sockaddr_ll addr = {
+ .sll_family = AF_PACKET,
+ .sll_protocol = htons(ETH_P_ALL),
+ };
+ struct ifreq ifr;
+ int one = 1;
+
+ ksock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ if (ksock < 0)
+ return -1;
+ memset(&ifr, 0, sizeof(ifr));
+ strlcpy(ifr.ifr_name, TAP_NAME, sizeof(ifr.ifr_name));
+ if (ioctl(ksock, SIOCGIFFLAGS, &ifr) < 0)
+ return -1;
+ ifr.ifr_flags |= IFF_UP;
+ if (ioctl(ksock, SIOCSIFFLAGS, &ifr) < 0)
+ return -1;
+ addr.sll_ifindex = if_nametoindex(TAP_NAME);
+ if (addr.sll_ifindex == 0 ||
+ bind(ksock, (const struct sockaddr *)&addr, sizeof(addr)) < 0 ||
+ setsockopt(ksock, SOL_PACKET, PACKET_VNET_HDR, &one, sizeof(one)) < 0)
+ return -1;
+
+ return 0;
+}
+
+static int
+test_virtio_user_setup(void)
+{
+ mp = rte_pktmbuf_pool_create("virtio_user_test", NB_MBUF, 32, 0,
+ RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
+ TEST_ASSERT_NOT_NULL(mp, "mempool creation failed: %s", rte_strerror(rte_errno));
+
+ /* The tests use one of the two queue pairs. The TAP interface takes CAP_NET_ADMIN. */
+ if (rte_vdev_init(VDEV_NAME, "path=/dev/vhost-net,iface=" TAP_NAME ",queues=2") < 0 ||
+ rte_eth_dev_get_port_by_name(VDEV_NAME, &port_id) != 0) {
+ printf("No virtio-user port on /dev/vhost-net, skipping test\n");
+ test_virtio_user_cleanup();
+ return TEST_SKIPPED;
+ }
+ if (kernel_open() < 0) {
+ printf("No packet socket on %s (%s), skipping test\n", TAP_NAME, strerror(errno));
+ test_virtio_user_cleanup();
+ return TEST_SKIPPED;
+ }
+
+ return TEST_SUCCESS;
+}
+
+static struct unit_test_suite test_pmd_virtio_user_suite = {
+ .setup = test_virtio_user_setup,
+ .teardown = test_virtio_user_cleanup,
+ .suite_name = "virtio-user PMD Unit Test Suite",
+ .unit_test_cases = {
+ TEST_CASE(test_virtio_user_rx_flows),
+ TEST_CASES_END()
+ }
+};
+
+static int
+test_pmd_virtio_user(void)
+{
+ return unit_test_suite_runner(&test_pmd_virtio_user_suite);
+}
+
+#endif /* RTE_EXEC_ENV_LINUX */
+
+REGISTER_FAST_TEST(virtio_user_pmd_autotest, NOHUGE_OK, ASAN_OK, test_pmd_virtio_user);
--
2.56.1
next prev parent reply other threads:[~2026-11-18 8:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 12:43 [PATCH 0/1] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-17 12:43 ` [PATCH 1/1] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-17 14:29 ` David Marchand
2026-11-17 19:51 ` Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 0/5] net/virtio: fix Rx interrupts " Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 1/5] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 2/5] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 3/5] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-17 22:00 ` [PATCH v2 4/5] dts: support virtio PCI ports Isaac Boukris
2026-11-17 22:00 ` [PATCH v2 5/5] dts: add Rx interrupt test suite Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 0/7] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 1/7] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 2/7] net/virtio-user: fix packet loss with unused queue pairs Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 3/7] test/virtio_user: add unit test of " Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 4/7] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 5/7] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 6/7] dts: support virtio PCI ports Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 7/7] dts: add Rx interrupt test suite Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 0/8] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 1/8] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 2/8] net/virtio-user: fix packet loss with unused queue pairs Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 3/8] net/virtio-user: fix unaligned reads of control commands Isaac Boukris
2026-11-18 8:27 ` Isaac Boukris [this message]
2026-11-18 8:27 ` [PATCH v4 5/8] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 6/8] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 7/8] dts: support virtio PCI ports Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 8/8] dts: add Rx interrupt test suite Isaac Boukris
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=20261118082752.1043794-5-iboukris@gmail.com \
--to=iboukris@gmail.com \
--cc=aman.deep.singh@intel.com \
--cc=chenbox@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=luca.vizzarro@arm.com \
--cc=maxime.coquelin@redhat.com \
--cc=patrickrobb1997@gmail.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.