qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: Fabiano Rosas <farosas@suse.de>, Peter Xu <peterx@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	"Dr. David Alan Gilbert" <dave@treblig.org>,
	Cedric Le Goater <clg@redhat.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Steve Sistare <steven.sistare@oracle.com>
Subject: [PATCH V5 10/19] tests/qtest: qtest_qemu_args
Date: Wed,  1 Oct 2025 08:34:02 -0700	[thread overview]
Message-ID: <1759332851-370353-11-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1759332851-370353-1-git-send-email-steven.sistare@oracle.com>

Define an accessor that returns all the arguments used to exec QEMU.
Collect the arguments that were passed to qtest_spawn_qemu, plus the trace
arguments that were composed inside qtest_spawn_qemu, and move them to a
new function qtest_qemu_args.

This will be needed to test the cpr-exec migration mode.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
---
 tests/qtest/libqtest.h |  8 ++++++++
 tests/qtest/libqtest.c | 54 +++++++++++++++++++++++++++++---------------------
 2 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index dc2cdd0..7f8dd0a 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -57,6 +57,14 @@ QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
 const char *qtest_qemu_binary(const char *var);
 
 /**
+ * qtest_qemu_args:
+ * @extra_args: Other arguments to pass to QEMU.
+ *
+ * Return the command line used to start QEMU, sans binary.
+ */
+gchar *qtest_qemu_args(const char *extra_args);
+
+/**
  * qtest_init:
  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
  * arguments are subject to word splitting and shell evaluation.
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 43fd997..b3b3fc2 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -409,20 +409,12 @@ static pid_t qtest_create_process(char *cmd)
 }
 #endif /* _WIN32 */
 
-static QTestState *G_GNUC_PRINTF(2, 3) qtest_spawn_qemu(const char *qemu_bin,
-                                                        const char *fmt, ...)
+static QTestState *qtest_spawn_qemu(const char *qemu_bin, const char *args)
 {
-    va_list ap;
     QTestState *s = g_new0(QTestState, 1);
-    const char *trace = g_getenv("QTEST_TRACE");
-    g_autofree char *tracearg = trace ?
-        g_strdup_printf("-trace %s ", trace) : g_strdup("");
     g_autoptr(GString) command = g_string_new("");
 
-    va_start(ap, fmt);
-    g_string_append_printf(command, CMD_EXEC "%s %s", qemu_bin, tracearg);
-    g_string_append_vprintf(command, fmt, ap);
-    va_end(ap);
+    g_string_printf(command, CMD_EXEC "%s %s", qemu_bin, args);
 
     qtest_add_abrt_handler(kill_qemu_hook_func, s);
 
@@ -466,6 +458,33 @@ static char *qtest_socket_path(const char *suffix)
     return g_strdup_printf("%s/qtest-%d.%s", g_get_tmp_dir(), getpid(), suffix);
 }
 
+gchar *qtest_qemu_args(const char *extra_args)
+{
+    g_autofree gchar *socket_path = qtest_socket_path("sock");
+    g_autofree gchar *qmp_socket_path = qtest_socket_path("qmp");
+    const char *trace = g_getenv("QTEST_TRACE");
+    g_autofree char *tracearg = trace ? g_strdup_printf("-trace %s ", trace) :
+                                        g_strdup("");
+    gchar *args = g_strdup_printf(
+                      "%s"
+                      "-qtest unix:%s "
+                      "-qtest-log %s "
+                      "-chardev socket,path=%s,id=char0 "
+                      "-mon chardev=char0,mode=control "
+                      "-display none "
+                      "-audio none "
+                      "%s"
+                      " -accel qtest",
+
+                      tracearg,
+                      socket_path,
+                      getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
+                      qmp_socket_path,
+                      extra_args ?: "");
+
+    return args;
+}
+
 static QTestState *qtest_init_internal(const char *qemu_bin,
                                        const char *extra_args,
                                        bool do_connect)
