Skip to contentSkip to conversation

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

PATCH Superseded Philippe Mathieu-Daudé 3 participants 21 messages Jan 19, 2023 – Jan 20, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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, then HVF.

Pending: How to test for (poisoned) HVF with qtest?

Philippe Mathieu-Daudé (8):
tests/qtest/boot-serial-test: Constify tests[] array tests/qtest/boot-serial-test: Build command line using GString API tests/qtest/boot-serial-test: Only use available accelerators tests/qtest/migration-test: Build command line using GString API tests/qtest/migration-test: Only use available accelerators tests/qtest/libqtest: Allow checking for HVF accelerator tests/qtest/boot-serial-test: Allow running with HVF tests/qtest/migration-test: Allow running with HVF

 tests/qtest/boot-serial-test.c |  42 ++++++++++----
 tests/qtest/libqtest.c         |   2 +
 tests/qtest/migration-test.c   | 101 +++++++++++++++++++--------------
 3 files changed, 91 insertions(+), 54 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/8 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 2/8 tests/qtest/boot-serial-test: Build command line using GString API

In reply to Philippe Mathieu-Daudé
---
 tests/qtest/boot-serial-test.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
tests/qtest/boot-serial-test.c +16 -9
index 3aef3a97a9..fccf706f99 100644
@@ -226,23 +226,25 @@ 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 = "";
     const uint8_t *code = NULL;
     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) {
         code = test->kernel;
-        codeparam = "-kernel";
+        g_string_append(cmd, "-kernel ");
     } else if (test->bios) {
         code = test->bios;
-        codeparam = "-bios";
+        g_string_append(cmd, "-bios ");
     }
-
     if (code) {
         ssize_t wlen;
         int code_fd;
@@ -252,17 +254,22 @@ static void test_machine(const void *data)
         wlen = write(code_fd, code, test->codesize);
         g_assert(wlen == test->codesize);
         close(code_fd);
+        g_string_append_printf(cmd, "%s ", 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 -M %s -no-shutdown "
-                      "-chardev file,id=serial0,path=%s "
-                      "-serial chardev:serial0 -accel tcg -accel kvm %s",
-                      codeparam, code ? 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 (code) {
         unlink(codetmp);
     }
Signature · 1 line
2.38.1
#3 lore raw

PATCH 3/8 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 fccf706f99..f8d0c684c2 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 */
@@ -264,8 +267,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);
@@ -292,6 +299,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
#4 lore raw

PATCH 4/8 tests/qtest/migration-test: Build command line using GString API

In reply to Philippe Mathieu-Daudé
---
 tests/qtest/migration-test.c | 85 ++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 43 deletions(-)
tests/qtest/migration-test.c +42 -43
index dbde726adf..36e6074653 100644
@@ -582,13 +582,13 @@ 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_autoptr(GString) cmd_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_autoptr(GString) cmd_target = NULL;
+    const gchar *ignore_stderr = NULL;
     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;
@@ -602,6 +602,12 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     }
 
     got_stop = false;
+
+    cmd_common = g_string_new("");
+    g_string_append(cmd_common, "-accel tcg ");
+    g_string_append_printf(cmd_common, "-accel kvm%s ",
+                           args->use_dirty_ring ? ",dirty-ring-size=4096" : "");
+
     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 */
@@ -645,65 +651,58 @@ 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) {
-#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 = "";
     }
 
     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("");
     }
 
