{"id":2221299,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2221299/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260409-work-qmp-monitor-hotplug-v4-5-89c4fdf69df1@kernel.org>","date":"2026-04-09T07:18:22","name":"[v4,5/5] tests/functional: add e2e test for dynamic QMP monitor hotplug","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e99a5ba625244741852bbe1c78f0e26790b2b2ef","submitter":{"id":82326,"url":"http://patchwork.ozlabs.org/api/1.0/people/82326/?format=json","name":"Christian Brauner","email":"brauner@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260409-work-qmp-monitor-hotplug-v4-5-89c4fdf69df1@kernel.org/mbox/","series":[{"id":499242,"url":"http://patchwork.ozlabs.org/api/1.0/series/499242/?format=json","date":"2026-04-09T07:18:17","name":"monitor: add dynamic QMP monitor hotplug support","version":4,"mbox":"http://patchwork.ozlabs.org/series/499242/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221299/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=LYVyzR2R;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frrtJ1zyzz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 17:20:08 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wAjfM-0007NK-3E; Thu, 09 Apr 2026 03:19:04 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <brauner@kernel.org>)\n id 1wAjfC-0007Lw-Aa\n for qemu-devel@nongnu.org; Thu, 09 Apr 2026 03:18:54 -0400","from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <brauner@kernel.org>)\n id 1wAjf6-0000Zr-8h\n for qemu-devel@nongnu.org; Thu, 09 Apr 2026 03:18:53 -0400","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n by tor.source.kernel.org (Postfix) with ESMTP id 248EF600AD;\n Thu,  9 Apr 2026 07:18:46 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 6A480C4AF09;\n Thu,  9 Apr 2026 07:18:43 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n s=k20201202; t=1775719125;\n bh=UlM9cP+a9nxMLP9UAsL1Afv6gPPfoTX0z4wL3Mi4BwE=;\n h=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n b=LYVyzR2RAT/hlQ6RkAzdPir5QjnF4P8o3YQwRIJoSm9dDmhfpt2iBhjNci0XFuDoz\n /Id20XxVaiEXyoHtTbjOMrRvZz53Hmh/pA/EPRyblfiaOLJZz+iU2HQcYQB8TLbMfB\n Pqp9Zn0oMNeEZwn3eozh5ObFd1CsNVd0PelytDw/f+l3XKtpwIWUQlOdKU96uqswpM\n CssjxIpdU1RnFMvxYmo8c04NeotTBZd6SJl84i8pvYX3O0DS6Te+Qv2K+X8aEBCS3Q\n y45QCL0bm8JkLIQpt6cL+BHJIrNkuyTbsKBUSb3nC/25iVVyfLPMq6bPrBq1OAGU85\n n9JCsR619XDiQ==","From":"Christian Brauner <brauner@kernel.org>","Date":"Thu, 09 Apr 2026 09:18:22 +0200","Subject":"[PATCH v4 5/5] tests/functional: add e2e test for dynamic QMP\n monitor hotplug","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260409-work-qmp-monitor-hotplug-v4-5-89c4fdf69df1@kernel.org>","References":"<20260409-work-qmp-monitor-hotplug-v4-0-89c4fdf69df1@kernel.org>","In-Reply-To":"<20260409-work-qmp-monitor-hotplug-v4-0-89c4fdf69df1@kernel.org>","To":"qemu-devel@nongnu.org","Cc":"Markus Armbruster <armbru@redhat.com>, Eric Blake <eblake@redhat.com>,\n  Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>,\n  Paolo Bonzini <pbonzini@redhat.com>, Thomas Huth <th.huth+qemu@posteo.eu>,\n\t=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>, =?utf-8?q?Dani?=\n\t=?utf-8?q?el_P=2E_Berrang=C3=A9?= <berrange@redhat.com>,\n  Christian Brauner <brauner@kernel.org>","X-Mailer":"b4 0.16-dev","X-Developer-Signature":"v=1; a=openpgp-sha256; l=7400; i=brauner@kernel.org;\n h=from:subject:message-id; bh=UlM9cP+a9nxMLP9UAsL1Afv6gPPfoTX0z4wL3Mi4BwE=;\n b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWReDzp6oYipsvTTjF0tMrWcl2ee/fFy51qxmyfCbR+ZL\n CpfnzCdoaOUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAisvMYGSa1cwTppkX3P+C5\n Enxh/YoLHjPK5Dli95ozfUk07vdxtWZk+CX+8WTIemdHXZaqiZcZhKLtd8W87BfeI7VPWaTHe7s\n dKwA=","X-Developer-Key":"i=brauner@kernel.org; a=openpgp;\n fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624","Received-SPF":"pass client-ip=2600:3c04:e001:324:0:1991:8:25;\n envelope-from=brauner@kernel.org; helo=tor.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,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n 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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"Add functional tests that exercise dynamic monitor hotplug with real\nsocket connections:\n\n- Hotplug cycle: chardev-add a unix socket, monitor-add, connect to the\n  socket, receive the QMP greeting, negotiate capabilities, send\n  query-version, disconnect, remove the monitor and chardev, then repeat\n  the entire cycle a second time to verify cleanup and reuse.\n\n- Self-removal: a dynamically-added monitor sends monitor-remove\n  targeting itself, verifying that the response is delivered before\n  the connection drops and that the monitor is gone afterwards.\n\n- Large response: send query-qmp-schema on a dynamic monitor to\n  exercise the output buffer flush path with a large response payload.\n\n- Events after negotiation: trigger STOP/RESUME events via the main\n  monitor and verify they are delivered on the dynamic monitor.\n\nThis complements the qtest unit tests by verifying that a real QMP\nclient can connect to a dynamically-added monitor and exchange messages.\n\nSigned-off-by: Christian Brauner (Amutable) <brauner@kernel.org>\n---\n tests/functional/generic/meson.build             |   1 +\n tests/functional/generic/test_monitor_hotplug.py | 170 +++++++++++++++++++++++\n 2 files changed, 171 insertions(+)","diff":"diff --git a/tests/functional/generic/meson.build b/tests/functional/generic/meson.build\nindex 09763c5d22..c94105c62e 100644\n--- a/tests/functional/generic/meson.build\n+++ b/tests/functional/generic/meson.build\n@@ -4,6 +4,7 @@ tests_generic_system = [\n   'empty_cpu_model',\n   'info_usernet',\n   'linters',\n+  'monitor_hotplug',\n   'version',\n   'vnc',\n ]\ndiff --git a/tests/functional/generic/test_monitor_hotplug.py b/tests/functional/generic/test_monitor_hotplug.py\nnew file mode 100644\nindex 0000000000..f81236e7b4\n--- /dev/null\n+++ b/tests/functional/generic/test_monitor_hotplug.py\n@@ -0,0 +1,170 @@\n+#!/usr/bin/env python3\n+#\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Functional test for dynamic QMP monitor hotplug\n+#\n+# Copyright (c) 2026 Christian Brauner\n+\n+import os\n+\n+from qemu_test import QemuSystemTest\n+\n+from qemu.qmp.legacy import QEMUMonitorProtocol\n+\n+\n+class MonitorHotplug(QemuSystemTest):\n+\n+    def setUp(self):\n+        super().setUp()\n+        sock_dir = self.socket_dir()\n+        self._sock_path = os.path.join(sock_dir.name, 'hotplug.sock')\n+\n+    def _add_monitor(self):\n+        \"\"\"Create a chardev + monitor and return the socket path.\"\"\"\n+        sock = self._sock_path\n+        self.vm.cmd('chardev-add', id='hotplug-chr', backend={\n+            'type': 'socket',\n+            'data': {\n+                'addr': {\n+                    'type': 'unix',\n+                    'data': {'path': sock}\n+                },\n+                'server': True,\n+                'wait': False,\n+            }\n+        })\n+        self.vm.cmd('monitor-add', id='hotplug-mon',\n+                    chardev='hotplug-chr')\n+        return sock\n+\n+    def _remove_monitor(self):\n+        \"\"\"Remove the monitor + chardev.\"\"\"\n+        self.vm.cmd('monitor-remove', id='hotplug-mon')\n+        self.vm.cmd('chardev-remove', id='hotplug-chr')\n+\n+    def _connect_and_handshake(self, sock_path):\n+        \"\"\"\n+        Connect to the dynamic monitor socket, perform the QMP\n+        greeting and capability negotiation, send a command, then\n+        disconnect.\n+        \"\"\"\n+        qmp = QEMUMonitorProtocol(sock_path)\n+\n+        # connect(negotiate=True) receives the greeting, validates it,\n+        # and sends qmp_capabilities automatically.\n+        greeting = qmp.connect(negotiate=True)\n+        self.assertIn('QMP', greeting)\n+        self.assertIn('version', greeting['QMP'])\n+        self.assertIn('capabilities', greeting['QMP'])\n+\n+        # Send a real command to prove the session is fully functional\n+        resp = qmp.cmd_obj({'execute': 'query-version'})\n+        self.assertIn('return', resp)\n+        self.assertIn('qemu', resp['return'])\n+\n+        qmp.close()\n+\n+    def test_hotplug_cycle(self):\n+        \"\"\"\n+        Hotplug a monitor, do the full QMP handshake, unplug it,\n+        then repeat the whole cycle a second time.\n+        \"\"\"\n+        self.set_machine('none')\n+        self.vm.add_args('-nodefaults')\n+        self.vm.launch()\n+\n+        # First cycle\n+        sock = self._add_monitor()\n+        self._connect_and_handshake(sock)\n+        self._remove_monitor()\n+\n+        # Second cycle -- same ids, same path, must work\n+        sock = self._add_monitor()\n+        self._connect_and_handshake(sock)\n+        self._remove_monitor()\n+\n+    def test_self_removal(self):\n+        \"\"\"\n+        A dynamically-added monitor sends monitor-remove targeting\n+        itself.  Verify the response is delivered before the\n+        connection drops, and that the monitor is gone afterwards.\n+        \"\"\"\n+        self.set_machine('none')\n+        self.vm.add_args('-nodefaults')\n+        self.vm.launch()\n+\n+        sock = self._add_monitor()\n+\n+        qmp = QEMUMonitorProtocol(sock)\n+        greeting = qmp.connect(negotiate=True)\n+        self.assertIn('QMP', greeting)\n+\n+        # Self-removal: the dynamic monitor removes itself\n+        resp = qmp.cmd_obj({'execute': 'monitor-remove',\n+                            'arguments': {'id': 'hotplug-mon'}})\n+        self.assertIn('return', resp)\n+\n+        qmp.close()\n+\n+        # The main monitor should no longer list the removed monitor\n+        monitors = self.vm.cmd('query-monitors')\n+        for m in monitors:\n+            self.assertNotEqual(m.get('id'), 'hotplug-mon')\n+\n+        # Clean up the chardev\n+        self.vm.cmd('chardev-remove', id='hotplug-chr')\n+\n+    def test_large_response(self):\n+        \"\"\"\n+        Send a command with a large response (query-qmp-schema) on a\n+        dynamically-added monitor to exercise the output buffer flush\n+        path.\n+        \"\"\"\n+        self.set_machine('none')\n+        self.vm.add_args('-nodefaults')\n+        self.vm.launch()\n+\n+        sock = self._add_monitor()\n+\n+        qmp = QEMUMonitorProtocol(sock)\n+        qmp.connect(negotiate=True)\n+\n+        resp = qmp.cmd_obj({'execute': 'query-qmp-schema'})\n+        self.assertIn('return', resp)\n+        self.assertIsInstance(resp['return'], list)\n+        self.assertGreater(len(resp['return']), 0)\n+\n+        qmp.close()\n+        self._remove_monitor()\n+\n+    def test_events_after_negotiation(self):\n+        \"\"\"\n+        Verify that QMP events are delivered on a dynamically-added\n+        monitor after capability negotiation completes.\n+        \"\"\"\n+        self.set_machine('none')\n+        self.vm.add_args('-nodefaults')\n+        self.vm.launch()\n+\n+        sock = self._add_monitor()\n+\n+        qmp = QEMUMonitorProtocol(sock)\n+        qmp.connect(negotiate=True)\n+\n+        # Trigger a STOP event via the main monitor, then read it\n+        # from the dynamic monitor.\n+        self.vm.cmd('stop')\n+        resp = qmp.pull_event(wait=True)\n+        self.assertEqual(resp['event'], 'STOP')\n+\n+        self.vm.cmd('cont')\n+        resp = qmp.pull_event(wait=True)\n+        self.assertEqual(resp['event'], 'RESUME')\n+\n+        qmp.close()\n+        self._remove_monitor()\n+\n+\n+if __name__ == '__main__':\n+    QemuSystemTest.main()\n","prefixes":["v4","5/5"]}