Skip to contentSkip to conversation

tests/qtest: Allow running boot-serial / migration with TCG disabled

PATCH Superseded Philippe Mathieu-Daudé 4 participants 31 messages Jan 19, 2023 – Jan 20, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover tests/qtest: Allow running boot-serial / migration with TCG disabled

Two test were failing on Darwin when testing Fabiano's series which allows building ARM targets without TCG accelerator:
https://lore.kernel.org/qemu-devel/[email protected]/

These patches allow boot-serial / migration tests to run without TCG / KVM.

Since v1:
- Split GString API conversion in multiple trivial patches (David)
- Use KVM first in migration test (David)
- Dropped HVF changes for now.

Philippe Mathieu-Daudé (11):
tests/qtest/boot-serial-test: Constify tests[] array tests/qtest/boot-serial-test: Simplify test_machine() a bit tests/qtest/boot-serial-test: Build command line using GString API tests/qtest/boot-serial-test: Only use available accelerators tests/qtest/migration-test: Inverse #ifdef'ry ladders tests/qtest/migration-test: Reduce 'cmd_source' string scope tests/qtest/migration-test: Build command line using GString API (1/4) tests/qtest/migration-test: Build command line using GString API (2/4) tests/qtest/migration-test: Build command line using GString API (3/4) tests/qtest/migration-test: Build command line using GString API (4/4) tests/qtest/migration-test: Only use available accelerators

 tests/qtest/boot-serial-test.c | 46 +++++++++-------
 tests/qtest/migration-test.c   | 95 ++++++++++++++++++----------------
 2 files changed, 79 insertions(+), 62 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 1/11 tests/qtest/boot-serial-test: Constify tests[] array

---
 tests/qtest/boot-serial-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/boot-serial-test.c +1 -1
index b216519b62..3aef3a97a9 100644
@@ -139,7 +139,7 @@ typedef struct testdef {
     const uint8_t *bios;    /* Set in case we use our own mini bios */
 } testdef_t;
 
