Skip to contentSkip to conversation

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

PATCH In review Philippe Mathieu-Daudé 4 participants 25 messages Jan 20, 2023 – Feb 1, 2023

lore
Share & tools
lore
#0 lore raw

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

Missing review: #7

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.

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   | 96 ++++++++++++++++++----------------
 2 files changed, 80 insertions(+), 62 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v3 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
#2 lore raw

PATCH v3 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
#3 lore raw

PATCH v3 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
#4 lore raw

PATCH v3 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
#5 lore raw

PATCH v3 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 1dd32c9506..5271ddb868 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
#7 lore raw

PATCH v3 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 5271ddb868..f96c73f552 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
#9 lore raw

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

Quoted 10 lines · Juan Quintela
Quoted 2 lines · Philippe Mathieu-Daudé

I am assuming that you will pull this patches through tests tree, not migration tree.

Otherwise, let me know.

I had some remarks (in v2 of the series), so I'm not going to pick this up (yet). If you want to take the migration part, feel free to do so.

I still think it's quite a lot of code churn for just supporting multiple "-accel" statements here.

What about introducing a new lib functions like this:

char *qtest_get_accel_params(bool use_tcg_first)

{
    bool tcg = qtest_has_accel("tcg");

    return g_strdup_printf("%s %s %s %s",
	      use_tcg_first && tcg   ? "-accel tcg" : "",
	      qtest_has_accel("kvm") ? "-accel kvm" : "",
	      qtest_has_accel("hvf") ? "-accel hvf" : "",
	      !use_tcg_first && tcg  ? "-accel tcg" : "");
}

... then all tests that want to run real code could simply call this function instead of having to deal with the list of supported accelerators again and again?

Thomas

#10 lore raw

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

Quoted 20 lines · Thomas Huth
Quoted 8 lines · Juan Quintela
Quoted 2 lines · Philippe Mathieu-Daudé

I am assuming that you will pull this patches through tests tree, not
migration tree.
Otherwise, let me know.

I had some remarks (in v2 of the series), so I'm not going to pick this up (yet). If you want to take the migration part, feel free to do so.

I still think it's quite a lot of code churn for just supporting multiple "-accel" statements here.

What about introducing a new lib functions like this:

char *qtest_get_accel_params(bool use_tcg_first)

Quoted 8 lines
{
    bool tcg = qtest_has_accel("tcg");

    return g_strdup_printf("%s %s %s %s",
	      use_tcg_first && tcg   ? "-accel tcg" : "",
	      qtest_has_accel("kvm") ? "-accel kvm" : "",
	      qtest_has_accel("hvf") ? "-accel hvf" : "",
	      !use_tcg_first && tcg  ? "-accel tcg" : "");

I know that it is me, but I don't find the ? operator especially readable.

What about:

GString *s = g_string_new("");
bool tcg = qtest_has_accel("tcg");

if (use_tcg_first && tcg)
g_string_append(s, "-accel tcg ");
if (qtest_has_accel("kvm"))
g_string_append(s, "-accel kvm ");
if (qtest_has_accel("hvf"))
g_string_append(s, "-accel hvf ");
if (!use_tcg_first && tcg)
g_string_append(s, "-accel tcg");

return s;

Yes, in the function that Phillipe is changing now, each time that I have to change it, I have to count to see what and where I need to put the format/change/whatever.

Quoted 5 lines

}

... then all tests that want to run real code could simply call this function instead of having to deal with the list of supported accelerators again and again?

It is ok with me.

Later, Juan.

#11 lore raw

PATCH v3 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 | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
tests/qtest/migration-test.c +14 -10
index f96c73f552..9cdef4fa65 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,29 @@ 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
Reviewed-by on v3 7/11
#12 lore raw

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

Quoted 3 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Part 1/4: Convert memory & machine options.

Quoted 80 lines
---
 tests/qtest/migration-test.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
tests/qtest/migration-test.c +14 -10
index f96c73f552..9cdef4fa65 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,29 @@ 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
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#14 lore raw