-    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) {
-        *from = qtest_init(cmd_source);
+        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);
+        }
+        *from = qtest_init(cmd_source->str);
     }
 
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s%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,
-                                 arch_target, shmem_opts,
-                                 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_source, ignore_stderr);
+    }
+    *to = qtest_init(cmd_target->str);
 
     /*
      * Remove shmem file immediately to avoid memory leak in test failed case.
Signature · 1 line
2.38.1
#5 lore raw

Re: [PATCH 4/8] tests/qtest/migration-test: Build command line using GString API

tests/qtest/migration-test.c typedef struct { · line 584

Quoted 13 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
---
 tests/qtest/migration-test.c | 85 ++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 43 deletions(-)
tests/qtest/migration-test.c +0 -0
index dbde726adf..36e6074653 100644
@@ -582,13 +582,13 @@ typedef struct {
 static int test_migrate_start(QTestState **from, QTestState **to,
                               const char *uri, MigrateStart *args)
 {

bit of a big change with lots of things moving around, I think it's mostly OK but...

Quoted 15 lines
tests/qtest/migration-test.c +4 -4
+    g_autoptr(GString) cmd_common = NULL;
     g_autofree gchar *arch_source = NULL;
+    g_autoptr(GString) cmd_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_autoptr(GString) cmd_target = NULL;
+    const gchar *ignore_stderr = NULL;
     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;

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

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

Isn't that swapping the order of -accel tcg and -accel kvm ? In the original it's
g_strdup_printf("-accel kvm%s -accel tcg%s%s "

I think you're ending up with tcg first?

Dave

Quoted 104 lines
tests/qtest/migration-test.c +32 -39
     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 */
@@ -645,65 +651,58 @@ 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) {
-#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 = "";
     }
 
     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("");
     }
 
-    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) {
-        *from = qtest_init(cmd_source);
+        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);
+        }
+        *from = qtest_init(cmd_source->str);
     }
 
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s%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,
-                                 arch_target, shmem_opts,
-                                 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_source, ignore_stderr);
+    }
+    *to = qtest_init(cmd_target->str);
 
     /*
      * Remove shmem file immediately to avoid memory leak in test failed case.
Signature · 1 line
2.38.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#6 lore raw

Re: [PATCH 4/8] tests/qtest/migration-test: Build command line using GString API

Quoted 6 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
---
  tests/qtest/migration-test.c | 85 ++++++++++++++++++------------------
  1 file changed, 42 insertions(+), 43 deletions(-)
Quoted 11 lines

tests/qtest/migration-test.c typedef struct { · line 584

Quoted 8 lines
tests/qtest/migration-test.c +0 -0
index dbde726adf..36e6074653 100644
@@ -582,13 +582,13 @@ typedef struct {
  static int test_migrate_start(QTestState **from, QTestState **to,
                                const char *uri, MigrateStart *args)
  {

bit of a big change with lots of things moving around, I think it's mostly OK but...

I'll see how to split.

Quoted 29 lines
Quoted 15 lines
tests/qtest/migration-test.c +4 -4
+    g_autoptr(GString) cmd_common = NULL;
      g_autofree gchar *arch_source = NULL;
+    g_autoptr(GString) cmd_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_autoptr(GString) cmd_target = NULL;
+    const gchar *ignore_stderr = NULL;
      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;

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

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

Isn't that swapping the order of -accel tcg and -accel kvm ? In the original it's
g_strdup_printf("-accel kvm%s -accel tcg%s%s "

Quoted 1 line

I think you're ending up with tcg first?

Oops good catch, thanks!

#7 lore raw

PATCH 5/8 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 36e6074653..1e7f1ea162 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;
 
 /*
@@ -604,9 +606,14 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
-    g_string_append(cmd_common, "-accel tcg ");
-    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 ");
+    }
+    if (has_kvm) {
+        g_string_append_printf(cmd_common, "-accel kvm%s ",
+                               args->use_dirty_ring
+                               ? ",dirty-ring-size=4096" : "");
+    }
 
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2458,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 v1 5/8
#8 lore raw

Re: [PATCH 5/8] tests/qtest/migration-test: Only use available accelerators

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

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

With the ordering proviso of the previous patch,

Quoted 54 lines
---
 tests/qtest/migration-test.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
tests/qtest/migration-test.c +13 -4
index 36e6074653..1e7f1ea162 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;
 
 /*
@@ -604,9 +606,14 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_stop = false;
 
     cmd_common = g_string_new("");
-    g_string_append(cmd_common, "-accel tcg ");
-    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 ");
+    }
+    if (has_kvm) {
+        g_string_append_printf(cmd_common, "-accel kvm%s ",
+                               args->use_dirty_ring
+                               ? ",dirty-ring-size=4096" : "");
+    }
 
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2458,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
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#9 lore raw

RFC PATCH 6/8 tests/qtest/libqtest: Allow checking for HVF accelerator

In reply to Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

  diff --git a/meson.build b/meson.build
  @@ -2547,6 +2547,7 @@ foreach target : target_dirs

accel_kconfig = []
foreach sym: accelerators
+ config_host_data.set(sym + '_QTEST', '')

       if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, [])
         config_target += { sym: 'y' }
         config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

---
 tests/qtest/libqtest.c | 2 ++
 1 file changed, 2 insertions(+)
tests/qtest/libqtest.c +2 -0
index 6b2216cb20..31650bdc9f 100644
@@ -901,6 +901,8 @@ bool qtest_has_accel(const char *accel_name)
                 }
             }
         }
+    } else if (g_str_equal(accel_name, "hvf")) {
+        return true; /* XXX CONFIG_HVF is poisoned... */
     } else {
         /* not implemented */
         g_assert_not_reached();
Signature · 1 line
2.38.1
#10 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

Quoted 9 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs
Quoted 8 lines

accel_kconfig = []
foreach sym: accelerators
+ config_host_data.set(sym + '_QTEST', '')

        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, [])
          config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