-static testdef_t tests[] = {
+static const testdef_t tests[] = {
     { "alpha", "clipper", "", "PCI:" },
     { "avr", "arduino-duemilanove", "", "T", sizeof(bios_avr), NULL, bios_avr },
     { "avr", "arduino-mega-2560-v3", "", "T", sizeof(bios_avr), NULL, bios_avr},
Signature · 1 line
2.38.1
#3 lore raw

PATCH v2 2/11 tests/qtest/boot-serial-test: Simplify test_machine() a bit

In reply to Philippe Mathieu-Daudé

Slighly modify test_machine() to simplify next commit review.

---
 tests/qtest/boot-serial-test.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
tests/qtest/boot-serial-test.c +7 -14
index 3aef3a97a9..3a854b0174 100644
@@ -227,7 +227,6 @@ static void test_machine(const void *data)
     g_autofree char *serialtmp = NULL;
     g_autofree char *codetmp = NULL;
     const char *codeparam = "";
-    const uint8_t *code = NULL;
     QTestState *qts;
     int ser_fd;
 
@@ -235,21 +234,13 @@ static void test_machine(const void *data)
     g_assert(ser_fd != -1);
     close(ser_fd);
 
-    if (test->kernel) {
-        code = test->kernel;
-        codeparam = "-kernel";
-    } else if (test->bios) {
-        code = test->bios;
-        codeparam = "-bios";
-    }
-
-    if (code) {
+    if (test->kernel || test->bios) {
         ssize_t wlen;
         int code_fd;
 
         code_fd = g_file_open_tmp("qtest-boot-serial-cXXXXXX", &codetmp, NULL);
         g_assert(code_fd != -1);
-        wlen = write(code_fd, code, test->codesize);
+        wlen = write(code_fd, test->kernel ? : test->bios, test->codesize);
         g_assert(wlen == test->codesize);
         close(code_fd);
     }
@@ -258,12 +249,14 @@ static void test_machine(const void *data)
      * Make sure that this test uses tcg if available: It is used as a
      * fast-enough smoketest for that.
      */
-    qts = qtest_initf("%s %s -M %s -no-shutdown "
+    qts = qtest_initf("%s %s %s -M %s -no-shutdown "
                       "-chardev file,id=serial0,path=%s "
                       "-serial chardev:serial0 -accel tcg -accel kvm %s",
-                      codeparam, code ? codetmp : "", test->machine,
+                      codeparam,
+                      test->kernel ? "-kernel " : test->bios ? "-bios " : "",
+                      codetmp ? : "", test->machine,
                       serialtmp, test->extra);
-    if (code) {
+    if (codetmp) {
         unlink(codetmp);
     }
 
Signature · 1 line
2.38.1
#5 lore raw

Re: [PATCH v2 02/11] tests/qtest/boot-serial-test: Simplify test_machine() a bit

In reply to Philippe Mathieu-Daudé
Quoted 30 lines · Philippe Mathieu-Daudé

Slighly modify test_machine() to simplify next commit review.

---
  tests/qtest/boot-serial-test.c | 21 +++++++--------------
  1 file changed, 7 insertions(+), 14 deletions(-)
tests/qtest/boot-serial-test.c +0 -8
index 3aef3a97a9..3a854b0174 100644
@@ -227,7 +227,6 @@ static void test_machine(const void *data)
      g_autofree char *serialtmp = NULL;
      g_autofree char *codetmp = NULL;
      const char *codeparam = "";
-    const uint8_t *code = NULL;
      QTestState *qts;
      int ser_fd;
 
@@ -235,21 +234,13 @@ static void test_machine(const void *data)
      g_assert(ser_fd != -1);
      close(ser_fd);
 
-    if (test->kernel) {
-        code = test->kernel;
-        codeparam = "-kernel";
-    } else if (test->bios) {
-        code = test->bios;
-        codeparam = "-bios";
-    }

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 243

Quoted 10 lines
tests/qtest/boot-serial-test.c +2 -3
-
-    if (code) {
+    if (test->kernel || test->bios) {
          ssize_t wlen;
          int code_fd;
 
          code_fd = g_file_open_tmp("qtest-boot-serial-cXXXXXX", &codetmp, NULL);
          g_assert(code_fd != -1);
-        wlen = write(code_fd, code, test->codesize);
+        wlen = write(code_fd, test->kernel ? : test->bios, test->codesize);

Just a matter of taste, but I prefer the Elvis operator without space in between.

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 255

Quoted 13 lines
tests/qtest/boot-serial-test.c +2 -2
          g_assert(wlen == test->codesize);
          close(code_fd);
      }
@@ -258,12 +249,14 @@ static void test_machine(const void *data)
       * Make sure that this test uses tcg if available: It is used as a
       * fast-enough smoketest for that.
       */
-    qts = qtest_initf("%s %s -M %s -no-shutdown "
+    qts = qtest_initf("%s %s %s -M %s -no-shutdown "
                        "-chardev file,id=serial0,path=%s "
                        "-serial chardev:serial0 -accel tcg -accel kvm %s",
-                      codeparam, code ? codetmp : "", test->machine,
+                      codeparam,

You removed the initialization of codeparam, so this is now always the empty string, isn't it? ... please just remove it completely now.

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 262

Quoted 8 lines
tests/qtest/boot-serial-test.c +3 -1
+                      test->kernel ? "-kernel " : test->bios ? "-bios " : "",
+                      codetmp ? : "", test->machine,
                        serialtmp, test->extra);
-    if (code) {
+    if (codetmp) {
          unlink(codetmp);
      }
 

Thomas

#6 lore raw

PATCH v2 3/11 tests/qtest/boot-serial-test: Build command line using GString API

In reply to Philippe Mathieu-Daudé
---
 tests/qtest/boot-serial-test.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
tests/qtest/boot-serial-test.c +15 -8
index 3a854b0174..92890b409d 100644
@@ -226,14 +226,17 @@ static void test_machine(const void *data)
     const testdef_t *test = data;
     g_autofree char *serialtmp = NULL;
     g_autofree char *codetmp = NULL;
-    const char *codeparam = "";
     QTestState *qts;
     int ser_fd;
+    g_autoptr(GString) cmd = g_string_new("");
 
     ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
     g_assert(ser_fd != -1);
     close(ser_fd);
 
+    g_string_append_printf(cmd, "-M %s ", test->machine);
+    g_string_append(cmd, "-no-shutdown ");
+
     if (test->kernel || test->bios) {
         ssize_t wlen;
         int code_fd;
@@ -243,19 +246,23 @@ static void test_machine(const void *data)
         wlen = write(code_fd, test->kernel ? : test->bios, test->codesize);
         g_assert(wlen == test->codesize);
         close(code_fd);
+        g_string_append_printf(cmd, "%s %s ",
+                               test->kernel ? "-kernel " : "-bios ", codetmp);
     }
 
+    g_string_append_printf(cmd, "-chardev file,id=serial0,path=%s "
+                                "-serial chardev:serial0 ", serialtmp);
+
     /*
      * Make sure that this test uses tcg if available: It is used as a
      * fast-enough smoketest for that.
      */
-    qts = qtest_initf("%s %s %s -M %s -no-shutdown "
-                      "-chardev file,id=serial0,path=%s "
-                      "-serial chardev:serial0 -accel tcg -accel kvm %s",
-                      codeparam,
-                      test->kernel ? "-kernel " : test->bios ? "-bios " : "",
-                      codetmp ? : "", test->machine,
-                      serialtmp, test->extra);
+    g_string_append(cmd, "-accel tcg ");
+    g_string_append(cmd, "-accel kvm ");
+    g_string_append(cmd, test->extra);
+
+    qts = qtest_init(cmd->str);
+
     if (codetmp) {
         unlink(codetmp);
     }
Signature · 1 line
2.38.1
#8 lore raw

Re: [PATCH v2 03/11] tests/qtest/boot-serial-test: Build command line using GString API

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé
---
  tests/qtest/boot-serial-test.c | 23 +++++++++++++++--------
  1 file changed, 15 insertions(+), 8 deletions(-)
tests/qtest/boot-serial-test.c +0 -0
index 3a854b0174..92890b409d 100644

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 231

Quoted 7 lines
tests/qtest/boot-serial-test.c +1 -1
@@ -226,14 +226,17 @@ static void test_machine(const void *data)
      const testdef_t *test = data;
      g_autofree char *serialtmp = NULL;
      g_autofree char *codetmp = NULL;
-    const char *codeparam = "";
      QTestState *qts;
      int ser_fd;
+    g_autoptr(GString) cmd = g_string_new("");

You could already start with the "-no-shutdown" here.

Quoted 11 lines
tests/qtest/boot-serial-test.c +3 -0
      ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
      g_assert(ser_fd != -1);
      close(ser_fd);
 
+    g_string_append_printf(cmd, "-M %s ", test->machine);
+    g_string_append(cmd, "-no-shutdown ");
+
      if (test->kernel || test->bios) {
          ssize_t wlen;
          int code_fd;

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 254

Quoted 9 lines
tests/qtest/boot-serial-test.c +4 -0
@@ -243,19 +246,23 @@ static void test_machine(const void *data)
          wlen = write(code_fd, test->kernel ? : test->bios, test->codesize);
          g_assert(wlen == test->codesize);
          close(code_fd);
+        g_string_append_printf(cmd, "%s %s ",
+                               test->kernel ? "-kernel " : "-bios ", codetmp);
      }
 
+    g_string_append_printf(cmd, "-chardev file,id=serial0,path=%s "
+                                "-serial chardev:serial0 ", serialtmp);

Why not include this in the initial g_string_append_printf statement already?

Quoted 6 lines
tests/qtest/boot-serial-test.c +0 -2
      /*
       * Make sure that this test uses tcg if available: It is used as a
       * fast-enough smoketest for that.
       */
-    qts = qtest_initf("%s %s %s -M %s -no-shutdown "
-                      "-chardev file,id=serial0,path=%s "

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 264

Quoted 10 lines
tests/qtest/boot-serial-test.c +5 -5
-                      "-serial chardev:serial0 -accel tcg -accel kvm %s",
-                      codeparam,
-                      test->kernel ? "-kernel " : test->bios ? "-bios " : "",
-                      codetmp ? : "", test->machine,
-                      serialtmp, test->extra);
+    g_string_append(cmd, "-accel tcg ");
+    g_string_append(cmd, "-accel kvm ");
+    g_string_append(cmd, test->extra);
+
+    qts = qtest_init(cmd->str);

... and I have to say that this is already quite a lot of code churn, just to get the -accel parameters tweaked in the end.

Why don't you simply do a single small patch that just replaces the "-accel tcg -accel" part with "%s %s" and add two parameters like this:

has_tcg ? "-accel tcg" : "", has_kvm ? "-accel kvm" : ""

?

Thomas

#9 lore raw

Re: [PATCH v2 03/11] tests/qtest/boot-serial-test: Build command line using GString API

Quoted 6 lines · Thomas Huth
Quoted 5 lines · Philippe Mathieu-Daudé

---
  tests/qtest/boot-serial-test.c | 23 +++++++++++++++--------

  1 file changed, 15 insertions(+), 8 deletions(-)
Quoted 14 lines

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 231

Quoted 12 lines
tests/qtest/boot-serial-test.c +1 -1
index 3a854b0174..92890b409d 100644
@@ -226,14 +226,17 @@ static void test_machine(const void *data)
       const testdef_t *test = data;
       g_autofree char *serialtmp = NULL;
       g_autofree char *codetmp = NULL;
-    const char *codeparam = "";
       QTestState *qts;
       int ser_fd;
+    g_autoptr(GString) cmd = g_string_new("");

You could already start with the "-no-shutdown" here.

It is just the matter of knowing the style of the maintainer :) IIRC Alex prefers starting with an empty "" to avoid future churn when adding new params (just add new line instead of modify).

I'll use your suggestion if I respin.

Quoted 42 lines
Quoted 11 lines
tests/qtest/boot-serial-test.c +3 -0
       ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
       g_assert(ser_fd != -1);
       close(ser_fd);
+    g_string_append_printf(cmd, "-M %s ", test->machine);
+    g_string_append(cmd, "-no-shutdown ");
+
       if (test->kernel || test->bios) {
           ssize_t wlen;
           int code_fd;

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 254

Quoted 9 lines
tests/qtest/boot-serial-test.c +4 -0
@@ -243,19 +246,23 @@ static void test_machine(const void *data)
           wlen = write(code_fd, test->kernel ? : test->bios, test->codesize);
           g_assert(wlen == test->codesize);
           close(code_fd);
+        g_string_append_printf(cmd, "%s %s ",
+                               test->kernel ? "-kernel " : "-bios ", 
 codetmp);
       }
+    g_string_append_printf(cmd, "-chardev file,id=serial0,path=%s "
+                                "-serial chardev:serial0 ", serialtmp);

Why not include this in the initial g_string_append_printf statement already?

Quoted 8 lines
tests/qtest/boot-serial-test.c +0 -3
       /*
        * Make sure that this test uses tcg if available: It is used as a
        * fast-enough smoketest for that.
        */
-    qts = qtest_initf("%s %s %s -M %s -no-shutdown "
-                      "-chardev file,id=serial0,path=%s "
-                      "-serial chardev:serial0 -accel tcg -accel kvm 
 %s",

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 264

Quoted 10 lines
tests/qtest/boot-serial-test.c +5 -4
-                      codeparam,
-                      test->kernel ? "-kernel " : test->bios ? "-bios 
 " : "",
-                      codetmp ? : "", test->machine,
-                      serialtmp, test->extra);
+    g_string_append(cmd, "-accel tcg ");
+    g_string_append(cmd, "-accel kvm ");
+    g_string_append(cmd, test->extra);
+
+    qts = qtest_init(cmd->str);
Quoted 5 lines

... and I have to say that this is already quite a lot of code churn, just to get the -accel parameters tweaked in the end.

Why don't you simply do a single small patch that just replaces the "-accel tcg -accel" part with "%s %s" and add two parameters like this:

  has_tcg ? "-accel tcg" : "", has_kvm ? "-accel kvm" : ""

I thought it would be simpler when adding HVF support later, KISS, but I don't mind to change.

Thanks,

Phil.

#10 lore raw

PATCH v2 4/11 tests/qtest/boot-serial-test: Only use available accelerators

In reply to Philippe Mathieu-Daudé

For example, avoid when TCG is disabled:

  $ make check-qtest-aarch64
  ...
  18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
  qemu-system-aarch64: -accel tcg: invalid accelerator tcg
---
 tests/qtest/boot-serial-test.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tests/qtest/boot-serial-test.c +12 -2
index 92890b409d..f375b16dae 100644
@@ -17,6 +17,9 @@
 #include "libqtest.h"
 #include "libqos/libqos-spapr.h"
 
+static bool has_tcg;
+static bool has_kvm;
+
 static const uint8_t bios_avr[] = {
     0x88, 0xe0,             /* ldi r24, 0x08   */
     0x80, 0x93, 0xc1, 0x00, /* sts 0x00C1, r24 ; Enable tx */
@@ -257,8 +260,12 @@ static void test_machine(const void *data)
      * Make sure that this test uses tcg if available: It is used as a
      * fast-enough smoketest for that.
      */
-    g_string_append(cmd, "-accel tcg ");
-    g_string_append(cmd, "-accel kvm ");
+    if (has_tcg) {
+        g_string_append(cmd, "-accel tcg ");
+    }
+    if (has_kvm) {
+        g_string_append(cmd, "-accel kvm ");
+    }
     g_string_append(cmd, test->extra);
 
     qts = qtest_init(cmd->str);
@@ -285,6 +292,9 @@ int main(int argc, char *argv[])
     const char *arch = qtest_get_arch();
     int i;
 
+    has_tcg = qtest_has_accel("tcg");
+    has_kvm = qtest_has_accel("kvm");
+
     g_test_init(&argc, &argv, NULL);
 
     for (i = 0; tests[i].arch != NULL; i++) {
Signature · 1 line
2.38.1
Reviewed-by on v2 4/11
#12 lore raw

Re: [PATCH v2 04/11] tests/qtest/boot-serial-test: Only use available accelerators

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

For example, avoid when TCG is disabled:

   $ make check-qtest-aarch64
   ...
   18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
   qemu-system-aarch64: -accel tcg: invalid accelerator tcg
---
  tests/qtest/boot-serial-test.c | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)

r~

#13 lore raw

PATCH v2 5/11 tests/qtest/migration-test: Inverse #ifdef'ry ladders

In reply to Philippe Mathieu-Daudé

This slighly simplify the logic, and eases the following conversion.

---
 tests/qtest/migration-test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/qtest/migration-test.c +3 -3
index dbde726adf..8beeda4686 100644
@@ -647,15 +647,15 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     }
 
     if (!getenv("QTEST_LOG") && args->hide_stderr) {
-#ifndef _WIN32
-        ignore_stderr = "2>/dev/null";
-#else
+#ifdef _WIN32
         /*
          * On Windows the QEMU executable is created via CreateProcess() and
          * IO redirection does not work, so don't bother adding IO redirection
          * to the command line.
          */
         ignore_stderr = "";
+#else
+        ignore_stderr = "2>/dev/null";
 #endif
     } else {
         ignore_stderr = "";
Signature · 1 line
2.38.1
#15 lore raw

PATCH v2 6/11 tests/qtest/migration-test: Reduce 'cmd_source' string scope

In reply to Philippe Mathieu-Daudé
---
 tests/qtest/migration-test.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
tests/qtest/migration-test.c +15 -14
index 8beeda4686..6c3db95113 100644
@@ -584,7 +584,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
 {
     g_autofree gchar *arch_source = NULL;
     g_autofree gchar *arch_target = NULL;
-    g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
     const gchar *ignore_stderr;
     g_autofree char *bootpath = NULL;
@@ -672,20 +671,22 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         shmem_opts = g_strdup("");
     }
 
-    cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
-                                 "-name source,debug-threads=on "
-                                 "-m %s "
-                                 "-serial file:%s/src_serial "
-                                 "%s %s %s %s",
-                                 args->use_dirty_ring ?
-                                 ",dirty-ring-size=4096" : "",
-                                 machine_opts ? " -machine " : "",
-                                 machine_opts ? machine_opts : "",
-                                 memory_size, tmpfs,
-                                 arch_source, shmem_opts,
-                                 args->opts_source ? args->opts_source : "",
-                                 ignore_stderr);
     if (!args->only_target) {
+        g_autofree gchar *cmd_source = NULL;
+
+        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+                                     "-name source,debug-threads=on "
+                                     "-m %s "
+                                     "-serial file:%s/src_serial "
+                                     "%s %s %s %s",
+                                     args->use_dirty_ring ?
+                                     ",dirty-ring-size=4096" : "",
+                                     machine_opts ? " -machine " : "",
+                                     machine_opts ? machine_opts : "",
+                                     memory_size, tmpfs,
+                                     arch_source, shmem_opts,
+                                     args->opts_source ? args->opts_source : "",
+                                     ignore_stderr);
         *from = qtest_init(cmd_source);
     }
 
Signature · 1 line
2.38.1
#18 lore raw

Re: [PATCH v2 06/11] tests/qtest/migration-test: Reduce 'cmd_source' string scope

Quoted 7 lines · Thomas Huth
Quoted 4 lines · Philippe Mathieu-Daudé

---
  tests/qtest/migration-test.c | 29 +++++++++++++++--------------

  1 file changed, 15 insertions(+), 14 deletions(-)

Missing explanation in the commit description. What's the benefit of doing this?

Reduce the changes in the next patches to ease David's review.

#19 lore raw

PATCH v2 7/11 tests/qtest/migration-test: Build command line using GString API (1/4)

In reply to Philippe Mathieu-Daudé

Part 1/4: Convert memory & machine options.

---
 tests/qtest/migration-test.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
tests/qtest/migration-test.c +12 -10
index 6c3db95113..7aa323a7a7 100644
@@ -582,6 +582,7 @@ typedef struct {
 static int test_migrate_start(QTestState **from, QTestState **to,
                               const char *uri, MigrateStart *args)
 {
+    g_autoptr(GString) cmd_common = NULL;
     g_autofree gchar *arch_source = NULL;
     g_autofree gchar *arch_target = NULL;
     g_autofree gchar *cmd_target = NULL;
@@ -601,6 +602,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     }
 
     got_stop = false;
+
+    cmd_common = g_string_new("");
+
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         /* the assembled x86 boot sector should be exactly one sector large */
@@ -644,6 +648,10 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     } else {
         g_assert_not_reached();
     }
+    if (machine_opts) {
+        g_string_append_printf(cmd_common, " -machine %s ", machine_opts);
+    }
+    g_string_append_printf(cmd_common, "-m %s ", memory_size);
 
     if (!getenv("QTEST_LOG") && args->hide_stderr) {
 #ifdef _WIN32
@@ -674,33 +682,27 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     if (!args->only_target) {
         g_autofree gchar *cmd_source = NULL;
 
-        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s "
                                      "-name source,debug-threads=on "
-                                     "-m %s "
                                      "-serial file:%s/src_serial "
                                      "%s %s %s %s",
                                      args->use_dirty_ring ?
                                      ",dirty-ring-size=4096" : "",
-                                     machine_opts ? " -machine " : "",
-                                     machine_opts ? machine_opts : "",
-                                     memory_size, tmpfs,
+                                     cmd_common->str, tmpfs,
                                      arch_source, shmem_opts,
                                      args->opts_source ? args->opts_source : "",
                                      ignore_stderr);
         *from = qtest_init(cmd_source);
     }
 
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s "
                                  "-name target,debug-threads=on "
-                                 "-m %s "
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
                                  "%s %s %s %s",
                                  args->use_dirty_ring ?
                                  ",dirty-ring-size=4096" : "",
-                                 machine_opts ? " -machine " : "",
-                                 machine_opts ? machine_opts : "",
-                                 memory_size, tmpfs, uri,
+                                 cmd_common->str, tmpfs, uri,
                                  arch_target, shmem_opts,
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr);
Signature · 1 line
2.38.1
#20 lore raw

Re: [PATCH v2 07/11] tests/qtest/migration-test: Build command line using GString API (1/4)

Quoted 44 lines · Philippe Mathieu-Daudé

Part 1/4: Convert memory & machine options.

---
  tests/qtest/migration-test.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
tests/qtest/migration-test.c +8 -0
index 6c3db95113..7aa323a7a7 100644
@@ -582,6 +582,7 @@ typedef struct {
  static int test_migrate_start(QTestState **from, QTestState **to,
                                const char *uri, MigrateStart *args)
  {
+    g_autoptr(GString) cmd_common = NULL;
      g_autofree gchar *arch_source = NULL;
      g_autofree gchar *arch_target = NULL;
      g_autofree gchar *cmd_target = NULL;
@@ -601,6 +602,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
      }
 
      got_stop = false;
+
+    cmd_common = g_string_new("");
+
      bootpath = g_strdup_printf("%s/bootsect", tmpfs);
      if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
          /* the assembled x86 boot sector should be exactly one sector large */
@@ -644,6 +648,10 @@ static int test_migrate_start(QTestState **from, QTestState **to,
      } else {
          g_assert_not_reached();
      }
+    if (machine_opts) {
+        g_string_append_printf(cmd_common, " -machine %s ", machine_opts);
+    }
+    g_string_append_printf(cmd_common, "-m %s ", memory_size);
 
      if (!getenv("QTEST_LOG") && args->hide_stderr) {
  #ifdef _WIN32
@@ -674,33 +682,27 @@ static int test_migrate_start(QTestState **from, QTestState **to,
      if (!args->only_target) {
          g_autofree gchar *cmd_source = NULL;
 

tests/qtest/migration-test.c static int test_migrate_start(QTestState **from, QTestState **to, · line 685

Quoted 10 lines
tests/qtest/migration-test.c +1 -4
-        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s "
                                       "-name source,debug-threads=on "
-                                     "-m %s "
                                       "-serial file:%s/src_serial "
                                       "%s %s %s %s",
                                       args->use_dirty_ring ?
                                       ",dirty-ring-size=4096" : "",
-                                     machine_opts ? " -machine " : "",
-                                     machine_opts ? machine_opts : "",

You removed two strings here, but only one %s above.

r~

Quoted 24 lines
tests/qtest/migration-test.c +3 -6
-                                     memory_size, tmpfs,
+                                     cmd_common->str, tmpfs,
                                       arch_source, shmem_opts,
                                       args->opts_source ? args->opts_source : "",
                                       ignore_stderr);
          *from = qtest_init(cmd_source);
      }
 
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s "
                                   "-name target,debug-threads=on "
-                                 "-m %s "
                                   "-serial file:%s/dest_serial "
                                   "-incoming %s "
                                   "%s %s %s %s",
                                   args->use_dirty_ring ?
                                   ",dirty-ring-size=4096" : "",
-                                 machine_opts ? " -machine " : "",
-                                 machine_opts ? machine_opts : "",
-                                 memory_size, tmpfs, uri,
+                                 cmd_common->str, tmpfs, uri,
                                   arch_target, shmem_opts,
                                   args->opts_target ? args->opts_target : "",
                                   ignore_stderr);
#21 lore raw

Re: [PATCH v2 07/11] tests/qtest/migration-test: Build command line using GString API (1/4)

Quoted 50 lines · Richard Henderson
Quoted 49 lines · Philippe Mathieu-Daudé

Part 1/4: Convert memory & machine options.

---
  tests/qtest/migration-test.c | 22 ++++++++++++----------

  1 file changed, 12 insertions(+), 10 deletions(-)
tests/qtest/migration-test.c +8 -0
index 6c3db95113..7aa323a7a7 100644
@@ -582,6 +582,7 @@ typedef struct {
   static int test_migrate_start(QTestState **from, QTestState **to,
                                 const char *uri, MigrateStart *args)
   {
+    g_autoptr(GString) cmd_common = NULL;
       g_autofree gchar *arch_source = NULL;
       g_autofree gchar *arch_target = NULL;
       g_autofree gchar *cmd_target = NULL;
@@ -601,6 +602,9 @@ static int test_migrate_start(QTestState **from, 
 QTestState **to,
       }
       got_stop = false;
+
+    cmd_common = g_string_new("");
+
       bootpath = g_strdup_printf("%s/bootsect", tmpfs);
       if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
           /* the assembled x86 boot sector should be exactly one sector large */
@@ -644,6 +648,10 @@ static int test_migrate_start(QTestState **from, 
 QTestState **to,
       } else {
           g_assert_not_reached();
       }
+    if (machine_opts) {
+        g_string_append_printf(cmd_common, " -machine %s ", 
 machine_opts);
+    }
+    g_string_append_printf(cmd_common, "-m %s ", memory_size);
       if (!getenv("QTEST_LOG") && args->hide_stderr) {

  #ifdef _WIN32

tests/qtest/migration-test.c +1 -1
@@ -674,33 +682,27 @@ static int test_migrate_start(QTestState **from, 
 QTestState **to,
       if (!args->only_target) {
           g_autofree gchar *cmd_source = NULL;
-        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s "

                                       "-name source,debug-threads=on " -                                     "-m %s "

Quoted 11 lines
Quoted 6 lines

                                       "-serial file:%s/src_serial " "%s %s %s %s", args->use_dirty_ring ? ",dirty-ring-size=4096" : "", -                                     machine_opts ? " -machine " : "", -                                     machine_opts ? machine_opts : "",

You removed two strings here, but only one %s above.

Quoted 2 lines

-                                     memory_size, tmpfs, +                                     cmd_common->str, tmpfs,

One new string is added here ^^^^^^^^^^^^^^^.

Quoted 22 lines
Quoted 21 lines

                                       arch_source, shmem_opts, args->opts_source ? args->opts_source : "", ignore_stderr);
          *from = qtest_init(cmd_source);
      }
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
+    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s "
                                   "-name target,debug-threads=on "
-                                 "-m %s "
                                   "-serial file:%s/dest_serial " "-incoming %s "
                                   "%s %s %s %s", args->use_dirty_ring ? ",dirty-ring-size=4096" : "",
-                                 machine_opts ? " -machine " : "",
-                                 machine_opts ? machine_opts : "",
-                                 memory_size, tmpfs, uri,
+                                 cmd_common->str, tmpfs, uri, arch_target, shmem_opts, args->opts_target ? args->opts_target : "", ignore_stderr);

#22 lore raw

PATCH v2 8/11 tests/qtest/migration-test: Build command line using GString API (2/4)

In reply to Philippe Mathieu-Daudé

Part 2/4: Convert shmem option.

---
 tests/qtest/migration-test.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
tests/qtest/migration-test.c +5 -11
index 7aa323a7a7..8377b3976a 100644
@@ -588,7 +588,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     g_autofree gchar *cmd_target = NULL;
     const gchar *ignore_stderr;
     g_autofree char *bootpath = NULL;
-    g_autofree char *shmem_opts = NULL;
     g_autofree char *shmem_path = NULL;
     const char *arch = qtest_get_arch();
     const char *machine_opts = NULL;
@@ -670,13 +669,10 @@ static int test_migrate_start(QTestState **from, QTestState **to,
 
     if (args->use_shmem) {
         shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid());
-        shmem_opts = g_strdup_printf(
+        g_string_append_printf(cmd_common,
             "-object memory-backend-file,id=mem0,size=%s"
             ",mem-path=%s,share=on -numa node,memdev=mem0",
             memory_size, shmem_path);
-    } else {
-        shmem_path = NULL;
-        shmem_opts = g_strdup("");
     }
 
     if (!args->only_target) {
@@ -685,11 +681,10 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s "
                                      "-name source,debug-threads=on "
                                      "-serial file:%s/src_serial "
-                                     "%s %s %s %s",
+                                     "%s %s %s",
                                      args->use_dirty_ring ?
                                      ",dirty-ring-size=4096" : "",
-                                     cmd_common->str, tmpfs,
-                                     arch_source, shmem_opts,
+                                     cmd_common->str, tmpfs, arch_source,
                                      args->opts_source ? args->opts_source : "",
                                      ignore_stderr);
         *from = qtest_init(cmd_source);
@@ -699,11 +694,10 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  "-name target,debug-threads=on "
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
-                                 "%s %s %s %s",
+                                 "%s %s %s",
                                  args->use_dirty_ring ?
                                  ",dirty-ring-size=4096" : "",
-                                 cmd_common->str, tmpfs, uri,
-                                 arch_target, shmem_opts,
+                                 cmd_common->str, tmpfs, uri, arch_target,
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr);
     *to = qtest_init(cmd_target);
Signature · 1 line
2.38.1
#24 lore raw

PATCH v2 9/11 tests/qtest/migration-test: Build command line using GString API (3/4)

In reply to Philippe Mathieu-Daudé

Part 3/4: Convert accelerator options.

---
 tests/qtest/migration-test.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
tests/qtest/migration-test.c +5 -6
index 8377b3976a..015b774a9e 100644
@@ -603,6 +603,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
+    g_string_append_printf(cmd_common, "-accel kvm%s ",
+                           args->use_dirty_ring ? ",dirty-ring-size=4096" : "");
+    g_string_append(cmd_common, "-accel tcg ");
 
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -678,25 +681,21 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     if (!args->only_target) {
         g_autofree gchar *cmd_source = NULL;
 
-        cmd_source = g_strdup_printf("-accel kvm%s -accel tcg%s "
+        cmd_source = g_strdup_printf("%s "
                                      "-name source,debug-threads=on "
                                      "-serial file:%s/src_serial "
                                      "%s %s %s",
-                                     args->use_dirty_ring ?
-                                     ",dirty-ring-size=4096" : "",
                                      cmd_common->str, tmpfs, arch_source,
                                      args->opts_source ? args->opts_source : "",
                                      ignore_stderr);
         *from = qtest_init(cmd_source);
     }
 
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s "
+    cmd_target = g_strdup_printf("%s "
                                  "-name target,debug-threads=on "
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
                                  "%s %s %s",
-                                 args->use_dirty_ring ?
-                                 ",dirty-ring-size=4096" : "",
                                  cmd_common->str, tmpfs, uri, arch_target,
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr);
Signature · 1 line
2.38.1
Reviewed-by on v2 9/11
#25 lore raw

Re: [PATCH v2 09/11] tests/qtest/migration-test: Build command line using GString API (3/4)

Quoted 12 lines · Philippe Mathieu-Daudé

Part 3/4: Convert accelerator options.

---
  tests/qtest/migration-test.c | 11 +++++------
  1 file changed, 5 insertions(+), 6 deletions(-)
tests/qtest/migration-test.c +0 -0
index 8377b3976a..015b774a9e 100644

tests/qtest/migration-test.c static int test_migrate_start(QTestState **from, QTestState **to, · line 608

Quoted 6 lines
tests/qtest/migration-test.c +3 -0
@@ -603,6 +603,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
      got_stop = false;
 
      cmd_common = g_string_new("");
+    g_string_append_printf(cmd_common, "-accel kvm%s ",
+                           args->use_dirty_ring ? ",dirty-ring-size=4096" : "");
+    g_string_append(cmd_common, "-accel tcg ");

Maybe clearer as

  if (args->use_dirty_ring) {
      g_string_append(s, "-accel kvm,dirty-ring-size=4096 ");
  } else {
      g_string_append(s, "-accel kvm ");
  }

but what you have works, so,

r~

#26 lore raw

Re: [PATCH v2 09/11] tests/qtest/migration-test: Build command line using GString API (3/4)

Quoted 23 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé

Part 3/4: Convert accelerator options.

---
  tests/qtest/migration-test.c | 11 +++++------

  1 file changed, 5 insertions(+), 6 deletions(-)
tests/qtest/migration-test.c +0 -0
index 8377b3976a..015b774a9e 100644

tests/qtest/migration-test.c static int test_migrate_start(QTestState **from, · line 609

Quoted 7 lines
tests/qtest/migration-test.c +3 -0
@@ -603,6 +603,9 @@ static int test_migrate_start(QTestState **from, 
 QTestState **to,
       got_stop = false;
       cmd_common = g_string_new("");
+    g_string_append_printf(cmd_common, "-accel kvm%s ",
+                           args->use_dirty_ring ? 
 ",dirty-ring-size=4096" : "");
+    g_string_append(cmd_common, "-accel tcg ");

Maybe clearer as

Quoted 5 lines

  if (args->use_dirty_ring) {
      g_string_append(s, "-accel kvm,dirty-ring-size=4096 "); } else {
      g_string_append(s, "-accel kvm ");
  }

Agreed, I first did that change, then went back to have simpler "one big patch" in v1. Now since v2 splits the changes I'll do that.

#27 lore raw

PATCH v2 10/11 tests/qtest/migration-test: Build command line using GString API (4/4)

In reply to Philippe Mathieu-Daudé

Part 4/4: Convert rest of options.

---
 tests/qtest/migration-test.c | 50 +++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 24 deletions(-)
tests/qtest/migration-test.c +26 -24
index 015b774a9e..a930964268 100644
@@ -585,8 +585,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     g_autoptr(GString) cmd_common = NULL;
     g_autofree gchar *arch_source = NULL;
     g_autofree gchar *arch_target = NULL;
-    g_autofree gchar *cmd_target = NULL;
-    const gchar *ignore_stderr;
+    g_autoptr(GString) cmd_target = NULL;
+    const gchar *ignore_stderr = NULL;
     g_autofree char *bootpath = NULL;
     g_autofree char *shmem_path = NULL;
     const char *arch = qtest_get_arch();
@@ -662,12 +662,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
          * IO redirection does not work, so don't bother adding IO redirection
          * to the command line.
          */
-        ignore_stderr = "";
 #else
         ignore_stderr = "2>/dev/null";
 #endif
-    } else {
-        ignore_stderr = "";
     }
 
     if (args->use_shmem) {
@@ -679,27 +676,32 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     }
 
     if (!args->only_target) {
-        g_autofree gchar *cmd_source = NULL;
-
-        cmd_source = g_strdup_printf("%s "
-                                     "-name source,debug-threads=on "
-                                     "-serial file:%s/src_serial "
-                                     "%s %s %s",
-                                     cmd_common->str, tmpfs, arch_source,
-                                     args->opts_source ? args->opts_source : "",
-                                     ignore_stderr);
-        *from = qtest_init(cmd_source);
+        g_autoptr(GString) cmd_source = g_string_new(cmd_common->str);
+        g_string_append(cmd_source, "-name source,debug-threads=on ");
+        g_string_append_printf(cmd_source, "-serial file:%s/src_serial ",
+                               tmpfs);
+        g_string_append_printf(cmd_source, "%s ", arch_source);
+        if (args->opts_source) {
+            g_string_append_printf(cmd_source, "%s ", args->opts_source);
+        }
+        if (ignore_stderr) {
+            g_string_append(cmd_source, ignore_stderr); /* last string */
+        }
+        *from = qtest_init(cmd_source->str);
     }
 
-    cmd_target = g_strdup_printf("%s "
-                                 "-name target,debug-threads=on "
-                                 "-serial file:%s/dest_serial "
-                                 "-incoming %s "
-                                 "%s %s %s",
-                                 cmd_common->str, tmpfs, uri, arch_target,
-                                 args->opts_target ? args->opts_target : "",
-                                 ignore_stderr);
-    *to = qtest_init(cmd_target);
+    cmd_target = g_string_new(cmd_common->str);
+    g_string_append(cmd_target, "-name target,debug-threads=on ");
+    g_string_append_printf(cmd_target, "-serial file:%s/dest_serial ", tmpfs);
+    g_string_append_printf(cmd_target, "-incoming %s ", uri);
+    g_string_append_printf(cmd_target, "%s ", arch_target);
+    if (args->opts_target) {
+        g_string_append_printf(cmd_target, "%s ", args->opts_target);
+    }
+    if (ignore_stderr) {
+        g_string_append(cmd_target, ignore_stderr); /* last string */
+    }
+    *to = qtest_init(cmd_target->str);
 
     /*
      * Remove shmem file immediately to avoid memory leak in test failed case.
Signature · 1 line
2.38.1
#29 lore raw

PATCH v2 11/11 tests/qtest/migration-test: Only use available accelerators

In reply to Philippe Mathieu-Daudé

For example, avoid when TCG is disabled:

  $ make check-qtest-aarch64
  ...
  20/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test
  qemu-system-aarch64: -accel tcg: invalid accelerator tcg
---
 tests/qtest/migration-test.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
tests/qtest/migration-test.c +13 -4
index a930964268..17783d7334 100644
@@ -45,6 +45,8 @@
 
 unsigned start_address;
 unsigned end_address;
+static bool has_tcg;
+static bool has_kvm;
 static bool uffd_feature_thread_id;
 
 /*
@@ -603,9 +605,14 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
-    g_string_append_printf(cmd_common, "-accel kvm%s ",
-                           args->use_dirty_ring ? ",dirty-ring-size=4096" : "");
-    g_string_append(cmd_common, "-accel tcg ");
+    if (has_kvm) { /* KVM first */
+        g_string_append_printf(cmd_common, "-accel kvm%s ",
+                               args->use_dirty_ring
+                               ? ",dirty-ring-size=4096" : "");
+    }
+    if (has_tcg) {
+        g_string_append(cmd_common, "-accel tcg ");
+    }
 
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2457,12 +2464,14 @@ static bool kvm_dirty_ring_supported(void)
 
 int main(int argc, char **argv)
 {
-    const bool has_kvm = qtest_has_accel("kvm");
     const bool has_uffd = ufd_version_check();
     const char *arch = qtest_get_arch();
     g_autoptr(GError) err = NULL;
     int ret;
 
+    has_tcg = qtest_has_accel("tcg");
+    has_kvm = qtest_has_accel("kvm");
+
     g_test_init(&argc, &argv, NULL);
 
     /*
Signature · 1 line
2.38.1
Reviewed-by on v2 11/11
#30 lore raw

Re: [PATCH v2 11/11] tests/qtest/migration-test: Only use available accelerators

Quoted 7 lines · Philippe Mathieu-Daudé

For example, avoid when TCG is disabled:

   $ make check-qtest-aarch64
   ...
   20/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test
   qemu-system-aarch64: -accel tcg: invalid accelerator tcg
Quoted 5 lines
---
  tests/qtest/migration-test.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)

r~