PATCH v3 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 | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
tests/qtest/migration-test.c +5 -9
index 9cdef4fa65..670097a956 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,12 +681,12 @@ 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,
+                                     arch_source,
                                      args->opts_source ? args->opts_source : "",
                                      ignore_stderr);
         *from = qtest_init(cmd_source);
@@ -700,12 +696,12 @@ 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,
+                                 arch_target,
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr);
     *to = qtest_init(cmd_target);
Signature · 1 line
2.38.1
#16 lore raw

PATCH v3 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 | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
tests/qtest/migration-test.c +9 -6
index 670097a956..1ed3505c91 100644
@@ -603,6 +603,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
+    /* KVM first */
+    if (args->use_dirty_ring) {
+        g_string_append(cmd_common, "-accel kvm,dirty-ring-size=4096 ");
+    } else {
+        g_string_append(cmd_common, "-accel kvm ");
+    }
+    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,12 +685,10 @@ 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,
@@ -692,13 +697,11 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         *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,
Signature · 1 line
2.38.1
Reviewed-by on v3 9/11
#17 lore raw

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

Quoted 13 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Part 3/4: Convert accelerator options.

---
 tests/qtest/migration-test.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
tests/qtest/migration-test.c +0 -0
index 670097a956..1ed3505c91 100644

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

Quoted 10 lines
tests/qtest/migration-test.c +7 -0
@@ -603,6 +603,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
+    /* KVM first */
+    if (args->use_dirty_ring) {
+        g_string_append(cmd_common, "-accel kvm,dirty-ring-size=4096 ");
+    } else {
+        g_string_append(cmd_common, "-accel kvm ");
+    }
+    g_string_append(cmd_common, "-accel tcg ");

Yep, that's the right way around this time :-)

Quoted 34 lines
tests/qtest/migration-test.c +2 -6
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -678,12 +685,10 @@ 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,
@@ -692,13 +697,11 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         *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,
Signature · 1 line
2.38.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#19 lore raw

PATCH v3 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 | 53 +++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 28 deletions(-)
tests/qtest/migration-test.c +25 -28
index 1ed3505c91..e7786bcbc5 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();
@@ -666,12 +666,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) {
@@ -683,31 +680,31 @@ 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
#21 lore raw

PATCH v3 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 | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
tests/qtest/migration-test.c +14 -7
index e7786bcbc5..b0eaddbf5a 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,13 +605,16 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
-    /* KVM first */
-    if (args->use_dirty_ring) {
-        g_string_append(cmd_common, "-accel kvm,dirty-ring-size=4096 ");
-    } else {
-        g_string_append(cmd_common, "-accel kvm ");
+    if (has_kvm) { /* KVM first */
+        if (args->use_dirty_ring) {
+            g_string_append(cmd_common, "-accel kvm,dirty-ring-size=4096 ");
+        } else {
+            g_string_append(cmd_common, "-accel kvm ");
+        }
+    }
+    if (has_tcg) {
+        g_string_append(cmd_common, "-accel 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) {
@@ -2460,12 +2465,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 v3 11/11
#22 lore raw

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

Quoted 10 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
#23 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Missing review: #7

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.

I just started reviewing while you were sending v3 ... please see my mails in reply to v2 for some comments.

Also, I don't quite understand why this is necessary. If you specify both, "-accel kvm -accel tcg" on the command line, QEMU should simply fall back to the second accelerator if the first one is not available? What's exactly the problem you are trying to solve here?

Thomas

#24 lore raw
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Philippe Mathieu-Daudé

Missing review: #7

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.

I just started reviewing while you were sending v3 ... please see my mails in reply to v2 for some comments.

Sure.

Quoted 1 line

Also, I don't quite understand why this is necessary. If you specify both, "-accel kvm -accel tcg" on the command line, QEMU should simply fall back to the second accelerator if the first one is not available? What's exactly the problem you are trying to solve here?

When testing Fabiano's series two tests hang, i.e. [*]:

18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg

Maybe it is just a matter of adding HVF to the test? I'll see when I switch back to that. Anyhow the "invalid accelerator" warning is annoying noise when looking for real problems in the output.

[*] https://lore.kernel.org/qemu-devel/[email protected]/