To fix this properly for HVF, I think you'd need a way to query the available accelerators via QMP, too... Hmmm, weren't there some patches for something like that in the past ... can't remember right now ...

Thomas

#11 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

Quoted 19 lines · Thomas Huth
Quoted 9 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs

Quoted 8 lines

      accel_kconfig = []
      foreach sym: accelerators
   +    config_host_data.set(sym + '_QTEST', '')
        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, []) config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

Quoted 7 lines

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

To fix this properly for HVF, I think you'd need a way to query the available accelerators via QMP, too... Hmmm, weren't there some patches for something like that in the past ... can't remember right now ...

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

#12 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 21 lines · Thomas Huth
Quoted 9 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs

Quoted 8 lines

      accel_kconfig = []
      foreach sym: accelerators
   +    config_host_data.set(sym + '_QTEST', '')
        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, []) config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

Quoted 7 lines
Quoted 5 lines

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

To fix this properly for HVF, I think you'd need a way to query the available accelerators via QMP, too... Hmmm, weren't there some patches for something like that in the past ... can't remember right now ...

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

Ah, right, and we ended up with the competing patch from Igor since we could not quite settle on the QAPI extensions?

Hmm, what happens if you execute "query-qmp-schema" on a HVF-enabled host these days? Is there a "hvf"-related entry somewhere in the response?

Thomas

#13 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

Quoted 27 lines · Thomas Huth
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Thomas Huth
Quoted 9 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs

Quoted 8 lines

      accel_kconfig = []
      foreach sym: accelerators
   +    config_host_data.set(sym + '_QTEST', '')
        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, []) config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

To fix this properly for HVF, I think you'd need a way to query the available accelerators via QMP, too... Hmmm, weren't there some patches for something like that in the past ... can't remember right now ...

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

Ah, right, and we ended up with the competing patch from Igor since we could not quite settle on the QAPI extensions?

Hmm, what happens if you execute "query-qmp-schema" on a HVF-enabled host these days? Is there a "hvf"-related entry somewhere in the response?

Alternative idea: execute QEMU once with "-accel help" via g_spawn_command_line_sync() or g_spawn_sync() once and look for the accelerator in the standard output.

Thomas

#14 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

Quoted 30 lines · Thomas Huth
Quoted 29 lines · Thomas Huth
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Thomas Huth
Quoted 9 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs

Quoted 8 lines

      accel_kconfig = []
      foreach sym: accelerators
   +    config_host_data.set(sym + '_QTEST', '')
        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, []) config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

To fix this properly for HVF, I think you'd need a way to query the available accelerators via QMP, too... Hmmm, weren't there some patches for something like that in the past ... can't remember right now ...

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

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

Ah, right, and we ended up with the competing patch from Igor since we could not quite settle on the QAPI extensions?

