From nobody Sun Jan 25 11:58:47 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769171065; cv=none; d=zohomail.com; s=zohoarc; b=TlpmGKN7pxomaqtuvAxH9x1eOy0bBqAXBXZxDKIUxCfmsF9TAXbmENXSs3w7a0RJCzjX27dC+WwfZmgMiDVQm0t7Ry318WaS2LAJdFs/7Rb4rmU/uraBNcZnlSyL/17gP9JYz72Ox3OJtQWZ2UjIGO2MRls9KFefiT3CnHzGC4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171065; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=feH2FujmpRO46VbJB4z/pcE4jUNKzw/fe/zu4QkB8Qw=; b=BxiNzWRnFUU3yJtyipchvkCtDc84wAA+wTy1tGltrRpHYfA4ee2D0OphHhNjqyu4FX3OHiJjGPXEyNr2tk4X9p3cavf9Cjr6OJN5aeiXt2/P1jZ+2OvZzeaYE9WWPljC9lCUK251ha7Y3K3rvPPPvjVV0FRV9WgZEbGlCQpNKak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769171065622705.451105276987; Fri, 23 Jan 2026 04:24:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGB1-0005nn-J6; Fri, 23 Jan 2026 07:22:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAj-0005LD-5s for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vjGAg-00056T-4P for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:52 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-4mTFS3kHNBuDXSF8LBAnRA-1; Fri, 23 Jan 2026 07:21:46 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3E625180047F; Fri, 23 Jan 2026 12:21:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E389230002D1; Fri, 23 Jan 2026 12:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=feH2FujmpRO46VbJB4z/pcE4jUNKzw/fe/zu4QkB8Qw=; b=Z8eBe9bVV9AhSHQnEugjAOWgq3HoTLF7epdPOXUbcEQQZrcJ1xXkH74rlpmlB54pKLsnhP 4VO6YdJ5T502SqdhYWemJBo+RIGCL7iWPwJRou1V9Fc7/URs/R3+lIxXORQuuhSvdN9bRo dzskXVT3LC+FQUgmravZSK2OYZA4YxA= X-MC-Unique: 4mTFS3kHNBuDXSF8LBAnRA-1 X-Mimecast-MFC-AGG-ID: 4mTFS3kHNBuDXSF8LBAnRA_1769170905 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang , Zhang Chen , Fabiano Rosas Subject: [PULL 10/13] tests/qtest: add test for filter-buffer interval change Date: Fri, 23 Jan 2026 20:20:59 +0800 Message-ID: <20260123122102.51422-11-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1769171068040154100 Content-Type: text/plain; charset="utf-8" Add test_change_interval_timer to verify that modifying the 'interval' property of filter-buffer at runtime takes effect immediately. The test uses socket backend and filter-redirector to verify timer behavior: - Creates filter-buffer with a very long interval (1000 seconds) - Sends a packet which gets buffered - Advances virtual clock by 1 second, verifies packet is still buffered - Changes interval to 1ms via qom-set (timer should be rescheduled) - Advances virtual clock by 2ms, verifies packet is now released - This proves the timer was rescheduled immediately when interval changed The test uses filter-redirector to observe when packets are released by filter-buffer, providing end-to-end verification of the timer rescheduling behavior. Reviewed-by: Zhang Chen Reviewed-by: Fabiano Rosas Signed-off-by: Jason Wang --- tests/qtest/meson.build | 1 + tests/qtest/test-filter-buffer.c | 169 +++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 tests/qtest/test-filter-buffer.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index a8b09d065f..dfb83650c6 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -46,6 +46,7 @@ qtests_cxl =3D \ # for the availability of the default NICs in the tests qtests_filter =3D \ (get_option('default_devices') and slirp.found() ? ['test-netfilter'] : = []) + \ + (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-buffer'] : []) + \ (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-mirror'] : []) + \ (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-redirector'] : []) =20 diff --git a/tests/qtest/test-filter-buffer.c b/tests/qtest/test-filter-buf= fer.c new file mode 100644 index 0000000000..441cbb975c --- /dev/null +++ b/tests/qtest/test-filter-buffer.c @@ -0,0 +1,169 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * QTest testcase for filter-buffer + * + * Copyright (c) 2025 Red Hat, Inc. + * Author: Jason Wang + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qobject/qdict.h" +#include "qemu/iov.h" +#include "qemu/sockets.h" + +/* + * Test that changing interval at runtime affects packet release timing. + * + * Traffic flow with filter-buffer and filter-redirector: + * + * test side | qemu side + * | + * +--------+ | +---------+ + * | send +------------------------>| backend | + * | sock[0]| | +----+----+ + * +--------+ | | + * | +----v----+ + * | | fbuf0 | filter-buffer (queue=3Dt= x) + * | +----+----+ + * | | + * | +----v----+ +----------+ + * | | rd0 +->| chardev0 | + * | +---------+ +----+-----+ + * | | + * +--------+ | | + * | recv |<--------------------------------------+ + * | sock | | + * +--------+ | + * + * The test verifies that when interval is changed via qom-set, the timer + * is rescheduled immediately, causing buffered packets to be released + * at the new interval rather than waiting for the old interval to elapse. + */ +static void test_change_interval_timer(void) +{ + QTestState *qts; + QDict *response; + int backend_sock[2], recv_sock; + int ret; + char send_buf[] =3D "Hello filter-buffer!"; + char recv_buf[128]; + char sock_path[] =3D "filter-buffer-test.XXXXXX"; + uint32_t size =3D sizeof(send_buf); + uint32_t len; + + size =3D htonl(size); + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path); + g_assert_cmpint(ret, !=3D, -1); + + /* + * Start QEMU with: + * - socket backend connected to our socketpair + * - filter-buffer with a very long interval (1000 seconds) + * - filter-redirector to send released packets to a chardev socket + * + * queue=3Dtx intercepts packets going from backend to the guest, + * i.e., data we send from the test side. + */ + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dchardev0,path=3D%s,server=3Don,wait=3Doff " + "-object filter-buffer,id=3Dfbuf0,netdev=3Dqtest-bn0," + "queue=3Dtx,interval=3D1000000000 " + "-object filter-redirector,id=3Drd0,netdev=3Dqtest-bn0," + "queue=3Dtx,outdev=3Dchardev0", + backend_sock[1], sock_path); + + /* Connect to the chardev socket to receive redirected packets */ + recv_sock =3D unix_connect(sock_path, NULL); + g_assert_cmpint(recv_sock, !=3D, -1); + + /* Send a QMP command to ensure chardev connection is established */ + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + /* + * Send a packet from the test side. + * It should be buffered by filter-buffer. + */ + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + ret =3D iov_send(backend_sock[0], iov, 2, 0, sizeof(size) + sizeof(sen= d_buf)); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + /* + * Advance virtual clock by 1 second (1,000,000,000 ns). + * This is much less than the 1000 second interval, so the packet + * should still be buffered. + */ + qtest_clock_step(qts, 1000000000LL); + + /* Try to receive with non-blocking - should fail (packet still buffer= ed) */ + ret =3D recv(recv_sock, recv_buf, sizeof(recv_buf), MSG_DONTWAIT); + g_assert_cmpint(ret, =3D=3D, -1); + g_assert(errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK); + + /* + * Now change the interval to 1000 us (1ms) via qom-set. + * This should reschedule the timer to fire in 1ms from now. + */ + response =3D qtest_qmp(qts, + "{'execute': 'qom-set'," + " 'arguments': {" + " 'path': 'fbuf0'," + " 'property': 'interval'," + " 'value': 1000" + "}}"); + g_assert(response); + g_assert(!qdict_haskey(response, "error")); + qobject_unref(response); + + /* + * Advance virtual clock by 2ms (2,000,000 ns). + * This exceeds the new 1ms interval, so the timer should fire + * and release the buffered packet. + * + * If the interval change didn't take effect immediately, we would + * still be waiting for the original 1000 second interval to elapse, + * and the packet would not be released. + */ + qtest_clock_step(qts, 2000000LL); + + /* + * Now we should be able to receive the packet through the redirector. + * The packet was released by filter-buffer and sent to filter-redirec= tor, + * which forwarded it to the chardev socket. + */ + ret =3D recv(recv_sock, &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + + ret =3D recv(recv_sock, recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + + close(recv_sock); + close(backend_sock[0]); + unlink(sock_path); + qtest_quit(qts); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + qtest_add_func("/netfilter/change_interval_timer", + test_change_interval_timer); + return g_test_run(); +} --=20 2.42.0