[PATCH v3 4/7] test/virtio_user: add unit test of Rx interrupts

Isaac Boukris iboukris at gmail.com
Wed Nov 18 01:19:15 CET 2026


Add a case that configures the port with Rx interrupts and an Rx
offload. It enables the interrupt of the Rx queue, sends a frame from
the kernel and sleeps on the interrupt. The frame must end the sleep.
Then it does the same after a second configure.

The port has two queue pairs and the test configures one Rx queue, so
the port has more interrupt eventfds than Rx queues. These eventfds
are the backend's call fds, and the driver must not release them. If
it does when it initializes the device again, the test fails.

Signed-off-by: Isaac Boukris <iboukris at gmail.com>
---
v3: on top of the previous patch. The test frame is now an IPv4 one.

 app/test/test_pmd_virtio_user.c | 73 +++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/app/test/test_pmd_virtio_user.c b/app/test/test_pmd_virtio_user.c
index d8cf4f6a5d..3b60b268ba 100644
--- a/app/test/test_pmd_virtio_user.c
+++ b/app/test/test_pmd_virtio_user.c
@@ -34,6 +34,7 @@ test_pmd_virtio_user(void)
 
 #include <rte_bus_vdev.h>
 #include <rte_cycles.h>
+#include <rte_epoll.h>
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 #include <rte_ip.h>
@@ -173,6 +174,77 @@ test_virtio_user_rx_flows(void)
 	return TEST_SUCCESS;
 }
 
+/* Sleep on the Rx queue's interrupt. A frame from the kernel must end the sleep. */
+static int
+rx_intr_wakes(void)
+{
+	uint64_t deadline = rte_get_timer_cycles() + rte_get_timer_hz() * WAIT_MS / 1000;
+	struct rte_epoll_event event;
+	bool found;
+	int ret;
+
+	ret = rte_eth_dev_rx_intr_ctl_q(port_id, 0, RTE_EPOLL_PER_THREAD, RTE_INTR_EVENT_ADD,
+					NULL);
+	TEST_ASSERT_SUCCESS(ret, "no interrupt for the Rx queue: %s", rte_strerror(-ret));
+
+	do {
+		/*
+		 * Enable the interrupt before the kernel sends. A frame that
+		 * arrives from now on raises it, also before the sleep below.
+		 */
+		ret = rte_eth_dev_rx_intr_enable(port_id, 0);
+		TEST_ASSERT_SUCCESS(ret, "Rx interrupt enable failed: %s", rte_strerror(-ret));
+		/* Drop the frames that the kernel sent earlier, and their event. */
+		port_receive();
+		rte_epoll_wait(RTE_EPOLL_PER_THREAD, &event, 1, 0);
+
+		TEST_ASSERT_SUCCESS(kernel_send(0), "kernel send failed");
+		ret = rte_epoll_wait(RTE_EPOLL_PER_THREAD, &event, 1, WAIT_MS);
+		TEST_ASSERT(ret == 1, "no Rx interrupt within %d ms", WAIT_MS);
+		ret = rte_eth_dev_rx_intr_disable(port_id, 0);
+		TEST_ASSERT_SUCCESS(ret, "Rx interrupt disable failed: %s", rte_strerror(-ret));
+		/* If another frame of the kernel raised the interrupt, send again. */
+		found = port_receive() != 0;
+	} while (!found && rte_get_timer_cycles() < deadline);
+	TEST_ASSERT(found, "frame from the kernel not received");
+
+	ret = rte_eth_dev_rx_intr_ctl_q(port_id, 0, RTE_EPOLL_PER_THREAD, RTE_INTR_EVENT_DEL,
+					NULL);
+	TEST_ASSERT_SUCCESS(ret, "Rx interrupt removal failed: %s", rte_strerror(-ret));
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Rx interrupts with an offload, which makes configure initialize the device
+ * twice. Then a second configure. The port has more interrupt eventfds than
+ * Rx queues. They belong to the backend, so the driver must not release them
+ * when it initializes the device again.
+ */
+static int
+test_virtio_user_rx_intr(void)
+{
+	struct rte_eth_conf conf = {
+		.intr_conf.rxq = 1,
+		.rxmode.offloads = RTE_ETH_RX_OFFLOAD_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_TCP_CKSUM,
+	};
+	struct rte_eth_dev_info info;
+	int round, ret;
+
+	ret = rte_eth_dev_info_get(port_id, &info);
+	TEST_ASSERT_SUCCESS(ret, "dev_info failed: %s", rte_strerror(-ret));
+	conf.rxmode.offloads &= info.rx_offload_capa;
+	TEST_ASSERT(conf.rxmode.offloads != 0, "no Rx checksum offload to request");
+
+	for (round = 0; round < 2; round++) {
+		TEST_ASSERT_SUCCESS(port_start(&conf), "round %d: port start failed", round);
+		TEST_ASSERT_SUCCESS(rx_intr_wakes(), "round %d: Rx interrupt failed", round);
+		TEST_ASSERT_SUCCESS(port_stop(), "round %d: port stop failed", round);
+	}
+
+	return TEST_SUCCESS;
+}
+
 static void
 test_virtio_user_cleanup(void)
 {
@@ -251,6 +323,7 @@ static struct unit_test_suite test_pmd_virtio_user_suite = {
 	.suite_name = "virtio-user PMD Unit Test Suite",
 	.unit_test_cases = {
 		TEST_CASE(test_virtio_user_rx_flows),
+		TEST_CASE(test_virtio_user_rx_intr),
 		TEST_CASES_END()
 	}
 };
-- 
2.56.1



More information about the dev mailing list