Hmm, what happens if you execute "query-qmp-schema" on a HVF-enabled host these days? Is there a "hvf"-related entry somewhere in the response?

Alternative idea: execute QEMU once with "-accel help" via g_spawn_command_line_sync() or g_spawn_sync() once and look for the accelerator in the standard output.

There is no stability guaranty with the help output.

QMP is a stable API, we should really rely on it here IMO.

#15 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 32 lines · Thomas Huth
Quoted 31 lines · Thomas Huth
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Thomas Huth
Quoted 9 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs

Quoted 8 lines

      accel_kconfig = []
      foreach sym: accelerators
   +    config_host_data.set(sym + '_QTEST', '')
        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, []) config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Then test for CONFIG_HVF_QTEST ...

Quoted 7 lines

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

To fix this properly for HVF, I think you'd need a way to query the available accelerators via QMP, too... Hmmm, weren't there some patches for something like that in the past ... can't remember right now ...

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

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Ah, right, and we ended up with the competing patch from Igor since we could not quite settle on the QAPI extensions?

Hmm, what happens if you execute "query-qmp-schema" on a HVF-enabled host these days? Is there a "hvf"-related entry somewhere in the response?

Alternative idea: execute QEMU once with "-accel help" via g_spawn_command_line_sync() or g_spawn_sync() once and look for the accelerator in the standard output.

There is no stability guaranty with the help output.

Sure, it's rather meant as a temporary solution until a proper QMP method is in place. We also have the advantage here that it is internal to the QEMU repository only - it's not like libvirt or some other upper layers are trying to parse the output here.

Quoted 1 line

QMP is a stable API, we should really rely on it here IMO.

I agree, QMP should certainly be the final goal.

Thomas

#16 lore raw

Re: [RFC PATCH 6/8] tests/qtest/libqtest: Allow checking for HVF accelerator

In reply to Thomas Huth
Quoted 17 lines · Thomas Huth
Quoted 16 lines · Philippe Mathieu-Daudé

---
RFC: CONFIG_HVF is poisoned.

We could pass host config definitions to qtest using:

   diff --git a/meson.build b/meson.build
   @@ -2547,6 +2547,7 @@ foreach target : target_dirs

      accel_kconfig = []
      foreach sym: accelerators
   +    config_host_data.set(sym + '_QTEST', '')
        if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, []) config_target += { sym: 'y' }
          config_all += { sym: 'y' }

Quoted 7 lines
Quoted 1 line

Then test for CONFIG_HVF_QTEST ...

I don't think that would really work well. The qtests are build once for all targets, and HVF is only available in the target that matches the host architecture. It's poisoned on purpose.

The TCG accelerator is special, since we have it in either none or in all targets, that's why we can use CONFIG_TCG there.

The kvm part is also rather a hack... we should maybe rather additionally use the "query-kvm" QAPI command to check whether it is really available...?

Scratch that ... I forgot that you already have to run with "-accel kvm" to see whether the accelerator is working with "query-kvm" ... so that would not work here for probing whether "-accel kvm" should be used or not ;-)

Thomas

#17 lore raw

PATCH 7/8 tests/qtest/boot-serial-test: Allow running with HVF

In reply to Philippe Mathieu-Daudé
---
 tests/qtest/boot-serial-test.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/qtest/boot-serial-test.c +5 -0
index f8d0c684c2..4a2cbcf8e8 100644
@@ -19,6 +19,7 @@
 
 static bool has_tcg;
 static bool has_kvm;