@@ -474,6 +493,7 @@ static QTestState *qtest_init_internal(const char *qemu_bin,
     int sock, qmpsock, i;
     g_autofree gchar *socket_path = qtest_socket_path("sock");
     g_autofree gchar *qmp_socket_path = qtest_socket_path("qmp");
+    g_autofree gchar *args = qtest_qemu_args(extra_args);
 
     /*
      * It's possible that if an earlier test run crashed it might
@@ -488,19 +508,7 @@ static QTestState *qtest_init_internal(const char *qemu_bin,
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
-    s = qtest_spawn_qemu(qemu_bin,
-                         "-qtest unix:%s "
-                         "-qtest-log %s "
-                         "-chardev socket,path=%s,id=char0 "
-                         "-mon chardev=char0,mode=control "
-                         "-display none "
-                         "-audio none "
-                         "%s"
-                         " -accel qtest",
-                         socket_path,
-                         getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
-                         qmp_socket_path,
-                         extra_args ?: "");
+    s = qtest_spawn_qemu(qemu_bin, args);
 
     qtest_client_set_rx_handler(s, qtest_client_socket_recv_line);
     qtest_client_set_tx_handler(s, qtest_client_socket_send);
-- 
1.8.3.1



  parent reply	other threads:[~2025-10-01 15:36 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-01 15:33 [PATCH V5 00/19] Live update: cpr-exec Steve Sistare
2025-10-01 15:33 ` [PATCH V5 01/19] migration: multi-mode notifier Steve Sistare
2025-10-01 15:33 ` [PATCH V5 02/19] migration: add cpr_walk_fd Steve Sistare
2025-10-01 15:33 ` [PATCH V5 03/19] oslib: qemu_clear_cloexec Steve Sistare
2025-10-01 15:33 ` [PATCH V5 04/19] migration: cpr-exec-command parameter Steve Sistare
2025-10-01 15:33 ` [PATCH V5 05/19] migration: cpr-exec save and load Steve Sistare
2025-10-01 16:36   ` Peter Xu
2025-10-01 15:33 ` [PATCH V5 06/19] migration: cpr-exec mode Steve Sistare
2025-10-01 15:33 ` [PATCH V5 07/19] migration: cpr-exec docs Steve Sistare
2025-10-01 15:34 ` [PATCH V5 08/19] vfio: cpr-exec mode Steve Sistare
2025-10-01 15:34 ` [PATCH V5 09/19] tests/qtest: export qtest_qemu_binary Steve Sistare
2025-10-01 15:34 ` Steve Sistare [this message]
2025-10-01 15:34 ` [PATCH V5 11/19] tests/qtest: qtest_create_test_state Steve Sistare
2025-10-01 15:34 ` [PATCH V5 12/19] tests/qtest: qtest_qemu_spawn_func Steve Sistare
2025-10-01 15:34 ` [PATCH V5 13/19] tests/qtest: qtest_init_after_exec Steve Sistare
2025-10-01 15:34 ` [PATCH V5 14/19] migration-test: only_source option Steve Sistare
2025-10-01 15:34 ` [PATCH V5 15/19] migration-test: shm path accessor Steve Sistare
2025-10-01 15:34 ` [PATCH V5 16/19] migration-test: misc exports Steve Sistare
2025-10-01 15:34 ` [PATCH V5 17/19] migration-test: migrate_args Steve Sistare
2025-10-01 15:34 ` [PATCH V5 18/19] migration-test: strv parameter Steve Sistare
2025-10-01 15:34 ` [PATCH V5 19/19] migration-test: test cpr-exec Steve Sistare
2025-10-01 18:56 ` [PATCH V5 00/19] Live update: cpr-exec Peter Xu
2025-10-01 19:07   ` Steven Sistare
2025-10-01 19:24     ` Steven Sistare
2025-10-01 20:05       ` Peter Xu
2025-10-02 12:44         ` Steven Sistare
2025-10-02  8:48       ` Cédric Le Goater
2025-10-01 20:03     ` Peter Xu
2025-10-02  8:50       ` Cédric Le Goater
2025-10-02 13:45         ` Steven Sistare
2025-10-02 13:44       ` Steven Sistare
2025-10-03 11:36         ` Steven Sistare
2025-10-03 13:11           ` Peter Xu
2025-10-03 13:36             ` Steven Sistare

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=1759332851-370353-11-git-send-email-steven.sistare@oracle.com \
    --to=steven.sistare@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=clg@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).