{"id":2220693,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2220693/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260407-work-qmp-monitor-hotplug-v3-5-cb259800fffb@kernel.org/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.1/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":"<20260407-work-qmp-monitor-hotplug-v3-5-cb259800fffb@kernel.org>","date":"2026-04-07T07:32:49","name":"[v3,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.1/people/82326/?format=json","name":"Christian Brauner","email":"brauner@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260407-work-qmp-monitor-hotplug-v3-5-cb259800fffb@kernel.org/mbox/","series":[{"id":499032,"url":"http://patchwork.ozlabs.org/api/1.1/series/499032/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499032","date":"2026-04-07T07:32:44","name":"monitor: add dynamic QMP monitor hotplug support","version":3,"mbox":"http://patchwork.ozlabs.org/series/499032/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2220693/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220693/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=T2ot9YPu;\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 (lists.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 4fqxJL5vnDz1yGf\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 08 Apr 2026 05:36:02 +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 1wABXK-00009T-Ds; Tue, 07 Apr 2026 14:52:30 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.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 1wABTw-0002eY-TV\n for qemu-devel@nongnu.org; Tue, 07 Apr 2026 14:49:01 -0400","from sea.source.kernel.org ([172.234.252.31])\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 1wA0w0-0007cv-3l\n for qemu-devel@nongnu.org; Tue, 07 Apr 2026 03:33:17 -0400","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n by sea.source.kernel.org (Postfix) with ESMTP id DC95E4428D;\n Tue,  7 Apr 2026 07:33:14 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id A6710C2BC9E;\n Tue,  7 Apr 2026 07:33:12 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n s=k20201202; t=1775547194;\n bh=UlM9cP+a9nxMLP9UAsL1Afv6gPPfoTX0z4wL3Mi4BwE=;\n h=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n b=T2ot9YPux08OYQ7MdJBGjToXsPOvxU9twImPmldshjzexcq0CRyT0w96hTZ5V4dtg\n iFGN57Ff+2aVMIGagrRI/NgC+swTXQEG7rcw7JBGEYKDJuou+ZErX6SxJdIKaHexbT\n 8EljSvIJJ0mJyrbwXyzt68stg+JOTGNliLymd/gk+vQCB6Kgk/ZfdAoDRh67+I3bYh\n 7cpZvAqWoCZSZx/pRIE9BI/kXgx0CagKwl/WbDUEuopsK0oHDVUOEXgJQ/UhuqV9PB\n cLSdiS274181kc11im/MV5VYvpF8baqyniNLqBrjRibqGV5MuBK01FKtEXbV69+dUK\n ZBD8og6/tAjJg==","From":"Christian Brauner <brauner@kernel.org>","Date":"Tue, 07 Apr 2026 09:32:49 +0200","Subject":"[PATCH v3 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":"<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 <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=owGbwMvMwCU28Zj0gdSKO4sYT6slMWRe2azl/V1rw5HfZYXJXIdjeQ8vvSEm5ubmITnjR0zMq\n o6V1owHOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYyyY2RYaLU8oiaY8ouPH5p\n L9b4lDDqOM2z0X7rct1z66KnFVrbghn+ysW/DJxbGpArXhd9dv2mv7xPs6sWVyRpfObXtK879Mm\n QCwA=","X-Developer-Key":"i=brauner@kernel.org; a=openpgp;\n fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624","Received-SPF":"pass client-ip=172.234.252.31; envelope-from=brauner@kernel.org;\n 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,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\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":["v3","5/5"]}