+static bool has_hvf;
 
 static const uint8_t bios_avr[] = {
     0x88, 0xe0,             /* ldi r24, 0x08   */
@@ -273,6 +274,9 @@ static void test_machine(const void *data)
     if (has_kvm) {
         g_string_append(cmd, "-accel kvm ");
     }
+    if (has_hvf) {
+        g_string_append(cmd, "-accel hvf ");
+    }
     g_string_append(cmd, test->extra);
 
     qts = qtest_init(cmd->str);
@@ -301,6 +305,7 @@ int main(int argc, char *argv[])
 
     has_tcg = qtest_has_accel("tcg");
     has_kvm = qtest_has_accel("kvm");
+    has_hvf = qtest_has_accel("hvf");
 
     g_test_init(&argc, &argv, NULL);
 
Signature · 1 line
2.38.1
#18 lore raw

PATCH 8/8 tests/qtest/migration-test: Allow running with HVF

In reply to Philippe Mathieu-Daudé
---
 tests/qtest/migration-test.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/qtest/migration-test.c +5 -0
index 1e7f1ea162..7a0fcfb81d 100644
@@ -47,6 +47,7 @@ unsigned start_address;
 unsigned end_address;
 static bool has_tcg;
 static bool has_kvm;
+static bool has_hvf;
 static bool uffd_feature_thread_id;
 
 /*
@@ -614,6 +615,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                args->use_dirty_ring
                                ? ",dirty-ring-size=4096" : "");
     }
+    if (has_hvf) {
+        g_string_append(cmd_common, "-accel hvf ");
+    }
 
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2472,6 +2476,7 @@ int main(int argc, char **argv)
 
     has_tcg = qtest_has_accel("tcg");
     has_kvm = qtest_has_accel("kvm");
+    has_hvf = qtest_has_accel("hvf");
 
     g_test_init(&argc, &argv, NULL);
 
Signature · 1 line
2.38.1
#19 lore raw

Re: [PATCH 8/8] tests/qtest/migration-test: Allow running with HVF

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

Does it support migration? I don't remember anyone ever mentioning it.

Dave

Quoted 37 lines
---
 tests/qtest/migration-test.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/qtest/migration-test.c +5 -0
index 1e7f1ea162..7a0fcfb81d 100644
@@ -47,6 +47,7 @@ unsigned start_address;
 unsigned end_address;
 static bool has_tcg;
 static bool has_kvm;
+static bool has_hvf;
 static bool uffd_feature_thread_id;
 
 /*
@@ -614,6 +615,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                args->use_dirty_ring
                                ? ",dirty-ring-size=4096" : "");
     }
+    if (has_hvf) {
+        g_string_append(cmd_common, "-accel hvf ");
+    }
 
     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2472,6 +2476,7 @@ int main(int argc, char **argv)
 
     has_tcg = qtest_has_accel("tcg");
     has_kvm = qtest_has_accel("kvm");
+    has_hvf = qtest_has_accel("hvf");
 
     g_test_init(&argc, &argv, NULL);
 
Signature · 1 line
2.38.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#20 lore raw

Re: [PATCH 8/8] tests/qtest/migration-test: Allow running with HVF

Quoted 4 lines · Dr. David Alan Gilbert
Quoted 1 line · * Philippe Mathieu-Daudé ([email protected]) wrote:

Does it support migration? I don't remember anyone ever mentioning it.

The test doesn't fail, but I have no idea what that means...

Quoted 37 lines
Quoted 37 lines
---
  tests/qtest/migration-test.c | 5 +++++
  1 file changed, 5 insertions(+)
tests/qtest/migration-test.c +5 -0
index 1e7f1ea162..7a0fcfb81d 100644
@@ -47,6 +47,7 @@ unsigned start_address;
  unsigned end_address;
  static bool has_tcg;
  static bool has_kvm;
+static bool has_hvf;
  static bool uffd_feature_thread_id;
 
  /*
@@ -614,6 +615,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                 args->use_dirty_ring
                                 ? ",dirty-ring-size=4096" : "");
      }
+    if (has_hvf) {
+        g_string_append(cmd_common, "-accel hvf ");
+    }
 
      bootpath = g_strdup_printf("%s/bootsect", tmpfs);
      if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2472,6 +2476,7 @@ int main(int argc, char **argv)
 
      has_tcg = qtest_has_accel("tcg");
      has_kvm = qtest_has_accel("kvm");
+    has_hvf = qtest_has_accel("hvf");
 
      g_test_init(&argc, &argv, NULL);
 
Signature · 1 line
2.38.1