From nobody Sat Apr 11 20:06:20 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1775590561; cv=none; d=zohomail.com; s=zohoarc; b=VDv0QXVLnU+keUogIOnvgldam1kUa7ONJ4Gh9mLU3b09k4iOQYjZGQ6yYYjTYwxOWcTfMeo7FVSRMezuNJvxa9fAyQ1cvEdKU+ZlZGA/tTWyVqdmiPvpJ5n3bY0Cd37+PBlcVfLZQ5WOdRNPspG3Ik0Q9EOxs/4JzFmQRi//o5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775590561; 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=DJSrh+0nDS60YSLJfYgg3cPoVa7txkbyAfgsvkxzjHo=; b=hftZRwdvy9PX1vb/5V0QQUD6rEfi8GxQoBemOp2ol2ZAl6ufeA6v4Fj20RU/W/WDq9r6DV14zPzRyGNuhA4rPcOYnDb4Af8xnokTfPcaiYdyFw1zBK8C/eGRg8IvzTAJ0JSO4PHk7SvbitrjmgSpMi/pYi5pqezk/Dug7EhsLkE= 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 1775590561733638.171950645223; Tue, 7 Apr 2026 12:36:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wABXK-00009T-Ds; Tue, 07 Apr 2026 14:52:30 -0400 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 1wABTw-0002eY-TV for qemu-devel@nongnu.org; Tue, 07 Apr 2026 14:49:01 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wA0w0-0007cv-3l for qemu-devel@nongnu.org; Tue, 07 Apr 2026 03:33:17 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id DC95E4428D; Tue, 7 Apr 2026 07:33:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6710C2BC9E; Tue, 7 Apr 2026 07:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775547194; bh=UlM9cP+a9nxMLP9UAsL1Afv6gPPfoTX0z4wL3Mi4BwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=T2ot9YPux08OYQ7MdJBGjToXsPOvxU9twImPmldshjzexcq0CRyT0w96hTZ5V4dtg iFGN57Ff+2aVMIGagrRI/NgC+swTXQEG7rcw7JBGEYKDJuou+ZErX6SxJdIKaHexbT 8EljSvIJJ0mJyrbwXyzt68stg+JOTGNliLymd/gk+vQCB6Kgk/ZfdAoDRh67+I3bYh 7cpZvAqWoCZSZx/pRIE9BI/kXgx0CagKwl/WbDUEuopsK0oHDVUOEXgJQ/UhuqV9PB cLSdiS274181kc11im/MV5VYvpF8baqyniNLqBrjRibqGV5MuBK01FKtEXbV69+dUK ZBD8og6/tAjJg== From: Christian Brauner Date: Tue, 07 Apr 2026 09:32:49 +0200 Subject: [PATCH v3 5/5] tests/functional: add e2e test for dynamic QMP monitor hotplug MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260407-work-qmp-monitor-hotplug-v3-5-cb259800fffb@kernel.org> References: <20260407-work-qmp-monitor-hotplug-v3-0-cb259800fffb@kernel.org> In-Reply-To: <20260407-work-qmp-monitor-hotplug-v3-0-cb259800fffb@kernel.org> To: qemu-devel@nongnu.org Cc: Markus Armbruster , Eric Blake , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Christian Brauner X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7400; i=brauner@kernel.org; h=from:subject:message-id; bh=UlM9cP+a9nxMLP9UAsL1Afv6gPPfoTX0z4wL3Mi4BwE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWRe2azl/V1rw5HfZYXJXIdjeQ8vvSEm5ubmITnjR0zMq o6V1owHOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYyyY2RYaLU8oiaY8ouPH5p L9b4lDDqOM2z0X7rct1z66KnFVrbghn+ysW/DJxbGpArXhd9dv2mv7xPs6sWVyRpfObXtK879Mm QCwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 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=172.234.252.31; envelope-from=brauner@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=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 @kernel.org) X-ZM-MESSAGEID: 1775590563010158500 Add functional tests that exercise dynamic monitor hotplug with real socket connections: - Hotplug cycle: chardev-add a unix socket, monitor-add, connect to the socket, receive the QMP greeting, negotiate capabilities, send query-version, disconnect, remove the monitor and chardev, then repeat the entire cycle a second time to verify cleanup and reuse. - Self-removal: a dynamically-added monitor sends monitor-remove targeting itself, verifying that the response is delivered before the connection drops and that the monitor is gone afterwards. - Large response: send query-qmp-schema on a dynamic monitor to exercise the output buffer flush path with a large response payload. - Events after negotiation: trigger STOP/RESUME events via the main monitor and verify they are delivered on the dynamic monitor. This complements the qtest unit tests by verifying that a real QMP client can connect to a dynamically-added monitor and exchange messages. Signed-off-by: Christian Brauner (Amutable) --- tests/functional/generic/meson.build | 1 + tests/functional/generic/test_monitor_hotplug.py | 170 +++++++++++++++++++= ++++ 2 files changed, 171 insertions(+) diff --git a/tests/functional/generic/meson.build b/tests/functional/generi= c/meson.build index 09763c5d22..c94105c62e 100644 --- a/tests/functional/generic/meson.build +++ b/tests/functional/generic/meson.build @@ -4,6 +4,7 @@ tests_generic_system =3D [ 'empty_cpu_model', 'info_usernet', 'linters', + 'monitor_hotplug', 'version', 'vnc', ] diff --git a/tests/functional/generic/test_monitor_hotplug.py b/tests/funct= ional/generic/test_monitor_hotplug.py new file mode 100644 index 0000000000..f81236e7b4 --- /dev/null +++ b/tests/functional/generic/test_monitor_hotplug.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Functional test for dynamic QMP monitor hotplug +# +# Copyright (c) 2026 Christian Brauner + +import os + +from qemu_test import QemuSystemTest + +from qemu.qmp.legacy import QEMUMonitorProtocol + + +class MonitorHotplug(QemuSystemTest): + + def setUp(self): + super().setUp() + sock_dir =3D self.socket_dir() + self._sock_path =3D os.path.join(sock_dir.name, 'hotplug.sock') + + def _add_monitor(self): + """Create a chardev + monitor and return the socket path.""" + sock =3D self._sock_path + self.vm.cmd('chardev-add', id=3D'hotplug-chr', backend=3D{ + 'type': 'socket', + 'data': { + 'addr': { + 'type': 'unix', + 'data': {'path': sock} + }, + 'server': True, + 'wait': False, + } + }) + self.vm.cmd('monitor-add', id=3D'hotplug-mon', + chardev=3D'hotplug-chr') + return sock + + def _remove_monitor(self): + """Remove the monitor + chardev.""" + self.vm.cmd('monitor-remove', id=3D'hotplug-mon') + self.vm.cmd('chardev-remove', id=3D'hotplug-chr') + + def _connect_and_handshake(self, sock_path): + """ + Connect to the dynamic monitor socket, perform the QMP + greeting and capability negotiation, send a command, then + disconnect. + """ + qmp =3D QEMUMonitorProtocol(sock_path) + + # connect(negotiate=3DTrue) receives the greeting, validates it, + # and sends qmp_capabilities automatically. + greeting =3D qmp.connect(negotiate=3DTrue) + self.assertIn('QMP', greeting) + self.assertIn('version', greeting['QMP']) + self.assertIn('capabilities', greeting['QMP']) + + # Send a real command to prove the session is fully functional + resp =3D qmp.cmd_obj({'execute': 'query-version'}) + self.assertIn('return', resp) + self.assertIn('qemu', resp['return']) + + qmp.close() + + def test_hotplug_cycle(self): + """ + Hotplug a monitor, do the full QMP handshake, unplug it, + then repeat the whole cycle a second time. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + # First cycle + sock =3D self._add_monitor() + self._connect_and_handshake(sock) + self._remove_monitor() + + # Second cycle -- same ids, same path, must work + sock =3D self._add_monitor() + self._connect_and_handshake(sock) + self._remove_monitor() + + def test_self_removal(self): + """ + A dynamically-added monitor sends monitor-remove targeting + itself. Verify the response is delivered before the + connection drops, and that the monitor is gone afterwards. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + greeting =3D qmp.connect(negotiate=3DTrue) + self.assertIn('QMP', greeting) + + # Self-removal: the dynamic monitor removes itself + resp =3D qmp.cmd_obj({'execute': 'monitor-remove', + 'arguments': {'id': 'hotplug-mon'}}) + self.assertIn('return', resp) + + qmp.close() + + # The main monitor should no longer list the removed monitor + monitors =3D self.vm.cmd('query-monitors') + for m in monitors: + self.assertNotEqual(m.get('id'), 'hotplug-mon') + + # Clean up the chardev + self.vm.cmd('chardev-remove', id=3D'hotplug-chr') + + def test_large_response(self): + """ + Send a command with a large response (query-qmp-schema) on a + dynamically-added monitor to exercise the output buffer flush + path. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + qmp.connect(negotiate=3DTrue) + + resp =3D qmp.cmd_obj({'execute': 'query-qmp-schema'}) + self.assertIn('return', resp) + self.assertIsInstance(resp['return'], list) + self.assertGreater(len(resp['return']), 0) + + qmp.close() + self._remove_monitor() + + def test_events_after_negotiation(self): + """ + Verify that QMP events are delivered on a dynamically-added + monitor after capability negotiation completes. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + qmp.connect(negotiate=3DTrue) + + # Trigger a STOP event via the main monitor, then read it + # from the dynamic monitor. + self.vm.cmd('stop') + resp =3D qmp.pull_event(wait=3DTrue) + self.assertEqual(resp['event'], 'STOP') + + self.vm.cmd('cont') + resp =3D qmp.pull_event(wait=3DTrue) + self.assertEqual(resp['event'], 'RESUME') + + qmp.close() + self._remove_monitor() + + +if __name__ =3D=3D '__main__': + QemuSystemTest.main() --=20 2.47.3