Configure the port with Rx interrupts and an Rx offload, enable the interrupt of the Rx queue, send a frame from the kernel and sleep on the interrupt. The frame must end the sleep. Do the same after a second configure.
The port has two queue pairs and one Rx queue, so it has more interrupt eventfds than Rx queues. They are the backend's call fds. If the driver releases them when it initializes the device again, the test fails. Signed-off-by: Isaac Boukris <[email protected]> --- v4: ask for the Rx offload without checking the capability first. Shorter comments. v3: on top of the previous patch. The test frame is now an IPv4 one. app/test/test_pmd_virtio_user.c | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/app/test/test_pmd_virtio_user.c b/app/test/test_pmd_virtio_user.c index c47d5a833b..f70f0c3d7f 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> @@ -174,6 +175,67 @@ 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 { + /* From here on a frame raises the interrupt, 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; +} + +/* + * Configure with Rx interrupts and an offload, which initializes the device + * twice, then configure again. The port has more interrupt eventfds than Rx + * queues. They are the backend's, so the driver must not release them. + */ +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, + }; + int round; + + 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) { @@ -249,6 +311,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

