All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Alex Williamson" <alex@shazbot.org>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH 32/32] tests/qtest: add D-Bus display hotplug test
Date: Fri, 29 May 2026 10:34:02 -0300	[thread overview]
Message-ID: <87fr3atk51.fsf@suse.de> (raw)
In-Reply-To: <20260529-b4-ui-v1-32-8db3068421ef@redhat.com>

Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Add a qtest that verifies display consoles are dynamically added and
> removed over D-Bus when a bochs-display device is hotplugged and
> unplugged on a q35 machine.
>
> The test plugs device_add a bochs-display, waits for the DEVICE_ADDED
> QMP event, and checks that the D-Bus VM interface reports a second
> console. It then device_del it, forces a system reset
> (q35 removal is ACPI-based and needs guest cooperation qtest cannot
> provide), waits for DEVICE_DELETED, and checks the console count again.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/qtest/dbus-display-test.c | 101 +++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 99 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/dbus-display-test.c b/tests/qtest/dbus-display-test.c
> index 5773776cad5..7838ce7323f 100644
> --- a/tests/qtest/dbus-display-test.c
> +++ b/tests/qtest/dbus-display-test.c
> @@ -7,6 +7,8 @@
>  #include <gio/gio.h>
>  #include <gio/gunixfdlist.h>
>  #include "libqtest.h"
> +#include "qobject/qdict.h"
> +#include "qobject/qstring.h"
>  #include "ui/dbus-display1.h"
>  
>  static GDBusConnection*
> @@ -38,11 +40,11 @@ test_dbus_p2p_from_fd(int fd)
>  }
>  
>  static void
> -test_setup(QTestState **qts, GDBusConnection **conn)
> +test_setup_args(QTestState **qts, GDBusConnection **conn, const char *args)
>  {
>      int pair[2];
>  
> -    *qts = qtest_init("-display dbus,p2p=yes -name dbus-test");
> +    *qts = qtest_init(args);
>  
>      g_assert_cmpint(qemu_socketpair(AF_UNIX, SOCK_STREAM, 0, pair), ==, 0);
>  
> @@ -52,6 +54,12 @@ test_setup(QTestState **qts, GDBusConnection **conn)
>      g_dbus_connection_start_message_processing(*conn);
>  }
>  
> +static void
> +test_setup(QTestState **qts, GDBusConnection **conn)
> +{
> +    test_setup_args(qts, conn, "-display dbus,p2p=yes -name dbus-test");
> +}
> +
>  static void
>  test_dbus_display_vm(void)
>  {
> @@ -360,6 +368,92 @@ test_dbus_display_keyboard(void)
>      qtest_quit(qts);
>  }
>  
> +static gsize
> +get_console_ids_count(GDBusConnection *conn)
> +{
> +    g_autoptr(GError) err = NULL;
> +    g_autoptr(QemuDBusDisplay1VMProxy) vm = NULL;
> +    GVariant *console_ids;
> +    gsize n_ids = 0;
> +
> +    vm = QEMU_DBUS_DISPLAY1_VM_PROXY(
> +        qemu_dbus_display1_vm_proxy_new_sync(
> +            conn,
> +            G_DBUS_PROXY_FLAGS_NONE,
> +            NULL,
> +            DBUS_DISPLAY1_ROOT "/VM",
> +            NULL,
> +            &err));
> +    g_assert_no_error(err);
> +
> +    console_ids = qemu_dbus_display1_vm_get_console_ids(
> +        QEMU_DBUS_DISPLAY1_VM(vm));
> +    if (console_ids) {
> +        n_ids = g_variant_n_children(console_ids);
> +    }
> +    return n_ids;
> +}
> +
> +static void
> +wait_device_event(QTestState *qts, const char *event_name, const char *id)
> +{
> +    QDict *resp, *data;
> +    QString *qstr;
> +
> +    for (;;) {
> +        resp = qtest_qmp_eventwait_ref(qts, event_name);
> +        data = qdict_get_qdict(resp, "data");
> +        if (!data || !qdict_get(data, "device")) {
> +            qobject_unref(resp);
> +            continue;
> +        }
> +        qstr = qobject_to(QString, qdict_get(data, "device"));
> +        if (!strcmp(qstring_get_str(qstr), id)) {
> +            qobject_unref(resp);
> +            break;
> +        }
> +        qobject_unref(resp);
> +    }
> +}
> +
> +static void
> +test_dbus_display_hotplug(void)
> +{
> +    g_autoptr(GDBusConnection) conn = NULL;
> +    QTestState *qts = NULL;
> +    gsize n;
> +
> +    test_setup_args(&qts, &conn,
> +        "-machine q35"
> +        " -device pcie-root-port,id=rp0"
> +        " -display dbus,p2p=yes"
> +        " -name dbus-test");
> +
> +    n = get_console_ids_count(conn);
> +    g_assert_cmpuint(n, ==, 1);
> +
> +    qtest_qmp_device_add(qts, "bochs-display", "bochs0",
> +                         "{'bus': 'rp0'}");
> +
> +    n = get_console_ids_count(conn);
> +    g_assert_cmpuint(n, ==, 2);
> +
> +    /*
> +     * On q35, PCI device removal is ACPI-based and requires guest
> +     * acknowledgement. Since qtest has no guest OS, issue the delete
> +     * request and force removal via system reset.
> +     */
> +    qtest_qmp_device_del_send(qts, "bochs0");
> +    qtest_system_reset_nowait(qts);
> +    wait_device_event(qts, "DEVICE_DELETED", "bochs0");
> +
> +    n = get_console_ids_count(conn);
> +    g_assert_cmpuint(n, ==, 1);
> +
> +    g_clear_object(&conn);
> +    qtest_quit(qts);
> +}
> +
>  int
>  main(int argc, char **argv)
>  {
> @@ -369,6 +463,9 @@ main(int argc, char **argv)
>      qtest_add_data_func("/dbus-display/console", GINT_TO_POINTER(false), test_dbus_display_console);
>      qtest_add_data_func("/dbus-display/console/map", GINT_TO_POINTER(true), test_dbus_display_console);
>      qtest_add_func("/dbus-display/keyboard", test_dbus_display_keyboard);
> +    if (qtest_has_machine("q35") && qtest_has_device("bochs-display")) {
> +        qtest_add_func("/dbus-display/hotplug", test_dbus_display_hotplug);
> +    }
>  
>      return g_test_run();
>  }

Reviewed-by: Fabiano Rosas <farosas@suse.de>


      reply	other threads:[~2026-05-29 13:34 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 11:16 [PATCH 00/32] ui: better console hotplug support Marc-André Lureau
2026-05-29 11:16 ` [PATCH 01/32] ui/gtk: fix bad widget realize on non-GFX VC Marc-André Lureau
2026-05-29 11:16 ` [PATCH 02/32] build-sys: build with -fno-omit-frame-pointer with ASAN Marc-André Lureau
2026-05-29 11:16 ` [PATCH 03/32] irq: add per-IRQ observer to fix qemu_irq_intercept_in leak Marc-André Lureau
2026-05-29 13:27   ` Fabiano Rosas
2026-05-29 13:44   ` Peter Maydell
2026-05-31  5:31     ` Marc-André Lureau
2026-05-29 11:16 ` [PATCH 04/32] scripts/lsan_suppressions: suppress fontconfig leaks Marc-André Lureau
2026-05-29 11:16 ` [PATCH 05/32] vfio/pci: close display console during unrealize, not finalize Marc-André Lureau
2026-05-29 11:16 ` [PATCH 06/32] glib-compat: add fallback for g_clear_fd/g_autofd Marc-André Lureau
2026-05-29 11:16 ` [PATCH 07/32] ui/dbus: remove mouse handler on dispose Marc-André Lureau
2026-05-29 11:16 ` [PATCH 08/32] ui/qmp: keep a reference of console across yield Marc-André Lureau
2026-05-29 11:16 ` [PATCH 09/32] ui: stop ui timer when closing Marc-André Lureau
2026-05-29 11:16 ` [PATCH 10/32] ui/console: init gl_unblock_timer in qemu_console_init Marc-André Lureau
2026-05-29 11:16 ` [PATCH 11/32] ui/spice: remove dead spice_displays Marc-André Lureau
2026-05-29 11:16 ` [PATCH 12/32] ui/spice: add cleanup on shutdown Marc-André Lureau
2026-05-29 11:16 ` [PATCH 13/32] ui: add display cleanup infrastructure Marc-André Lureau
2026-05-29 11:16 ` [PATCH 14/32] ui/curses: implement display cleanup Marc-André Lureau
2026-05-29 11:16 ` [PATCH 15/32] ui/sdl2: " Marc-André Lureau
2026-05-29 11:16 ` [PATCH 16/32] ui/spice-app: " Marc-André Lureau
2026-05-29 11:16 ` [PATCH 17/32] ui/egl: implement display and EGL cleanup Marc-André Lureau
2026-05-29 11:16 ` [PATCH 18/32] ui/cocoa: implement display cleanup Marc-André Lureau
2026-05-29 11:16 ` [PATCH 19/32] ui/dbus: " Marc-André Lureau
2026-05-29 12:17   ` Akihiko Odaki
2026-05-29 11:16 ` [PATCH 20/32] ui/gtk: " Marc-André Lureau
2026-05-29 11:16 ` [PATCH 21/32] ui/console: add console event notifier infrastructure Marc-André Lureau
2026-05-29 11:16 ` [PATCH 22/32] ui/console: fire console ADDED/REMOVED notifications Marc-André Lureau
2026-05-29 11:16 ` [PATCH 23/32] ui/console-vc: fire " Marc-André Lureau
2026-05-29 11:16 ` [PATCH 24/32] ui/gtk: convert VirtualConsole storage from fixed array to GPtrArray Marc-André Lureau
2026-05-29 12:21   ` Akihiko Odaki
2026-05-29 11:16 ` [PATCH 25/32] ui/gtk: move global display settings out of per-console init Marc-André Lureau
2026-05-29 11:16 ` [PATCH 26/32] ui/gtk: fix tab re-insertion order on window close Marc-André Lureau
2026-05-29 11:16 ` [PATCH 27/32] ui/gtk: centralize console menu and shortcut management Marc-André Lureau
2026-05-29 11:16 ` [PATCH 28/32] ui/gtk: handle console hotplug/unplug events Marc-André Lureau
2026-05-29 11:16 ` [PATCH 29/32] ui/console: register console in QOM tree dynamically Marc-André Lureau
2026-05-29 11:16 ` [PATCH 30/32] ui/console: unregister console from QOM tree on close Marc-André Lureau
2026-05-29 11:16 ` [PATCH 31/32] ui/dbus: handle console hotplug/unplug events Marc-André Lureau
2026-05-29 11:16 ` [PATCH 32/32] tests/qtest: add D-Bus display hotplug test Marc-André Lureau
2026-05-29 13:34   ` Fabiano Rosas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fr3atk51.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=alex@shazbot.org \
    --cc=berrange@redhat.com \
    --cc=clg@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@mailo.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.