qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/42] Migration test refactoring
@ 2023-06-08 22:49 Juan Quintela
  2023-06-08 22:49 ` [PATCH 01/42] migration-test: Be consistent for ppc Juan Quintela
                   ` (41 more replies)
  0 siblings, 42 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Hi

This series do a lot of much neededs cleanups and fixes to migration-test:

- We make source and target machines coherent/constent
- We make all command line options consistent
- We split test_migrate_start() and test_migrate_end() into:

  * guest_start() from from and to.  It is the same function, just
    defines the basic options.  I am open to renaming it to
    guest_define() or anything else that people can came with.

  * guest_destroy(), you have guessed it, right?

  * guest_realize() after guest_start() and adding any options we
    need, we just create the guest.  We use the same function from
    source and target, making inconsistencies disapear.

- uri: right now it is a mess, we can have:
  * uri created with migration_start()
  * or listen_uri
  * or connect_uri
  * or by hand
  now we just setup to->uri, and we get the migrate uri automatically from there.

- we were creating bootfile for each migration test.  Change the code
  so we only create it once for the whole migration test.

- Introduce GuestState.  Using QTestState directly means that we can
  add state by guest, making it abuse local variables.  Now we move
  all guest state into GuestState.

- Apart from test found by Fabiano, we had another problems with
  multifd + cancel:

  * We didn't wait for "to" guest to finish before we launch second
    target guest "to2".  We fixed it by destroying "to" before
    launching "to2".

  * We reused "dest_serial" filename from "to" and "to2", so in a very
    loaded host, it could be that we contact with the wrong vm, and we
    never end.

  * I change the code so the serial filename is dependent on guest
    name, that made changing the interface:
    wait_for_serial("dest_serial") to
    wait_for_relial(to) (or to2 or ...) so we can't fail.

- we move the global event variables to GuestState, so no more
  got_src_stop or got_dst_resume, we just check
    who->got_event

- create a function from migrate-incoming, so now we do:
  migrate_incoming(uri) and it does what we want/expect.

- vcpu_dirty_limit is not related to migration at all, just is easier
  to write with migration infrastructure.  Move all useful functions
  to migration-helpers.[ch] and split the test into
  vcpu-dirty-limit-test.c.  I think that we can declare that test slow.

- Now that guest_create/destry exist, we can "reuse" them in
  vcpu_dirty_limit test.

- The removal of files, like "migsocket" was flaky at least, i.e. not
  always removed.  "migsocket-recover" was not even tried to remove.
  New code just remove them by default.

- MigrationStart is gone, instead of creating that flags, I just call
  functions that do that function.

- if no uri is given for a target guest, it launches with -incoming
  defer, that should be the default.

ToDo:

- Tests shouldn't really use QMP, if we need QMP, we should hide it
  behind a c function.  Almost everything is there now, except things
  like "reuse".

- I think we should split auto-converge test:
  * we are not testing migration there, we are testing vcpu slowdown
  * the test is really slow, see documentation why we can't make it much faster.

- I still need to make test faster with stoping switchover.

Please, review.

Juan Quintela (42):
  migration-test: Be consistent for ppc
  migration-test: Make ignore_stderr regular with other options
  migration-test: simplify shmem_opts handling
  migration-test: Make machine_opts regular with other options
  migration-test: Create arch_opts
  migration-test: machine_opts is really arch specific
  migration-test: Create kvm_opts
  migration-test: bootpath is the same for all tests and for all archs
  migration-test: Add bootfile_create/delete() functions
  migration-test: dirtylimit checks for x86_64 arch before
  migration-test: Update test_ignore_shared to use args
  migration-test: Enable back ignore-shared test
  migration-test: Check for shared memory like for everything else
  migration-test: test_migrate_start() always return 0
  migration-test: migrate_postcopy_prepare() always return 0
  migration-test: Create do_migrate()
  migration-test: Introduce GuestState
  migration-test: Create guest before calling do_test_validate_uuid()
  migration-test: Create guest before calling test_precopy_common()
  migration-test: Create guest before calling test_postcopy_common()
  migration-test: Move common guest code to guest_create()
  migration-test: Create guest_use_dirty_log()
  migration-test: Move serial to GuestState
  migration-test: Re-enable multifd_cancel test
  migration-test: We were not waiting for "target" to finish
  migration-test: create guest_use_shmem()
  migration-test: Create guest_extra_opts()
  migration-test: Create guest_hide_stderr()
  migration-test: Create the migration unix socket by guest
  migration-test: Hooks also need GuestState
  migration-test: Preffer to->uri to uri parameter for migration
  migration-test: Create guest_set_uri()
  migration-test: Remove connect_uri
  migration-test: Use new schema for all tests that use unix sockets
  migration-test: Set uri for tcp tests with guest_set_uri()
  migration-test: Remove unused listen_uri
  migration-test: Create get_event GuestState variable
  migration-test: Create guest_realize()
  migration-test: Unfold test_migrate_end() into three functions
  migration-test: Create migrate_incoming() function
  migration-test: Move functions to migration-helpers.c
  migration-test: Split vcpu-dirty-limit-test

 MAINTAINERS                         |    3 +-
 tests/qtest/migration-helpers.h     |   39 +
 tests/qtest/migration-helpers.c     |  242 +++++
 tests/qtest/migration-test.c        | 1525 +++++++++------------------
 tests/qtest/vcpu-dirty-limit-test.c |  310 ++++++
 tests/qtest/meson.build             |    5 +-
 6 files changed, 1113 insertions(+), 1011 deletions(-)
 create mode 100644 tests/qtest/vcpu-dirty-limit-test.c


base-commit: 45ae97993a75f975f1a01d25564724c7e10a543f
prerequisite-patch-id: f95418b6f47019ec82d47aac8ba5247775f503a3
-- 
2.40.1



^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 01/42] migration-test: Be consistent for ppc
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 14:54   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 02/42] migration-test: Make ignore_stderr regular with other options Juan Quintela
                   ` (40 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

It makes no sense that we don't have the same configuration on both sides.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index b0c355bbd9..c5e0c69c6b 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -646,7 +646,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                       "'nvramrc=hex .\" _\" begin %x %x "
                                       "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
                                       "until'", end_address, start_address);
-        arch_target = g_strdup("");
+        arch_target = g_strdup("-nodefaults");
     } else if (strcmp(arch, "aarch64") == 0) {
         init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
         machine_opts = "virt,gic-version=max";
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 02/42] migration-test: Make ignore_stderr regular with other options
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
  2023-06-08 22:49 ` [PATCH 01/42] migration-test: Be consistent for ppc Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 14:59   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 03/42] migration-test: simplify shmem_opts handling Juan Quintela
                   ` (39 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index c5e0c69c6b..73b2f01427 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -602,7 +602,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     g_autofree gchar *arch_target = NULL;
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
-    const gchar *ignore_stderr;
+    const gchar *ignore_stderr = NULL;
     g_autofree char *bootpath = NULL;
     g_autofree char *shmem_opts = NULL;
     g_autofree char *shmem_path = NULL;
@@ -672,10 +672,7 @@ 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 = "";
 #endif
-    } else {
-        ignore_stderr = "";
     }
 
     if (args->use_shmem) {
@@ -701,7 +698,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  memory_size, tmpfs,
                                  arch_source, shmem_opts,
                                  args->opts_source ? args->opts_source : "",
-                                 ignore_stderr);
+                                 ignore_stderr ? ignore_stderr : "");
+
     if (!args->only_target) {
         *from = qtest_init(cmd_source);
         qtest_qmp_set_event_callback(*from,
@@ -722,7 +720,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  memory_size, tmpfs, uri,
                                  arch_target, shmem_opts,
                                  args->opts_target ? args->opts_target : "",
-                                 ignore_stderr);
+                                 ignore_stderr ? ignore_stderr : "");
     *to = qtest_init(cmd_target);
     qtest_qmp_set_event_callback(*to,
                                  migrate_watch_for_resume,
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 03/42] migration-test: simplify shmem_opts handling
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
  2023-06-08 22:49 ` [PATCH 01/42] migration-test: Be consistent for ppc Juan Quintela
  2023-06-08 22:49 ` [PATCH 02/42] migration-test: Make ignore_stderr regular with other options Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:02   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 04/42] migration-test: Make machine_opts regular with other options Juan Quintela
                   ` (38 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 73b2f01427..95ccc9bce7 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -681,9 +681,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
             "-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 "
@@ -696,7 +693,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  machine_opts ? " -machine " : "",
                                  machine_opts ? machine_opts : "",
                                  memory_size, tmpfs,
-                                 arch_source, shmem_opts,
+                                 arch_source,
+                                 shmem_opts ? shmem_opts : "",
                                  args->opts_source ? args->opts_source : "",
                                  ignore_stderr ? ignore_stderr : "");
 
@@ -718,7 +716,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  machine_opts ? " -machine " : "",
                                  machine_opts ? machine_opts : "",
                                  memory_size, tmpfs, uri,
-                                 arch_target, shmem_opts,
+                                 arch_target,
+                                 shmem_opts ? shmem_opts : "",
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr ? ignore_stderr : "");
     *to = qtest_init(cmd_target);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 04/42] migration-test: Make machine_opts regular with other options
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (2 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 03/42] migration-test: simplify shmem_opts handling Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:03   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 05/42] migration-test: Create arch_opts Juan Quintela
                   ` (37 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 95ccc9bce7..2490035569 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -637,7 +637,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         start_address = S390_TEST_MEM_START;
         end_address = S390_TEST_MEM_END;
     } else if (strcmp(arch, "ppc64") == 0) {
-        machine_opts = "vsmt=8";
+        machine_opts = "-machine vsmt=8";
         memory_size = "256M";
         start_address = PPC_TEST_MEM_START;
         end_address = PPC_TEST_MEM_END;
@@ -649,7 +649,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         arch_target = g_strdup("-nodefaults");
     } else if (strcmp(arch, "aarch64") == 0) {
         init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
-        machine_opts = "virt,gic-version=max";
+        machine_opts = "-machine virt,gic-version=max";
         memory_size = "150M";
         arch_source = g_strdup_printf("-cpu max "
                                       "-kernel %s",
@@ -683,14 +683,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
             memory_size, shmem_path);
     }
 
-    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,
                                  arch_source,
@@ -705,7 +704,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                      &got_src_stop);
     }
 
-    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 "
@@ -713,7 +712,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  "%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,
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 05/42] migration-test: Create arch_opts
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (3 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 04/42] migration-test: Make machine_opts regular with other options Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:06   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 06/42] migration-test: machine_opts is really arch specific Juan Quintela
                   ` (36 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

This will contain the options needed for both source and target.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 2490035569..6b4e3bf827 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -600,6 +600,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
 {
     g_autofree gchar *arch_source = NULL;
     g_autofree gchar *arch_target = NULL;
+    /* options for source and target */
+    g_autofree gchar *arch_opts = NULL;
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
     const gchar *ignore_stderr = NULL;
@@ -625,15 +627,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         assert(sizeof(x86_bootsect) == 512);
         init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect));
         memory_size = "150M";
-        arch_source = g_strdup_printf("-drive file=%s,format=raw", bootpath);
-        arch_target = g_strdup(arch_source);
+        arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
         start_address = X86_TEST_MEM_START;
         end_address = X86_TEST_MEM_END;
     } else if (g_str_equal(arch, "s390x")) {
         init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf));
         memory_size = "128M";
-        arch_source = g_strdup_printf("-bios %s", bootpath);
-        arch_target = g_strdup(arch_source);
+        arch_opts = g_strdup_printf("-bios %s", bootpath);
         start_address = S390_TEST_MEM_START;
         end_address = S390_TEST_MEM_END;
     } else if (strcmp(arch, "ppc64") == 0) {
@@ -641,20 +641,16 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         memory_size = "256M";
         start_address = PPC_TEST_MEM_START;
         end_address = PPC_TEST_MEM_END;
-        arch_source = g_strdup_printf("-nodefaults "
-                                      "-prom-env 'use-nvramrc?=true' -prom-env "
+        arch_source = g_strdup_printf("-prom-env 'use-nvramrc?=true' -prom-env "
                                       "'nvramrc=hex .\" _\" begin %x %x "
                                       "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
                                       "until'", end_address, start_address);
-        arch_target = g_strdup("-nodefaults");
+        arch_opts = g_strdup("-nodefaults");
     } else if (strcmp(arch, "aarch64") == 0) {
         init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
         machine_opts = "-machine virt,gic-version=max";
         memory_size = "150M";
-        arch_source = g_strdup_printf("-cpu max "
-                                      "-kernel %s",
-                                      bootpath);
-        arch_target = g_strdup(arch_source);
+        arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
         start_address = ARM_TEST_MEM_START;
         end_address = ARM_TEST_MEM_END;
 
@@ -687,12 +683,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  "-name source,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/src_serial "
-                                 "%s %s %s %s",
+                                 "%s %s %s %s %s",
                                  args->use_dirty_ring ?
                                  ",dirty-ring-size=4096" : "",
                                  machine_opts ? machine_opts : "",
                                  memory_size, tmpfs,
-                                 arch_source,
+                                 arch_opts ? arch_opts : "",
+                                 arch_source ? arch_source : "",
                                  shmem_opts ? shmem_opts : "",
                                  args->opts_source ? args->opts_source : "",
                                  ignore_stderr ? ignore_stderr : "");
@@ -709,12 +706,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  "-m %s "
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
-                                 "%s %s %s %s",
+                                 "%s %s %s %s %s",
                                  args->use_dirty_ring ?
                                  ",dirty-ring-size=4096" : "",
                                  machine_opts ? machine_opts : "",
                                  memory_size, tmpfs, uri,
-                                 arch_target,
+                                 arch_opts ? arch_opts : "",
+                                 arch_target ? arch_target : "",
                                  shmem_opts ? shmem_opts : "",
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr ? ignore_stderr : "");
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 06/42] migration-test: machine_opts is really arch specific
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (4 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 05/42] migration-test: Create arch_opts Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:07   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 07/42] migration-test: Create kvm_opts Juan Quintela
                   ` (35 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

And it needs to be in both source and target, so put it on arch_opts.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 6b4e3bf827..cd49c249d3 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -609,7 +609,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     g_autofree char *shmem_opts = NULL;
     g_autofree char *shmem_path = NULL;
     const char *arch = qtest_get_arch();
-    const char *machine_opts = NULL;
     const char *memory_size;
 
     if (args->use_shmem) {
@@ -637,7 +636,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         start_address = S390_TEST_MEM_START;
         end_address = S390_TEST_MEM_END;
     } else if (strcmp(arch, "ppc64") == 0) {
-        machine_opts = "-machine vsmt=8";
         memory_size = "256M";
         start_address = PPC_TEST_MEM_START;
         end_address = PPC_TEST_MEM_END;
@@ -645,12 +643,12 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                       "'nvramrc=hex .\" _\" begin %x %x "
                                       "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
                                       "until'", end_address, start_address);
-        arch_opts = g_strdup("-nodefaults");
+        arch_opts = g_strdup("-nodefaults -machine vsmt=8");
     } else if (strcmp(arch, "aarch64") == 0) {
         init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
-        machine_opts = "-machine virt,gic-version=max";
         memory_size = "150M";
-        arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
+        arch_opts = g_strdup_printf("-machine virt,gic-version=max -cpu max "
+                                    "-kernel %s", bootpath);
         start_address = ARM_TEST_MEM_START;
         end_address = ARM_TEST_MEM_END;
 
@@ -679,14 +677,13 @@ static int test_migrate_start(QTestState **from, QTestState **to,
             memory_size, shmem_path);
     }
 
-    cmd_source = g_strdup_printf("-accel kvm%s -accel tcg %s "
+    cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name source,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/src_serial "
                                  "%s %s %s %s %s",
                                  args->use_dirty_ring ?
                                  ",dirty-ring-size=4096" : "",
-                                 machine_opts ? machine_opts : "",
                                  memory_size, tmpfs,
                                  arch_opts ? arch_opts : "",
                                  arch_source ? arch_source : "",
@@ -701,7 +698,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                      &got_src_stop);
     }
 
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg %s "
+    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name target,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/dest_serial "
@@ -709,7 +706,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  "%s %s %s %s %s",
                                  args->use_dirty_ring ?
                                  ",dirty-ring-size=4096" : "",
-                                 machine_opts ? machine_opts : "",
                                  memory_size, tmpfs, uri,
                                  arch_opts ? arch_opts : "",
                                  arch_target ? arch_target : "",
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 07/42] migration-test: Create kvm_opts
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (5 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 06/42] migration-test: machine_opts is really arch specific Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:07   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 08/42] migration-test: bootpath is the same for all tests and for all archs Juan Quintela
                   ` (34 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So arch_dirty_ring option becomes one option like the others.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index cd49c249d3..1fa815fa66 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -608,6 +608,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     g_autofree char *bootpath = NULL;
     g_autofree char *shmem_opts = NULL;
     g_autofree char *shmem_path = NULL;
+    const char *kvm_opts = NULL;
     const char *arch = qtest_get_arch();
     const char *memory_size;
 
@@ -677,13 +678,16 @@ static int test_migrate_start(QTestState **from, QTestState **to,
             memory_size, shmem_path);
     }
 
+    if (args->use_dirty_ring) {
+        kvm_opts = ",dirty-ring-size=4096";
+    }
+
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name source,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/src_serial "
                                  "%s %s %s %s %s",
-                                 args->use_dirty_ring ?
-                                 ",dirty-ring-size=4096" : "",
+                                 kvm_opts ? kvm_opts : "",
                                  memory_size, tmpfs,
                                  arch_opts ? arch_opts : "",
                                  arch_source ? arch_source : "",
@@ -704,8 +708,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
                                  "%s %s %s %s %s",
-                                 args->use_dirty_ring ?
-                                 ",dirty-ring-size=4096" : "",
+                                 kvm_opts ? kvm_opts : "",
                                  memory_size, tmpfs, uri,
                                  arch_opts ? arch_opts : "",
                                  arch_target ? arch_target : "",
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 08/42] migration-test: bootpath is the same for all tests and for all archs
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (6 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 07/42] migration-test: Create kvm_opts Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:11   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 09/42] migration-test: Add bootfile_create/delete() functions Juan Quintela
                   ` (33 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So just make it a global variable.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 1fa815fa66..6453216e4e 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -102,6 +102,7 @@ static bool ufd_version_check(void)
 #endif
 
 static char *tmpfs;
+static char *bootpath;
 
 /* The boot file modifies memory area in [start_address, end_address)
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
@@ -110,7 +111,7 @@ static char *tmpfs;
 #include "tests/migration/aarch64/a-b-kernel.h"
 #include "tests/migration/s390x/a-b-bios.h"
 
-static void init_bootfile(const char *bootpath, void *content, size_t len)
+static void init_bootfile(void *content, size_t len)
 {
     FILE *bootfile = fopen(bootpath, "wb");
 
@@ -605,7 +606,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *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 *kvm_opts = NULL;
@@ -621,17 +621,16 @@ static int test_migrate_start(QTestState **from, QTestState **to,
 
     got_src_stop = false;
     got_dst_resume = false;
-    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 */
         assert(sizeof(x86_bootsect) == 512);
-        init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect));
+        init_bootfile(x86_bootsect, sizeof(x86_bootsect));
         memory_size = "150M";
         arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
         start_address = X86_TEST_MEM_START;
         end_address = X86_TEST_MEM_END;
     } else if (g_str_equal(arch, "s390x")) {
-        init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf));
+        init_bootfile(s390x_elf, sizeof(s390x_elf));
         memory_size = "128M";
         arch_opts = g_strdup_printf("-bios %s", bootpath);
         start_address = S390_TEST_MEM_START;
@@ -646,7 +645,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                       "until'", end_address, start_address);
         arch_opts = g_strdup("-nodefaults -machine vsmt=8");
     } else if (strcmp(arch, "aarch64") == 0) {
-        init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
+        init_bootfile(aarch64_kernel, sizeof(aarch64_kernel));
         memory_size = "150M";
         arch_opts = g_strdup_printf("-machine virt,gic-version=max -cpu max "
                                     "-kernel %s", bootpath);
@@ -759,7 +758,6 @@ static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
 
     qtest_quit(to);
 
-    cleanup("bootsect");
     cleanup("migsocket");
     cleanup("src_serial");
     cleanup("dest_serial");
@@ -2488,12 +2486,10 @@ static QTestState *dirtylimit_start_vm(void)
     QTestState *vm = NULL;
     g_autofree gchar *cmd = NULL;
     const char *arch = qtest_get_arch();
-    g_autofree char *bootpath = NULL;
 
     assert((strcmp(arch, "x86_64") == 0));
-    bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     assert(sizeof(x86_bootsect) == 512);
-    init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect));
+    init_bootfile(x86_bootsect, sizeof(x86_bootsect));
 
     cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
                           "-name dirtylimit-test,debug-threads=on "
@@ -2509,7 +2505,6 @@ static QTestState *dirtylimit_start_vm(void)
 static void dirtylimit_stop_vm(QTestState *vm)
 {
     qtest_quit(vm);
-    cleanup("bootsect");
     cleanup("vm_serial");
 }
 
@@ -2671,6 +2666,7 @@ int main(int argc, char **argv)
                        g_get_tmp_dir(), err->message);
     }
     g_assert(tmpfs);
+    bootpath = g_strdup_printf("%s/bootsect", tmpfs);
 
     module_call_init(MODULE_INIT_QOM);
 
@@ -2814,6 +2810,8 @@ int main(int argc, char **argv)
 
     g_assert_cmpint(ret, ==, 0);
 
+    cleanup("bootsect");
+    g_free(bootpath);
     ret = rmdir(tmpfs);
     if (ret != 0) {
         g_test_message("unable to rmdir: path (%s): %s",
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 09/42] migration-test: Add bootfile_create/delete() functions
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (7 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 08/42] migration-test: bootpath is the same for all tests and for all archs Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:17   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 10/42] migration-test: dirtylimit checks for x86_64 arch before Juan Quintela
                   ` (32 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

The bootsector code is read only from the guest (otherwise we are
going to have problems with it being read from both source and
destination).

Create a single copy for all the tests.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 50 ++++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 6453216e4e..613fda79bb 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -111,14 +111,47 @@ static char *bootpath;
 #include "tests/migration/aarch64/a-b-kernel.h"
 #include "tests/migration/s390x/a-b-bios.h"
 
-static void init_bootfile(void *content, size_t len)
+static void bootfile_create(char *dir)
 {
+    const char *arch = qtest_get_arch();
+    unsigned char *content;
+    size_t len;
+
+    bootpath = g_strdup_printf("%s/bootsect", dir);
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        /* the assembled x86 boot sector should be exactly one sector large */
+        g_assert(sizeof(x86_bootsect) == 512);
+        content = x86_bootsect;
+        len = sizeof(x86_bootsect);
+    } else if (g_str_equal(arch, "s390x")) {
+        content = s390x_elf;
+        len = sizeof(s390x_elf);
+    } else if (strcmp(arch, "ppc64") == 0) {
+        /*
+         * sane architectures can be programmed at the boot prompt
+         */
+        return;
+    } else if (strcmp(arch, "aarch64") == 0) {
+        content = aarch64_kernel;
+        len = sizeof(aarch64_kernel);
+        g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
+    } else {
+        g_assert_not_reached();
+    }
+
     FILE *bootfile = fopen(bootpath, "wb");
 
     g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
     fclose(bootfile);
 }
 
+static void bootfile_delete(void)
+{
+    unlink(bootpath);
+    g_free(bootpath);
+    bootpath = NULL;
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -622,15 +655,11 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     got_src_stop = false;
     got_dst_resume = false;
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        /* the assembled x86 boot sector should be exactly one sector large */
-        assert(sizeof(x86_bootsect) == 512);
-        init_bootfile(x86_bootsect, sizeof(x86_bootsect));
         memory_size = "150M";
         arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
         start_address = X86_TEST_MEM_START;
         end_address = X86_TEST_MEM_END;
     } else if (g_str_equal(arch, "s390x")) {
-        init_bootfile(s390x_elf, sizeof(s390x_elf));
         memory_size = "128M";
         arch_opts = g_strdup_printf("-bios %s", bootpath);
         start_address = S390_TEST_MEM_START;
@@ -645,14 +674,11 @@ static int test_migrate_start(QTestState **from, QTestState **to,
                                       "until'", end_address, start_address);
         arch_opts = g_strdup("-nodefaults -machine vsmt=8");
     } else if (strcmp(arch, "aarch64") == 0) {
-        init_bootfile(aarch64_kernel, sizeof(aarch64_kernel));
         memory_size = "150M";
         arch_opts = g_strdup_printf("-machine virt,gic-version=max -cpu max "
                                     "-kernel %s", bootpath);
         start_address = ARM_TEST_MEM_START;
         end_address = ARM_TEST_MEM_END;
-
-        g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
     } else {
         g_assert_not_reached();
     }
@@ -2488,9 +2514,6 @@ static QTestState *dirtylimit_start_vm(void)
     const char *arch = qtest_get_arch();
 
     assert((strcmp(arch, "x86_64") == 0));
-    assert(sizeof(x86_bootsect) == 512);
-    init_bootfile(x86_bootsect, sizeof(x86_bootsect));
-
     cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
                           "-name dirtylimit-test,debug-threads=on "
                           "-m 150M -smp 1 "
@@ -2666,7 +2689,7 @@ int main(int argc, char **argv)
                        g_get_tmp_dir(), err->message);
     }
     g_assert(tmpfs);
-    bootpath = g_strdup_printf("%s/bootsect", tmpfs);
+    bootfile_create(tmpfs);
 
     module_call_init(MODULE_INIT_QOM);
 
@@ -2810,8 +2833,7 @@ int main(int argc, char **argv)
 
     g_assert_cmpint(ret, ==, 0);
 
-    cleanup("bootsect");
-    g_free(bootpath);
+    bootfile_delete();
     ret = rmdir(tmpfs);
     if (ret != 0) {
         g_test_message("unable to rmdir: path (%s): %s",
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 10/42] migration-test: dirtylimit checks for x86_64 arch before
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (8 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 09/42] migration-test: Add bootfile_create/delete() functions Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:18   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 11/42] migration-test: Update test_ignore_shared to use args Juan Quintela
                   ` (31 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So no need to assert we are in x86_64.
Once there, refactor the function to remove useless variables.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 613fda79bb..743aa873e6 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2510,10 +2510,7 @@ static int64_t get_limit_rate(QTestState *who)
 static QTestState *dirtylimit_start_vm(void)
 {
     QTestState *vm = NULL;
-    g_autofree gchar *cmd = NULL;
-    const char *arch = qtest_get_arch();
-
-    assert((strcmp(arch, "x86_64") == 0));
+    g_autofree gchar *
     cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
                           "-name dirtylimit-test,debug-threads=on "
                           "-m 150M -smp 1 "
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 11/42] migration-test: Update test_ignore_shared to use args
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (9 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 10/42] migration-test: dirtylimit checks for x86_64 arch before Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:21   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 12/42] migration-test: Enable back ignore-shared test Juan Quintela
                   ` (30 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

It missed this treatment:

commit 11f1a4ce14803f15d59cff42a4cfb7ac50d36bd0
Author: Juan Quintela <quintela@redhat.com>
Date:   Mon Nov 29 18:57:51 2021 +0100

    migration-test: Check for shared memory like for everything else

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 743aa873e6..7178c8e679 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1597,8 +1597,11 @@ static void test_ignore_shared(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     QTestState *from, *to;
+    MigrateStart args = {
+        .use_shmem = true
+    };
 
-    if (test_migrate_start(&from, &to, uri, false, true, NULL, NULL)) {
+    if (test_migrate_start(&from, &to, uri, &args)) {
         return;
     }
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 12/42] migration-test: Enable back ignore-shared test
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (10 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 11/42] migration-test: Update test_ignore_shared to use args Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:27   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 13/42] migration-test: Check for shared memory like for everything else Juan Quintela
                   ` (29 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

It failed on aarch64 tcg, lets see if that is still the case.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 7178c8e679..daaf5cd71a 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1591,8 +1591,6 @@ static void test_precopy_unix_tls_x509_override_host(void)
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
 
-#if 0
-/* Currently upset on aarch64 TCG */
 static void test_ignore_shared(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
@@ -1629,7 +1627,6 @@ static void test_ignore_shared(void)
 
     test_migrate_end(from, to, true);
 }
-#endif
 
 static void *
 test_migrate_xbzrle_start(QTestState *from,
@@ -2771,7 +2768,7 @@ int main(int argc, char **argv)
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
 
-    /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
+    qtest_add_func("/migration/ignore_shared", test_ignore_shared);
 #ifndef _WIN32
     qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
 #endif
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 13/42] migration-test: Check for shared memory like for everything else
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (11 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 12/42] migration-test: Enable back ignore-shared test Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:32   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 14/42] migration-test: test_migrate_start() always return 0 Juan Quintela
                   ` (28 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Makes things easier and cleaner.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index daaf5cd71a..5837060138 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -645,13 +645,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     const char *arch = qtest_get_arch();
     const char *memory_size;
 
-    if (args->use_shmem) {
-        if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
-            g_test_skip("/dev/shm is not supported");
-            return -1;
-        }
-    }
-
     got_src_stop = false;
     got_dst_resume = false;
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -2639,6 +2632,15 @@ static bool kvm_dirty_ring_supported(void)
 #endif
 }
 
+static bool shm_supported(void)
+{
+    if (g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
+        return true;
+    }
+    g_test_message("Skipping test: shared memory not available");
+    return false;
+}
+
 int main(int argc, char **argv)
 {
     bool has_kvm, has_tcg;
@@ -2768,7 +2770,9 @@ int main(int argc, char **argv)
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
 
-    qtest_add_func("/migration/ignore_shared", test_ignore_shared);
+    if (shm_supported()) {
+        qtest_add_func("/migration/ignore_shared", test_ignore_shared);
+    }
 #ifndef _WIN32
     qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
 #endif
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 14/42] migration-test: test_migrate_start() always return 0
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (12 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 13/42] migration-test: Check for shared memory like for everything else Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:35   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 15/42] migration-test: migrate_postcopy_prepare() " Juan Quintela
                   ` (27 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So make it return void instead and adjust all callers.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 38 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 5837060138..b57811da75 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -629,8 +629,8 @@ typedef struct {
     bool postcopy_preempt;
 } MigrateCommon;
 
-static int test_migrate_start(QTestState **from, QTestState **to,
-                              const char *uri, MigrateStart *args)
+static void test_migrate_start(QTestState **from, QTestState **to,
+                               const char *uri, MigrateStart *args)
 {
     g_autofree gchar *arch_source = NULL;
     g_autofree gchar *arch_target = NULL;
@@ -745,8 +745,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     if (args->use_shmem) {
         unlink(shmem_path);
     }
-
-    return 0;
 }
 
 static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
@@ -1155,9 +1153,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr,
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     QTestState *from, *to;
 
-    if (test_migrate_start(&from, &to, uri, &args->start)) {
-        return -1;
-    }
+    test_migrate_start(&from, &to, uri, &args->start);
 
     if (args->start_hook) {
         args->postcopy_data = args->start_hook(from, to);
@@ -1387,9 +1383,7 @@ static void test_baddest(void)
     };
     QTestState *from, *to;
 
-    if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", &args)) {
-        return;
-    }
+    test_migrate_start(&from, &to, "tcp:127.0.0.1:0", &args);
     migrate_qmp(from, "tcp:127.0.0.1:0", "{}");
     wait_for_migration_fail(from, false);
     test_migrate_end(from, to, false);
@@ -1400,9 +1394,7 @@ static void test_precopy_common(MigrateCommon *args)
     QTestState *from, *to;
     void *data_hook = NULL;
 
-    if (test_migrate_start(&from, &to, args->listen_uri, &args->start)) {
-        return;
-    }
+    test_migrate_start(&from, &to, args->listen_uri, &args->start);
 
     if (args->start_hook) {
         data_hook = args->start_hook(from, to);
@@ -1592,9 +1584,7 @@ static void test_ignore_shared(void)
         .use_shmem = true
     };
 
-    if (test_migrate_start(&from, &to, uri, &args)) {
-        return;
-    }
+    test_migrate_start(&from, &to, uri, &args);
 
     migrate_set_capability(from, "x-ignore-shared", true);
     migrate_set_capability(to, "x-ignore-shared", true);
@@ -1893,9 +1883,7 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     QTestState *from, *to;
 
-    if (test_migrate_start(&from, &to, uri, args)) {
-        return;
-    }
+    test_migrate_start(&from, &to, uri, args);
 
     /*
      * UUID validation is at the begin of migration. So, the main process of
@@ -1990,9 +1978,7 @@ static void test_migrate_auto_converge(void)
      */
     const int64_t init_pct = 5, inc_pct = 25, max_pct = 95;
 
-    if (test_migrate_start(&from, &to, uri, &args)) {
-        return;
-    }
+    test_migrate_start(&from, &to, uri, &args);
 
     migrate_set_capability(from, "auto-converge", true);
     migrate_set_parameter_int(from, "cpu-throttle-initial", init_pct);
@@ -2302,9 +2288,7 @@ static void test_multifd_tcp_cancel(void)
     QTestState *from, *to, *to2;
     g_autofree char *uri = NULL;
 
-    if (test_migrate_start(&from, &to, "defer", &args)) {
-        return;
-    }
+    test_migrate_start(&from, &to, "defer", &args);
 
     migrate_ensure_non_converge(from);
 
@@ -2337,9 +2321,7 @@ static void test_multifd_tcp_cancel(void)
         .only_target = true,
     };
 
-    if (test_migrate_start(&from, &to2, "defer", &args)) {
-        return;
-    }
+    test_migrate_start(&from, &to2, "defer", &args);
 
     migrate_set_parameter_int(to2, "multifd-channels", 16);
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 15/42] migration-test: migrate_postcopy_prepare() always return 0
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (13 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 14/42] migration-test: test_migrate_start() always return 0 Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:36   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 16/42] migration-test: Create do_migrate() Juan Quintela
                   ` (26 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So make it return void.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index b57811da75..e623c43957 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1146,9 +1146,9 @@ test_migrate_compress_nowait_start(QTestState *from,
     return NULL;
 }
 
-static int migrate_postcopy_prepare(QTestState **from_ptr,
-                                    QTestState **to_ptr,
-                                    MigrateCommon *args)
+static void migrate_postcopy_prepare(QTestState **from_ptr,
+                                     QTestState **to_ptr,
+                                     MigrateCommon *args)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     QTestState *from, *to;
@@ -1179,8 +1179,6 @@ static int migrate_postcopy_prepare(QTestState **from_ptr,
 
     *from_ptr = from;
     *to_ptr = to;
-
-    return 0;
 }
 
 static void migrate_postcopy_complete(QTestState *from, QTestState *to,
@@ -1207,9 +1205,7 @@ static void test_postcopy_common(MigrateCommon *args)
 {
     QTestState *from, *to;
 
-    if (migrate_postcopy_prepare(&from, &to, args)) {
-        return;
-    }
+    migrate_postcopy_prepare(&from, &to, args);
     migrate_postcopy_start(from, to);
     migrate_postcopy_complete(from, to, args);
 }
@@ -1270,9 +1266,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
     /* Always hide errors for postcopy recover tests since they're expected */
     args->start.hide_stderr = true;
 
-    if (migrate_postcopy_prepare(&from, &to, args)) {
-        return;
-    }
+    migrate_postcopy_prepare(&from, &to, args);
 
     /* Turn postcopy speed down, 4K/s is slow enough on any machines */
     migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 16/42] migration-test: Create do_migrate()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (14 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 15/42] migration-test: migrate_postcopy_prepare() " Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-20 15:53   ` Peter Xu
  2023-06-08 22:49 ` [PATCH 17/42] migration-test: Introduce GuestState Juan Quintela
                   ` (25 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

We called migrate_qmp() in lot of places.  And there are tricks like
changing tcp address with the right port.

Only two callers remaining:
- postcopy resume: It needs to play with the qmp.
- baddest: We want to do a unvalid URI. For that we need to do it by
  hand.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 41 ++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index e623c43957..96b495f255 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -528,6 +528,17 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to)
     qtest_qmp_eventwait(to, "RESUME");
 }
 
+static void do_migrate(QTestState *from, QTestState *to, const gchar *uri)
+{
+    if (!uri) {
+        g_autofree char *tcp_uri =
+            migrate_get_socket_address(to, "socket-address");
+        migrate_qmp(from, tcp_uri, "{}");
+    } else {
+        migrate_qmp(from, uri, "{}");
+    }
+}
+
 typedef struct {
     /*
      * QTEST_LOG=1 may override this.  When QTEST_LOG=1, we always dump errors
@@ -1173,7 +1184,7 @@ static void migrate_postcopy_prepare(QTestState **from_ptr,
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
-    migrate_qmp(from, uri, "{}");
+    do_migrate(from, to, uri);
 
     wait_for_migration_pass(from);
 
@@ -1378,6 +1389,9 @@ static void test_baddest(void)
     QTestState *from, *to;
 
     test_migrate_start(&from, &to, "tcp:127.0.0.1:0", &args);
+    /*
+     * Don't change to do_migrate(). We are using a wrong uri on purpose.
+     */
     migrate_qmp(from, "tcp:127.0.0.1:0", "{}");
     wait_for_migration_fail(from, false);
     test_migrate_end(from, to, false);
@@ -1424,14 +1438,7 @@ static void test_precopy_common(MigrateCommon *args)
         }
     }
 
-    if (!args->connect_uri) {
-        g_autofree char *local_connect_uri =
-            migrate_get_socket_address(to, "socket-address");
-        migrate_qmp(from, local_connect_uri, "{}");
-    } else {
-        migrate_qmp(from, args->connect_uri, "{}");
-    }
-
+    do_migrate(from, to, args->connect_uri);
 
     if (args->result != MIG_TEST_SUCCEED) {
         bool allow_active = args->result == MIG_TEST_FAIL;
@@ -1586,7 +1593,7 @@ static void test_ignore_shared(void)
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
-    migrate_qmp(from, uri, "{}");
+    do_migrate(from, to, uri);
 
     wait_for_migration_pass(from);
 
@@ -1890,7 +1897,7 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
-    migrate_qmp(from, uri, "{}");
+    do_migrate(from, to, uri);
 
     if (should_fail) {
         qtest_set_expected_status(to, EXIT_FAILURE);
@@ -1991,7 +1998,7 @@ static void test_migrate_auto_converge(void)
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
-    migrate_qmp(from, uri, "{}");
+    do_migrate(from, to, uri);
 
     /* Wait for throttling begins */
     percentage = 0;
@@ -2280,7 +2287,6 @@ static void test_multifd_tcp_cancel(void)
         .hide_stderr = true,
     };
     QTestState *from, *to, *to2;
-    g_autofree char *uri = NULL;
 
     test_migrate_start(&from, &to, "defer", &args);
 
@@ -2299,9 +2305,7 @@ static void test_multifd_tcp_cancel(void)
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
-    uri = migrate_get_socket_address(to, "socket-address");
-
-    migrate_qmp(from, uri, "{}");
+    do_migrate(from, to, "127.0.0.1:0");
 
     wait_for_migration_pass(from);
 
@@ -2325,14 +2329,11 @@ static void test_multifd_tcp_cancel(void)
     qtest_qmp_assert_success(to2, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
 
-    g_free(uri);
-    uri = migrate_get_socket_address(to2, "socket-address");
-
     wait_for_migration_status(from, "cancelled", NULL);
 
     migrate_ensure_converge(from);
 
-    migrate_qmp(from, uri, "{}");
+    do_migrate(from, to2, "127.0.0.1:0");
 
     wait_for_migration_pass(from);
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 17/42] migration-test: Introduce GuestState
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (15 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 16/42] migration-test: Create do_migrate() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 18/42] migration-test: Create guest before calling do_test_validate_uuid() Juan Quintela
                   ` (24 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

It will contain all the information that we need for a guest.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 330 +++++++++++++++++++----------------
 1 file changed, 180 insertions(+), 150 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 96b495f255..5cfc7a6ebc 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -152,6 +152,26 @@ static void bootfile_delete(void)
     bootpath = NULL;
 }
 
+typedef struct {
+    QTestState *qs;
+    const gchar *name;
+} GuestState;
+
+static GuestState *guest_create(const char *name)
+{
+    GuestState *vm = g_new0(GuestState, 1);
+
+    vm->name = name;
+
+    return vm;
+}
+
+static void guest_destroy(GuestState *vm)
+{
+    qtest_quit(vm->qs);
+    g_free(vm);
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -272,7 +292,7 @@ static void wait_for_migration_pass(QTestState *who)
     } while (pass == initial_pass && !got_src_stop);
 }
 
-static void check_guests_ram(QTestState *who)
+static void check_guests_ram(GuestState *who)
 {
     /* Our ASM test will have been incrementing one byte from each page from
      * start_address to < end_address in order. This gives us a constraint
@@ -287,14 +307,14 @@ static void check_guests_ram(QTestState *who)
     bool hit_edge = false;
     int bad = 0;
 
-    qtest_memread(who, start_address, &first_byte, 1);
+    qtest_memread(who->qs, start_address, &first_byte, 1);
     last_byte = first_byte;
 
     for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
          address += TEST_MEM_PAGE_SIZE)
     {
         uint8_t b;
-        qtest_memread(who, address, &b, 1);
+        qtest_memread(who->qs, address, &b, 1);
         if (b != last_byte) {
             if (((b + 1) % 256) == last_byte && !hit_edge) {
                 /* This is OK, the guest stopped at the point of
@@ -528,14 +548,14 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to)
     qtest_qmp_eventwait(to, "RESUME");
 }
 
-static void do_migrate(QTestState *from, QTestState *to, const gchar *uri)
+static void do_migrate(GuestState *from, GuestState *to, const gchar *uri)
 {
     if (!uri) {
         g_autofree char *tcp_uri =
-            migrate_get_socket_address(to, "socket-address");
-        migrate_qmp(from, tcp_uri, "{}");
+            migrate_get_socket_address(to->qs, "socket-address");
+        migrate_qmp(from->qs, tcp_uri, "{}");
     } else {
-        migrate_qmp(from, uri, "{}");
+        migrate_qmp(from->qs, uri, "{}");
     }
 }
 
@@ -640,7 +660,7 @@ typedef struct {
     bool postcopy_preempt;
 } MigrateCommon;
 
-static void test_migrate_start(QTestState **from, QTestState **to,
+static void test_migrate_start(GuestState *from, GuestState *to,
                                const char *uri, MigrateStart *args)
 {
     g_autofree gchar *arch_source = NULL;
@@ -712,11 +732,12 @@ static void test_migrate_start(QTestState **from, QTestState **to,
     }
 
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
-                                 "-name source,debug-threads=on "
+                                 "-name %s,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/src_serial "
                                  "%s %s %s %s %s",
                                  kvm_opts ? kvm_opts : "",
+                                 from->name,
                                  memory_size, tmpfs,
                                  arch_opts ? arch_opts : "",
                                  arch_source ? arch_source : "",
@@ -725,27 +746,28 @@ static void test_migrate_start(QTestState **from, QTestState **to,
                                  ignore_stderr ? ignore_stderr : "");
 
     if (!args->only_target) {
-        *from = qtest_init(cmd_source);
-        qtest_qmp_set_event_callback(*from,
+        from->qs = qtest_init(cmd_source);
+        qtest_qmp_set_event_callback(from->qs,
                                      migrate_watch_for_stop,
                                      &got_src_stop);
     }
 
     cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
-                                 "-name target,debug-threads=on "
+                                 "-name %s,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
                                  "%s %s %s %s %s",
                                  kvm_opts ? kvm_opts : "",
+                                 to->name,
                                  memory_size, tmpfs, uri,
                                  arch_opts ? arch_opts : "",
                                  arch_target ? arch_target : "",
                                  shmem_opts ? shmem_opts : "",
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr ? ignore_stderr : "");
-    *to = qtest_init(cmd_target);
-    qtest_qmp_set_event_callback(*to,
+    to->qs = qtest_init(cmd_target);
+    qtest_qmp_set_event_callback(to->qs,
                                  migrate_watch_for_resume,
                                  &got_dst_resume);
 
@@ -758,33 +780,33 @@ static void test_migrate_start(QTestState **from, QTestState **to,
     }
 }
 
-static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
+static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
 {
     unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
 
-    qtest_quit(from);
+    guest_destroy(from);
 
     if (test_dest) {
-        qtest_memread(to, start_address, &dest_byte_a, 1);
+        qtest_memread(to->qs, start_address, &dest_byte_a, 1);
 
         /* Destination still running, wait for a byte to change */
         do {
-            qtest_memread(to, start_address, &dest_byte_b, 1);
+            qtest_memread(to->qs, start_address, &dest_byte_b, 1);
             usleep(1000 * 10);
         } while (dest_byte_a == dest_byte_b);
 
-        qtest_qmp_assert_success(to, "{ 'execute' : 'stop'}");
+        qtest_qmp_assert_success(to->qs, "{ 'execute' : 'stop'}");
 
         /* With it stopped, check nothing changes */
-        qtest_memread(to, start_address, &dest_byte_c, 1);
+        qtest_memread(to->qs, start_address, &dest_byte_c, 1);
         usleep(1000 * 200);
-        qtest_memread(to, start_address, &dest_byte_d, 1);
+        qtest_memread(to->qs, start_address, &dest_byte_d, 1);
         g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
 
         check_guests_ram(to);
     }
 
-    qtest_quit(to);
+    guest_destroy(to);
 
     cleanup("migsocket");
     cleanup("src_serial");
@@ -1157,55 +1179,51 @@ test_migrate_compress_nowait_start(QTestState *from,
     return NULL;
 }
 
-static void migrate_postcopy_prepare(QTestState **from_ptr,
-                                     QTestState **to_ptr,
+static void migrate_postcopy_prepare(GuestState *from,
+                                     GuestState *to,
                                      MigrateCommon *args)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-    QTestState *from, *to;
 
-    test_migrate_start(&from, &to, uri, &args->start);
+    test_migrate_start(from, to, uri, &args->start);
 
     if (args->start_hook) {
-        args->postcopy_data = args->start_hook(from, to);
+        args->postcopy_data = args->start_hook(from->qs, to->qs);
     }
 
-    migrate_set_capability(from, "postcopy-ram", true);
-    migrate_set_capability(to, "postcopy-ram", true);
-    migrate_set_capability(to, "postcopy-blocktime", true);
+    migrate_set_capability(from->qs, "postcopy-ram", true);
+    migrate_set_capability(to->qs, "postcopy-ram", true);
+    migrate_set_capability(to->qs, "postcopy-blocktime", true);
 
     if (args->postcopy_preempt) {
-        migrate_set_capability(from, "postcopy-preempt", true);
-        migrate_set_capability(to, "postcopy-preempt", true);
+        migrate_set_capability(from->qs, "postcopy-preempt", true);
+        migrate_set_capability(to->qs, "postcopy-preempt", true);
     }
 
-    migrate_ensure_non_converge(from);
+    migrate_ensure_non_converge(from->qs);
 
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
     do_migrate(from, to, uri);
 
-    wait_for_migration_pass(from);
-
-    *from_ptr = from;
-    *to_ptr = to;
+    wait_for_migration_pass(from->qs);
 }
 
-static void migrate_postcopy_complete(QTestState *from, QTestState *to,
+static void migrate_postcopy_complete(GuestState *from, GuestState *to,
                                       MigrateCommon *args)
 {
-    wait_for_migration_complete(from);
+    wait_for_migration_complete(from->qs);
 
     /* Make sure we get at least one "B" on destination */
     wait_for_serial("dest_serial");
 
     if (uffd_feature_thread_id) {
-        read_blocktime(to);
+        read_blocktime(to->qs);
     }
 
     if (args->finish_hook) {
-        args->finish_hook(from, to, args->postcopy_data);
+        args->finish_hook(from->qs, to->qs, args->postcopy_data);
         args->postcopy_data = NULL;
     }
 
@@ -1214,10 +1232,11 @@ static void migrate_postcopy_complete(QTestState *from, QTestState *to,
 
 static void test_postcopy_common(MigrateCommon *args)
 {
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
 
-    migrate_postcopy_prepare(&from, &to, args);
-    migrate_postcopy_start(from, to);
+    migrate_postcopy_prepare(from, to, args);
+    migrate_postcopy_start(from->qs, to->qs);
     migrate_postcopy_complete(from, to, args);
 }
 
@@ -1271,38 +1290,40 @@ static void test_postcopy_preempt_tls_psk(void)
 
 static void test_postcopy_recovery_common(MigrateCommon *args)
 {
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
+
     g_autofree char *uri = NULL;
 
     /* Always hide errors for postcopy recover tests since they're expected */
     args->start.hide_stderr = true;
 
-    migrate_postcopy_prepare(&from, &to, args);
+    migrate_postcopy_prepare(from, to, args);
 
     /* Turn postcopy speed down, 4K/s is slow enough on any machines */
-    migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096);
+    migrate_set_parameter_int(from->qs, "max-postcopy-bandwidth", 4096);
 
     /* Now we start the postcopy */
-    migrate_postcopy_start(from, to);
+    migrate_postcopy_start(from->qs, to->qs);
 
     /*
      * Wait until postcopy is really started; we can only run the
      * migrate-pause command during a postcopy
      */
-    wait_for_migration_status(from, "postcopy-active", NULL);
+    wait_for_migration_status(from->qs, "postcopy-active", NULL);
 
     /*
      * Manually stop the postcopy migration. This emulates a network
      * failure with the migration socket
      */
-    migrate_pause(from);
+    migrate_pause(from->qs);
 
     /*
      * Wait for destination side to reach postcopy-paused state.  The
      * migrate-recover command can only succeed if destination machine
      * is in the paused state
      */
-    wait_for_migration_status(to, "postcopy-paused",
+    wait_for_migration_status(to->qs, "postcopy-paused",
                               (const char * []) { "failed", "active",
                                                   "completed", NULL });
 
@@ -1312,19 +1333,19 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
      * listen to the new port
      */
     uri = g_strdup_printf("unix:%s/migsocket-recover", tmpfs);
-    migrate_recover(to, uri);
+    migrate_recover(to->qs, uri);
 
     /*
      * Try to rebuild the migration channel using the resume flag and
      * the newly created channel
      */
-    wait_for_migration_status(from, "postcopy-paused",
+    wait_for_migration_status(from->qs, "postcopy-paused",
                               (const char * []) { "failed", "active",
                                                   "completed", NULL });
-    migrate_qmp(from, uri, "{'resume': true}");
+    migrate_qmp(from->qs, uri, "{'resume': true}");
 
     /* Restore the postcopy bandwidth to unlimited */
-    migrate_set_parameter_int(from, "max-postcopy-bandwidth", 0);
+    migrate_set_parameter_int(from->qs, "max-postcopy-bandwidth", 0);
 
     migrate_postcopy_complete(from, to, args);
 }
@@ -1386,26 +1407,29 @@ static void test_baddest(void)
     MigrateStart args = {
         .hide_stderr = true
     };
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
 
-    test_migrate_start(&from, &to, "tcp:127.0.0.1:0", &args);
+    test_migrate_start(from, to, "tcp:127.0.0.1:0", &args);
     /*
      * Don't change to do_migrate(). We are using a wrong uri on purpose.
      */
-    migrate_qmp(from, "tcp:127.0.0.1:0", "{}");
-    wait_for_migration_fail(from, false);
+    migrate_qmp(from->qs, "tcp:127.0.0.1:0", "{}");
+    wait_for_migration_fail(from->qs, false);
     test_migrate_end(from, to, false);
 }
 
 static void test_precopy_common(MigrateCommon *args)
 {
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
+
     void *data_hook = NULL;
 
-    test_migrate_start(&from, &to, args->listen_uri, &args->start);
+    test_migrate_start(from, to, args->listen_uri, &args->start);
 
     if (args->start_hook) {
-        data_hook = args->start_hook(from, to);
+        data_hook = args->start_hook(from->qs, to->qs);
     }
 
     /* Wait for the first serial output from the source */
@@ -1421,7 +1445,7 @@ static void test_precopy_common(MigrateCommon *args)
          * this with a ridiculosly low bandwidth that guarantees
          * non-convergance.
          */
-        migrate_ensure_non_converge(from);
+        migrate_ensure_non_converge(from->qs);
     } else {
         /*
          * Testing non-live migration, we allow it to run at
@@ -1430,11 +1454,11 @@ static void test_precopy_common(MigrateCommon *args)
          * change anything.
          */
         if (args->result == MIG_TEST_SUCCEED) {
-            qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
+            qtest_qmp_assert_success(from->qs, "{ 'execute' : 'stop'}");
             if (!got_src_stop) {
-                qtest_qmp_eventwait(from, "STOP");
+                qtest_qmp_eventwait(from->qs, "STOP");
             }
-            migrate_ensure_converge(from);
+            migrate_ensure_converge(from->qs);
         }
     }
 
@@ -1442,53 +1466,53 @@ static void test_precopy_common(MigrateCommon *args)
 
     if (args->result != MIG_TEST_SUCCEED) {
         bool allow_active = args->result == MIG_TEST_FAIL;
-        wait_for_migration_fail(from, allow_active);
+        wait_for_migration_fail(from->qs, allow_active);
 
         if (args->result == MIG_TEST_FAIL_DEST_QUIT_ERR) {
-            qtest_set_expected_status(to, EXIT_FAILURE);
+            qtest_set_expected_status(to->qs, EXIT_FAILURE);
         }
     } else {
         if (args->live) {
             if (args->iterations) {
                 while (args->iterations--) {
-                    wait_for_migration_pass(from);
+                    wait_for_migration_pass(from->qs);
                 }
             } else {
-                wait_for_migration_pass(from);
+                wait_for_migration_pass(from->qs);
             }
 
-            migrate_ensure_converge(from);
+            migrate_ensure_converge(from->qs);
 
             /*
              * We do this first, as it has a timeout to stop us
              * hanging forever if migration didn't converge
              */
-            wait_for_migration_complete(from);
+            wait_for_migration_complete(from->qs);
 
             if (!got_src_stop) {
-                qtest_qmp_eventwait(from, "STOP");
+                qtest_qmp_eventwait(from->qs, "STOP");
             }
         } else {
-            wait_for_migration_complete(from);
+            wait_for_migration_complete(from->qs);
             /*
              * Must wait for dst to finish reading all incoming
              * data on the socket before issuing 'cont' otherwise
              * it'll be ignored
              */
-            wait_for_migration_complete(to);
+            wait_for_migration_complete(to->qs);
 
-            qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
+            qtest_qmp_assert_success(to->qs, "{ 'execute' : 'cont'}");
         }
 
         if (!got_dst_resume) {
-            qtest_qmp_eventwait(to, "RESUME");
+            qtest_qmp_eventwait(to->qs, "RESUME");
         }
 
         wait_for_serial("dest_serial");
     }
 
     if (args->finish_hook) {
-        args->finish_hook(from, to, data_hook);
+        args->finish_hook(from->qs, to->qs, data_hook);
     }
 
     test_migrate_end(from, to, args->result == MIG_TEST_SUCCEED);
@@ -1580,34 +1604,36 @@ static void test_precopy_unix_tls_x509_override_host(void)
 static void test_ignore_shared(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateStart args = {
         .use_shmem = true
     };
 
-    test_migrate_start(&from, &to, uri, &args);
+    test_migrate_start(from, to, uri, &args);
 
-    migrate_set_capability(from, "x-ignore-shared", true);
-    migrate_set_capability(to, "x-ignore-shared", true);
+    migrate_set_capability(from->qs, "x-ignore-shared", true);
+    migrate_set_capability(to->qs, "x-ignore-shared", true);
 
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
 
     do_migrate(from, to, uri);
 
-    wait_for_migration_pass(from);
+    wait_for_migration_pass(from->qs);
 
     if (!got_src_stop) {
-        qtest_qmp_eventwait(from, "STOP");
+        qtest_qmp_eventwait(from->qs, "STOP");
     }
 
-    qtest_qmp_eventwait(to, "RESUME");
+    qtest_qmp_eventwait(to->qs, "RESUME");
 
     wait_for_serial("dest_serial");
-    wait_for_migration_complete(from);
+    wait_for_migration_complete(from->qs);
 
     /* Check whether shared RAM has been really skipped */
-    g_assert_cmpint(read_ram_property_int(from, "transferred"), <, 1024 * 1024);
+    g_assert_cmpint(
+        read_ram_property_int(from->qs, "transferred"), <, 1024 * 1024);
 
     test_migrate_end(from, to, true);
 }
@@ -1882,17 +1908,18 @@ static void test_migrate_fd_proto(void)
 static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
 
-    test_migrate_start(&from, &to, uri, args);
+    test_migrate_start(from, to, uri, args);
 
     /*
      * UUID validation is at the begin of migration. So, the main process of
      * migration is not interesting for us here. Thus, set huge downtime for
      * very fast migration.
      */
-    migrate_set_parameter_int(from, "downtime-limit", 1000000);
-    migrate_set_capability(from, "validate-uuid", true);
+    migrate_set_parameter_int(from->qs, "downtime-limit", 1000000);
+    migrate_set_capability(from->qs, "validate-uuid", true);
 
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
@@ -1900,10 +1927,10 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
     do_migrate(from, to, uri);
 
     if (should_fail) {
-        qtest_set_expected_status(to, EXIT_FAILURE);
-        wait_for_migration_fail(from, true);
+        qtest_set_expected_status(to->qs, EXIT_FAILURE);
+        wait_for_migration_fail(from->qs, true);
     } else {
-        wait_for_migration_complete(from);
+        wait_for_migration_complete(from->qs);
     }
 
     test_migrate_end(from, to, false);
@@ -1969,7 +1996,8 @@ static void test_migrate_auto_converge(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     MigrateStart args = {};
-    QTestState *from, *to;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     int64_t percentage;
 
     /*
@@ -1979,21 +2007,21 @@ static void test_migrate_auto_converge(void)
      */
     const int64_t init_pct = 5, inc_pct = 25, max_pct = 95;
 
-    test_migrate_start(&from, &to, uri, &args);
+    test_migrate_start(from, to, uri, &args);
 
-    migrate_set_capability(from, "auto-converge", true);
-    migrate_set_parameter_int(from, "cpu-throttle-initial", init_pct);
-    migrate_set_parameter_int(from, "cpu-throttle-increment", inc_pct);
-    migrate_set_parameter_int(from, "max-cpu-throttle", max_pct);
+    migrate_set_capability(from->qs, "auto-converge", true);
+    migrate_set_parameter_int(from->qs, "cpu-throttle-initial", init_pct);
+    migrate_set_parameter_int(from->qs, "cpu-throttle-increment", inc_pct);
+    migrate_set_parameter_int(from->qs, "max-cpu-throttle", max_pct);
 
     /*
      * Set the initial parameters so that the migration could not converge
      * without throttling.
      */
-    migrate_ensure_non_converge(from);
+    migrate_ensure_non_converge(from->qs);
 
     /* To check remaining size after precopy */
-    migrate_set_capability(from, "pause-before-switchover", true);
+    migrate_set_capability(from->qs, "pause-before-switchover", true);
 
     /* Wait for the first serial output from the source */
     wait_for_serial("src_serial");
@@ -2003,7 +2031,8 @@ static void test_migrate_auto_converge(void)
     /* Wait for throttling begins */
     percentage = 0;
     do {
-        percentage = read_migrate_property_int(from, "cpu-throttle-percentage");
+        percentage = read_migrate_property_int(from->qs,
+                                               "cpu-throttle-percentage");
         if (percentage != 0) {
             break;
         }
@@ -2013,23 +2042,23 @@ static void test_migrate_auto_converge(void)
     /* The first percentage of throttling should be at least init_pct */
     g_assert_cmpint(percentage, >=, init_pct);
     /* Now, when we tested that throttling works, let it converge */
-    migrate_ensure_converge(from);
+    migrate_ensure_converge(from->qs);
 
     /*
      * Wait for pre-switchover status to check last throttle percentage
      * and remaining. These values will be zeroed later
      */
-    wait_for_migration_status(from, "pre-switchover", NULL);
+    wait_for_migration_status(from->qs, "pre-switchover", NULL);
 
     /* The final percentage of throttling shouldn't be greater than max_pct */
-    percentage = read_migrate_property_int(from, "cpu-throttle-percentage");
+    percentage = read_migrate_property_int(from->qs, "cpu-throttle-percentage");
     g_assert_cmpint(percentage, <=, max_pct);
-    migrate_continue(from, "pre-switchover");
+    migrate_continue(from->qs, "pre-switchover");
 
-    qtest_qmp_eventwait(to, "RESUME");
+    qtest_qmp_eventwait(to->qs, "RESUME");
 
     wait_for_serial("dest_serial");
-    wait_for_migration_complete(from);
+    wait_for_migration_complete(from->qs);
 
     test_migrate_end(from, to, true);
 }
@@ -2286,20 +2315,22 @@ static void test_multifd_tcp_cancel(void)
     MigrateStart args = {
         .hide_stderr = true,
     };
-    QTestState *from, *to, *to2;
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
+    GuestState *to2 = guest_create("target2");
 
-    test_migrate_start(&from, &to, "defer", &args);
+    test_migrate_start(from, to, "defer", &args);
 
-    migrate_ensure_non_converge(from);
+    migrate_ensure_non_converge(from->qs);
 
-    migrate_set_parameter_int(from, "multifd-channels", 16);
-    migrate_set_parameter_int(to, "multifd-channels", 16);
+    migrate_set_parameter_int(from->qs, "multifd-channels", 16);
+    migrate_set_parameter_int(to->qs, "multifd-channels", 16);
 
-    migrate_set_capability(from, "multifd", true);
-    migrate_set_capability(to, "multifd", true);
+    migrate_set_capability(from->qs, "multifd", true);
+    migrate_set_capability(to->qs, "multifd", true);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
+    qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
 
     /* Wait for the first serial output from the source */
@@ -2307,43 +2338,43 @@ static void test_multifd_tcp_cancel(void)
 
     do_migrate(from, to, "127.0.0.1:0");
 
-    wait_for_migration_pass(from);
+    wait_for_migration_pass(from->qs);
 
-    migrate_cancel(from);
+    migrate_cancel(from->qs);
 
     /* Make sure QEMU process "to" exited */
-    qtest_set_expected_status(to, EXIT_FAILURE);
-    qtest_wait_qemu(to);
+    qtest_set_expected_status(to->qs, EXIT_FAILURE);
+    qtest_wait_qemu(to->qs);
 
     args = (MigrateStart){
         .only_target = true,
     };
 
-    test_migrate_start(&from, &to2, "defer", &args);
+    test_migrate_start(from, to2, "defer", &args);
 
-    migrate_set_parameter_int(to2, "multifd-channels", 16);
+    migrate_set_parameter_int(to2->qs, "multifd-channels", 16);
 
-    migrate_set_capability(to2, "multifd", true);
+    migrate_set_capability(to2->qs, "multifd", true);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to2, "{ 'execute': 'migrate-incoming',"
+    qtest_qmp_assert_success(to2->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
 
-    wait_for_migration_status(from, "cancelled", NULL);
+    wait_for_migration_status(from->qs, "cancelled", NULL);
 
-    migrate_ensure_converge(from);
+    migrate_ensure_converge(from->qs);
 
     do_migrate(from, to2, "127.0.0.1:0");
 
-    wait_for_migration_pass(from);
+    wait_for_migration_pass(from->qs);
 
     if (!got_src_stop) {
-        qtest_qmp_eventwait(from, "STOP");
+        qtest_qmp_eventwait(from->qs, "STOP");
     }
-    qtest_qmp_eventwait(to2, "RESUME");
+    qtest_qmp_eventwait(to2->qs, "RESUME");
 
     wait_for_serial("dest_serial");
-    wait_for_migration_complete(from);
+    wait_for_migration_complete(from->qs);
     test_migrate_end(from, to2, true);
 }
 
@@ -2477,9 +2508,9 @@ static int64_t get_limit_rate(QTestState *who)
     return dirtyrate;
 }
 
-static QTestState *dirtylimit_start_vm(void)
+static GuestState *dirtylimit_start_vm(void)
 {
-    QTestState *vm = NULL;
+    GuestState *vm = guest_create("dirtylimit-test");
     g_autofree gchar *
     cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
                           "-name dirtylimit-test,debug-threads=on "
@@ -2488,19 +2519,18 @@ static QTestState *dirtylimit_start_vm(void)
                           "-drive file=%s,format=raw ",
                           tmpfs, bootpath);
 
-    vm = qtest_init(cmd);
+    vm->qs = qtest_init(cmd);
     return vm;
 }
 
-static void dirtylimit_stop_vm(QTestState *vm)
+static void dirtylimit_stop_vm(GuestState *vm)
 {
-    qtest_quit(vm);
+    guest_destroy(vm);
     cleanup("vm_serial");
 }
 
 static void test_vcpu_dirty_limit(void)
 {
-    QTestState *vm;
     int64_t origin_rate;
     int64_t quota_rate;
     int64_t rate ;
@@ -2508,19 +2538,19 @@ static void test_vcpu_dirty_limit(void)
     int hit = 0;
 
     /* Start vm for vcpu dirtylimit test */
-    vm = dirtylimit_start_vm();
+    GuestState *vm = dirtylimit_start_vm();
 
     /* Wait for the first serial output from the vm*/
     wait_for_serial("vm_serial");
 
     /* Do dirtyrate measurement with calc time equals 1s */
-    calc_dirty_rate(vm, 1);
+    calc_dirty_rate(vm->qs, 1);
 
     /* Sleep calc time and wait for calc dirtyrate complete */
-    wait_for_calc_dirtyrate_complete(vm, 1);
+    wait_for_calc_dirtyrate_complete(vm->qs, 1);
 
     /* Query original dirty page rate */
-    origin_rate = get_dirty_rate(vm);
+    origin_rate = get_dirty_rate(vm->qs);
 
     /* VM booted from bootsect should dirty memory steadily */
     assert(origin_rate != 0);
@@ -2529,13 +2559,13 @@ static void test_vcpu_dirty_limit(void)
     quota_rate = origin_rate / 2;
 
     /* Set dirtylimit */
-    dirtylimit_set_all(vm, quota_rate);
+    dirtylimit_set_all(vm->qs, quota_rate);
 
     /*
      * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
      * works literally
      */
-    g_assert_cmpint(quota_rate, ==, get_limit_rate(vm));
+    g_assert_cmpint(quota_rate, ==, get_limit_rate(vm->qs));
 
     /* Sleep a bit to check if it take effect */
     usleep(2000000);
@@ -2546,9 +2576,9 @@ static void test_vcpu_dirty_limit(void)
      * doesn't take effect, fail test.
      */
     while (--max_try_count) {
-        calc_dirty_rate(vm, 1);
-        wait_for_calc_dirtyrate_complete(vm, 1);
-        rate = get_dirty_rate(vm);
+        calc_dirty_rate(vm->qs, 1);
+        wait_for_calc_dirtyrate_complete(vm->qs, 1);
+        rate = get_dirty_rate(vm->qs);
 
         /*
          * Assume hitting if current rate is less
@@ -2566,11 +2596,11 @@ static void test_vcpu_dirty_limit(void)
     max_try_count = 20;
 
     /* Check if dirtylimit cancellation take effect */
-    cancel_vcpu_dirty_limit(vm);
+    cancel_vcpu_dirty_limit(vm->qs);
     while (--max_try_count) {
-        calc_dirty_rate(vm, 1);
-        wait_for_calc_dirtyrate_complete(vm, 1);
-        rate = get_dirty_rate(vm);
+        calc_dirty_rate(vm->qs, 1);
+        wait_for_calc_dirtyrate_complete(vm->qs, 1);
+        rate = get_dirty_rate(vm->qs);
 
         /*
          * Assume dirtylimit be canceled if current rate is
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 18/42] migration-test: Create guest before calling do_test_validate_uuid()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (16 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 17/42] migration-test: Introduce GuestState Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 19/42] migration-test: Create guest before calling test_precopy_common() Juan Quintela
                   ` (23 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 5cfc7a6ebc..14f4fd579b 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1905,11 +1905,10 @@ static void test_migrate_fd_proto(void)
 }
 #endif /* _WIN32 */
 
-static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
+static void do_test_validate_uuid(GuestState *from, GuestState *to,
+                                  MigrateStart *args, bool should_fail)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-    GuestState *from = guest_create("source");
-    GuestState *to = guest_create("target");
 
     test_migrate_start(from, to, uri, args);
 
@@ -1938,43 +1937,51 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
 
 static void test_validate_uuid(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateStart args = {
         .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
         .opts_target = "-uuid 11111111-1111-1111-1111-111111111111",
     };
 
-    do_test_validate_uuid(&args, false);
+    do_test_validate_uuid(from, to, &args, false);
 }
 
 static void test_validate_uuid_error(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateStart args = {
         .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
         .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
         .hide_stderr = true,
     };
 
-    do_test_validate_uuid(&args, true);
+    do_test_validate_uuid(from, to, &args, true);
 }
 
 static void test_validate_uuid_src_not_set(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateStart args = {
         .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
         .hide_stderr = true,
     };
 
-    do_test_validate_uuid(&args, false);
+    do_test_validate_uuid(from, to, &args, false);
 }
 
 static void test_validate_uuid_dst_not_set(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateStart args = {
         .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
         .hide_stderr = true,
     };
 
-    do_test_validate_uuid(&args, false);
+    do_test_validate_uuid(from, to, &args, false);
 }
 
 /*
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 19/42] migration-test: Create guest before calling test_precopy_common()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (17 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 18/42] migration-test: Create guest before calling do_test_validate_uuid() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 20/42] migration-test: Create guest before calling test_postcopy_common() Juan Quintela
                   ` (22 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 122 +++++++++++++++++++++++++----------
 1 file changed, 89 insertions(+), 33 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 14f4fd579b..528dc571ef 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1419,11 +1419,9 @@ static void test_baddest(void)
     test_migrate_end(from, to, false);
 }
 
-static void test_precopy_common(MigrateCommon *args)
+static void test_precopy_common(GuestState *from, GuestState *to,
+                                MigrateCommon *args)
 {
-    GuestState *from = guest_create("source");
-    GuestState *to = guest_create("target");
-
     void *data_hook = NULL;
 
     test_migrate_start(from, to, args->listen_uri, &args->start);
@@ -1521,6 +1519,8 @@ static void test_precopy_common(MigrateCommon *args)
 static void test_precopy_unix_plain(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = uri,
         .connect_uri = uri,
@@ -1531,13 +1531,15 @@ static void test_precopy_unix_plain(void)
         .live = true,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 
 static void test_precopy_unix_dirty_ring(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .use_dirty_ring = true,
@@ -1551,13 +1553,15 @@ static void test_precopy_unix_dirty_ring(void)
         .live = true,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_GNUTLS
 static void test_precopy_unix_tls_psk(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .connect_uri = uri,
         .listen_uri = uri,
@@ -1565,13 +1569,15 @@ static void test_precopy_unix_tls_psk(void)
         .finish_hook = test_migrate_tls_psk_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_TASN1
 static void test_precopy_unix_tls_x509_default_host(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -1583,12 +1589,14 @@ static void test_precopy_unix_tls_x509_default_host(void)
         .result = MIG_TEST_FAIL_DEST_QUIT_ERR,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_unix_tls_x509_override_host(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .connect_uri = uri,
         .listen_uri = uri,
@@ -1596,7 +1604,7 @@ static void test_precopy_unix_tls_x509_override_host(void)
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
@@ -1653,6 +1661,8 @@ test_migrate_xbzrle_start(QTestState *from,
 static void test_precopy_unix_xbzrle(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .connect_uri = uri,
         .listen_uri = uri,
@@ -1665,12 +1675,14 @@ static void test_precopy_unix_xbzrle(void)
         .live = true,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_unix_compress(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .connect_uri = uri,
         .listen_uri = uri,
@@ -1688,12 +1700,14 @@ static void test_precopy_unix_compress(void)
         .live = true,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_unix_compress_nowait(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .connect_uri = uri,
         .listen_uri = uri,
@@ -1707,32 +1721,38 @@ static void test_precopy_unix_compress_nowait(void)
         .live = true,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_plain(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "tcp:127.0.0.1:0",
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_GNUTLS
 static void test_precopy_tcp_tls_psk_match(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_psk_mismatch(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -1743,34 +1763,40 @@ static void test_precopy_tcp_tls_psk_mismatch(void)
         .result = MIG_TEST_FAIL,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_TASN1
 static void test_precopy_tcp_tls_x509_default_host(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_default_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_x509_override_host(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_override_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_x509_mismatch_host(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -1781,22 +1807,26 @@ static void test_precopy_tcp_tls_x509_mismatch_host(void)
         .result = MIG_TEST_FAIL_DEST_QUIT_ERR,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_x509_friendly_client(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_friendly_client,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_x509_hostile_client(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -1807,22 +1837,26 @@ static void test_precopy_tcp_tls_x509_hostile_client(void)
         .result = MIG_TEST_FAIL,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_x509_allow_anon_client(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_allow_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_tcp_tls_x509_reject_anon_client(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -1833,7 +1867,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
         .result = MIG_TEST_FAIL,
     };
 
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
@@ -1895,13 +1929,15 @@ static void test_migrate_fd_finish_hook(QTestState *from,
 
 static void test_migrate_fd_proto(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .connect_uri = "fd:fd-mig",
         .start_hook = test_migrate_fd_start_hook,
         .finish_hook = test_migrate_fd_finish_hook
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 #endif /* _WIN32 */
 
@@ -2116,6 +2152,8 @@ test_migrate_precopy_tcp_multifd_zstd_start(QTestState *from,
 
 static void test_multifd_tcp_none(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_precopy_tcp_multifd_start,
@@ -2126,26 +2164,30 @@ static void test_multifd_tcp_none(void)
          */
         .live = true,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_multifd_tcp_zlib(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_precopy_tcp_multifd_zlib_start,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_ZSTD
 static void test_multifd_tcp_zstd(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_precopy_tcp_multifd_zstd_start,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 #endif
 
@@ -2210,16 +2252,20 @@ test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState *from,
 
 static void test_multifd_tcp_tls_psk_match(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tcp_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_multifd_tcp_tls_psk_mismatch(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -2229,28 +2275,32 @@ static void test_multifd_tcp_tls_psk_mismatch(void)
         .finish_hook = test_migrate_tls_psk_finish,
         .result = MIG_TEST_FAIL,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_TASN1
 static void test_multifd_tcp_tls_x509_default_host(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_default_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_multifd_tcp_tls_x509_override_host(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_override_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_multifd_tcp_tls_x509_mismatch_host(void)
@@ -2268,6 +2318,8 @@ static void test_multifd_tcp_tls_x509_mismatch_host(void)
      * to load migration state, and thus just aborts the migration
      * without exiting.
      */
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -2277,21 +2329,25 @@ static void test_multifd_tcp_tls_x509_mismatch_host(void)
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_multifd_tcp_tls_x509_allow_anon_client(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_allow_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 
 static void test_multifd_tcp_tls_x509_reject_anon_client(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start = {
             .hide_stderr = true,
@@ -2301,7 +2357,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
     };
-    test_precopy_common(&args);
+    test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 20/42] migration-test: Create guest before calling test_postcopy_common()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (18 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 19/42] migration-test: Create guest before calling test_precopy_common() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 21/42] migration-test: Move common guest code to guest_create() Juan Quintela
                   ` (21 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 528dc571ef..a18b3ce1e2 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1230,11 +1230,9 @@ static void migrate_postcopy_complete(GuestState *from, GuestState *to,
     test_migrate_end(from, to, true);
 }
 
-static void test_postcopy_common(MigrateCommon *args)
+static void test_postcopy_common(GuestState *from, GuestState *to,
+                                 MigrateCommon *args)
 {
-    GuestState *from = guest_create("source");
-    GuestState *to = guest_create("target");
-
     migrate_postcopy_prepare(from, to, args);
     migrate_postcopy_start(from->qs, to->qs);
     migrate_postcopy_complete(from, to, args);
@@ -1242,49 +1240,59 @@ static void test_postcopy_common(MigrateCommon *args)
 
 static void test_postcopy(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = { };
 
-    test_postcopy_common(&args);
+    test_postcopy_common(from, to, &args);
 }
 
 static void test_postcopy_compress(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start_hook = test_migrate_compress_start
     };
 
-    test_postcopy_common(&args);
+    test_postcopy_common(from, to, &args);
 }
 
 static void test_postcopy_preempt(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .postcopy_preempt = true,
     };
 
-    test_postcopy_common(&args);
+    test_postcopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_GNUTLS
 static void test_postcopy_tls_psk(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .start_hook = test_migrate_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
 
-    test_postcopy_common(&args);
+    test_postcopy_common(from, to, &args);
 }
 
 static void test_postcopy_preempt_tls_psk(void)
 {
+    GuestState *from = guest_create("source");
+    GuestState *to = guest_create("target");
     MigrateCommon args = {
         .postcopy_preempt = true,
         .start_hook = test_migrate_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
 
-    test_postcopy_common(&args);
+    test_postcopy_common(from, to, &args);
 }
 #endif
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 21/42] migration-test: Move common guest code to guest_create()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (19 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 20/42] migration-test: Create guest before calling test_postcopy_common() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 22/42] migration-test: Create guest_use_dirty_log() Juan Quintela
                   ` (20 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 104 ++++++++++++++++++-----------------
 1 file changed, 55 insertions(+), 49 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index a18b3ce1e2..9671c4c6e5 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -40,8 +40,6 @@
 #include "linux/kvm.h"
 #endif
 
-unsigned start_address;
-unsigned end_address;
 static bool uffd_feature_thread_id;
 static bool got_src_stop;
 static bool got_dst_resume;
@@ -154,12 +152,50 @@ static void bootfile_delete(void)
 
 typedef struct {
     QTestState *qs;
+    /* options for source and target */
+    gchar *arch_opts;
+    gchar *arch_source;
+    gchar *arch_target;
+    const gchar *memory_size;
     const gchar *name;
+    unsigned start_address;
+    unsigned end_address;
 } GuestState;
 
 static GuestState *guest_create(const char *name)
 {
     GuestState *vm = g_new0(GuestState, 1);
+    const char *arch = qtest_get_arch();
+
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        vm->memory_size = "150M";
+        vm->arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
+        vm->start_address = X86_TEST_MEM_START;
+        vm->end_address = X86_TEST_MEM_END;
+    } else if (g_str_equal(arch, "s390x")) {
+        vm->memory_size = "128M";
+        vm->arch_opts = g_strdup_printf("-bios %s", bootpath);
+        vm->start_address = S390_TEST_MEM_START;
+        vm->end_address = S390_TEST_MEM_END;
+    } else if (strcmp(arch, "ppc64") == 0) {
+        vm->memory_size = "256M";
+        vm->start_address = PPC_TEST_MEM_START;
+        vm->end_address = PPC_TEST_MEM_END;
+        vm->arch_source = g_strdup_printf(
+            "-prom-env 'use-nvramrc?=true' -prom-env "
+            "'nvramrc=hex .\" _\" begin %x %x "
+            "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
+            "until'", vm->end_address, vm->start_address);
+        vm->arch_opts = g_strdup("-nodefaults -machine vsmt=8");
+    } else if (strcmp(arch, "aarch64") == 0) {
+        vm->memory_size = "150M";
+        vm->arch_opts = g_strdup_printf(
+            "-machine virt,gic-version=max -cpu max -kernel %s", bootpath);
+        vm->start_address = ARM_TEST_MEM_START;
+        vm->end_address = ARM_TEST_MEM_END;
+    } else {
+        g_assert_not_reached();
+    }
 
     vm->name = name;
 
@@ -169,6 +205,9 @@ static GuestState *guest_create(const char *name)
 static void guest_destroy(GuestState *vm)
 {
     qtest_quit(vm->qs);
+    g_free(vm->arch_opts);
+    g_free(vm->arch_source);
+    g_free(vm->arch_target);
     g_free(vm);
 }
 
@@ -307,10 +346,11 @@ static void check_guests_ram(GuestState *who)
     bool hit_edge = false;
     int bad = 0;
 
-    qtest_memread(who->qs, start_address, &first_byte, 1);
+    qtest_memread(who->qs, who->start_address, &first_byte, 1);
     last_byte = first_byte;
 
-    for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+    for (address = who->start_address + TEST_MEM_PAGE_SIZE;
+         address < who->end_address;
          address += TEST_MEM_PAGE_SIZE)
     {
         uint8_t b;
@@ -663,49 +703,15 @@ typedef struct {
 static void test_migrate_start(GuestState *from, GuestState *to,
                                const char *uri, MigrateStart *args)
 {
-    g_autofree gchar *arch_source = NULL;
-    g_autofree gchar *arch_target = NULL;
-    /* options for source and target */
-    g_autofree gchar *arch_opts = NULL;
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
     const gchar *ignore_stderr = NULL;
     g_autofree char *shmem_opts = NULL;
     g_autofree char *shmem_path = NULL;
     const char *kvm_opts = NULL;
-    const char *arch = qtest_get_arch();
-    const char *memory_size;
 
     got_src_stop = false;
     got_dst_resume = false;
-    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        memory_size = "150M";
-        arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
-        start_address = X86_TEST_MEM_START;
-        end_address = X86_TEST_MEM_END;
-    } else if (g_str_equal(arch, "s390x")) {
-        memory_size = "128M";
-        arch_opts = g_strdup_printf("-bios %s", bootpath);
-        start_address = S390_TEST_MEM_START;
-        end_address = S390_TEST_MEM_END;
-    } else if (strcmp(arch, "ppc64") == 0) {
-        memory_size = "256M";
-        start_address = PPC_TEST_MEM_START;
-        end_address = PPC_TEST_MEM_END;
-        arch_source = g_strdup_printf("-prom-env 'use-nvramrc?=true' -prom-env "
-                                      "'nvramrc=hex .\" _\" begin %x %x "
-                                      "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
-                                      "until'", end_address, start_address);
-        arch_opts = g_strdup("-nodefaults -machine vsmt=8");
-    } else if (strcmp(arch, "aarch64") == 0) {
-        memory_size = "150M";
-        arch_opts = g_strdup_printf("-machine virt,gic-version=max -cpu max "
-                                    "-kernel %s", bootpath);
-        start_address = ARM_TEST_MEM_START;
-        end_address = ARM_TEST_MEM_END;
-    } else {
-        g_assert_not_reached();
-    }
 
     if (!getenv("QTEST_LOG") && args->hide_stderr) {
 #ifndef _WIN32
@@ -724,7 +730,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
         shmem_opts = g_strdup_printf(
             "-object memory-backend-file,id=mem0,size=%s"
             ",mem-path=%s,share=on -numa node,memdev=mem0",
-            memory_size, shmem_path);
+            from->memory_size, shmem_path);
     }
 
     if (args->use_dirty_ring) {
@@ -738,9 +744,9 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  "%s %s %s %s %s",
                                  kvm_opts ? kvm_opts : "",
                                  from->name,
-                                 memory_size, tmpfs,
-                                 arch_opts ? arch_opts : "",
-                                 arch_source ? arch_source : "",
+                                 from->memory_size, tmpfs,
+                                 from->arch_opts ? from->arch_opts : "",
+                                 from->arch_source ? from->arch_source : "",
                                  shmem_opts ? shmem_opts : "",
                                  args->opts_source ? args->opts_source : "",
                                  ignore_stderr ? ignore_stderr : "");
@@ -760,9 +766,9 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  "%s %s %s %s %s",
                                  kvm_opts ? kvm_opts : "",
                                  to->name,
-                                 memory_size, tmpfs, uri,
-                                 arch_opts ? arch_opts : "",
-                                 arch_target ? arch_target : "",
+                                 to->memory_size, tmpfs, uri,
+                                 to->arch_opts ? to->arch_opts : "",
+                                 to->arch_target ? to->arch_target : "",
                                  shmem_opts ? shmem_opts : "",
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr ? ignore_stderr : "");
@@ -787,20 +793,20 @@ static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
     guest_destroy(from);
 
     if (test_dest) {
-        qtest_memread(to->qs, start_address, &dest_byte_a, 1);
+        qtest_memread(to->qs, to->start_address, &dest_byte_a, 1);
 
         /* Destination still running, wait for a byte to change */
         do {
-            qtest_memread(to->qs, start_address, &dest_byte_b, 1);
+            qtest_memread(to->qs, to->start_address, &dest_byte_b, 1);
             usleep(1000 * 10);
         } while (dest_byte_a == dest_byte_b);
 
         qtest_qmp_assert_success(to->qs, "{ 'execute' : 'stop'}");
 
         /* With it stopped, check nothing changes */
-        qtest_memread(to->qs, start_address, &dest_byte_c, 1);
+        qtest_memread(to->qs, to->start_address, &dest_byte_c, 1);
         usleep(1000 * 200);
-        qtest_memread(to->qs, start_address, &dest_byte_d, 1);
+        qtest_memread(to->qs, to->start_address, &dest_byte_d, 1);
         g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
 
         check_guests_ram(to);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 22/42] migration-test: Create guest_use_dirty_log()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (20 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 21/42] migration-test: Move common guest code to guest_create() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 23/42] migration-test: Move serial to GuestState Juan Quintela
                   ` (19 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 9671c4c6e5..69a3728e4b 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -156,6 +156,7 @@ typedef struct {
     gchar *arch_opts;
     gchar *arch_source;
     gchar *arch_target;
+    gchar *kvm_opts;
     const gchar *memory_size;
     const gchar *name;
     unsigned start_address;
@@ -208,9 +209,16 @@ static void guest_destroy(GuestState *vm)
     g_free(vm->arch_opts);
     g_free(vm->arch_source);
     g_free(vm->arch_target);
+    g_free(vm->kvm_opts);
     g_free(vm);
 }
 
+static void guest_use_dirty_ring(GuestState *vm)
+{
+    g_assert(vm->kvm_opts == NULL);
+    vm->kvm_opts = g_strdup(",dirty-ring-size=4096");
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -608,8 +616,6 @@ typedef struct {
     bool use_shmem;
     /* only launch the target process */
     bool only_target;
-    /* Use dirty ring if true; dirty logging otherwise */
-    bool use_dirty_ring;
     const char *opts_source;
     const char *opts_target;
 } MigrateStart;
@@ -708,7 +714,6 @@ static void test_migrate_start(GuestState *from, GuestState *to,
     const gchar *ignore_stderr = NULL;
     g_autofree char *shmem_opts = NULL;
     g_autofree char *shmem_path = NULL;
-    const char *kvm_opts = NULL;
 
     got_src_stop = false;
     got_dst_resume = false;
@@ -733,16 +738,12 @@ static void test_migrate_start(GuestState *from, GuestState *to,
             from->memory_size, shmem_path);
     }
 
-    if (args->use_dirty_ring) {
-        kvm_opts = ",dirty-ring-size=4096";
-    }
-
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name %s,debug-threads=on "
                                  "-m %s "
                                  "-serial file:%s/src_serial "
                                  "%s %s %s %s %s",
-                                 kvm_opts ? kvm_opts : "",
+                                 from->kvm_opts ? from->kvm_opts : "",
                                  from->name,
                                  from->memory_size, tmpfs,
                                  from->arch_opts ? from->arch_opts : "",
@@ -764,7 +765,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  "-serial file:%s/dest_serial "
                                  "-incoming %s "
                                  "%s %s %s %s %s",
-                                 kvm_opts ? kvm_opts : "",
+                                 to->kvm_opts ? to->kvm_opts : "",
                                  to->name,
                                  to->memory_size, tmpfs, uri,
                                  to->arch_opts ? to->arch_opts : "",
@@ -1555,9 +1556,6 @@ static void test_precopy_unix_dirty_ring(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .use_dirty_ring = true,
-        },
         .listen_uri = uri,
         .connect_uri = uri,
         /*
@@ -1567,6 +1565,8 @@ static void test_precopy_unix_dirty_ring(void)
         .live = true,
     };
 
+    guest_use_dirty_ring(from);
+    guest_use_dirty_ring(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -2588,6 +2588,9 @@ static int64_t get_limit_rate(QTestState *who)
 static GuestState *dirtylimit_start_vm(void)
 {
     GuestState *vm = guest_create("dirtylimit-test");
+
+    guest_use_dirty_ring(vm);
+
     g_autofree gchar *
     cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
                           "-name dirtylimit-test,debug-threads=on "
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 23/42] migration-test: Move serial to GuestState
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (21 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 22/42] migration-test: Create guest_use_dirty_log() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 24/42] migration-test: Re-enable multifd_cancel test Juan Quintela
                   ` (18 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 65 ++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 28 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 69a3728e4b..01ab51a391 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -158,7 +158,12 @@ typedef struct {
     gchar *arch_target;
     gchar *kvm_opts;
     const gchar *memory_size;
+    /*
+     * name must *not* contain "target" if it is the target of a
+     * migration.
+     */
     const gchar *name;
+    gchar *serial_path;
     unsigned start_address;
     unsigned end_address;
 } GuestState;
@@ -199,7 +204,7 @@ static GuestState *guest_create(const char *name)
     }
 
     vm->name = name;
-
+    vm->serial_path = g_strdup_printf("%s/%s", tmpfs, vm->name);
     return vm;
 }
 
@@ -210,6 +215,8 @@ static void guest_destroy(GuestState *vm)
     g_free(vm->arch_source);
     g_free(vm->arch_target);
     g_free(vm->kvm_opts);
+    unlink(vm->serial_path);
+    g_free(vm->serial_path);
     g_free(vm);
 }
 
@@ -224,12 +231,12 @@ static void guest_use_dirty_ring(GuestState *vm)
  * we get an 'A' followed by an endless string of 'B's
  * but on the destination we won't have the A.
  */
-static void wait_for_serial(const char *side)
+static void wait_for_serial(GuestState *vm)
 {
-    g_autofree char *serialpath = g_strdup_printf("%s/%s", tmpfs, side);
-    FILE *serialfile = fopen(serialpath, "r");
+    FILE *serialfile = fopen(vm->serial_path, "r");
     const char *arch = qtest_get_arch();
-    int started = (strcmp(side, "src_serial") == 0 &&
+    /* see serial_path comment on GuestState definition */
+    int started = (strstr(vm->serial_path, "target") == NULL &&
                    strcmp(arch, "ppc64") == 0) ? 0 : 1;
 
     do {
@@ -262,14 +269,15 @@ static void wait_for_serial(const char *side)
             return;
 
         case EOF:
-            started = (strcmp(side, "src_serial") == 0 &&
+            started = (strstr(vm->serial_path, "target") == NULL &&
                        strcmp(arch, "ppc64") == 0) ? 0 : 1;
             fseek(serialfile, 0, SEEK_SET);
             usleep(1000);
             break;
 
         default:
-            fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, side);
+            fprintf(stderr, "Unexpected %d on %s serial\n", readvalue,
+                    vm->serial_path);
             g_assert_not_reached();
         }
     } while (true);
@@ -741,11 +749,12 @@ static void test_migrate_start(GuestState *from, GuestState *to,
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name %s,debug-threads=on "
                                  "-m %s "
-                                 "-serial file:%s/src_serial "
+                                 "-serial file:%s "
                                  "%s %s %s %s %s",
                                  from->kvm_opts ? from->kvm_opts : "",
                                  from->name,
-                                 from->memory_size, tmpfs,
+                                 from->memory_size,
+                                 from->serial_path,
                                  from->arch_opts ? from->arch_opts : "",
                                  from->arch_source ? from->arch_source : "",
                                  shmem_opts ? shmem_opts : "",
@@ -762,12 +771,14 @@ static void test_migrate_start(GuestState *from, GuestState *to,
     cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name %s,debug-threads=on "
                                  "-m %s "
-                                 "-serial file:%s/dest_serial "
+                                 "-serial file:%s "
                                  "-incoming %s "
                                  "%s %s %s %s %s",
                                  to->kvm_opts ? to->kvm_opts : "",
                                  to->name,
-                                 to->memory_size, tmpfs, uri,
+                                 to->memory_size,
+                                 to->serial_path,
+                                 uri,
                                  to->arch_opts ? to->arch_opts : "",
                                  to->arch_target ? to->arch_target : "",
                                  shmem_opts ? shmem_opts : "",
@@ -816,8 +827,6 @@ static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
     guest_destroy(to);
 
     cleanup("migsocket");
-    cleanup("src_serial");
-    cleanup("dest_serial");
 }
 
 #ifdef CONFIG_GNUTLS
@@ -1210,7 +1219,7 @@ static void migrate_postcopy_prepare(GuestState *from,
     migrate_ensure_non_converge(from->qs);
 
     /* Wait for the first serial output from the source */
-    wait_for_serial("src_serial");
+    wait_for_serial(from);
 
     do_migrate(from, to, uri);
 
@@ -1223,7 +1232,7 @@ static void migrate_postcopy_complete(GuestState *from, GuestState *to,
     wait_for_migration_complete(from->qs);
 
     /* Make sure we get at least one "B" on destination */
-    wait_for_serial("dest_serial");
+    wait_for_serial(to);
 
     if (uffd_feature_thread_id) {
         read_blocktime(to->qs);
@@ -1447,7 +1456,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
 
     /* Wait for the first serial output from the source */
     if (args->result == MIG_TEST_SUCCEED) {
-        wait_for_serial("src_serial");
+        wait_for_serial(from);
     }
 
     if (args->live) {
@@ -1521,7 +1530,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
             qtest_qmp_eventwait(to->qs, "RESUME");
         }
 
-        wait_for_serial("dest_serial");
+        wait_for_serial(to);
     }
 
     if (args->finish_hook) {
@@ -1638,7 +1647,7 @@ static void test_ignore_shared(void)
     migrate_set_capability(to->qs, "x-ignore-shared", true);
 
     /* Wait for the first serial output from the source */
-    wait_for_serial("src_serial");
+    wait_for_serial(from);
 
     do_migrate(from, to, uri);
 
@@ -1650,7 +1659,7 @@ static void test_ignore_shared(void)
 
     qtest_qmp_eventwait(to->qs, "RESUME");
 
-    wait_for_serial("dest_serial");
+    wait_for_serial(to);
     wait_for_migration_complete(from->qs);
 
     /* Check whether shared RAM has been really skipped */
@@ -1971,7 +1980,7 @@ static void do_test_validate_uuid(GuestState *from, GuestState *to,
     migrate_set_capability(from->qs, "validate-uuid", true);
 
     /* Wait for the first serial output from the source */
-    wait_for_serial("src_serial");
+    wait_for_serial(from);
 
     do_migrate(from, to, uri);
 
@@ -2081,7 +2090,7 @@ static void test_migrate_auto_converge(void)
     migrate_set_capability(from->qs, "pause-before-switchover", true);
 
     /* Wait for the first serial output from the source */
-    wait_for_serial("src_serial");
+    wait_for_serial(from);
 
     do_migrate(from, to, uri);
 
@@ -2114,7 +2123,7 @@ static void test_migrate_auto_converge(void)
 
     qtest_qmp_eventwait(to->qs, "RESUME");
 
-    wait_for_serial("dest_serial");
+    wait_for_serial(to);
     wait_for_migration_complete(from->qs);
 
     test_migrate_end(from, to, true);
@@ -2411,7 +2420,7 @@ static void test_multifd_tcp_cancel(void)
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
 
     /* Wait for the first serial output from the source */
-    wait_for_serial("src_serial");
+    wait_for_serial(from);
 
     do_migrate(from, to, "127.0.0.1:0");
 
@@ -2450,7 +2459,7 @@ static void test_multifd_tcp_cancel(void)
     }
     qtest_qmp_eventwait(to2->qs, "RESUME");
 
-    wait_for_serial("dest_serial");
+    wait_for_serial(to2);
     wait_for_migration_complete(from->qs);
     test_migrate_end(from, to2, true);
 }
@@ -2595,9 +2604,10 @@ static GuestState *dirtylimit_start_vm(void)
     cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
                           "-name dirtylimit-test,debug-threads=on "
                           "-m 150M -smp 1 "
-                          "-serial file:%s/vm_serial "
+                          "-serial file:%s "
                           "-drive file=%s,format=raw ",
-                          tmpfs, bootpath);
+                          vm->serial_path,
+                          bootpath);
 
     vm->qs = qtest_init(cmd);
     return vm;
@@ -2606,7 +2616,6 @@ static GuestState *dirtylimit_start_vm(void)
 static void dirtylimit_stop_vm(GuestState *vm)
 {
     guest_destroy(vm);
-    cleanup("vm_serial");
 }
 
 static void test_vcpu_dirty_limit(void)
@@ -2621,7 +2630,7 @@ static void test_vcpu_dirty_limit(void)
     GuestState *vm = dirtylimit_start_vm();
 
     /* Wait for the first serial output from the vm*/
-    wait_for_serial("vm_serial");
+    wait_for_serial(vm);
 
     /* Do dirtyrate measurement with calc time equals 1s */
     calc_dirty_rate(vm->qs, 1);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 24/42] migration-test: Re-enable multifd_cancel test
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (22 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 23/42] migration-test: Move serial to GuestState Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-09  7:53   ` Daniel P. Berrangé
  2023-06-08 22:49 ` [PATCH 25/42] migration-test: We were not waiting for "target" to finish Juan Quintela
                   ` (17 subsequent siblings)
  41 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 01ab51a391..9f86d9bc80 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2886,14 +2886,8 @@ int main(int argc, char **argv)
     }
     qtest_add_func("/migration/multifd/tcp/plain/none",
                    test_multifd_tcp_none);
-    /*
-     * This test is flaky and sometimes fails in CI and otherwise:
-     * don't run unless user opts in via environment variable.
-     */
-    if (getenv("QEMU_TEST_FLAKY_TESTS")) {
-        qtest_add_func("/migration/multifd/tcp/plain/cancel",
-                       test_multifd_tcp_cancel);
-    }
+    qtest_add_func("/migration/multifd/tcp/plain/cancel",
+                   test_multifd_tcp_cancel);
     qtest_add_func("/migration/multifd/tcp/plain/zlib",
                    test_multifd_tcp_zlib);
 #ifdef CONFIG_ZSTD
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 25/42] migration-test: We were not waiting for "target" to finish
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (23 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 24/42] migration-test: Re-enable multifd_cancel test Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 26/42] migration-test: create guest_use_shmem() Juan Quintela
                   ` (16 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

This could create the problem that we start the "second" target before
the first one has removed the serial socket.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 9f86d9bc80..933000ad81 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2432,6 +2432,8 @@ static void test_multifd_tcp_cancel(void)
     qtest_set_expected_status(to->qs, EXIT_FAILURE);
     qtest_wait_qemu(to->qs);
 
+    guest_destroy(to);
+
     args = (MigrateStart){
         .only_target = true,
     };
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 26/42] migration-test: create guest_use_shmem()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (24 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 25/42] migration-test: We were not waiting for "target" to finish Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 27/42] migration-test: Create guest_extra_opts() Juan Quintela
                   ` (15 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So now this is the same that everything else.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 46 +++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 933000ad81..0130a00707 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -164,6 +164,8 @@ typedef struct {
      */
     const gchar *name;
     gchar *serial_path;
+    gchar *shmem_opts;
+    gchar *shmem_path;
     unsigned start_address;
     unsigned end_address;
 } GuestState;
@@ -217,6 +219,9 @@ static void guest_destroy(GuestState *vm)
     g_free(vm->kvm_opts);
     unlink(vm->serial_path);
     g_free(vm->serial_path);
+    g_free(vm->shmem_opts);
+    unlink(vm->shmem_path);
+    g_free(vm->shmem_path);
     g_free(vm);
 }
 
@@ -226,6 +231,18 @@ static void guest_use_dirty_ring(GuestState *vm)
     vm->kvm_opts = g_strdup(",dirty-ring-size=4096");
 }
 
+static void guest_use_shmem(GuestState *vm)
+{
+    g_assert(vm->shmem_opts == NULL);
+    g_assert(vm->shmem_path == NULL);
+
+    vm->shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid());
+    vm->shmem_opts = g_strdup_printf(
+        "-object memory-backend-file,id=mem0,size=%s"
+        ",mem-path=%s,share=on -numa node,memdev=mem0",
+        vm->memory_size, vm->shmem_path);
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -621,7 +638,6 @@ typedef struct {
      * unconditionally, because it means the user would like to be verbose.
      */
     bool hide_stderr;
-    bool use_shmem;
     /* only launch the target process */
     bool only_target;
     const char *opts_source;
@@ -720,8 +736,6 @@ static void test_migrate_start(GuestState *from, GuestState *to,
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
     const gchar *ignore_stderr = NULL;
-    g_autofree char *shmem_opts = NULL;
-    g_autofree char *shmem_path = NULL;
 
     got_src_stop = false;
     got_dst_resume = false;
@@ -738,14 +752,6 @@ static void test_migrate_start(GuestState *from, GuestState *to,
 #endif
     }
 
-    if (args->use_shmem) {
-        shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid());
-        shmem_opts = g_strdup_printf(
-            "-object memory-backend-file,id=mem0,size=%s"
-            ",mem-path=%s,share=on -numa node,memdev=mem0",
-            from->memory_size, shmem_path);
-    }
-
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name %s,debug-threads=on "
                                  "-m %s "
@@ -757,7 +763,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  from->serial_path,
                                  from->arch_opts ? from->arch_opts : "",
                                  from->arch_source ? from->arch_source : "",
-                                 shmem_opts ? shmem_opts : "",
+                                 from->shmem_opts ? from->shmem_opts : "",
                                  args->opts_source ? args->opts_source : "",
                                  ignore_stderr ? ignore_stderr : "");
 
@@ -781,21 +787,13 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  uri,
                                  to->arch_opts ? to->arch_opts : "",
                                  to->arch_target ? to->arch_target : "",
-                                 shmem_opts ? shmem_opts : "",
+                                 to->shmem_opts ? to->shmem_opts : "",
                                  args->opts_target ? args->opts_target : "",
                                  ignore_stderr ? ignore_stderr : "");
     to->qs = qtest_init(cmd_target);
     qtest_qmp_set_event_callback(to->qs,
                                  migrate_watch_for_resume,
                                  &got_dst_resume);
-
-    /*
-     * Remove shmem file immediately to avoid memory leak in test failed case.
-     * It's valid becase QEMU has already opened this file
-     */
-    if (args->use_shmem) {
-        unlink(shmem_path);
-    }
 }
 
 static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
@@ -1637,10 +1635,10 @@ static void test_ignore_shared(void)
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = {
-        .use_shmem = true
-    };
+    MigrateStart args = { };
 
+    guest_use_shmem(from);
+    guest_use_shmem(to);
     test_migrate_start(from, to, uri, &args);
 
     migrate_set_capability(from->qs, "x-ignore-shared", true);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 27/42] migration-test: Create guest_extra_opts()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (25 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 26/42] migration-test: create guest_use_shmem() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 28/42] migration-test: Create guest_hide_stderr() Juan Quintela
                   ` (14 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

If a guest has extra command line options, add it with this.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 0130a00707..b9b11ebb0f 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -156,6 +156,7 @@ typedef struct {
     gchar *arch_opts;
     gchar *arch_source;
     gchar *arch_target;
+    const gchar *extra_opts;
     gchar *kvm_opts;
     const gchar *memory_size;
     /*
@@ -243,6 +244,12 @@ static void guest_use_shmem(GuestState *vm)
         vm->memory_size, vm->shmem_path);
 }
 
+static void guest_extra_opts(GuestState *vm, const gchar *opts)
+{
+    g_assert(vm->extra_opts == NULL);
+    vm->extra_opts = opts;
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -640,8 +647,6 @@ typedef struct {
     bool hide_stderr;
     /* only launch the target process */
     bool only_target;
-    const char *opts_source;
-    const char *opts_target;
 } MigrateStart;
 
 /*
@@ -764,7 +769,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  from->arch_opts ? from->arch_opts : "",
                                  from->arch_source ? from->arch_source : "",
                                  from->shmem_opts ? from->shmem_opts : "",
-                                 args->opts_source ? args->opts_source : "",
+                                 from->extra_opts ? from->extra_opts : "",
                                  ignore_stderr ? ignore_stderr : "");
 
     if (!args->only_target) {
@@ -788,7 +793,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  to->arch_opts ? to->arch_opts : "",
                                  to->arch_target ? to->arch_target : "",
                                  to->shmem_opts ? to->shmem_opts : "",
-                                 args->opts_target ? args->opts_target : "",
+                                 to->extra_opts ? to->extra_opts : "",
                                  ignore_stderr ? ignore_stderr : "");
     to->qs = qtest_init(cmd_target);
     qtest_qmp_set_event_callback(to->qs,
@@ -1996,11 +2001,10 @@ static void test_validate_uuid(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = {
-        .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
-        .opts_target = "-uuid 11111111-1111-1111-1111-111111111111",
-    };
+    MigrateStart args = { };
 
+    guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
+    guest_extra_opts(to, "-uuid 11111111-1111-1111-1111-111111111111");
     do_test_validate_uuid(from, to, &args, false);
 }
 
@@ -2009,11 +2013,11 @@ static void test_validate_uuid_error(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateStart args = {
-        .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
-        .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
         .hide_stderr = true,
     };
 
+    guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
+    guest_extra_opts(to, "-uuid 22222222-2222-2222-2222-222222222222");
     do_test_validate_uuid(from, to, &args, true);
 }
 
@@ -2022,10 +2026,10 @@ static void test_validate_uuid_src_not_set(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateStart args = {
-        .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
         .hide_stderr = true,
     };
 
+    guest_extra_opts(to, "-uuid 22222222-2222-2222-2222-222222222222");
     do_test_validate_uuid(from, to, &args, false);
 }
 
@@ -2034,10 +2038,10 @@ static void test_validate_uuid_dst_not_set(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateStart args = {
-        .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
         .hide_stderr = true,
     };
 
+    guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
     do_test_validate_uuid(from, to, &args, false);
 }
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 28/42] migration-test: Create guest_hide_stderr()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (26 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 27/42] migration-test: Create guest_extra_opts() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 29/42] migration-test: Create the migration unix socket by guest Juan Quintela
                   ` (13 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So we can handle in a single place all the error output handling.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 115 ++++++++++++++++-------------------
 1 file changed, 54 insertions(+), 61 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index b9b11ebb0f..c70b08e7db 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -157,6 +157,7 @@ typedef struct {
     gchar *arch_source;
     gchar *arch_target;
     const gchar *extra_opts;
+    const gchar *hide_stderr;
     gchar *kvm_opts;
     const gchar *memory_size;
     /*
@@ -244,6 +245,23 @@ static void guest_use_shmem(GuestState *vm)
         vm->memory_size, vm->shmem_path);
 }
 
+static void guest_hide_stderr(GuestState *vm)
+{
+    g_assert(vm->hide_stderr == NULL);
+
+     if (!getenv("QTEST_LOG")) {
+#ifndef _WIN32
+        vm->hide_stderr = "2>/dev/null";
+#else
+        /*
+         * 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.
+         */
+#endif
+    }
+}
+
 static void guest_extra_opts(GuestState *vm, const gchar *opts)
 {
     g_assert(vm->extra_opts == NULL);
@@ -640,11 +658,6 @@ static void do_migrate(GuestState *from, GuestState *to, const gchar *uri)
 }
 
 typedef struct {
-    /*
-     * QTEST_LOG=1 may override this.  When QTEST_LOG=1, we always dump errors
-     * unconditionally, because it means the user would like to be verbose.
-     */
-    bool hide_stderr;
     /* only launch the target process */
     bool only_target;
 } MigrateStart;
@@ -740,23 +753,10 @@ static void test_migrate_start(GuestState *from, GuestState *to,
 {
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
-    const gchar *ignore_stderr = NULL;
 
     got_src_stop = false;
     got_dst_resume = false;
 
-    if (!getenv("QTEST_LOG") && args->hide_stderr) {
-#ifndef _WIN32
-        ignore_stderr = "2>/dev/null";
-#else
-        /*
-         * 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.
-         */
-#endif
-    }
-
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name %s,debug-threads=on "
                                  "-m %s "
@@ -770,7 +770,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  from->arch_source ? from->arch_source : "",
                                  from->shmem_opts ? from->shmem_opts : "",
                                  from->extra_opts ? from->extra_opts : "",
-                                 ignore_stderr ? ignore_stderr : "");
+                                 from->hide_stderr ? from->hide_stderr : "");
 
     if (!args->only_target) {
         from->qs = qtest_init(cmd_source);
@@ -794,7 +794,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  to->arch_target ? to->arch_target : "",
                                  to->shmem_opts ? to->shmem_opts : "",
                                  to->extra_opts ? to->extra_opts : "",
-                                 ignore_stderr ? ignore_stderr : "");
+                                 to->hide_stderr ? to->hide_stderr : "");
     to->qs = qtest_init(cmd_target);
     qtest_qmp_set_event_callback(to->qs,
                                  migrate_watch_for_resume,
@@ -1323,8 +1323,8 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
     g_autofree char *uri = NULL;
 
     /* Always hide errors for postcopy recover tests since they're expected */
-    args->start.hide_stderr = true;
-
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     migrate_postcopy_prepare(from, to, args);
 
     /* Turn postcopy speed down, 4K/s is slow enough on any machines */
@@ -1431,12 +1431,12 @@ static void test_postcopy_preempt_all(void)
 
 static void test_baddest(void)
 {
-    MigrateStart args = {
-        .hide_stderr = true
-    };
+    MigrateStart args = { };
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_migrate_start(from, to, "tcp:127.0.0.1:0", &args);
     /*
      * Don't change to do_migrate(). We are using a wrong uri on purpose.
@@ -1605,9 +1605,6 @@ static void test_precopy_unix_tls_x509_default_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_tls_x509_start_default_host,
@@ -1615,6 +1612,8 @@ static void test_precopy_unix_tls_x509_default_host(void)
         .result = MIG_TEST_FAIL_DEST_QUIT_ERR,
     };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -1780,15 +1779,14 @@ static void test_precopy_tcp_tls_psk_mismatch(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_psk_start_mismatch,
         .finish_hook = test_migrate_tls_psk_finish,
         .result = MIG_TEST_FAIL,
     };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -1824,15 +1822,14 @@ static void test_precopy_tcp_tls_x509_mismatch_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_mismatch_host,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL_DEST_QUIT_ERR,
     };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -1854,15 +1851,14 @@ static void test_precopy_tcp_tls_x509_hostile_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_hostile_client,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
     };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -1884,15 +1880,14 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_reject_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
     };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
@@ -2012,10 +2007,10 @@ static void test_validate_uuid_error(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = {
-        .hide_stderr = true,
-    };
+    MigrateStart args = { };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
     guest_extra_opts(to, "-uuid 22222222-2222-2222-2222-222222222222");
     do_test_validate_uuid(from, to, &args, true);
@@ -2025,10 +2020,10 @@ static void test_validate_uuid_src_not_set(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = {
-        .hide_stderr = true,
-    };
+    MigrateStart args = { };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     guest_extra_opts(to, "-uuid 22222222-2222-2222-2222-222222222222");
     do_test_validate_uuid(from, to, &args, false);
 }
@@ -2037,10 +2032,10 @@ static void test_validate_uuid_dst_not_set(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = {
-        .hide_stderr = true,
-    };
+    MigrateStart args = { };
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
     do_test_validate_uuid(from, to, &args, false);
 }
@@ -2292,14 +2287,13 @@ static void test_multifd_tcp_tls_psk_mismatch(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tcp_tls_psk_start_mismatch,
         .finish_hook = test_migrate_tls_psk_finish,
         .result = MIG_TEST_FAIL,
     };
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -2346,14 +2340,13 @@ static void test_multifd_tcp_tls_x509_mismatch_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_mismatch_host,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
     };
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -2374,14 +2367,13 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .start = {
-            .hide_stderr = true,
-        },
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_reject_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
     };
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
     test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
@@ -2400,13 +2392,14 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
  */
 static void test_multifd_tcp_cancel(void)
 {
-    MigrateStart args = {
-        .hide_stderr = true,
-    };
+    MigrateStart args = { };
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     GuestState *to2 = guest_create("target2");
 
+    guest_hide_stderr(from);
+    guest_hide_stderr(to);
+
     test_migrate_start(from, to, "defer", &args);
 
     migrate_ensure_non_converge(from->qs);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 29/42] migration-test: Create the migration unix socket by guest
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (27 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 28/42] migration-test: Create guest_hide_stderr() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 30/42] migration-test: Hooks also need GuestState Juan Quintela
                   ` (12 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 50 +++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index c70b08e7db..a0ed8eb05a 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -168,6 +168,8 @@ typedef struct {
     gchar *serial_path;
     gchar *shmem_opts;
     gchar *shmem_path;
+    gchar *unix_socket;
+    gchar *uri;
     unsigned start_address;
     unsigned end_address;
 } GuestState;
@@ -224,6 +226,11 @@ static void guest_destroy(GuestState *vm)
     g_free(vm->shmem_opts);
     unlink(vm->shmem_path);
     g_free(vm->shmem_path);
+    if (vm->unix_socket) {
+        unlink(vm->unix_socket);
+        g_free(vm->unix_socket);
+    }
+    g_free(vm->uri);
     g_free(vm);
 }
 
@@ -268,6 +275,17 @@ static void guest_extra_opts(GuestState *vm, const gchar *opts)
     vm->extra_opts = opts;
 }
 
+static void guest_listen_unix_socket(GuestState *vm)
+{
+    if (vm->unix_socket) {
+        unlink(vm->unix_socket);
+        g_free(vm->unix_socket);
+    }
+    g_free(vm->uri);
+    vm->unix_socket = g_strdup_printf("%s/migsocket", tmpfs);
+    vm->uri = g_strdup_printf("unix:%s", vm->unix_socket);
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -789,7 +807,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  to->name,
                                  to->memory_size,
                                  to->serial_path,
-                                 uri,
+                                 to->uri ? to->uri : uri,
                                  to->arch_opts ? to->arch_opts : "",
                                  to->arch_target ? to->arch_target : "",
                                  to->shmem_opts ? to->shmem_opts : "",
@@ -1202,9 +1220,8 @@ static void migrate_postcopy_prepare(GuestState *from,
                                      GuestState *to,
                                      MigrateCommon *args)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-
-    test_migrate_start(from, to, uri, &args->start);
+    guest_listen_unix_socket(to);
+    test_migrate_start(from, to, NULL, &args->start);
 
     if (args->start_hook) {
         args->postcopy_data = args->start_hook(from->qs, to->qs);
@@ -1224,7 +1241,7 @@ static void migrate_postcopy_prepare(GuestState *from,
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, uri);
+    do_migrate(from, to, to->uri);
 
     wait_for_migration_pass(from->qs);
 }
@@ -1320,8 +1337,6 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
 
-    g_autofree char *uri = NULL;
-
     /* Always hide errors for postcopy recover tests since they're expected */
     guest_hide_stderr(from);
     guest_hide_stderr(to);
@@ -1359,8 +1374,8 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
      * from the broken migration channel; tell the destination to
      * listen to the new port
      */
-    uri = g_strdup_printf("unix:%s/migsocket-recover", tmpfs);
-    migrate_recover(to->qs, uri);
+    guest_listen_unix_socket(to);
+    migrate_recover(to->qs, to->uri);
 
     /*
      * Try to rebuild the migration channel using the resume flag and
@@ -1369,7 +1384,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
     wait_for_migration_status(from->qs, "postcopy-paused",
                               (const char * []) { "failed", "active",
                                                   "completed", NULL });
-    migrate_qmp(from->qs, uri, "{'resume': true}");
+    migrate_qmp(from->qs, to->uri, "{'resume': true}");
 
     /* Restore the postcopy bandwidth to unlimited */
     migrate_set_parameter_int(from->qs, "max-postcopy-bandwidth", 0);
@@ -1651,7 +1666,7 @@ static void test_ignore_shared(void)
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, uri);
+    do_migrate(from, to, to->uri);
 
     wait_for_migration_pass(from->qs);
 
@@ -1965,9 +1980,8 @@ static void test_migrate_fd_proto(void)
 static void do_test_validate_uuid(GuestState *from, GuestState *to,
                                   MigrateStart *args, bool should_fail)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-
-    test_migrate_start(from, to, uri, args);
+    guest_listen_unix_socket(to);
+    test_migrate_start(from, to, NULL, args);
 
     /*
      * UUID validation is at the begin of migration. So, the main process of
@@ -1980,7 +1994,7 @@ static void do_test_validate_uuid(GuestState *from, GuestState *to,
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, uri);
+    do_migrate(from, to, to->uri);
 
     if (should_fail) {
         qtest_set_expected_status(to->qs, EXIT_FAILURE);
@@ -2057,7 +2071,6 @@ static void test_validate_uuid_dst_not_set(void)
  */
 static void test_migrate_auto_converge(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     MigrateStart args = {};
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
@@ -2070,7 +2083,8 @@ static void test_migrate_auto_converge(void)
      */
     const int64_t init_pct = 5, inc_pct = 25, max_pct = 95;
 
-    test_migrate_start(from, to, uri, &args);
+    guest_listen_unix_socket(to);
+    test_migrate_start(from, to, to->uri, &args);
 
     migrate_set_capability(from->qs, "auto-converge", true);
     migrate_set_parameter_int(from->qs, "cpu-throttle-initial", init_pct);
@@ -2089,7 +2103,7 @@ static void test_migrate_auto_converge(void)
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, uri);
+    do_migrate(from, to, to->uri);
 
     /* Wait for throttling begins */
     percentage = 0;
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 30/42] migration-test: Hooks also need GuestState
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (28 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 29/42] migration-test: Create the migration unix socket by guest Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 31/42] migration-test: Preffer to->uri to uri parameter for migration Juan Quintela
                   ` (11 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 198 +++++++++++++++--------------------
 1 file changed, 86 insertions(+), 112 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index a0ed8eb05a..6438379dcf 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -653,15 +653,16 @@ static void migrate_set_capability(QTestState *who, const char *capability,
                              capability, value);
 }
 
-static void migrate_postcopy_start(QTestState *from, QTestState *to)
+static void migrate_postcopy_start(GuestState *from, GuestState *to)
 {
-    qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
+    qtest_qmp_assert_success(from->qs,
+                             "{ 'execute': 'migrate-start-postcopy' }");
 
     if (!got_src_stop) {
-        qtest_qmp_eventwait(from, "STOP");
+        qtest_qmp_eventwait(from->qs, "STOP");
     }
 
-    qtest_qmp_eventwait(to, "RESUME");
+    qtest_qmp_eventwait(to->qs, "RESUME");
 }
 
 static void do_migrate(GuestState *from, GuestState *to, const gchar *uri)
@@ -688,8 +689,7 @@ typedef struct {
  * Returns: NULL, or a pointer to opaque state to be
  *          later passed to the TestMigrateFinishHook
  */
-typedef void * (*TestMigrateStartHook)(QTestState *from,
-                                       QTestState *to);
+typedef void * (*TestMigrateStartHook)(GuestState *from, GuestState *to);
 
 /*
  * A hook that runs after the migration has finished,
@@ -700,8 +700,7 @@ typedef void * (*TestMigrateStartHook)(QTestState *from,
  * @opaque is a pointer to state previously returned
  * by the TestMigrateStartHook if any, or NULL.
  */
-typedef void (*TestMigrateFinishHook)(QTestState *from,
-                                      QTestState *to,
+typedef void (*TestMigrateFinishHook)(GuestState *from, GuestState *to,
                                       void *opaque);
 
 typedef struct {
@@ -859,8 +858,7 @@ struct TestMigrateTLSPSKData {
 };
 
 static void *
-test_migrate_tls_psk_start_common(QTestState *from,
-                                  QTestState *to,
+test_migrate_tls_psk_start_common(GuestState *from, GuestState *to,
                                   bool mismatch)
 {
     struct TestMigrateTLSPSKData *data =
@@ -880,7 +878,7 @@ test_migrate_tls_psk_start_common(QTestState *from,
         test_tls_psk_init_alt(data->pskfilealt);
     }
 
-    qtest_qmp_assert_success(from,
+    qtest_qmp_assert_success(from->qs,
                              "{ 'execute': 'object-add',"
                              "  'arguments': { 'qom-type': 'tls-creds-psk',"
                              "                 'id': 'tlscredspsk0',"
@@ -889,7 +887,7 @@ test_migrate_tls_psk_start_common(QTestState *from,
                              "                 'username': 'qemu'} }",
                              data->workdir);
 
-    qtest_qmp_assert_success(to,
+    qtest_qmp_assert_success(to->qs,
                              "{ 'execute': 'object-add',"
                              "  'arguments': { 'qom-type': 'tls-creds-psk',"
                              "                 'id': 'tlscredspsk0',"
@@ -897,30 +895,26 @@ test_migrate_tls_psk_start_common(QTestState *from,
                              "                 'dir': %s } }",
                              mismatch ? data->workdiralt : data->workdir);
 
-    migrate_set_parameter_str(from, "tls-creds", "tlscredspsk0");
-    migrate_set_parameter_str(to, "tls-creds", "tlscredspsk0");
+    migrate_set_parameter_str(from->qs, "tls-creds", "tlscredspsk0");
+    migrate_set_parameter_str(to->qs, "tls-creds", "tlscredspsk0");
 
     return data;
 }
 
 static void *
-test_migrate_tls_psk_start_match(QTestState *from,
-                                 QTestState *to)
+test_migrate_tls_psk_start_match(GuestState *from, GuestState *to)
 {
     return test_migrate_tls_psk_start_common(from, to, false);
 }
 
 static void *
-test_migrate_tls_psk_start_mismatch(QTestState *from,
-                                    QTestState *to)
+test_migrate_tls_psk_start_mismatch(GuestState *from, GuestState *to)
 {
     return test_migrate_tls_psk_start_common(from, to, true);
 }
 
 static void
-test_migrate_tls_psk_finish(QTestState *from,
-                            QTestState *to,
-                            void *opaque)
+test_migrate_tls_psk_finish(GuestState *from, GuestState *to, void *opaque)
 {
     struct TestMigrateTLSPSKData *data = opaque;
 
@@ -961,8 +955,7 @@ typedef struct {
 } TestMigrateTLSX509;
 
 static void *
-test_migrate_tls_x509_start_common(QTestState *from,
-                                   QTestState *to,
+test_migrate_tls_x509_start_common(GuestState *from, GuestState *to,
                                    TestMigrateTLSX509 *args)
 {
     TestMigrateTLSX509Data *data = g_new0(TestMigrateTLSX509Data, 1);
@@ -1008,7 +1001,7 @@ test_migrate_tls_x509_start_common(QTestState *from,
                                args->certhostname,
                                args->certipaddr);
 
-    qtest_qmp_assert_success(from,
+    qtest_qmp_assert_success(from->qs,
                              "{ 'execute': 'object-add',"
                              "  'arguments': { 'qom-type': 'tls-creds-x509',"
                              "                 'id': 'tlscredsx509client0',"
@@ -1017,12 +1010,12 @@ test_migrate_tls_x509_start_common(QTestState *from,
                              "                 'sanity-check': true,"
                              "                 'verify-peer': true} }",
                              data->workdir);
-    migrate_set_parameter_str(from, "tls-creds", "tlscredsx509client0");
+    migrate_set_parameter_str(from->qs, "tls-creds", "tlscredsx509client0");
     if (args->certhostname) {
-        migrate_set_parameter_str(from, "tls-hostname", args->certhostname);
+        migrate_set_parameter_str(from->qs, "tls-hostname", args->certhostname);
     }
 
-    qtest_qmp_assert_success(to,
+    qtest_qmp_assert_success(to->qs,
                              "{ 'execute': 'object-add',"
                              "  'arguments': { 'qom-type': 'tls-creds-x509',"
                              "                 'id': 'tlscredsx509server0',"
@@ -1031,16 +1024,16 @@ test_migrate_tls_x509_start_common(QTestState *from,
                              "                 'sanity-check': true,"
                              "                 'verify-peer': %i} }",
                              data->workdir, args->verifyclient);
-    migrate_set_parameter_str(to, "tls-creds", "tlscredsx509server0");
+    migrate_set_parameter_str(to->qs, "tls-creds", "tlscredsx509server0");
 
     if (args->authzclient) {
-        qtest_qmp_assert_success(to,
+        qtest_qmp_assert_success(to->qs,
                                  "{ 'execute': 'object-add',"
                                  "  'arguments': { 'qom-type': 'authz-simple',"
                                  "                 'id': 'tlsauthz0',"
                                  "                 'identity': %s} }",
                                  "CN=" QCRYPTO_TLS_TEST_CLIENT_NAME);
-        migrate_set_parameter_str(to, "tls-authz", "tlsauthz0");
+        migrate_set_parameter_str(to->qs, "tls-authz", "tlsauthz0");
     }
 
     return data;
@@ -1051,8 +1044,7 @@ test_migrate_tls_x509_start_common(QTestState *from,
  * whatever host we were telling QEMU to connect to (if any)
  */
 static void *
-test_migrate_tls_x509_start_default_host(QTestState *from,
-                                         QTestState *to)
+test_migrate_tls_x509_start_default_host(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .verifyclient = true,
@@ -1068,8 +1060,7 @@ test_migrate_tls_x509_start_default_host(QTestState *from,
  * so we must give QEMU an explicit hostname to validate
  */
 static void *
-test_migrate_tls_x509_start_override_host(QTestState *from,
-                                          QTestState *to)
+test_migrate_tls_x509_start_override_host(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .verifyclient = true,
@@ -1085,8 +1076,7 @@ test_migrate_tls_x509_start_override_host(QTestState *from,
  * expect the client to reject the server
  */
 static void *
-test_migrate_tls_x509_start_mismatch_host(QTestState *from,
-                                          QTestState *to)
+test_migrate_tls_x509_start_mismatch_host(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .verifyclient = true,
@@ -1097,8 +1087,7 @@ test_migrate_tls_x509_start_mismatch_host(QTestState *from,
 }
 
 static void *
-test_migrate_tls_x509_start_friendly_client(QTestState *from,
-                                            QTestState *to)
+test_migrate_tls_x509_start_friendly_client(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .verifyclient = true,
@@ -1110,8 +1099,7 @@ test_migrate_tls_x509_start_friendly_client(QTestState *from,
 }
 
 static void *
-test_migrate_tls_x509_start_hostile_client(QTestState *from,
-                                           QTestState *to)
+test_migrate_tls_x509_start_hostile_client(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .verifyclient = true,
@@ -1128,8 +1116,7 @@ test_migrate_tls_x509_start_hostile_client(QTestState *from,
  * and no server verification
  */
 static void *
-test_migrate_tls_x509_start_allow_anon_client(QTestState *from,
-                                              QTestState *to)
+test_migrate_tls_x509_start_allow_anon_client(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .certipaddr = "127.0.0.1",
@@ -1142,8 +1129,7 @@ test_migrate_tls_x509_start_allow_anon_client(QTestState *from,
  * and server verification rejecting
  */
 static void *
-test_migrate_tls_x509_start_reject_anon_client(QTestState *from,
-                                               QTestState *to)
+test_migrate_tls_x509_start_reject_anon_client(GuestState *from, GuestState *to)
 {
     TestMigrateTLSX509 args = {
         .verifyclient = true,
@@ -1153,9 +1139,7 @@ test_migrate_tls_x509_start_reject_anon_client(QTestState *from,
 }
 
 static void
-test_migrate_tls_x509_finish(QTestState *from,
-                             QTestState *to,
-                             void *opaque)
+test_migrate_tls_x509_finish(GuestState *from, GuestState *to, void *opaque)
 {
     TestMigrateTLSX509Data *data = opaque;
 
@@ -1187,31 +1171,29 @@ test_migrate_tls_x509_finish(QTestState *from,
 #endif /* CONFIG_GNUTLS */
 
 static void *
-test_migrate_compress_start(QTestState *from,
-                            QTestState *to)
+test_migrate_compress_start(GuestState *from, GuestState *to)
 {
-    migrate_set_parameter_int(from, "compress-level", 1);
-    migrate_set_parameter_int(from, "compress-threads", 4);
-    migrate_set_parameter_bool(from, "compress-wait-thread", true);
-    migrate_set_parameter_int(to, "decompress-threads", 4);
+    migrate_set_parameter_int(from->qs, "compress-level", 1);
+    migrate_set_parameter_int(from->qs, "compress-threads", 4);
+    migrate_set_parameter_bool(from->qs, "compress-wait-thread", true);
+    migrate_set_parameter_int(to->qs, "decompress-threads", 4);
 
-    migrate_set_capability(from, "compress", true);
-    migrate_set_capability(to, "compress", true);
+    migrate_set_capability(from->qs, "compress", true);
+    migrate_set_capability(to->qs, "compress", true);
 
     return NULL;
 }
 
 static void *
-test_migrate_compress_nowait_start(QTestState *from,
-                                   QTestState *to)
+test_migrate_compress_nowait_start(GuestState *from, GuestState *to)
 {
-    migrate_set_parameter_int(from, "compress-level", 9);
-    migrate_set_parameter_int(from, "compress-threads", 1);
-    migrate_set_parameter_bool(from, "compress-wait-thread", false);
-    migrate_set_parameter_int(to, "decompress-threads", 1);
+    migrate_set_parameter_int(from->qs, "compress-level", 9);
+    migrate_set_parameter_int(from->qs, "compress-threads", 1);
+    migrate_set_parameter_bool(from->qs, "compress-wait-thread", false);
+    migrate_set_parameter_int(to->qs, "decompress-threads", 1);
 
-    migrate_set_capability(from, "compress", true);
-    migrate_set_capability(to, "compress", true);
+    migrate_set_capability(from->qs, "compress", true);
+    migrate_set_capability(to->qs, "compress", true);
 
     return NULL;
 }
@@ -1224,7 +1206,7 @@ static void migrate_postcopy_prepare(GuestState *from,
     test_migrate_start(from, to, NULL, &args->start);
 
     if (args->start_hook) {
-        args->postcopy_data = args->start_hook(from->qs, to->qs);
+        args->postcopy_data = args->start_hook(from, to);
     }
 
     migrate_set_capability(from->qs, "postcopy-ram", true);
@@ -1259,7 +1241,7 @@ static void migrate_postcopy_complete(GuestState *from, GuestState *to,
     }
 
     if (args->finish_hook) {
-        args->finish_hook(from->qs, to->qs, args->postcopy_data);
+        args->finish_hook(from, to, args->postcopy_data);
         args->postcopy_data = NULL;
     }
 
@@ -1270,7 +1252,7 @@ static void test_postcopy_common(GuestState *from, GuestState *to,
                                  MigrateCommon *args)
 {
     migrate_postcopy_prepare(from, to, args);
-    migrate_postcopy_start(from->qs, to->qs);
+    migrate_postcopy_start(from, to);
     migrate_postcopy_complete(from, to, args);
 }
 
@@ -1346,7 +1328,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
     migrate_set_parameter_int(from->qs, "max-postcopy-bandwidth", 4096);
 
     /* Now we start the postcopy */
-    migrate_postcopy_start(from->qs, to->qs);
+    migrate_postcopy_start(from, to);
 
     /*
      * Wait until postcopy is really started; we can only run the
@@ -1469,7 +1451,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
     test_migrate_start(from, to, args->listen_uri, &args->start);
 
     if (args->start_hook) {
-        data_hook = args->start_hook(from->qs, to->qs);
+        data_hook = args->start_hook(from, to);
     }
 
     /* Wait for the first serial output from the source */
@@ -1552,7 +1534,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
     }
 
     if (args->finish_hook) {
-        args->finish_hook(from->qs, to->qs, data_hook);
+        args->finish_hook(from, to, data_hook);
     }
 
     test_migrate_end(from, to, args->result == MIG_TEST_SUCCEED);
@@ -1687,13 +1669,12 @@ static void test_ignore_shared(void)
 }
 
 static void *
-test_migrate_xbzrle_start(QTestState *from,
-                          QTestState *to)
+test_migrate_xbzrle_start(GuestState *from, GuestState *to)
 {
-    migrate_set_parameter_int(from, "xbzrle-cache-size", 33554432);
+    migrate_set_parameter_int(from->qs, "xbzrle-cache-size", 33554432);
 
-    migrate_set_capability(from, "xbzrle", true);
-    migrate_set_capability(to, "xbzrle", true);
+    migrate_set_capability(from->qs, "xbzrle", true);
+    migrate_set_capability(to->qs, "xbzrle", true);
 
     return NULL;
 }
@@ -1909,8 +1890,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
 #endif /* CONFIG_GNUTLS */
 
 #ifndef _WIN32
-static void *test_migrate_fd_start_hook(QTestState *from,
-                                        QTestState *to)
+static void *test_migrate_fd_start_hook(GuestState *from, GuestState *to)
 {
     int ret;
     int pair[2];
@@ -1920,17 +1900,17 @@ static void *test_migrate_fd_start_hook(QTestState *from,
     g_assert_cmpint(ret, ==, 0);
 
     /* Send the 1st socket to the target */
-    qtest_qmp_fds_assert_success(to, &pair[0], 1,
+    qtest_qmp_fds_assert_success(to->qs, &pair[0], 1,
                                  "{ 'execute': 'getfd',"
                                  "  'arguments': { 'fdname': 'fd-mig' }}");
     close(pair[0]);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
+    qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'fd:fd-mig' }}");
 
     /* Send the 2nd socket to the target */
-    qtest_qmp_fds_assert_success(from, &pair[1], 1,
+    qtest_qmp_fds_assert_success(from->qs, &pair[1], 1,
                                  "{ 'execute': 'getfd',"
                                  "  'arguments': { 'fdname': 'fd-mig' }}");
     close(pair[1]);
@@ -1938,8 +1918,7 @@ static void *test_migrate_fd_start_hook(QTestState *from,
     return NULL;
 }
 
-static void test_migrate_fd_finish_hook(QTestState *from,
-                                        QTestState *to,
+static void test_migrate_fd_finish_hook(GuestState *from, GuestState *to,
                                         void *opaque)
 {
     QDict *rsp;
@@ -1948,14 +1927,14 @@ static void test_migrate_fd_finish_hook(QTestState *from,
     /* Test closing fds */
     /* We assume, that QEMU removes named fd from its list,
      * so this should fail */
-    rsp = qtest_qmp(from, "{ 'execute': 'closefd',"
+    rsp = qtest_qmp(from->qs, "{ 'execute': 'closefd',"
                           "  'arguments': { 'fdname': 'fd-mig' }}");
     g_assert_true(qdict_haskey(rsp, "error"));
     error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
     g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
     qobject_unref(rsp);
 
-    rsp = qtest_qmp(to, "{ 'execute': 'closefd',"
+    rsp = qtest_qmp(to->qs, "{ 'execute': 'closefd',"
                         "  'arguments': { 'fdname': 'fd-mig' }}");
     g_assert_true(qdict_haskey(rsp, "error"));
     error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
@@ -2141,44 +2120,40 @@ static void test_migrate_auto_converge(void)
 }
 
 static void *
-test_migrate_precopy_tcp_multifd_start_common(QTestState *from,
-                                              QTestState *to,
+test_migrate_precopy_tcp_multifd_start_common(GuestState *from, GuestState *to,
                                               const char *method)
 {
-    migrate_set_parameter_int(from, "multifd-channels", 16);
-    migrate_set_parameter_int(to, "multifd-channels", 16);
+    migrate_set_parameter_int(from->qs, "multifd-channels", 16);
+    migrate_set_parameter_int(to->qs, "multifd-channels", 16);
 
-    migrate_set_parameter_str(from, "multifd-compression", method);
-    migrate_set_parameter_str(to, "multifd-compression", method);
+    migrate_set_parameter_str(from->qs, "multifd-compression", method);
+    migrate_set_parameter_str(to->qs, "multifd-compression", method);
 
-    migrate_set_capability(from, "multifd", true);
-    migrate_set_capability(to, "multifd", true);
+    migrate_set_capability(from->qs, "multifd", true);
+    migrate_set_capability(to->qs, "multifd", true);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
+    qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
 
     return NULL;
 }
 
 static void *
-test_migrate_precopy_tcp_multifd_start(QTestState *from,
-                                       QTestState *to)
+test_migrate_precopy_tcp_multifd_start(GuestState *from, GuestState *to)
 {
     return test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
 }
 
 static void *
-test_migrate_precopy_tcp_multifd_zlib_start(QTestState *from,
-                                            QTestState *to)
+test_migrate_precopy_tcp_multifd_zlib_start(GuestState *from, GuestState *to)
 {
     return test_migrate_precopy_tcp_multifd_start_common(from, to, "zlib");
 }
 
 #ifdef CONFIG_ZSTD
 static void *
-test_migrate_precopy_tcp_multifd_zstd_start(QTestState *from,
-                                            QTestState *to)
+test_migrate_precopy_tcp_multifd_zstd_start(GuestState *from, GuestState *to)
 {
     return test_migrate_precopy_tcp_multifd_start_common(from, to, "zstd");
 }
@@ -2227,16 +2202,15 @@ static void test_multifd_tcp_zstd(void)
 
 #ifdef CONFIG_GNUTLS
 static void *
-test_migrate_multifd_tcp_tls_psk_start_match(QTestState *from,
-                                             QTestState *to)
+test_migrate_multifd_tcp_tls_psk_start_match(GuestState *from, GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_psk_start_match(from, to);
 }
 
 static void *
-test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState *from,
-                                                QTestState *to)
+test_migrate_multifd_tcp_tls_psk_start_mismatch(GuestState *from,
+                                                GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_psk_start_mismatch(from, to);
@@ -2244,40 +2218,40 @@ test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState *from,
 
 #ifdef CONFIG_TASN1
 static void *
-test_migrate_multifd_tls_x509_start_default_host(QTestState *from,
-                                                 QTestState *to)
+test_migrate_multifd_tls_x509_start_default_host(GuestState *from,
+                                                 GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_x509_start_default_host(from, to);
 }
 
 static void *
-test_migrate_multifd_tls_x509_start_override_host(QTestState *from,
-                                                  QTestState *to)
+test_migrate_multifd_tls_x509_start_override_host(GuestState *from,
+                                                  GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_x509_start_override_host(from, to);
 }
 
 static void *
-test_migrate_multifd_tls_x509_start_mismatch_host(QTestState *from,
-                                                  QTestState *to)
+test_migrate_multifd_tls_x509_start_mismatch_host(GuestState *from,
+                                                  GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_x509_start_mismatch_host(from, to);
 }
 
 static void *
-test_migrate_multifd_tls_x509_start_allow_anon_client(QTestState *from,
-                                                      QTestState *to)
+test_migrate_multifd_tls_x509_start_allow_anon_client(GuestState *from,
+                                                      GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_x509_start_allow_anon_client(from, to);
 }
 
 static void *
-test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState *from,
-                                                       QTestState *to)
+test_migrate_multifd_tls_x509_start_reject_anon_client(GuestState *from,
+                                                       GuestState *to)
 {
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_x509_start_reject_anon_client(from, to);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 31/42] migration-test: Preffer to->uri to uri parameter for migration
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (29 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 30/42] migration-test: Hooks also need GuestState Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 32/42] migration-test: Create guest_set_uri() Juan Quintela
                   ` (10 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 6438379dcf..0afe871cfb 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -667,12 +667,22 @@ static void migrate_postcopy_start(GuestState *from, GuestState *to)
 
 static void do_migrate(GuestState *from, GuestState *to, const gchar *uri)
 {
-    if (!uri) {
-        g_autofree char *tcp_uri =
-            migrate_get_socket_address(to->qs, "socket-address");
-        migrate_qmp(from->qs, tcp_uri, "{}");
+    if (to->uri) {
+        if (strncmp(to->uri, "tcp:", strlen("tcp:")) == 0) {
+            g_autofree char *tcp_uri =
+                migrate_get_socket_address(to->qs, "socket-address");
+            migrate_qmp(from->qs, tcp_uri, "{}");
+        } else {
+            migrate_qmp(from->qs, to->uri, "{}");
+        }
     } else {
-        migrate_qmp(from->qs, uri, "{}");
+        if (!uri) {
+            g_autofree char *tcp_uri =
+                migrate_get_socket_address(to->qs, "socket-address");
+            migrate_qmp(from->qs, tcp_uri, "{}");
+        } else {
+            migrate_qmp(from->qs, uri, "{}");
+        }
     }
 }
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 32/42] migration-test: Create guest_set_uri()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (30 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 31/42] migration-test: Preffer to->uri to uri parameter for migration Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 33/42] migration-test: Remove connect_uri Juan Quintela
                   ` (9 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

We need this for migration-incoming cases.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 0afe871cfb..f029258f67 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -286,6 +286,12 @@ static void guest_listen_unix_socket(GuestState *vm)
     vm->uri = g_strdup_printf("unix:%s", vm->unix_socket);
 }
 
+static void guest_set_uri(GuestState *vm, const gchar *uri)
+{
+    g_free(vm->uri);
+    vm->uri = g_strdup(uri);
+}
+
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's
@@ -1918,6 +1924,7 @@ static void *test_migrate_fd_start_hook(GuestState *from, GuestState *to)
     /* Start incoming migration from the 1st socket */
     qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'fd:fd-mig' }}");
+    guest_set_uri(to, "fd:fd-mig");
 
     /* Send the 2nd socket to the target */
     qtest_qmp_fds_assert_success(from->qs, &pair[1], 1,
@@ -1958,7 +1965,6 @@ static void test_migrate_fd_proto(void)
     GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = "defer",
-        .connect_uri = "fd:fd-mig",
         .start_hook = test_migrate_fd_start_hook,
         .finish_hook = test_migrate_fd_finish_hook
     };
@@ -2145,6 +2151,7 @@ test_migrate_precopy_tcp_multifd_start_common(GuestState *from, GuestState *to,
     /* Start incoming migration from the 1st socket */
     qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
+    guest_set_uri(to, "tcp:127.0.0.1:0");
 
     return NULL;
 }
@@ -2411,6 +2418,7 @@ static void test_multifd_tcp_cancel(void)
     /* Start incoming migration from the 1st socket */
     qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
+    guest_set_uri(to, "tcp:127.0.0.1:0");
 
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
@@ -2440,6 +2448,7 @@ static void test_multifd_tcp_cancel(void)
     /* Start incoming migration from the 1st socket */
     qtest_qmp_assert_success(to2->qs, "{ 'execute': 'migrate-incoming',"
                              "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
+    guest_set_uri(to2, "tcp:127.0.0.1:0");
 
     wait_for_migration_status(from->qs, "cancelled", NULL);
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 33/42] migration-test: Remove connect_uri
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (31 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 32/42] migration-test: Create guest_set_uri() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 34/42] migration-test: Use new schema for all tests that use unix sockets Juan Quintela
                   ` (8 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

We are using to->uri in everywhere know.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 52 +++++++++---------------------------
 1 file changed, 13 insertions(+), 39 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index f029258f67..3b1b76fe6f 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -671,24 +671,14 @@ static void migrate_postcopy_start(GuestState *from, GuestState *to)
     qtest_qmp_eventwait(to->qs, "RESUME");
 }
 
-static void do_migrate(GuestState *from, GuestState *to, const gchar *uri)
+static void do_migrate(GuestState *from, GuestState *to)
 {
-    if (to->uri) {
-        if (strncmp(to->uri, "tcp:", strlen("tcp:")) == 0) {
-            g_autofree char *tcp_uri =
-                migrate_get_socket_address(to->qs, "socket-address");
-            migrate_qmp(from->qs, tcp_uri, "{}");
-        } else {
-            migrate_qmp(from->qs, to->uri, "{}");
-        }
+    if (!to->uri || strncmp(to->uri, "tcp:", strlen("tcp:")) == 0) {
+        g_autofree char *tcp_uri =
+            migrate_get_socket_address(to->qs, "socket-address");
+        migrate_qmp(from->qs, tcp_uri, "{}");
     } else {
-        if (!uri) {
-            g_autofree char *tcp_uri =
-                migrate_get_socket_address(to->qs, "socket-address");
-            migrate_qmp(from->qs, tcp_uri, "{}");
-        } else {
-            migrate_qmp(from->qs, uri, "{}");
-        }
+        migrate_qmp(from->qs, to->uri, "{}");
     }
 }
 
@@ -726,14 +716,6 @@ typedef struct {
     /* Required: the URI for the dst QEMU to listen on */
     const char *listen_uri;
 
-    /*
-     * Optional: the URI for the src QEMU to connect to
-     * If NULL, then it will query the dst QEMU for its actual
-     * listening address and use that as the connect address.
-     * This allows for dynamically picking a free TCP port.
-     */
-    const char *connect_uri;
-
     /* Optional: callback to run at start to set migration parameters */
     TestMigrateStartHook start_hook;
     /* Optional: callback to run at finish to cleanup */
@@ -1239,7 +1221,7 @@ static void migrate_postcopy_prepare(GuestState *from,
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, to->uri);
+    do_migrate(from, to);
 
     wait_for_migration_pass(from->qs);
 }
@@ -1500,7 +1482,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
         }
     }
 
-    do_migrate(from, to, args->connect_uri);
+    do_migrate(from, to);
 
     if (args->result != MIG_TEST_SUCCEED) {
         bool allow_active = args->result == MIG_TEST_FAIL;
@@ -1563,7 +1545,6 @@ static void test_precopy_unix_plain(void)
     GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = uri,
-        .connect_uri = uri,
         /*
          * The simplest use case of precopy, covering smoke tests of
          * get-dirty-log dirty tracking.
@@ -1582,7 +1563,6 @@ static void test_precopy_unix_dirty_ring(void)
     GuestState *to = guest_create("target");
     MigrateCommon args = {
         .listen_uri = uri,
-        .connect_uri = uri,
         /*
          * Besides the precopy/unix basic test, cover dirty ring interface
          * rather than get-dirty-log.
@@ -1602,7 +1582,6 @@ static void test_precopy_unix_tls_psk(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
@@ -1618,7 +1597,6 @@ static void test_precopy_unix_tls_x509_default_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_tls_x509_start_default_host,
         .finish_hook = test_migrate_tls_x509_finish,
@@ -1636,7 +1614,6 @@ static void test_precopy_unix_tls_x509_override_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_tls_x509_start_override_host,
         .finish_hook = test_migrate_tls_x509_finish,
@@ -1664,7 +1641,7 @@ static void test_ignore_shared(void)
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, to->uri);
+    do_migrate(from, to);
 
     wait_for_migration_pass(from->qs);
 
@@ -1701,7 +1678,6 @@ static void test_precopy_unix_xbzrle(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_xbzrle_start,
         .iterations = 2,
@@ -1721,7 +1697,6 @@ static void test_precopy_unix_compress(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_compress_start,
         /*
@@ -1746,7 +1721,6 @@ static void test_precopy_unix_compress_nowait(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .connect_uri = uri,
         .listen_uri = uri,
         .start_hook = test_migrate_compress_nowait_start,
         /*
@@ -1989,7 +1963,7 @@ static void do_test_validate_uuid(GuestState *from, GuestState *to,
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, to->uri);
+    do_migrate(from, to);
 
     if (should_fail) {
         qtest_set_expected_status(to->qs, EXIT_FAILURE);
@@ -2098,7 +2072,7 @@ static void test_migrate_auto_converge(void)
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, to->uri);
+    do_migrate(from, to);
 
     /* Wait for throttling begins */
     percentage = 0;
@@ -2423,7 +2397,7 @@ static void test_multifd_tcp_cancel(void)
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
 
-    do_migrate(from, to, "127.0.0.1:0");
+    do_migrate(from, to);
 
     wait_for_migration_pass(from->qs);
 
@@ -2454,7 +2428,7 @@ static void test_multifd_tcp_cancel(void)
 
     migrate_ensure_converge(from->qs);
 
-    do_migrate(from, to2, "127.0.0.1:0");
+    do_migrate(from, to2);
 
     wait_for_migration_pass(from->qs);
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 34/42] migration-test: Use new schema for all tests that use unix sockets
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (32 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 33/42] migration-test: Remove connect_uri Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 35/42] migration-test: Set uri for tcp tests with guest_set_uri() Juan Quintela
                   ` (7 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Once there we can remove the now unused cleanup() function.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 39 ++++++++++--------------------------
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 3b1b76fe6f..76a5f8d353 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -462,13 +462,6 @@ static void check_guests_ram(GuestState *who)
     g_assert(bad == 0);
 }
 
-static void cleanup(const char *filename)
-{
-    g_autofree char *path = g_strdup_printf("%s/%s", tmpfs, filename);
-
-    unlink(path);
-}
-
 static char *SocketAddress_to_str(SocketAddress *addr)
 {
     switch (addr->type) {
@@ -843,8 +836,6 @@ static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
     }
 
     guest_destroy(to);
-
-    cleanup("migsocket");
 }
 
 #ifdef CONFIG_GNUTLS
@@ -1540,11 +1531,9 @@ static void test_precopy_common(GuestState *from, GuestState *to,
 
 static void test_precopy_unix_plain(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         /*
          * The simplest use case of precopy, covering smoke tests of
          * get-dirty-log dirty tracking.
@@ -1552,17 +1541,16 @@ static void test_precopy_unix_plain(void)
         .live = true,
     };
 
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
 
 static void test_precopy_unix_dirty_ring(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         /*
          * Besides the precopy/unix basic test, cover dirty ring interface
          * rather than get-dirty-log.
@@ -1572,32 +1560,30 @@ static void test_precopy_unix_dirty_ring(void)
 
     guest_use_dirty_ring(from);
     guest_use_dirty_ring(to);
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_GNUTLS
 static void test_precopy_unix_tls_psk(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         .start_hook = test_migrate_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
 
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
 #ifdef CONFIG_TASN1
 static void test_precopy_unix_tls_x509_default_host(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         .start_hook = test_migrate_tls_x509_start_default_host,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL_DEST_QUIT_ERR,
@@ -1605,20 +1591,20 @@ static void test_precopy_unix_tls_x509_default_host(void)
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_unix_tls_x509_override_host(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         .start_hook = test_migrate_tls_x509_start_override_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
@@ -1626,14 +1612,14 @@ static void test_precopy_unix_tls_x509_override_host(void)
 
 static void test_ignore_shared(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateStart args = { };
 
     guest_use_shmem(from);
     guest_use_shmem(to);
-    test_migrate_start(from, to, uri, &args);
+    guest_listen_unix_socket(to);
+    test_migrate_start(from, to, NULL, &args);
 
     migrate_set_capability(from->qs, "x-ignore-shared", true);
     migrate_set_capability(to->qs, "x-ignore-shared", true);
@@ -1674,11 +1660,9 @@ test_migrate_xbzrle_start(GuestState *from, GuestState *to)
 
 static void test_precopy_unix_xbzrle(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         .start_hook = test_migrate_xbzrle_start,
         .iterations = 2,
         /*
@@ -1688,16 +1672,15 @@ static void test_precopy_unix_xbzrle(void)
         .live = true,
     };
 
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_unix_compress(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         .start_hook = test_migrate_compress_start,
         /*
          * Test that no invalid thread state is left over from
@@ -1712,16 +1695,15 @@ static void test_precopy_unix_compress(void)
         .live = true,
     };
 
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
 static void test_precopy_unix_compress_nowait(void)
 {
-    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = uri,
         .start_hook = test_migrate_compress_nowait_start,
         /*
          * Test that no invalid thread state is left over from
@@ -1732,6 +1714,7 @@ static void test_precopy_unix_compress_nowait(void)
         .live = true,
     };
 
+    guest_listen_unix_socket(to);
     test_precopy_common(from, to, &args);
 }
 
@@ -2053,7 +2036,7 @@ static void test_migrate_auto_converge(void)
     const int64_t init_pct = 5, inc_pct = 25, max_pct = 95;
 
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, to->uri, &args);
+    test_migrate_start(from, to, NULL, &args);
 
     migrate_set_capability(from->qs, "auto-converge", true);
     migrate_set_parameter_int(from->qs, "cpu-throttle-initial", init_pct);
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 35/42] migration-test: Set uri for tcp tests with guest_set_uri()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (33 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 34/42] migration-test: Use new schema for all tests that use unix sockets Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 36/42] migration-test: Remove unused listen_uri Juan Quintela
                   ` (6 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 76a5f8d353..8d497d0940 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1423,7 +1423,8 @@ static void test_baddest(void)
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
-    test_migrate_start(from, to, "tcp:127.0.0.1:0", &args);
+    guest_set_uri(to, "tcp:127.0.0.1:0");
+    test_migrate_start(from, to, NULL, &args);
     /*
      * Don't change to do_migrate(). We are using a wrong uri on purpose.
      */
@@ -1722,10 +1723,9 @@ static void test_precopy_tcp_plain(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
-    };
+    MigrateCommon args = { };
 
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1735,11 +1735,11 @@ static void test_precopy_tcp_tls_psk_match(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
 
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1748,7 +1748,6 @@ static void test_precopy_tcp_tls_psk_mismatch(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_psk_start_mismatch,
         .finish_hook = test_migrate_tls_psk_finish,
         .result = MIG_TEST_FAIL,
@@ -1756,6 +1755,7 @@ static void test_precopy_tcp_tls_psk_mismatch(void)
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1765,11 +1765,11 @@ static void test_precopy_tcp_tls_x509_default_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_default_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1778,11 +1778,11 @@ static void test_precopy_tcp_tls_x509_override_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_override_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1791,7 +1791,6 @@ static void test_precopy_tcp_tls_x509_mismatch_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_mismatch_host,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL_DEST_QUIT_ERR,
@@ -1799,6 +1798,7 @@ static void test_precopy_tcp_tls_x509_mismatch_host(void)
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1807,11 +1807,11 @@ static void test_precopy_tcp_tls_x509_friendly_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_friendly_client,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1820,7 +1820,6 @@ static void test_precopy_tcp_tls_x509_hostile_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_hostile_client,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
@@ -1828,6 +1827,7 @@ static void test_precopy_tcp_tls_x509_hostile_client(void)
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1836,11 +1836,11 @@ static void test_precopy_tcp_tls_x509_allow_anon_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_allow_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
     };
 
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 
@@ -1849,7 +1849,6 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_reject_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
@@ -1857,6 +1856,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
+    guest_set_uri(to, "tcp:127.0.0.1:0");
     test_precopy_common(from, to, &args);
 }
 #endif /* CONFIG_TASN1 */
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 36/42] migration-test: Remove unused listen_uri
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (34 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 35/42] migration-test: Set uri for tcp tests with guest_set_uri() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 37/42] migration-test: Create get_event GuestState variable Juan Quintela
                   ` (5 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Only remaining use was to transfer "defer".  But we make "defer" the
default if no uri is given.  Once there Remove the uri parameter to
test_migrate_start().

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 8d497d0940..95b7c9ed73 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -706,9 +706,6 @@ typedef struct {
     /* Optional: fine tune start parameters */
     MigrateStart start;
 
-    /* Required: the URI for the dst QEMU to listen on */
-    const char *listen_uri;
-
     /* Optional: callback to run at start to set migration parameters */
     TestMigrateStartHook start_hook;
     /* Optional: callback to run at finish to cleanup */
@@ -757,7 +754,7 @@ typedef struct {
 } MigrateCommon;
 
 static void test_migrate_start(GuestState *from, GuestState *to,
-                               const char *uri, MigrateStart *args)
+                               MigrateStart *args)
 {
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
@@ -797,7 +794,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
                                  to->name,
                                  to->memory_size,
                                  to->serial_path,
-                                 to->uri ? to->uri : uri,
+                                 to->uri ? to->uri : "defer",
                                  to->arch_opts ? to->arch_opts : "",
                                  to->arch_target ? to->arch_target : "",
                                  to->shmem_opts ? to->shmem_opts : "",
@@ -1192,7 +1189,7 @@ static void migrate_postcopy_prepare(GuestState *from,
                                      MigrateCommon *args)
 {
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, NULL, &args->start);
+    test_migrate_start(from, to, &args->start);
 
     if (args->start_hook) {
         args->postcopy_data = args->start_hook(from, to);
@@ -1424,7 +1421,7 @@ static void test_baddest(void)
     guest_hide_stderr(from);
     guest_hide_stderr(to);
     guest_set_uri(to, "tcp:127.0.0.1:0");
-    test_migrate_start(from, to, NULL, &args);
+    test_migrate_start(from, to, &args);
     /*
      * Don't change to do_migrate(). We are using a wrong uri on purpose.
      */
@@ -1438,7 +1435,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
 {
     void *data_hook = NULL;
 
-    test_migrate_start(from, to, args->listen_uri, &args->start);
+    test_migrate_start(from, to, &args->start);
 
     if (args->start_hook) {
         data_hook = args->start_hook(from, to);
@@ -1620,7 +1617,7 @@ static void test_ignore_shared(void)
     guest_use_shmem(from);
     guest_use_shmem(to);
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, NULL, &args);
+    test_migrate_start(from, to, &args);
 
     migrate_set_capability(from->qs, "x-ignore-shared", true);
     migrate_set_capability(to->qs, "x-ignore-shared", true);
@@ -1921,7 +1918,6 @@ static void test_migrate_fd_proto(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_fd_start_hook,
         .finish_hook = test_migrate_fd_finish_hook
     };
@@ -1933,7 +1929,7 @@ static void do_test_validate_uuid(GuestState *from, GuestState *to,
                                   MigrateStart *args, bool should_fail)
 {
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, NULL, args);
+    test_migrate_start(from, to, args);
 
     /*
      * UUID validation is at the begin of migration. So, the main process of
@@ -2036,7 +2032,7 @@ static void test_migrate_auto_converge(void)
     const int64_t init_pct = 5, inc_pct = 25, max_pct = 95;
 
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, NULL, &args);
+    test_migrate_start(from, to, &args);
 
     migrate_set_capability(from->qs, "auto-converge", true);
     migrate_set_parameter_int(from->qs, "cpu-throttle-initial", init_pct);
@@ -2138,7 +2134,6 @@ static void test_multifd_tcp_none(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_precopy_tcp_multifd_start,
         /*
          * Multifd is more complicated than most of the features, it
@@ -2155,7 +2150,6 @@ static void test_multifd_tcp_zlib(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_precopy_tcp_multifd_zlib_start,
     };
     test_precopy_common(from, to, &args);
@@ -2167,7 +2161,6 @@ static void test_multifd_tcp_zstd(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_precopy_tcp_multifd_zstd_start,
     };
     test_precopy_common(from, to, &args);
@@ -2237,7 +2230,6 @@ static void test_multifd_tcp_tls_psk_match(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tcp_tls_psk_start_match,
         .finish_hook = test_migrate_tls_psk_finish,
     };
@@ -2249,7 +2241,6 @@ static void test_multifd_tcp_tls_psk_mismatch(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tcp_tls_psk_start_mismatch,
         .finish_hook = test_migrate_tls_psk_finish,
         .result = MIG_TEST_FAIL,
@@ -2265,7 +2256,6 @@ static void test_multifd_tcp_tls_x509_default_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_default_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
@@ -2277,7 +2267,6 @@ static void test_multifd_tcp_tls_x509_override_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_override_host,
         .finish_hook = test_migrate_tls_x509_finish,
     };
@@ -2302,7 +2291,6 @@ static void test_multifd_tcp_tls_x509_mismatch_host(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_mismatch_host,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
@@ -2317,7 +2305,6 @@ static void test_multifd_tcp_tls_x509_allow_anon_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_allow_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
     };
@@ -2329,7 +2316,6 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     MigrateCommon args = {
-        .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_reject_anon_client,
         .finish_hook = test_migrate_tls_x509_finish,
         .result = MIG_TEST_FAIL,
@@ -2362,7 +2348,7 @@ static void test_multifd_tcp_cancel(void)
     guest_hide_stderr(from);
     guest_hide_stderr(to);
 
-    test_migrate_start(from, to, "defer", &args);
+    test_migrate_start(from, to, &args);
 
     migrate_ensure_non_converge(from->qs);
 
@@ -2396,7 +2382,7 @@ static void test_multifd_tcp_cancel(void)
         .only_target = true,
     };
 
-    test_migrate_start(from, to2, "defer", &args);
+    test_migrate_start(from, to2, &args);
 
     migrate_set_parameter_int(to2->qs, "multifd-channels", 16);
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 37/42] migration-test: Create get_event GuestState variable
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (35 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 36/42] migration-test: Remove unused listen_uri Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 38/42] migration-test: Create guest_realize() Juan Quintela
                   ` (4 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So we don't use a global variable for events.  We use one by guest.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 48 +++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 95b7c9ed73..a96eb3eec7 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -41,8 +41,6 @@
 #endif
 
 static bool uffd_feature_thread_id;
-static bool got_src_stop;
-static bool got_dst_resume;
 
 /*
  * Dirtylimit stop working if dirty page rate error
@@ -172,6 +170,7 @@ typedef struct {
     gchar *uri;
     unsigned start_address;
     unsigned end_address;
+    bool got_event;
 } GuestState;
 
 static GuestState *guest_create(const char *name)
@@ -396,21 +395,21 @@ static void read_blocktime(QTestState *who)
     qobject_unref(rsp_return);
 }
 
-static void wait_for_migration_pass(QTestState *who)
+static void wait_for_migration_pass(GuestState *who)
 {
-    uint64_t initial_pass = get_migration_pass(who);
+    uint64_t initial_pass = get_migration_pass(who->qs);
     uint64_t pass;
 
     /* Wait for the 1st sync */
-    while (!got_src_stop && !initial_pass) {
+    while (!who->got_event && !initial_pass) {
         usleep(1000);
-        initial_pass = get_migration_pass(who);
+        initial_pass = get_migration_pass(who->qs);
     }
 
     do {
         usleep(1000);
-        pass = get_migration_pass(who);
-    } while (pass == initial_pass && !got_src_stop);
+        pass = get_migration_pass(who->qs);
+    } while (pass == initial_pass && !who->got_event);
 }
 
 static void check_guests_ram(GuestState *who)
@@ -657,7 +656,7 @@ static void migrate_postcopy_start(GuestState *from, GuestState *to)
     qtest_qmp_assert_success(from->qs,
                              "{ 'execute': 'migrate-start-postcopy' }");
 
-    if (!got_src_stop) {
+    if (!from->got_event) {
         qtest_qmp_eventwait(from->qs, "STOP");
     }
 
@@ -759,9 +758,6 @@ static void test_migrate_start(GuestState *from, GuestState *to,
     g_autofree gchar *cmd_source = NULL;
     g_autofree gchar *cmd_target = NULL;
 
-    got_src_stop = false;
-    got_dst_resume = false;
-
     cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
                                  "-name %s,debug-threads=on "
                                  "-m %s "
@@ -781,7 +777,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
         from->qs = qtest_init(cmd_source);
         qtest_qmp_set_event_callback(from->qs,
                                      migrate_watch_for_stop,
-                                     &got_src_stop);
+                                     &from->got_event);
     }
 
     cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
@@ -803,7 +799,7 @@ static void test_migrate_start(GuestState *from, GuestState *to,
     to->qs = qtest_init(cmd_target);
     qtest_qmp_set_event_callback(to->qs,
                                  migrate_watch_for_resume,
-                                 &got_dst_resume);
+                                 &to->got_event);
 }
 
 static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
@@ -1211,7 +1207,7 @@ static void migrate_postcopy_prepare(GuestState *from,
 
     do_migrate(from, to);
 
-    wait_for_migration_pass(from->qs);
+    wait_for_migration_pass(from);
 }
 
 static void migrate_postcopy_complete(GuestState *from, GuestState *to,
@@ -1464,7 +1460,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
          */
         if (args->result == MIG_TEST_SUCCEED) {
             qtest_qmp_assert_success(from->qs, "{ 'execute' : 'stop'}");
-            if (!got_src_stop) {
+            if (!from->got_event) {
                 qtest_qmp_eventwait(from->qs, "STOP");
             }
             migrate_ensure_converge(from->qs);
@@ -1484,10 +1480,10 @@ static void test_precopy_common(GuestState *from, GuestState *to,
         if (args->live) {
             if (args->iterations) {
                 while (args->iterations--) {
-                    wait_for_migration_pass(from->qs);
+                    wait_for_migration_pass(from);
                 }
             } else {
-                wait_for_migration_pass(from->qs);
+                wait_for_migration_pass(from);
             }
 
             migrate_ensure_converge(from->qs);
@@ -1498,7 +1494,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
              */
             wait_for_migration_complete(from->qs);
 
-            if (!got_src_stop) {
+            if (!from->got_event) {
                 qtest_qmp_eventwait(from->qs, "STOP");
             }
         } else {
@@ -1513,7 +1509,7 @@ static void test_precopy_common(GuestState *from, GuestState *to,
             qtest_qmp_assert_success(to->qs, "{ 'execute' : 'cont'}");
         }
 
-        if (!got_dst_resume) {
+        if (!to->got_event) {
             qtest_qmp_eventwait(to->qs, "RESUME");
         }
 
@@ -1627,9 +1623,9 @@ static void test_ignore_shared(void)
 
     do_migrate(from, to);
 
-    wait_for_migration_pass(from->qs);
+    wait_for_migration_pass(from);
 
-    if (!got_src_stop) {
+    if (!from->got_event) {
         qtest_qmp_eventwait(from->qs, "STOP");
     }
 
@@ -2062,7 +2058,7 @@ static void test_migrate_auto_converge(void)
             break;
         }
         usleep(20);
-        g_assert_false(got_src_stop);
+        g_assert_false(from->got_event);
     } while (true);
     /* The first percentage of throttling should be at least init_pct */
     g_assert_cmpint(percentage, >=, init_pct);
@@ -2368,7 +2364,7 @@ static void test_multifd_tcp_cancel(void)
 
     do_migrate(from, to);
 
-    wait_for_migration_pass(from->qs);
+    wait_for_migration_pass(from);
 
     migrate_cancel(from->qs);
 
@@ -2399,9 +2395,9 @@ static void test_multifd_tcp_cancel(void)
 
     do_migrate(from, to2);
 
-    wait_for_migration_pass(from->qs);
+    wait_for_migration_pass(from);
 
-    if (!got_src_stop) {
+    if (!from->got_event) {
         qtest_qmp_eventwait(from->qs, "STOP");
     }
     qtest_qmp_eventwait(to2->qs, "RESUME");
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 38/42] migration-test: Create guest_realize()
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (36 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 37/42] migration-test: Create get_event GuestState variable Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 39/42] migration-test: Unfold test_migrate_end() into three functions Juan Quintela
                   ` (3 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

So we can get rid of the duplication in test_migrate_start().
- unfold test_migrate_start() because it is just two calls to
  guest_realize().
- make dirty_limit test use guest_realize()
- get rid of MigrateStart as now it is empty.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 147 +++++++++++++----------------------
 1 file changed, 54 insertions(+), 93 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index a96eb3eec7..29147b2be3 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -233,6 +233,39 @@ static void guest_destroy(GuestState *vm)
     g_free(vm);
 }
 
+static void guest_realize(GuestState *who)
+{
+    bool target = false;
+    if (strncmp(who->name, "target", strlen("target")) == 0) {
+        target = true;
+    }
+    gchar *
+    cmd = g_strdup_printf("-accel kvm%s -accel tcg "
+                          "-name %s,debug-threads=on "
+                          "-m %s "
+                          "-serial file:%s "
+                          "%s %s "
+                          "%s %s %s %s %s",
+                          who->kvm_opts ? who->kvm_opts : "",
+                          who->name,
+                          who->memory_size,
+                          who->serial_path,
+                          target ? "-incoming" : "",
+                          target ? who->uri ? who->uri : "defer"
+                                 : "",
+                          who->arch_opts ? who->arch_opts : "",
+                          target ? who->arch_target ? who->arch_target : ""
+                                 : who->arch_source ? who->arch_source : "",
+                          who->shmem_opts ? who->shmem_opts : "",
+                          who->extra_opts ? who->extra_opts : "",
+                          who->hide_stderr ? who->hide_stderr : "");
+    who->qs = qtest_init(cmd);
+    qtest_qmp_set_event_callback(who->qs,
+                                 target ? migrate_watch_for_resume
+                                        : migrate_watch_for_stop,
+                                 &who->got_event);
+}
+
 static void guest_use_dirty_ring(GuestState *vm)
 {
     g_assert(vm->kvm_opts == NULL);
@@ -674,11 +707,6 @@ static void do_migrate(GuestState *from, GuestState *to)
     }
 }
 
-typedef struct {
-    /* only launch the target process */
-    bool only_target;
-} MigrateStart;
-
 /*
  * A hook that runs after the src and dst QEMUs have been
  * created, but before the migration is started. This can
@@ -702,9 +730,6 @@ typedef void (*TestMigrateFinishHook)(GuestState *from, GuestState *to,
                                       void *opaque);
 
 typedef struct {
-    /* Optional: fine tune start parameters */
-    MigrateStart start;
-
     /* Optional: callback to run at start to set migration parameters */
     TestMigrateStartHook start_hook;
     /* Optional: callback to run at finish to cleanup */
@@ -752,56 +777,6 @@ typedef struct {
     bool postcopy_preempt;
 } MigrateCommon;
 
-static void test_migrate_start(GuestState *from, GuestState *to,
-                               MigrateStart *args)
-{
-    g_autofree gchar *cmd_source = NULL;
-    g_autofree gchar *cmd_target = NULL;
-
-    cmd_source = g_strdup_printf("-accel kvm%s -accel tcg "
-                                 "-name %s,debug-threads=on "
-                                 "-m %s "
-                                 "-serial file:%s "
-                                 "%s %s %s %s %s",
-                                 from->kvm_opts ? from->kvm_opts : "",
-                                 from->name,
-                                 from->memory_size,
-                                 from->serial_path,
-                                 from->arch_opts ? from->arch_opts : "",
-                                 from->arch_source ? from->arch_source : "",
-                                 from->shmem_opts ? from->shmem_opts : "",
-                                 from->extra_opts ? from->extra_opts : "",
-                                 from->hide_stderr ? from->hide_stderr : "");
-
-    if (!args->only_target) {
-        from->qs = qtest_init(cmd_source);
-        qtest_qmp_set_event_callback(from->qs,
-                                     migrate_watch_for_stop,
-                                     &from->got_event);
-    }
-
-    cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
-                                 "-name %s,debug-threads=on "
-                                 "-m %s "
-                                 "-serial file:%s "
-                                 "-incoming %s "
-                                 "%s %s %s %s %s",
-                                 to->kvm_opts ? to->kvm_opts : "",
-                                 to->name,
-                                 to->memory_size,
-                                 to->serial_path,
-                                 to->uri ? to->uri : "defer",
-                                 to->arch_opts ? to->arch_opts : "",
-                                 to->arch_target ? to->arch_target : "",
-                                 to->shmem_opts ? to->shmem_opts : "",
-                                 to->extra_opts ? to->extra_opts : "",
-                                 to->hide_stderr ? to->hide_stderr : "");
-    to->qs = qtest_init(cmd_target);
-    qtest_qmp_set_event_callback(to->qs,
-                                 migrate_watch_for_resume,
-                                 &to->got_event);
-}
-
 static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
 {
     unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
@@ -1185,7 +1160,8 @@ static void migrate_postcopy_prepare(GuestState *from,
                                      MigrateCommon *args)
 {
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, &args->start);
+    guest_realize(from);
+    guest_realize(to);
 
     if (args->start_hook) {
         args->postcopy_data = args->start_hook(from, to);
@@ -1410,14 +1386,14 @@ static void test_postcopy_preempt_all(void)
 
 static void test_baddest(void)
 {
-    MigrateStart args = { };
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
     guest_set_uri(to, "tcp:127.0.0.1:0");
-    test_migrate_start(from, to, &args);
+    guest_realize(from);
+    guest_realize(to);
     /*
      * Don't change to do_migrate(). We are using a wrong uri on purpose.
      */
@@ -1431,7 +1407,8 @@ static void test_precopy_common(GuestState *from, GuestState *to,
 {
     void *data_hook = NULL;
 
-    test_migrate_start(from, to, &args->start);
+    guest_realize(from);
+    guest_realize(to);
 
     if (args->start_hook) {
         data_hook = args->start_hook(from, to);
@@ -1608,12 +1585,12 @@ static void test_ignore_shared(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = { };
 
     guest_use_shmem(from);
     guest_use_shmem(to);
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, &args);
+    guest_realize(from);
+    guest_realize(to);
 
     migrate_set_capability(from->qs, "x-ignore-shared", true);
     migrate_set_capability(to->qs, "x-ignore-shared", true);
@@ -1922,10 +1899,11 @@ static void test_migrate_fd_proto(void)
 #endif /* _WIN32 */
 
 static void do_test_validate_uuid(GuestState *from, GuestState *to,
-                                  MigrateStart *args, bool should_fail)
+                                  bool should_fail)
 {
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, args);
+    guest_realize(from);
+    guest_realize(to);
 
     /*
      * UUID validation is at the begin of migration. So, the main process of
@@ -1954,48 +1932,44 @@ static void test_validate_uuid(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = { };
 
     guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
     guest_extra_opts(to, "-uuid 11111111-1111-1111-1111-111111111111");
-    do_test_validate_uuid(from, to, &args, false);
+    do_test_validate_uuid(from, to, false);
 }
 
 static void test_validate_uuid_error(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = { };
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
     guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
     guest_extra_opts(to, "-uuid 22222222-2222-2222-2222-222222222222");
-    do_test_validate_uuid(from, to, &args, true);
+    do_test_validate_uuid(from, to, true);
 }
 
 static void test_validate_uuid_src_not_set(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = { };
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
     guest_extra_opts(to, "-uuid 22222222-2222-2222-2222-222222222222");
-    do_test_validate_uuid(from, to, &args, false);
+    do_test_validate_uuid(from, to, false);
 }
 
 static void test_validate_uuid_dst_not_set(void)
 {
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
-    MigrateStart args = { };
 
     guest_hide_stderr(from);
     guest_hide_stderr(to);
     guest_extra_opts(from, "-uuid 11111111-1111-1111-1111-111111111111");
-    do_test_validate_uuid(from, to, &args, false);
+    do_test_validate_uuid(from, to, false);
 }
 
 /*
@@ -2015,7 +1989,6 @@ static void test_validate_uuid_dst_not_set(void)
  */
 static void test_migrate_auto_converge(void)
 {
-    MigrateStart args = {};
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     int64_t percentage;
@@ -2028,7 +2001,8 @@ static void test_migrate_auto_converge(void)
     const int64_t init_pct = 5, inc_pct = 25, max_pct = 95;
 
     guest_listen_unix_socket(to);
-    test_migrate_start(from, to, &args);
+    guest_realize(from);
+    guest_realize(to);
 
     migrate_set_capability(from->qs, "auto-converge", true);
     migrate_set_parameter_int(from->qs, "cpu-throttle-initial", init_pct);
@@ -2336,7 +2310,6 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
  */
 static void test_multifd_tcp_cancel(void)
 {
-    MigrateStart args = { };
     GuestState *from = guest_create("source");
     GuestState *to = guest_create("target");
     GuestState *to2 = guest_create("target2");
@@ -2344,7 +2317,8 @@ static void test_multifd_tcp_cancel(void)
     guest_hide_stderr(from);
     guest_hide_stderr(to);
 
-    test_migrate_start(from, to, &args);
+    guest_realize(from);
+    guest_realize(to);
 
     migrate_ensure_non_converge(from->qs);
 
@@ -2374,11 +2348,7 @@ static void test_multifd_tcp_cancel(void)
 
     guest_destroy(to);
 
-    args = (MigrateStart){
-        .only_target = true,
-    };
-
-    test_migrate_start(from, to2, &args);
+    guest_realize(to2);
 
     migrate_set_parameter_int(to2->qs, "multifd-channels", 16);
 
@@ -2542,17 +2512,8 @@ static GuestState *dirtylimit_start_vm(void)
     GuestState *vm = guest_create("dirtylimit-test");
 
     guest_use_dirty_ring(vm);
+    guest_realize(vm);
 
-    g_autofree gchar *
-    cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
-                          "-name dirtylimit-test,debug-threads=on "
-                          "-m 150M -smp 1 "
-                          "-serial file:%s "
-                          "-drive file=%s,format=raw ",
-                          vm->serial_path,
-                          bootpath);
-
-    vm->qs = qtest_init(cmd);
     return vm;
 }
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 39/42] migration-test: Unfold test_migrate_end() into three functions
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (37 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 38/42] migration-test: Create guest_realize() Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 40/42] migration-test: Create migrate_incoming() function Juan Quintela
                   ` (2 subsequent siblings)
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

guest_destroy(from)
test_migrate_check(from, to): depending of test value
guest_destroy(to);

This mimics previous change that split test_migrate_start()

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 63 ++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 28 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 29147b2be3..1a03077166 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -777,33 +777,26 @@ typedef struct {
     bool postcopy_preempt;
 } MigrateCommon;
 
-static void test_migrate_end(GuestState *from, GuestState *to, bool test_dest)
+static void test_migrate_check(GuestState *from, GuestState *to)
 {
     unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
 
-    guest_destroy(from);
+    qtest_memread(to->qs, to->start_address, &dest_byte_a, 1);
 
-    if (test_dest) {
-        qtest_memread(to->qs, to->start_address, &dest_byte_a, 1);
+    /* Destination still running, wait for a byte to change */
+    do {
+        qtest_memread(to->qs, to->start_address, &dest_byte_b, 1);
+        usleep(1000 * 10);
+    } while (dest_byte_a == dest_byte_b);
 
-        /* Destination still running, wait for a byte to change */
-        do {
-            qtest_memread(to->qs, to->start_address, &dest_byte_b, 1);
-            usleep(1000 * 10);
-        } while (dest_byte_a == dest_byte_b);
+    qtest_qmp_assert_success(to->qs, "{ 'execute' : 'stop'}");
 
-        qtest_qmp_assert_success(to->qs, "{ 'execute' : 'stop'}");
-
-        /* With it stopped, check nothing changes */
-        qtest_memread(to->qs, to->start_address, &dest_byte_c, 1);
-        usleep(1000 * 200);
-        qtest_memread(to->qs, to->start_address, &dest_byte_d, 1);
-        g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
-
-        check_guests_ram(to);
-    }
-
-    guest_destroy(to);
+    /* With it stopped, check nothing changes */
+    qtest_memread(to->qs, to->start_address, &dest_byte_c, 1);
+    usleep(1000 * 200);
+    qtest_memread(to->qs, to->start_address, &dest_byte_d, 1);
+    g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
+    check_guests_ram(to);
 }
 
 #ifdef CONFIG_GNUTLS
@@ -1203,7 +1196,9 @@ static void migrate_postcopy_complete(GuestState *from, GuestState *to,
         args->postcopy_data = NULL;
     }
 
-    test_migrate_end(from, to, true);
+    guest_destroy(from);
+    test_migrate_check(from, to);
+    guest_destroy(to);
 }
 
 static void test_postcopy_common(GuestState *from, GuestState *to,
@@ -1399,7 +1394,8 @@ static void test_baddest(void)
      */
     migrate_qmp(from->qs, "tcp:127.0.0.1:0", "{}");
     wait_for_migration_fail(from->qs, false);
-    test_migrate_end(from, to, false);
+    guest_destroy(from);
+    guest_destroy(to);
 }
 
 static void test_precopy_common(GuestState *from, GuestState *to,
@@ -1497,7 +1493,11 @@ static void test_precopy_common(GuestState *from, GuestState *to,
         args->finish_hook(from, to, data_hook);
     }
 
-    test_migrate_end(from, to, args->result == MIG_TEST_SUCCEED);
+    guest_destroy(from);
+    if (args->result == MIG_TEST_SUCCEED) {
+        test_migrate_check(from, to);
+    }
+    guest_destroy(to);
 }
 
 static void test_precopy_unix_plain(void)
@@ -1615,7 +1615,9 @@ static void test_ignore_shared(void)
     g_assert_cmpint(
         read_ram_property_int(from->qs, "transferred"), <, 1024 * 1024);
 
-    test_migrate_end(from, to, true);
+    guest_destroy(from);
+    test_migrate_check(from, to);
+    guest_destroy(to);
 }
 
 static void *
@@ -1925,7 +1927,8 @@ static void do_test_validate_uuid(GuestState *from, GuestState *to,
         wait_for_migration_complete(from->qs);
     }
 
-    test_migrate_end(from, to, false);
+    guest_destroy(from);
+    guest_destroy(to);
 }
 
 static void test_validate_uuid(void)
@@ -2055,7 +2058,9 @@ static void test_migrate_auto_converge(void)
     wait_for_serial(to);
     wait_for_migration_complete(from->qs);
 
-    test_migrate_end(from, to, true);
+    guest_destroy(from);
+    test_migrate_check(from, to);
+    guest_destroy(to);
 }
 
 static void *
@@ -2374,7 +2379,9 @@ static void test_multifd_tcp_cancel(void)
 
     wait_for_serial(to2);
     wait_for_migration_complete(from->qs);
-    test_migrate_end(from, to2, true);
+    guest_destroy(from);
+    test_migrate_check(from, to2);
+    guest_destroy(to2);
 }
 
 static void calc_dirty_rate(QTestState *who, uint64_t calc_time)
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 40/42] migration-test: Create migrate_incoming() function
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (38 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 39/42] migration-test: Unfold test_migrate_end() into three functions Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 41/42] migration-test: Move functions to migration-helpers.c Juan Quintela
  2023-06-08 22:49 ` [PATCH 42/42] migration-test: Split vcpu-dirty-limit-test Juan Quintela
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 1a03077166..d8479abb4a 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -684,6 +684,13 @@ static void migrate_set_capability(QTestState *who, const char *capability,
                              capability, value);
 }
 
+static void migrate_incoming(GuestState *who, const char *uri)
+{
+    qtest_qmp_assert_success(who->qs, "{ 'execute': 'migrate-incoming',"
+                             "  'arguments': { 'uri': %s }}", uri);
+    guest_set_uri(who, uri);
+}
+
 static void migrate_postcopy_start(GuestState *from, GuestState *to)
 {
     qtest_qmp_assert_success(from->qs,
@@ -1851,9 +1858,7 @@ static void *test_migrate_fd_start_hook(GuestState *from, GuestState *to)
     close(pair[0]);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
-                             "  'arguments': { 'uri': 'fd:fd-mig' }}");
-    guest_set_uri(to, "fd:fd-mig");
+    migrate_incoming(to, "fd:fd-mig");
 
     /* Send the 2nd socket to the target */
     qtest_qmp_fds_assert_success(from->qs, &pair[1], 1,
@@ -2077,9 +2082,7 @@ test_migrate_precopy_tcp_multifd_start_common(GuestState *from, GuestState *to,
     migrate_set_capability(to->qs, "multifd", true);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
-                             "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
-    guest_set_uri(to, "tcp:127.0.0.1:0");
+    migrate_incoming(to, "tcp:127.0.0.1:0");
 
     return NULL;
 }
@@ -2334,9 +2337,7 @@ static void test_multifd_tcp_cancel(void)
     migrate_set_capability(to->qs, "multifd", true);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to->qs, "{ 'execute': 'migrate-incoming',"
-                             "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
-    guest_set_uri(to, "tcp:127.0.0.1:0");
+    migrate_incoming(to, "tcp:127.0.0.1:0");
 
     /* Wait for the first serial output from the source */
     wait_for_serial(from);
@@ -2360,9 +2361,7 @@ static void test_multifd_tcp_cancel(void)
     migrate_set_capability(to2->qs, "multifd", true);
 
     /* Start incoming migration from the 1st socket */
-    qtest_qmp_assert_success(to2->qs, "{ 'execute': 'migrate-incoming',"
-                             "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
-    guest_set_uri(to2, "tcp:127.0.0.1:0");
+    migrate_incoming(to2, "tcp:127.0.0.1:0");
 
     wait_for_migration_status(from->qs, "cancelled", NULL);
 
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 41/42] migration-test: Move functions to migration-helpers.c
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (39 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 40/42] migration-test: Create migrate_incoming() function Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  2023-06-08 22:49 ` [PATCH 42/42] migration-test: Split vcpu-dirty-limit-test Juan Quintela
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

This will help on next patch to split vcpu-dirty-limit-test.c

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-helpers.h |  39 +++++
 tests/qtest/migration-helpers.c | 242 +++++++++++++++++++++++++++++
 tests/qtest/migration-test.c    | 260 --------------------------------
 3 files changed, 281 insertions(+), 260 deletions(-)

diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 009e250e90..6096ffd82a 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -15,6 +15,8 @@
 
 #include "libqtest.h"
 
+extern char *tmpfs;
+
 bool migrate_watch_for_stop(QTestState *who, const char *name,
                             QDict *event, void *opaque);
 bool migrate_watch_for_resume(QTestState *who, const char *name,
@@ -33,4 +35,41 @@ void wait_for_migration_complete(QTestState *who);
 
 void wait_for_migration_fail(QTestState *from, bool allow_active);
 
+typedef struct {
+    QTestState *qs;
+    /* options for source and target */
+    gchar *arch_opts;
+    gchar *arch_source;
+    gchar *arch_target;
+    const gchar *extra_opts;
+    const gchar *hide_stderr;
+    gchar *kvm_opts;
+    const gchar *memory_size;
+    /*
+     * name must *not* contain "target" if it is the target of a
+     * migration.
+     */
+    const gchar *name;
+    gchar *serial_path;
+    gchar *shmem_opts;
+    gchar *shmem_path;
+    gchar *unix_socket;
+    gchar *uri;
+    unsigned start_address;
+    unsigned end_address;
+    bool got_event;
+} GuestState;
+
+GuestState *guest_create(const char *name);
+void guest_destroy(GuestState *vm);
+void guest_realize(GuestState *who);
+void guest_use_dirty_ring(GuestState *vm);
+
+void wait_for_serial(GuestState *vm);
+
+void bootfile_create(char *dir);
+void bootfile_delete(void);
+
+bool kvm_dirty_ring_supported(void);
+
 #endif /* MIGRATION_HELPERS_H */
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index be00c52d00..ffdc689a88 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -13,8 +13,23 @@
 #include "qemu/osdep.h"
 #include "qapi/qmp/qjson.h"
 
+#include "tests/migration/migration-test.h"
 #include "migration-helpers.h"
 
+#if defined(__linux__)
+#include <sys/syscall.h>
+#include <sys/ioctl.h>
+#include <sys/vfs.h>
+#endif
+
+/* For dirty ring test; so far only x86_64 is supported */
+#if defined(__linux__) && defined(HOST_X86_64)
+#include "linux/kvm.h"
+#endif
+
+char *tmpfs;
+static char *bootpath;
+
 /*
  * Number of seconds we wait when looking for migration
  * status changes, to avoid test suite hanging forever
@@ -180,3 +195,230 @@ void wait_for_migration_fail(QTestState *from, bool allow_active)
     g_assert(qdict_get_bool(rsp_return, "running"));
     qobject_unref(rsp_return);
 }
+
+/* The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
+ */
+#include "tests/migration/i386/a-b-bootblock.h"
+#include "tests/migration/aarch64/a-b-kernel.h"
+#include "tests/migration/s390x/a-b-bios.h"
+
+void bootfile_create(char *dir)
+{
+    const char *arch = qtest_get_arch();
+    unsigned char *content;
+    size_t len;
+
+    bootpath = g_strdup_printf("%s/bootsect", dir);
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        /* the assembled x86 boot sector should be exactly one sector large */
+        g_assert(sizeof(x86_bootsect) == 512);
+        content = x86_bootsect;
+        len = sizeof(x86_bootsect);
+    } else if (g_str_equal(arch, "s390x")) {
+        content = s390x_elf;
+        len = sizeof(s390x_elf);
+    } else if (strcmp(arch, "ppc64") == 0) {
+        /*
+         * sane architectures can be programmed at the boot prompt
+         */
+        return;
+    } else if (strcmp(arch, "aarch64") == 0) {
+        content = aarch64_kernel;
+        len = sizeof(aarch64_kernel);
+        g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
+    } else {
+        g_assert_not_reached();
+    }
+
+    FILE *bootfile = fopen(bootpath, "wb");
+
+    g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
+    fclose(bootfile);
+}
+
+void bootfile_delete(void)
+{
+    unlink(bootpath);
+    g_free(bootpath);
+    bootpath = NULL;
+}
+
+GuestState *guest_create(const char *name)
+{
+    GuestState *vm = g_new0(GuestState, 1);
+    const char *arch = qtest_get_arch();
+
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        vm->memory_size = "150M";
+        vm->arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
+        vm->start_address = X86_TEST_MEM_START;
+        vm->end_address = X86_TEST_MEM_END;
+    } else if (g_str_equal(arch, "s390x")) {
+        vm->memory_size = "128M";
+        vm->arch_opts = g_strdup_printf("-bios %s", bootpath);
+        vm->start_address = S390_TEST_MEM_START;
+        vm->end_address = S390_TEST_MEM_END;
+    } else if (strcmp(arch, "ppc64") == 0) {
+        vm->memory_size = "256M";
+        vm->start_address = PPC_TEST_MEM_START;
+        vm->end_address = PPC_TEST_MEM_END;
+        vm->arch_source = g_strdup_printf(
+            "-prom-env 'use-nvramrc?=true' -prom-env "
+            "'nvramrc=hex .\" _\" begin %x %x "
+            "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
+            "until'", vm->end_address, vm->start_address);
+        vm->arch_opts = g_strdup("-nodefaults -machine vsmt=8");
+    } else if (strcmp(arch, "aarch64") == 0) {
+        vm->memory_size = "150M";
+        vm->arch_opts = g_strdup_printf(
+            "-machine virt,gic-version=max -cpu max -kernel %s", bootpath);
+        vm->start_address = ARM_TEST_MEM_START;
+        vm->end_address = ARM_TEST_MEM_END;
+    } else {
+        g_assert_not_reached();
+    }
+
+    vm->name = name;
+    vm->serial_path = g_strdup_printf("%s/%s", tmpfs, vm->name);
+    return vm;
+}
+
+void guest_destroy(GuestState *vm)
+{
+    qtest_quit(vm->qs);
+    g_free(vm->arch_opts);
+    g_free(vm->arch_source);
+    g_free(vm->arch_target);
+    g_free(vm->kvm_opts);
+    unlink(vm->serial_path);
+    g_free(vm->serial_path);
+    g_free(vm->shmem_opts);
+    unlink(vm->shmem_path);
+    g_free(vm->shmem_path);
+    if (vm->unix_socket) {
+        unlink(vm->unix_socket);
+        g_free(vm->unix_socket);
+    }
+    g_free(vm->uri);
+    g_free(vm);
+}
+
+void guest_realize(GuestState *who)
+{
+    bool target = false;
+    if (strncmp(who->name, "target", strlen("target")) == 0) {
+        target = true;
+    }
+    gchar *
+    cmd = g_strdup_printf("-accel kvm%s -accel tcg "
+                          "-name %s,debug-threads=on "
+                          "-m %s "
+                          "-serial file:%s "
+                          "%s %s "
+                          "%s %s %s %s %s",
+                          who->kvm_opts ? who->kvm_opts : "",
+                          who->name,
+                          who->memory_size,
+                          who->serial_path,
+                          target ? "-incoming" : "",
+                          target ? who->uri ? who->uri : "defer"
+                                 : "",
+                          who->arch_opts ? who->arch_opts : "",
+                          target ? who->arch_target ? who->arch_target : ""
+                                 : who->arch_source ? who->arch_source : "",
+                          who->shmem_opts ? who->shmem_opts : "",
+                          who->extra_opts ? who->extra_opts : "",
+                          who->hide_stderr ? who->hide_stderr : "");
+    who->qs = qtest_init(cmd);
+    qtest_qmp_set_event_callback(who->qs,
+                                 target ? migrate_watch_for_resume
+                                        : migrate_watch_for_stop,
+                                 &who->got_event);
+}
+
+void guest_use_dirty_ring(GuestState *vm)
+{
+    g_assert(vm->kvm_opts == NULL);
+    vm->kvm_opts = g_strdup(",dirty-ring-size=4096");
+}
+
+/*
+ * Wait for some output in the serial output file,
+ * we get an 'A' followed by an endless string of 'B's
+ * but on the destination we won't have the A.
+ */
+void wait_for_serial(GuestState *vm)
+{
+    FILE *serialfile = fopen(vm->serial_path, "r");
+    const char *arch = qtest_get_arch();
+    /* see serial_path comment on GuestState definition */
+    int started = (strstr(vm->serial_path, "target") == NULL &&
+                   strcmp(arch, "ppc64") == 0) ? 0 : 1;
+
+    do {
+        int readvalue = fgetc(serialfile);
+
+        if (!started) {
+            /* SLOF prints its banner before starting test,
+             * to ignore it, mark the start of the test with '_',
+             * ignore all characters until this marker
+             */
+            switch (readvalue) {
+            case '_':
+                started = 1;
+                break;
+            case EOF:
+                fseek(serialfile, 0, SEEK_SET);
+                usleep(1000);
+                break;
+            }
+            continue;
+        }
+        switch (readvalue) {
+        case 'A':
+            /* Fine */
+            break;
+
+        case 'B':
+            /* It's alive! */
+            fclose(serialfile);
+            return;
+
+        case EOF:
+            started = (strstr(vm->serial_path, "target") == NULL &&
+                       strcmp(arch, "ppc64") == 0) ? 0 : 1;
+            fseek(serialfile, 0, SEEK_SET);
+            usleep(1000);
+            break;
+
+        default:
+            fprintf(stderr, "Unexpected %d on %s serial\n", readvalue,
+                    vm->serial_path);
+            g_assert_not_reached();
+        }
+    } while (true);
+}
+
+bool kvm_dirty_ring_supported(void)
+{
+#if defined(__linux__) && defined(HOST_X86_64)
+    int ret, kvm_fd = open("/dev/kvm", O_RDONLY);
+
+    if (kvm_fd < 0) {
+        return false;
+    }
+
+    ret = ioctl(kvm_fd, KVM_CHECK_EXTENSION, KVM_CAP_DIRTY_LOG_RING);
+    close(kvm_fd);
+
+    /* We test with 4096 slots */
+    if (ret < 4096) {
+        return false;
+    }
+
+    return true;
+#else
+    return false;
+#endif
+}
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index d8479abb4a..4d3321b7b3 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -35,11 +35,6 @@
 # endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
 
-/* For dirty ring test; so far only x86_64 is supported */
-#if defined(__linux__) && defined(HOST_X86_64)
-#include "linux/kvm.h"
-#endif
-
 static bool uffd_feature_thread_id;
 
 /*
@@ -97,181 +92,6 @@ static bool ufd_version_check(void)
 
 #endif
 
-static char *tmpfs;
-static char *bootpath;
-
-/* The boot file modifies memory area in [start_address, end_address)
- * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
- */
-#include "tests/migration/i386/a-b-bootblock.h"
-#include "tests/migration/aarch64/a-b-kernel.h"
-#include "tests/migration/s390x/a-b-bios.h"
-
-static void bootfile_create(char *dir)
-{
-    const char *arch = qtest_get_arch();
-    unsigned char *content;
-    size_t len;
-
-    bootpath = g_strdup_printf("%s/bootsect", dir);
-    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        /* the assembled x86 boot sector should be exactly one sector large */
-        g_assert(sizeof(x86_bootsect) == 512);
-        content = x86_bootsect;
-        len = sizeof(x86_bootsect);
-    } else if (g_str_equal(arch, "s390x")) {
-        content = s390x_elf;
-        len = sizeof(s390x_elf);
-    } else if (strcmp(arch, "ppc64") == 0) {
-        /*
-         * sane architectures can be programmed at the boot prompt
-         */
-        return;
-    } else if (strcmp(arch, "aarch64") == 0) {
-        content = aarch64_kernel;
-        len = sizeof(aarch64_kernel);
-        g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
-    } else {
-        g_assert_not_reached();
-    }
-
-    FILE *bootfile = fopen(bootpath, "wb");
-
-    g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
-    fclose(bootfile);
-}
-
-static void bootfile_delete(void)
-{
-    unlink(bootpath);
-    g_free(bootpath);
-    bootpath = NULL;
-}
-
-typedef struct {
-    QTestState *qs;
-    /* options for source and target */
-    gchar *arch_opts;
-    gchar *arch_source;
-    gchar *arch_target;
-    const gchar *extra_opts;
-    const gchar *hide_stderr;
-    gchar *kvm_opts;
-    const gchar *memory_size;
-    /*
-     * name must *not* contain "target" if it is the target of a
-     * migration.
-     */
-    const gchar *name;
-    gchar *serial_path;
-    gchar *shmem_opts;
-    gchar *shmem_path;
-    gchar *unix_socket;
-    gchar *uri;
-    unsigned start_address;
-    unsigned end_address;
-    bool got_event;
-} GuestState;
-
-static GuestState *guest_create(const char *name)
-{
-    GuestState *vm = g_new0(GuestState, 1);
-    const char *arch = qtest_get_arch();
-
-    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        vm->memory_size = "150M";
-        vm->arch_opts = g_strdup_printf("-drive file=%s,format=raw", bootpath);
-        vm->start_address = X86_TEST_MEM_START;
-        vm->end_address = X86_TEST_MEM_END;
-    } else if (g_str_equal(arch, "s390x")) {
-        vm->memory_size = "128M";
-        vm->arch_opts = g_strdup_printf("-bios %s", bootpath);
-        vm->start_address = S390_TEST_MEM_START;
-        vm->end_address = S390_TEST_MEM_END;
-    } else if (strcmp(arch, "ppc64") == 0) {
-        vm->memory_size = "256M";
-        vm->start_address = PPC_TEST_MEM_START;
-        vm->end_address = PPC_TEST_MEM_END;
-        vm->arch_source = g_strdup_printf(
-            "-prom-env 'use-nvramrc?=true' -prom-env "
-            "'nvramrc=hex .\" _\" begin %x %x "
-            "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
-            "until'", vm->end_address, vm->start_address);
-        vm->arch_opts = g_strdup("-nodefaults -machine vsmt=8");
-    } else if (strcmp(arch, "aarch64") == 0) {
-        vm->memory_size = "150M";
-        vm->arch_opts = g_strdup_printf(
-            "-machine virt,gic-version=max -cpu max -kernel %s", bootpath);
-        vm->start_address = ARM_TEST_MEM_START;
-        vm->end_address = ARM_TEST_MEM_END;
-    } else {
-        g_assert_not_reached();
-    }
-
-    vm->name = name;
-    vm->serial_path = g_strdup_printf("%s/%s", tmpfs, vm->name);
-    return vm;
-}
-
-static void guest_destroy(GuestState *vm)
-{
-    qtest_quit(vm->qs);
-    g_free(vm->arch_opts);
-    g_free(vm->arch_source);
-    g_free(vm->arch_target);
-    g_free(vm->kvm_opts);
-    unlink(vm->serial_path);
-    g_free(vm->serial_path);
-    g_free(vm->shmem_opts);
-    unlink(vm->shmem_path);
-    g_free(vm->shmem_path);
-    if (vm->unix_socket) {
-        unlink(vm->unix_socket);
-        g_free(vm->unix_socket);
-    }
-    g_free(vm->uri);
-    g_free(vm);
-}
-
-static void guest_realize(GuestState *who)
-{
-    bool target = false;
-    if (strncmp(who->name, "target", strlen("target")) == 0) {
-        target = true;
-    }
-    gchar *
-    cmd = g_strdup_printf("-accel kvm%s -accel tcg "
-                          "-name %s,debug-threads=on "
-                          "-m %s "
-                          "-serial file:%s "
-                          "%s %s "
-                          "%s %s %s %s %s",
-                          who->kvm_opts ? who->kvm_opts : "",
-                          who->name,
-                          who->memory_size,
-                          who->serial_path,
-                          target ? "-incoming" : "",
-                          target ? who->uri ? who->uri : "defer"
-                                 : "",
-                          who->arch_opts ? who->arch_opts : "",
-                          target ? who->arch_target ? who->arch_target : ""
-                                 : who->arch_source ? who->arch_source : "",
-                          who->shmem_opts ? who->shmem_opts : "",
-                          who->extra_opts ? who->extra_opts : "",
-                          who->hide_stderr ? who->hide_stderr : "");
-    who->qs = qtest_init(cmd);
-    qtest_qmp_set_event_callback(who->qs,
-                                 target ? migrate_watch_for_resume
-                                        : migrate_watch_for_stop,
-                                 &who->got_event);
-}
-
-static void guest_use_dirty_ring(GuestState *vm)
-{
-    g_assert(vm->kvm_opts == NULL);
-    vm->kvm_opts = g_strdup(",dirty-ring-size=4096");
-}
-
 static void guest_use_shmem(GuestState *vm)
 {
     g_assert(vm->shmem_opts == NULL);
@@ -324,63 +144,6 @@ static void guest_set_uri(GuestState *vm, const gchar *uri)
     vm->uri = g_strdup(uri);
 }
 
-/*
- * Wait for some output in the serial output file,
- * we get an 'A' followed by an endless string of 'B's
- * but on the destination we won't have the A.
- */
-static void wait_for_serial(GuestState *vm)
-{
-    FILE *serialfile = fopen(vm->serial_path, "r");
-    const char *arch = qtest_get_arch();
-    /* see serial_path comment on GuestState definition */
-    int started = (strstr(vm->serial_path, "target") == NULL &&
-                   strcmp(arch, "ppc64") == 0) ? 0 : 1;
-
-    do {
-        int readvalue = fgetc(serialfile);
-
-        if (!started) {
-            /* SLOF prints its banner before starting test,
-             * to ignore it, mark the start of the test with '_',
-             * ignore all characters until this marker
-             */
-            switch (readvalue) {
-            case '_':
-                started = 1;
-                break;
-            case EOF:
-                fseek(serialfile, 0, SEEK_SET);
-                usleep(1000);
-                break;
-            }
-            continue;
-        }
-        switch (readvalue) {
-        case 'A':
-            /* Fine */
-            break;
-
-        case 'B':
-            /* It's alive! */
-            fclose(serialfile);
-            return;
-
-        case EOF:
-            started = (strstr(vm->serial_path, "target") == NULL &&
-                       strcmp(arch, "ppc64") == 0) ? 0 : 1;
-            fseek(serialfile, 0, SEEK_SET);
-            usleep(1000);
-            break;
-
-        default:
-            fprintf(stderr, "Unexpected %d on %s serial\n", readvalue,
-                    vm->serial_path);
-            g_assert_not_reached();
-        }
-    } while (true);
-}
-
 /*
  * It's tricky to use qemu's migration event capability with qtest,
  * events suddenly appearing confuse the qmp()/hmp() responses.
@@ -2615,29 +2378,6 @@ static void test_vcpu_dirty_limit(void)
     dirtylimit_stop_vm(vm);
 }
 
-static bool kvm_dirty_ring_supported(void)
-{
-#if defined(__linux__) && defined(HOST_X86_64)
-    int ret, kvm_fd = open("/dev/kvm", O_RDONLY);
-
-    if (kvm_fd < 0) {
-        return false;
-    }
-
-    ret = ioctl(kvm_fd, KVM_CHECK_EXTENSION, KVM_CAP_DIRTY_LOG_RING);
-    close(kvm_fd);
-
-    /* We test with 4096 slots */
-    if (ret < 4096) {
-        return false;
-    }
-
-    return true;
-#else
-    return false;
-#endif
-}
-
 static bool shm_supported(void)
 {
     if (g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 42/42] migration-test: Split vcpu-dirty-limit-test
  2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
                   ` (40 preceding siblings ...)
  2023-06-08 22:49 ` [PATCH 41/42] migration-test: Move functions to migration-helpers.c Juan Quintela
@ 2023-06-08 22:49 ` Juan Quintela
  41 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-08 22:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Juan Quintela, Daniel P . Berrangé,
	Leonardo Bras

It is not really a migration test, it just happens that migration
infrastructure is useful to it.

Once there, put migration-helpers.* as maintained.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 MAINTAINERS                         |   3 +-
 tests/qtest/migration-test.c        | 246 ----------------------
 tests/qtest/vcpu-dirty-limit-test.c | 310 ++++++++++++++++++++++++++++
 tests/qtest/meson.build             |   5 +-
 4 files changed, 316 insertions(+), 248 deletions(-)
 create mode 100644 tests/qtest/vcpu-dirty-limit-test.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 436b3f0afe..20de5ae8b5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3176,7 +3176,8 @@ F: include/qemu/userfaultfd.h
 F: migration/
 F: scripts/vmstate-static-checker.py
 F: tests/vmstate-static-checker-data/
-F: tests/qtest/migration-test.c
+F: tests/qtest/migration-*
+F: tests/qtest/vcpu-dirty-limit-test.c
 F: docs/devel/migration.rst
 F: qapi/migration.json
 F: tests/migration/
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 4d3321b7b3..58bb829dcf 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -14,17 +14,11 @@
 
 #include "libqtest.h"
 #include "qapi/error.h"
-#include "qapi/qmp/qdict.h"
-#include "qemu/module.h"
 #include "qemu/option.h"
-#include "qemu/range.h"
 #include "qemu/sockets.h"
-#include "chardev/char.h"
 #include "qapi/qapi-visit-sockets.h"
 #include "qapi/qobject-input-visitor.h"
-#include "qapi/qobject-output-visitor.h"
 #include "crypto/tlscredspsk.h"
-#include "qapi/qmp/qlist.h"
 
 #include "migration-helpers.h"
 #include "tests/migration/migration-test.h"
@@ -37,12 +31,6 @@
 
 static bool uffd_feature_thread_id;
 
-/*
- * Dirtylimit stop working if dirty page rate error
- * value less than DIRTYLIMIT_TOLERANCE_RANGE
- */
-#define DIRTYLIMIT_TOLERANCE_RANGE  25  /* MB/s */
-
 #if defined(__linux__)
 #include <sys/syscall.h>
 #include <sys/vfs.h>
@@ -2146,238 +2134,6 @@ static void test_multifd_tcp_cancel(void)
     guest_destroy(to2);
 }
 
-static void calc_dirty_rate(QTestState *who, uint64_t calc_time)
-{
-    qtest_qmp_assert_success(who,
-                             "{ 'execute': 'calc-dirty-rate',"
-                             "'arguments': { "
-                             "'calc-time': %" PRIu64 ","
-                             "'mode': 'dirty-ring' }}",
-                             calc_time);
-}
-
-static QDict *query_dirty_rate(QTestState *who)
-{
-    return qtest_qmp_assert_success_ref(who,
-                                        "{ 'execute': 'query-dirty-rate' }");
-}
-
-static void dirtylimit_set_all(QTestState *who, uint64_t dirtyrate)
-{
-    qtest_qmp_assert_success(who,
-                             "{ 'execute': 'set-vcpu-dirty-limit',"
-                             "'arguments': { "
-                             "'dirty-rate': %" PRIu64 " } }",
-                             dirtyrate);
-}
-
-static void cancel_vcpu_dirty_limit(QTestState *who)
-{
-    qtest_qmp_assert_success(who,
-                             "{ 'execute': 'cancel-vcpu-dirty-limit' }");
-}
-
-static QDict *query_vcpu_dirty_limit(QTestState *who)
-{
-    QDict *rsp;
-
-    rsp = qtest_qmp(who, "{ 'execute': 'query-vcpu-dirty-limit' }");
-    g_assert(!qdict_haskey(rsp, "error"));
-    g_assert(qdict_haskey(rsp, "return"));
-
-    return rsp;
-}
-
-static bool calc_dirtyrate_ready(QTestState *who)
-{
-    QDict *rsp_return;
-    gchar *status;
-
-    rsp_return = query_dirty_rate(who);
-    g_assert(rsp_return);
-
-    status = g_strdup(qdict_get_str(rsp_return, "status"));
-    g_assert(status);
-
-    return g_strcmp0(status, "measuring");
-}
-
-static void wait_for_calc_dirtyrate_complete(QTestState *who,
-                                             int64_t time_s)
-{
-    int max_try_count = 10000;
-    usleep(time_s * 1000000);
-
-    while (!calc_dirtyrate_ready(who) && max_try_count--) {
-        usleep(1000);
-    }
-
-    /*
-     * Set the timeout with 10 s(max_try_count * 1000us),
-     * if dirtyrate measurement not complete, fail test.
-     */
-    g_assert_cmpint(max_try_count, !=, 0);
-}
-
-static int64_t get_dirty_rate(QTestState *who)
-{
-    QDict *rsp_return;
-    gchar *status;
-    QList *rates;
-    const QListEntry *entry;
-    QDict *rate;
-    int64_t dirtyrate;
-
-    rsp_return = query_dirty_rate(who);
-    g_assert(rsp_return);
-
-    status = g_strdup(qdict_get_str(rsp_return, "status"));
-    g_assert(status);
-    g_assert_cmpstr(status, ==, "measured");
-
-    rates = qdict_get_qlist(rsp_return, "vcpu-dirty-rate");
-    g_assert(rates && !qlist_empty(rates));
-
-    entry = qlist_first(rates);
-    g_assert(entry);
-
-    rate = qobject_to(QDict, qlist_entry_obj(entry));
-    g_assert(rate);
-
-    dirtyrate = qdict_get_try_int(rate, "dirty-rate", -1);
-
-    qobject_unref(rsp_return);
-    return dirtyrate;
-}
-
-static int64_t get_limit_rate(QTestState *who)
-{
-    QDict *rsp_return;
-    QList *rates;
-    const QListEntry *entry;
-    QDict *rate;
-    int64_t dirtyrate;
-
-    rsp_return = query_vcpu_dirty_limit(who);
-    g_assert(rsp_return);
-
-    rates = qdict_get_qlist(rsp_return, "return");
-    g_assert(rates && !qlist_empty(rates));
-
-    entry = qlist_first(rates);
-    g_assert(entry);
-
-    rate = qobject_to(QDict, qlist_entry_obj(entry));
-    g_assert(rate);
-
-    dirtyrate = qdict_get_try_int(rate, "limit-rate", -1);
-
-    qobject_unref(rsp_return);
-    return dirtyrate;
-}
-
-static GuestState *dirtylimit_start_vm(void)
-{
-    GuestState *vm = guest_create("dirtylimit-test");
-
-    guest_use_dirty_ring(vm);
-    guest_realize(vm);
-
-    return vm;
-}
-
-static void dirtylimit_stop_vm(GuestState *vm)
-{
-    guest_destroy(vm);
-}
-
-static void test_vcpu_dirty_limit(void)
-{
-    int64_t origin_rate;
-    int64_t quota_rate;
-    int64_t rate ;
-    int max_try_count = 20;
-    int hit = 0;
-
-    /* Start vm for vcpu dirtylimit test */
-    GuestState *vm = dirtylimit_start_vm();
-
-    /* Wait for the first serial output from the vm*/
-    wait_for_serial(vm);
-
-    /* Do dirtyrate measurement with calc time equals 1s */
-    calc_dirty_rate(vm->qs, 1);
-
-    /* Sleep calc time and wait for calc dirtyrate complete */
-    wait_for_calc_dirtyrate_complete(vm->qs, 1);
-
-    /* Query original dirty page rate */
-    origin_rate = get_dirty_rate(vm->qs);
-
-    /* VM booted from bootsect should dirty memory steadily */
-    assert(origin_rate != 0);
-
-    /* Setup quota dirty page rate at half of origin */
-    quota_rate = origin_rate / 2;
-
-    /* Set dirtylimit */
-    dirtylimit_set_all(vm->qs, quota_rate);
-
-    /*
-     * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
-     * works literally
-     */
-    g_assert_cmpint(quota_rate, ==, get_limit_rate(vm->qs));
-
-    /* Sleep a bit to check if it take effect */
-    usleep(2000000);
-
-    /*
-     * Check if dirtylimit take effect realistically, set the
-     * timeout with 20 s(max_try_count * 1s), if dirtylimit
-     * doesn't take effect, fail test.
-     */
-    while (--max_try_count) {
-        calc_dirty_rate(vm->qs, 1);
-        wait_for_calc_dirtyrate_complete(vm->qs, 1);
-        rate = get_dirty_rate(vm->qs);
-
-        /*
-         * Assume hitting if current rate is less
-         * than quota rate (within accepting error)
-         */
-        if (rate < (quota_rate + DIRTYLIMIT_TOLERANCE_RANGE)) {
-            hit = 1;
-            break;
-        }
-    }
-
-    g_assert_cmpint(hit, ==, 1);
-
-    hit = 0;
-    max_try_count = 20;
-
-    /* Check if dirtylimit cancellation take effect */
-    cancel_vcpu_dirty_limit(vm->qs);
-    while (--max_try_count) {
-        calc_dirty_rate(vm->qs, 1);
-        wait_for_calc_dirtyrate_complete(vm->qs, 1);
-        rate = get_dirty_rate(vm->qs);
-
-        /*
-         * Assume dirtylimit be canceled if current rate is
-         * greater than quota rate (within accepting error)
-         */
-        if (rate > (quota_rate + DIRTYLIMIT_TOLERANCE_RANGE)) {
-            hit = 1;
-            break;
-        }
-    }
-
-    g_assert_cmpint(hit, ==, 1);
-    dirtylimit_stop_vm(vm);
-}
-
 static bool shm_supported(void)
 {
     if (g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
@@ -2566,8 +2322,6 @@ int main(int argc, char **argv)
     if (g_str_equal(arch, "x86_64") && has_kvm && kvm_dirty_ring_supported()) {
         qtest_add_func("/migration/dirty_ring",
                        test_precopy_unix_dirty_ring);
-        qtest_add_func("/migration/vcpu_dirty_limit",
-                       test_vcpu_dirty_limit);
     }
 
     ret = g_test_run();
diff --git a/tests/qtest/vcpu-dirty-limit-test.c b/tests/qtest/vcpu-dirty-limit-test.c
new file mode 100644
index 0000000000..eebcf04509
--- /dev/null
+++ b/tests/qtest/vcpu-dirty-limit-test.c
@@ -0,0 +1,310 @@
+/*
+ * QTest testcase for vcpu-dirty-limit
+ *
+ * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+ *   based on the vhost-user-test.c that is:
+ *      Copyright (c) 2014 Virtual Open Systems Sarl.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "qemu/module.h"
+#include "qapi/qmp/qlist.h"
+
+#include "migration-helpers.h"
+
+/* For dirty ring test */
+#if defined(__linux__) && defined(HOST_X86_64)
+#include "linux/kvm.h"
+#include <sys/ioctl.h>
+#endif
+
+/*
+ * Dirtylimit stop working if dirty page rate error
+ * value less than DIRTYLIMIT_TOLERANCE_RANGE
+ */
+#define DIRTYLIMIT_TOLERANCE_RANGE  25  /* MB/s */
+
+static void calc_dirty_rate(QTestState *who, uint64_t calc_time)
+{
+    qtest_qmp_assert_success(who,
+                             "{ 'execute': 'calc-dirty-rate',"
+                             "'arguments': { "
+                             "'calc-time': %" PRIu64 ","
+                             "'mode': 'dirty-ring' }}",
+                             calc_time);
+}
+
+static QDict *query_dirty_rate(QTestState *who)
+{
+    return qtest_qmp_assert_success_ref(who,
+                                        "{ 'execute': 'query-dirty-rate' }");
+}
+
+static void dirtylimit_set_all(QTestState *who, uint64_t dirtyrate)
+{
+    qtest_qmp_assert_success(who,
+                             "{ 'execute': 'set-vcpu-dirty-limit',"
+                             "'arguments': { "
+                             "'dirty-rate': %" PRIu64 " } }",
+                             dirtyrate);
+}
+
+static void cancel_vcpu_dirty_limit(QTestState *who)
+{
+    qtest_qmp_assert_success(who,
+                             "{ 'execute': 'cancel-vcpu-dirty-limit' }");
+}
+
+static QDict *query_vcpu_dirty_limit(QTestState *who)
+{
+    QDict *rsp;
+
+    rsp = qtest_qmp(who, "{ 'execute': 'query-vcpu-dirty-limit' }");
+    g_assert(!qdict_haskey(rsp, "error"));
+    g_assert(qdict_haskey(rsp, "return"));
+
+    return rsp;
+}
+
+static bool calc_dirtyrate_ready(QTestState *who)
+{
+    QDict *rsp_return;
+    gchar *status;
+
+    rsp_return = query_dirty_rate(who);
+    g_assert(rsp_return);
+
+    status = g_strdup(qdict_get_str(rsp_return, "status"));
+    g_assert(status);
+
+    return g_strcmp0(status, "measuring");
+}
+
+static void wait_for_calc_dirtyrate_complete(QTestState *who,
+                                             int64_t time_s)
+{
+    int max_try_count = 10000;
+    usleep(time_s * 1000000);
+
+    while (!calc_dirtyrate_ready(who) && max_try_count--) {
+        usleep(1000);
+    }
+
+    /*
+     * Set the timeout with 10 s(max_try_count * 1000us),
+     * if dirtyrate measurement not complete, fail test.
+     */
+    g_assert_cmpint(max_try_count, !=, 0);
+}
+
+static int64_t get_dirty_rate(QTestState *who)
+{
+    QDict *rsp_return;
+    gchar *status;
+    QList *rates;
+    const QListEntry *entry;
+    QDict *rate;
+    int64_t dirtyrate;
+
+    rsp_return = query_dirty_rate(who);
+    g_assert(rsp_return);
+
+    status = g_strdup(qdict_get_str(rsp_return, "status"));
+    g_assert(status);
+    g_assert_cmpstr(status, ==, "measured");
+
+    rates = qdict_get_qlist(rsp_return, "vcpu-dirty-rate");
+    g_assert(rates && !qlist_empty(rates));
+
+    entry = qlist_first(rates);
+    g_assert(entry);
+
+    rate = qobject_to(QDict, qlist_entry_obj(entry));
+    g_assert(rate);
+
+    dirtyrate = qdict_get_try_int(rate, "dirty-rate", -1);
+
+    qobject_unref(rsp_return);
+    return dirtyrate;
+}
+
+static int64_t get_limit_rate(QTestState *who)
+{
+    QDict *rsp_return;
+    QList *rates;
+    const QListEntry *entry;
+    QDict *rate;
+    int64_t dirtyrate;
+
+    rsp_return = query_vcpu_dirty_limit(who);
+    g_assert(rsp_return);
+
+    rates = qdict_get_qlist(rsp_return, "return");
+    g_assert(rates && !qlist_empty(rates));
+
+    entry = qlist_first(rates);
+    g_assert(entry);
+
+    rate = qobject_to(QDict, qlist_entry_obj(entry));
+    g_assert(rate);
+
+    dirtyrate = qdict_get_try_int(rate, "limit-rate", -1);
+
+    qobject_unref(rsp_return);
+    return dirtyrate;
+}
+
+static GuestState *dirtylimit_start_vm(void)
+{
+    GuestState *vm = guest_create("dirtylimit-test");
+
+    guest_use_dirty_ring(vm);
+    guest_realize(vm);
+
+    return vm;
+}
+
+static void dirtylimit_stop_vm(GuestState *vm)
+{
+    guest_destroy(vm);
+}
+
+static void test_vcpu_dirty_limit(void)
+{
+    int64_t origin_rate;
+    int64_t quota_rate;
+    int64_t rate ;
+    int max_try_count = 20;
+    int hit = 0;
+
+    /* Start vm for vcpu dirtylimit test */
+    GuestState *vm = dirtylimit_start_vm();
+
+    /* Wait for the first serial output from the vm*/
+    wait_for_serial(vm);
+
+    /* Do dirtyrate measurement with calc time equals 1s */
+    calc_dirty_rate(vm->qs, 1);
+
+    /* Sleep calc time and wait for calc dirtyrate complete */
+    wait_for_calc_dirtyrate_complete(vm->qs, 1);
+
+    /* Query original dirty page rate */
+    origin_rate = get_dirty_rate(vm->qs);
+
+    /* VM booted from bootsect should dirty memory steadily */
+    assert(origin_rate != 0);
+
+    /* Setup quota dirty page rate at half of origin */
+    quota_rate = origin_rate / 2;
+
+    /* Set dirtylimit */
+    dirtylimit_set_all(vm->qs, quota_rate);
+
+    /*
+     * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
+     * works literally
+     */
+    g_assert_cmpint(quota_rate, ==, get_limit_rate(vm->qs));
+
+    /* Sleep a bit to check if it take effect */
+    usleep(2000000);
+
+    /*
+     * Check if dirtylimit take effect realistically, set the
+     * timeout with 20 s(max_try_count * 1s), if dirtylimit
+     * doesn't take effect, fail test.
+     */
+    while (--max_try_count) {
+        calc_dirty_rate(vm->qs, 1);
+        wait_for_calc_dirtyrate_complete(vm->qs, 1);
+        rate = get_dirty_rate(vm->qs);
+
+        /*
+         * Assume hitting if current rate is less
+         * than quota rate (within accepting error)
+         */
+        if (rate < (quota_rate + DIRTYLIMIT_TOLERANCE_RANGE)) {
+            hit = 1;
+            break;
+        }
+    }
+
+    g_assert_cmpint(hit, ==, 1);
+
+    hit = 0;
+    max_try_count = 20;
+
+    /* Check if dirtylimit cancellation take effect */
+    cancel_vcpu_dirty_limit(vm->qs);
+    while (--max_try_count) {
+        calc_dirty_rate(vm->qs, 1);
+        wait_for_calc_dirtyrate_complete(vm->qs, 1);
+        rate = get_dirty_rate(vm->qs);
+
+        /*
+         * Assume dirtylimit be canceled if current rate is
+         * greater than quota rate (within accepting error)
+         */
+        if (rate > (quota_rate + DIRTYLIMIT_TOLERANCE_RANGE)) {
+            hit = 1;
+            break;
+        }
+    }
+
+    g_assert_cmpint(hit, ==, 1);
+    dirtylimit_stop_vm(vm);
+}
+
+int main(int argc, char **argv)
+{
+    g_autoptr(GError) err = NULL;
+
+    g_test_init(&argc, &argv, NULL);
+
+    if (!qtest_has_accel("kvm")) {
+        g_test_skip("No KVM or TCG accelerator available");
+        return 0;
+    }
+
+    if (!g_str_equal(qtest_get_arch(), "x86_64")) {
+        g_test_skip("Only x86_64 support available");
+        return 0;
+    }
+
+    if (!kvm_dirty_ring_supported()) {
+        g_test_skip("KVM dirty ring is not supported");
+        return 0;
+    }
+
+    tmpfs = g_dir_make_tmp("vcpu-dirty-limit-test-XXXXXX", &err);
+    if (!tmpfs) {
+        g_test_message("Can't create temporary directory in %s: %s",
+                       g_get_tmp_dir(), err->message);
+    }
+    g_assert(tmpfs);
+    bootfile_create(tmpfs);
+
+    module_call_init(MODULE_INIT_QOM);
+
+    qtest_add_func("/vcpu_dirty_limit/basic", test_vcpu_dirty_limit);
+
+    int ret = g_test_run();
+
+    g_assert_cmpint(ret, ==, 0);
+
+    bootfile_delete();
+    ret = rmdir(tmpfs);
+    if (ret != 0) {
+        g_test_message("unable to rmdir: path (%s): %s",
+                       tmpfs, strerror(errno));
+    }
+    g_free(tmpfs);
+
+    return ret;
+}
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 5fa6833ad7..ed0d03e3d3 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -9,6 +9,7 @@ slow_qtests = {
   'qos-test' : 60,
   'qom-test' : 300,
   'test-hmp' : 120,
+  'vcpu-dirty-limit' : 150,
 }
 
 qtests_generic = [
@@ -101,7 +102,8 @@ qtests_i386 = \
    'vmgenid-test',
    'migration-test',
    'test-x86-cpuid-compat',
-   'numa-test'
+   'numa-test',
+   'vcpu-dirty-limit-test',
   ]
 
 if dbus_display and targetos != 'windows'
@@ -315,6 +317,7 @@ qtests = {
   'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
   'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'),
   'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'),
+  'vcpu-dirty-limit-test': migration_files,
 }
 
 if vnc.found()
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 76+ messages in thread

* Re: [PATCH 24/42] migration-test: Re-enable multifd_cancel test
  2023-06-08 22:49 ` [PATCH 24/42] migration-test: Re-enable multifd_cancel test Juan Quintela
@ 2023-06-09  7:53   ` Daniel P. Berrangé
  2023-06-09 10:22     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Daniel P. Berrangé @ 2023-06-09  7:53 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:25AM +0200, Juan Quintela wrote:

Please explain why this is considered ok, given the comment about
why it is disabled. ie if we fixed something, refrence the commit.

> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  tests/qtest/migration-test.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 01ab51a391..9f86d9bc80 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2886,14 +2886,8 @@ int main(int argc, char **argv)
>      }
>      qtest_add_func("/migration/multifd/tcp/plain/none",
>                     test_multifd_tcp_none);
> -    /*
> -     * This test is flaky and sometimes fails in CI and otherwise:
> -     * don't run unless user opts in via environment variable.
> -     */
> -    if (getenv("QEMU_TEST_FLAKY_TESTS")) {
> -        qtest_add_func("/migration/multifd/tcp/plain/cancel",
> -                       test_multifd_tcp_cancel);
> -    }
> +    qtest_add_func("/migration/multifd/tcp/plain/cancel",
> +                   test_multifd_tcp_cancel);
>      qtest_add_func("/migration/multifd/tcp/plain/zlib",
>                     test_multifd_tcp_zlib);
>  #ifdef CONFIG_ZSTD
> -- 
> 2.40.1
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 24/42] migration-test: Re-enable multifd_cancel test
  2023-06-09  7:53   ` Daniel P. Berrangé
@ 2023-06-09 10:22     ` Juan Quintela
  2023-06-09 10:40       ` Daniel P. Berrangé
  0 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-09 10:22 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Leonardo Bras

Daniel P. Berrangé <berrange@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:25AM +0200, Juan Quintela wrote:
>
> Please explain why this is considered ok, given the comment about
> why it is disabled. ie if we fixed something, refrence the commit.

I did in the cover letter, will put that on the commit:

- We used to share dest_serial file for the two targets of migration (to
  and to2), where we have a race.

- this series fixes the races in two ways:

  * we wait for "to" to finish before we launch "to2", so the race can't
    happen.

  * One of the reasons why I created GuestState is that I needed a place
    to store the serial file name (now I call it "target" and "target2").

- I put on the cover letter that this is not enough, we also need
  Fabiano fix for the thread list.

- Peter Mayel was the most vocal about this particular failure, I cc'd
  him and asked on the cover letter for the people to used to have
  failures to test.

So how should I handled this to be clearer?

Later, Juan.

>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>  tests/qtest/migration-test.c | 10 ++--------
>>  1 file changed, 2 insertions(+), 8 deletions(-)
>> 
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index 01ab51a391..9f86d9bc80 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -2886,14 +2886,8 @@ int main(int argc, char **argv)
>>      }
>>      qtest_add_func("/migration/multifd/tcp/plain/none",
>>                     test_multifd_tcp_none);
>> -    /*
>> -     * This test is flaky and sometimes fails in CI and otherwise:
>> -     * don't run unless user opts in via environment variable.
>> -     */
>> -    if (getenv("QEMU_TEST_FLAKY_TESTS")) {
>> -        qtest_add_func("/migration/multifd/tcp/plain/cancel",
>> -                       test_multifd_tcp_cancel);
>> -    }
>> +    qtest_add_func("/migration/multifd/tcp/plain/cancel",
>> +                   test_multifd_tcp_cancel);
>>      qtest_add_func("/migration/multifd/tcp/plain/zlib",
>>                     test_multifd_tcp_zlib);
>>  #ifdef CONFIG_ZSTD
>> -- 
>> 2.40.1
>> 
>
> With regards,
> Daniel



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 24/42] migration-test: Re-enable multifd_cancel test
  2023-06-09 10:22     ` Juan Quintela
@ 2023-06-09 10:40       ` Daniel P. Berrangé
  0 siblings, 0 replies; 76+ messages in thread
From: Daniel P. Berrangé @ 2023-06-09 10:40 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth, Peter Xu,
	Peter Maydell, Leonardo Bras

On Fri, Jun 09, 2023 at 12:22:33PM +0200, Juan Quintela wrote:
> Daniel P. Berrangé <berrange@redhat.com> wrote:
> > On Fri, Jun 09, 2023 at 12:49:25AM +0200, Juan Quintela wrote:
> >
> > Please explain why this is considered ok, given the comment about
> > why it is disabled. ie if we fixed something, refrence the commit.
> 
> I did in the cover letter, will put that on the commit:
> 
> - We used to share dest_serial file for the two targets of migration (to
>   and to2), where we have a race.
> 
> - this series fixes the races in two ways:
> 
>   * we wait for "to" to finish before we launch "to2", so the race can't
>     happen.
> 
>   * One of the reasons why I created GuestState is that I needed a place
>     to store the serial file name (now I call it "target" and "target2").
> 
> - I put on the cover letter that this is not enough, we also need
>   Fabiano fix for the thread list.
> 
> - Peter Mayel was the most vocal about this particular failure, I cc'd
>   him and asked on the cover letter for the people to used to have
>   failures to test.
> 
> So how should I handled this to be clearer?

Details just need to be in the commit message, because cover letters
aren't visible when someone is looking back at 'git log' to find out
why the test was re-enabled.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 01/42] migration-test: Be consistent for ppc
  2023-06-08 22:49 ` [PATCH 01/42] migration-test: Be consistent for ppc Juan Quintela
@ 2023-06-20 14:54   ` Peter Xu
  2023-06-20 19:27     ` Laurent Vivier
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 14:54 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:02AM +0200, Juan Quintela wrote:
> It makes no sense that we don't have the same configuration on both sides.

I hope Laurent can see this one out of 40s.

Makes sense to me, but does it mean that the devices are not matching
before on ppc?  Confused how did it work then..

> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  tests/qtest/migration-test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index b0c355bbd9..c5e0c69c6b 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -646,7 +646,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>                                        "'nvramrc=hex .\" _\" begin %x %x "
>                                        "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
>                                        "until'", end_address, start_address);
> -        arch_target = g_strdup("");
> +        arch_target = g_strdup("-nodefaults");
>      } else if (strcmp(arch, "aarch64") == 0) {
>          init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
>          machine_opts = "virt,gic-version=max";
> -- 
> 2.40.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 02/42] migration-test: Make ignore_stderr regular with other options
  2023-06-08 22:49 ` [PATCH 02/42] migration-test: Make ignore_stderr regular with other options Juan Quintela
@ 2023-06-20 14:59   ` Peter Xu
  2023-06-21 10:20     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 14:59 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:03AM +0200, Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  tests/qtest/migration-test.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index c5e0c69c6b..73b2f01427 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -602,7 +602,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>      g_autofree gchar *arch_target = NULL;
>      g_autofree gchar *cmd_source = NULL;
>      g_autofree gchar *cmd_target = NULL;
> -    const gchar *ignore_stderr;
> +    const gchar *ignore_stderr = NULL;
>      g_autofree char *bootpath = NULL;
>      g_autofree char *shmem_opts = NULL;
>      g_autofree char *shmem_path = NULL;
> @@ -672,10 +672,7 @@ 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 = "";

Personally maybe I won't bother with such a patch as a whole.. but if we do
want to, we could also remove "#else" here and move comment above it.

>  #endif
> -    } else {
> -        ignore_stderr = "";
>      }
>  
>      if (args->use_shmem) {
> @@ -701,7 +698,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>                                   memory_size, tmpfs,
>                                   arch_source, shmem_opts,
>                                   args->opts_source ? args->opts_source : "",
> -                                 ignore_stderr);
> +                                 ignore_stderr ? ignore_stderr : "");
> +
>      if (!args->only_target) {
>          *from = qtest_init(cmd_source);
>          qtest_qmp_set_event_callback(*from,
> @@ -722,7 +720,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>                                   memory_size, tmpfs, uri,
>                                   arch_target, shmem_opts,
>                                   args->opts_target ? args->opts_target : "",
> -                                 ignore_stderr);
> +                                 ignore_stderr ? ignore_stderr : "");
>      *to = qtest_init(cmd_target);
>      qtest_qmp_set_event_callback(*to,
>                                   migrate_watch_for_resume,
> -- 
> 2.40.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 03/42] migration-test: simplify shmem_opts handling
  2023-06-08 22:49 ` [PATCH 03/42] migration-test: simplify shmem_opts handling Juan Quintela
@ 2023-06-20 15:02   ` Peter Xu
  2023-06-21  9:42     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:02 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:04AM +0200, Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  tests/qtest/migration-test.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 73b2f01427..95ccc9bce7 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -681,9 +681,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>              "-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 "
> @@ -696,7 +693,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>                                   machine_opts ? " -machine " : "",
>                                   machine_opts ? machine_opts : "",
>                                   memory_size, tmpfs,
> -                                 arch_source, shmem_opts,
> +                                 arch_source,
> +                                 shmem_opts ? shmem_opts : "",
>                                   args->opts_source ? args->opts_source : "",
>                                   ignore_stderr ? ignore_stderr : "");
>  
> @@ -718,7 +716,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>                                   machine_opts ? " -machine " : "",
>                                   machine_opts ? machine_opts : "",
>                                   memory_size, tmpfs, uri,
> -                                 arch_target, shmem_opts,
> +                                 arch_target,
> +                                 shmem_opts ? shmem_opts : "",

Isn't this adding duplications instead?

Meanwhile, shmem_opts right now is auto-free.  If we do this we don't need
it to be auto-free anymore..

>                                   args->opts_target ? args->opts_target : "",
>                                   ignore_stderr ? ignore_stderr : "");
>      *to = qtest_init(cmd_target);
> -- 
> 2.40.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 04/42] migration-test: Make machine_opts regular with other options
  2023-06-08 22:49 ` [PATCH 04/42] migration-test: Make machine_opts regular with other options Juan Quintela
@ 2023-06-20 15:03   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:03 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:05AM +0200, Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 05/42] migration-test: Create arch_opts
  2023-06-08 22:49 ` [PATCH 05/42] migration-test: Create arch_opts Juan Quintela
@ 2023-06-20 15:06   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:06 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:06AM +0200, Juan Quintela wrote:
> This will contain the options needed for both source and target.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 06/42] migration-test: machine_opts is really arch specific
  2023-06-08 22:49 ` [PATCH 06/42] migration-test: machine_opts is really arch specific Juan Quintela
@ 2023-06-20 15:07   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:07 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:07AM +0200, Juan Quintela wrote:
> And it needs to be in both source and target, so put it on arch_opts.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 07/42] migration-test: Create kvm_opts
  2023-06-08 22:49 ` [PATCH 07/42] migration-test: Create kvm_opts Juan Quintela
@ 2023-06-20 15:07   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:07 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:08AM +0200, Juan Quintela wrote:
> So arch_dirty_ring option becomes one option like the others.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 08/42] migration-test: bootpath is the same for all tests and for all archs
  2023-06-08 22:49 ` [PATCH 08/42] migration-test: bootpath is the same for all tests and for all archs Juan Quintela
@ 2023-06-20 15:11   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:11 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:09AM +0200, Juan Quintela wrote:
> So just make it a global variable.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 09/42] migration-test: Add bootfile_create/delete() functions
  2023-06-08 22:49 ` [PATCH 09/42] migration-test: Add bootfile_create/delete() functions Juan Quintela
@ 2023-06-20 15:17   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:17 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:10AM +0200, Juan Quintela wrote:
> The bootsector code is read only from the guest (otherwise we are
> going to have problems with it being read from both source and
> destination).
> 
> Create a single copy for all the tests.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 10/42] migration-test: dirtylimit checks for x86_64 arch before
  2023-06-08 22:49 ` [PATCH 10/42] migration-test: dirtylimit checks for x86_64 arch before Juan Quintela
@ 2023-06-20 15:18   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:18 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:11AM +0200, Juan Quintela wrote:
> So no need to assert we are in x86_64.
> Once there, refactor the function to remove useless variables.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 11/42] migration-test: Update test_ignore_shared to use args
  2023-06-08 22:49 ` [PATCH 11/42] migration-test: Update test_ignore_shared to use args Juan Quintela
@ 2023-06-20 15:21   ` Peter Xu
  2023-06-21  9:58     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:21 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:12AM +0200, Juan Quintela wrote:
> It missed this treatment:
> 
> commit 11f1a4ce14803f15d59cff42a4cfb7ac50d36bd0
> Author: Juan Quintela <quintela@redhat.com>
> Date:   Mon Nov 29 18:57:51 2021 +0100
> 
>     migration-test: Check for shared memory like for everything else
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

This is still under "#if 0" block.. and the old code doesn't even compile,
but the change looks fine.

Reviewed-by: Peter Xu <peterx@redhat.com>

> ---
>  tests/qtest/migration-test.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 743aa873e6..7178c8e679 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -1597,8 +1597,11 @@ static void test_ignore_shared(void)
>  {
>      g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
>      QTestState *from, *to;
> +    MigrateStart args = {
> +        .use_shmem = true
> +    };
>  
> -    if (test_migrate_start(&from, &to, uri, false, true, NULL, NULL)) {
> +    if (test_migrate_start(&from, &to, uri, &args)) {
>          return;
>      }
>  
> -- 
> 2.40.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 12/42] migration-test: Enable back ignore-shared test
  2023-06-08 22:49 ` [PATCH 12/42] migration-test: Enable back ignore-shared test Juan Quintela
@ 2023-06-20 15:27   ` Peter Xu
  2023-06-21 19:38     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:27 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras,
	Yury Kotov

On Fri, Jun 09, 2023 at 12:49:13AM +0200, Juan Quintela wrote:
> It failed on aarch64 tcg, lets see if that is still the case.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

According to the history:

https://lore.kernel.org/all/20190305180635.GA3803@work-vm/

It's never enabled, and not sure whether Yury followed it up.  Juan: have
you tried it out on aarch64 before enabling it again?  I assume we rely on
the previous patch but that doesn't even sound like aarch64 specific.  I
worry it'll just keep failing on aarch64.

Copy Yury too.

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 13/42] migration-test: Check for shared memory like for everything else
  2023-06-08 22:49 ` [PATCH 13/42] migration-test: Check for shared memory like for everything else Juan Quintela
@ 2023-06-20 15:32   ` Peter Xu
  2023-06-21 10:07     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:32 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:14AM +0200, Juan Quintela wrote:
> Makes things easier and cleaner.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  tests/qtest/migration-test.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index daaf5cd71a..5837060138 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -645,13 +645,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>      const char *arch = qtest_get_arch();
>      const char *memory_size;
>  
> -    if (args->use_shmem) {
> -        if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
> -            g_test_skip("/dev/shm is not supported");
> -            return -1;
> -        }
> -    }

Maybe assert on: "!args->use_shmem || shm_supported()" here?

Either way:

Reviewed-by: Peter Xu <peterx@redhat.com>

> -
>      got_src_stop = false;
>      got_dst_resume = false;
>      if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
> @@ -2639,6 +2632,15 @@ static bool kvm_dirty_ring_supported(void)
>  #endif
>  }
>  
> +static bool shm_supported(void)
> +{
> +    if (g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
> +        return true;
> +    }
> +    g_test_message("Skipping test: shared memory not available");
> +    return false;
> +}
> +
>  int main(int argc, char **argv)
>  {
>      bool has_kvm, has_tcg;
> @@ -2768,7 +2770,9 @@ int main(int argc, char **argv)
>  #endif /* CONFIG_TASN1 */
>  #endif /* CONFIG_GNUTLS */
>  
> -    qtest_add_func("/migration/ignore_shared", test_ignore_shared);
> +    if (shm_supported()) {
> +        qtest_add_func("/migration/ignore_shared", test_ignore_shared);
> +    }
>  #ifndef _WIN32
>      qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
>  #endif
> -- 
> 2.40.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 14/42] migration-test: test_migrate_start() always return 0
  2023-06-08 22:49 ` [PATCH 14/42] migration-test: test_migrate_start() always return 0 Juan Quintela
@ 2023-06-20 15:35   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:35 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:15AM +0200, Juan Quintela wrote:
> So make it return void instead and adjust all callers.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 15/42] migration-test: migrate_postcopy_prepare() always return 0
  2023-06-08 22:49 ` [PATCH 15/42] migration-test: migrate_postcopy_prepare() " Juan Quintela
@ 2023-06-20 15:36   ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:36 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:16AM +0200, Juan Quintela wrote:
> So make it return void.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 16/42] migration-test: Create do_migrate()
  2023-06-08 22:49 ` [PATCH 16/42] migration-test: Create do_migrate() Juan Quintela
@ 2023-06-20 15:53   ` Peter Xu
  2023-06-21 10:30     ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-20 15:53 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Fri, Jun 09, 2023 at 12:49:17AM +0200, Juan Quintela wrote:
> We called migrate_qmp() in lot of places.  And there are tricks like
> changing tcp address with the right port.
> 
> Only two callers remaining:
> - postcopy resume: It needs to play with the qmp.
> - baddest: We want to do a unvalid URI. For that we need to do it by
>   hand.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  tests/qtest/migration-test.c | 41 ++++++++++++++++++------------------
>  1 file changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index e623c43957..96b495f255 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -528,6 +528,17 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to)
>      qtest_qmp_eventwait(to, "RESUME");
>  }
>  
> +static void do_migrate(QTestState *from, QTestState *to, const gchar *uri)
> +{
> +    if (!uri) {
> +        g_autofree char *tcp_uri =
> +            migrate_get_socket_address(to, "socket-address");
> +        migrate_qmp(from, tcp_uri, "{}");
> +    } else {
> +        migrate_qmp(from, uri, "{}");
> +    }
> +}
> +
>  typedef struct {
>      /*
>       * QTEST_LOG=1 may override this.  When QTEST_LOG=1, we always dump errors
> @@ -1173,7 +1184,7 @@ static void migrate_postcopy_prepare(QTestState **from_ptr,
>      /* Wait for the first serial output from the source */
>      wait_for_serial("src_serial");
>  
> -    migrate_qmp(from, uri, "{}");
> +    do_migrate(from, to, uri);
>  
>      wait_for_migration_pass(from);
>  
> @@ -1378,6 +1389,9 @@ static void test_baddest(void)
>      QTestState *from, *to;
>  
>      test_migrate_start(&from, &to, "tcp:127.0.0.1:0", &args);
> +    /*
> +     * Don't change to do_migrate(). We are using a wrong uri on purpose.
> +     */
>      migrate_qmp(from, "tcp:127.0.0.1:0", "{}");
>      wait_for_migration_fail(from, false);
>      test_migrate_end(from, to, false);
> @@ -1424,14 +1438,7 @@ static void test_precopy_common(MigrateCommon *args)
>          }
>      }
>  
> -    if (!args->connect_uri) {
> -        g_autofree char *local_connect_uri =
> -            migrate_get_socket_address(to, "socket-address");
> -        migrate_qmp(from, local_connect_uri, "{}");
> -    } else {
> -        migrate_qmp(from, args->connect_uri, "{}");
> -    }
> -
> +    do_migrate(from, to, args->connect_uri);
>  
>      if (args->result != MIG_TEST_SUCCEED) {
>          bool allow_active = args->result == MIG_TEST_FAIL;
> @@ -1586,7 +1593,7 @@ static void test_ignore_shared(void)
>      /* Wait for the first serial output from the source */
>      wait_for_serial("src_serial");
>  
> -    migrate_qmp(from, uri, "{}");
> +    do_migrate(from, to, uri);
>  
>      wait_for_migration_pass(from);
>  
> @@ -1890,7 +1897,7 @@ static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
>      /* Wait for the first serial output from the source */
>      wait_for_serial("src_serial");
>  
> -    migrate_qmp(from, uri, "{}");
> +    do_migrate(from, to, uri);
>  
>      if (should_fail) {
>          qtest_set_expected_status(to, EXIT_FAILURE);
> @@ -1991,7 +1998,7 @@ static void test_migrate_auto_converge(void)
>      /* Wait for the first serial output from the source */
>      wait_for_serial("src_serial");
>  
> -    migrate_qmp(from, uri, "{}");
> +    do_migrate(from, to, uri);
>  
>      /* Wait for throttling begins */
>      percentage = 0;
> @@ -2280,7 +2287,6 @@ static void test_multifd_tcp_cancel(void)
>          .hide_stderr = true,
>      };
>      QTestState *from, *to, *to2;
> -    g_autofree char *uri = NULL;
>  
>      test_migrate_start(&from, &to, "defer", &args);
>  
> @@ -2299,9 +2305,7 @@ static void test_multifd_tcp_cancel(void)
>      /* Wait for the first serial output from the source */
>      wait_for_serial("src_serial");
>  
> -    uri = migrate_get_socket_address(to, "socket-address");
> -
> -    migrate_qmp(from, uri, "{}");
> +    do_migrate(from, to, "127.0.0.1:0");

I think this means migrating to "127.0.0.1:0".  Can this work?

>  
>      wait_for_migration_pass(from);
>  
> @@ -2325,14 +2329,11 @@ static void test_multifd_tcp_cancel(void)
>      qtest_qmp_assert_success(to2, "{ 'execute': 'migrate-incoming',"
>                               "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
>  
> -    g_free(uri);
> -    uri = migrate_get_socket_address(to2, "socket-address");
> -
>      wait_for_migration_status(from, "cancelled", NULL);
>  
>      migrate_ensure_converge(from);
>  
> -    migrate_qmp(from, uri, "{}");
> +    do_migrate(from, to2, "127.0.0.1:0");
>  
>      wait_for_migration_pass(from);
>  
> -- 
> 2.40.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 01/42] migration-test: Be consistent for ppc
  2023-06-20 14:54   ` Peter Xu
@ 2023-06-20 19:27     ` Laurent Vivier
  2023-06-20 19:42       ` Peter Xu
  0 siblings, 1 reply; 76+ messages in thread
From: Laurent Vivier @ 2023-06-20 19:27 UTC (permalink / raw)
  To: Peter Xu, Juan Quintela, Thomas Huth
  Cc: qemu-devel, Paolo Bonzini, Peter Maydell, Daniel P. Berrangé,
	Leonardo Bras

On 6/20/23 16:54, Peter Xu wrote:
> On Fri, Jun 09, 2023 at 12:49:02AM +0200, Juan Quintela wrote:
>> It makes no sense that we don't have the same configuration on both sides.
> 
> I hope Laurent can see this one out of 40s.

I had some luck...

> 
> Makes sense to me, but does it mean that the devices are not matching
> before on ppc?  Confused how did it work then..

I agree we need the -nodefaults on both sides.

It has been introduced by
fc71e3e562b7 ("tests/migration: Speed up the test on ppc64") (Thomas)

I think it works because destination side doesn't check for what is missing.

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

Thanks,
Laurent
> 
>>
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>   tests/qtest/migration-test.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index b0c355bbd9..c5e0c69c6b 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -646,7 +646,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>                                         "'nvramrc=hex .\" _\" begin %x %x "
>>                                         "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
>>                                         "until'", end_address, start_address);
>> -        arch_target = g_strdup("");
>> +        arch_target = g_strdup("-nodefaults");
>>       } else if (strcmp(arch, "aarch64") == 0) {
>>           init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
>>           machine_opts = "virt,gic-version=max";
>> -- 
>> 2.40.1
>>
> 



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 01/42] migration-test: Be consistent for ppc
  2023-06-20 19:27     ` Laurent Vivier
@ 2023-06-20 19:42       ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-20 19:42 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Juan Quintela, Thomas Huth, qemu-devel, Paolo Bonzini,
	Peter Maydell, Daniel P. Berrangé, Leonardo Bras

On Tue, Jun 20, 2023 at 09:27:17PM +0200, Laurent Vivier wrote:
> On 6/20/23 16:54, Peter Xu wrote:
> > On Fri, Jun 09, 2023 at 12:49:02AM +0200, Juan Quintela wrote:
> > > It makes no sense that we don't have the same configuration on both sides.
> > 
> > I hope Laurent can see this one out of 40s.
> 
> I had some luck...

:-D

> 
> > 
> > Makes sense to me, but does it mean that the devices are not matching
> > before on ppc?  Confused how did it work then..
> 
> I agree we need the -nodefaults on both sides.
> 
> It has been introduced by
> fc71e3e562b7 ("tests/migration: Speed up the test on ppc64") (Thomas)
> 
> I think it works because destination side doesn't check for what is missing.

Oh!  Makes sense.. just notice this (fact). Then no fixes needed either.

> 
> Reviewed-by: Laurent Vivier <lvivier@redhat.com>

Thanks, Laurent!

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 03/42] migration-test: simplify shmem_opts handling
  2023-06-20 15:02   ` Peter Xu
@ 2023-06-21  9:42     ` Juan Quintela
  2023-06-21 13:15       ` Peter Xu
  0 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-21  9:42 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

Peter Xu <peterx@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:04AM +0200, Juan Quintela wrote:
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>  tests/qtest/migration-test.c | 9 ++++-----
>>  1 file changed, 4 insertions(+), 5 deletions(-)
>> 
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index 73b2f01427..95ccc9bce7 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -681,9 +681,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>              "-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 "
>> @@ -696,7 +693,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>                                   machine_opts ? " -machine " : "",
>>                                   machine_opts ? machine_opts : "",
>>                                   memory_size, tmpfs,
>> -                                 arch_source, shmem_opts,
>> +                                 arch_source,
>> +                                 shmem_opts ? shmem_opts : "",
>>                                   args->opts_source ? args->opts_source : "",
>>                                   ignore_stderr ? ignore_stderr : "");
>>  
>> @@ -718,7 +716,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>                                   machine_opts ? " -machine " : "",
>>                                   machine_opts ? machine_opts : "",
>>                                   memory_size, tmpfs, uri,
>> -                                 arch_target, shmem_opts,
>> +                                 arch_target,
>> +                                 shmem_opts ? shmem_opts : "",
>
> Isn't this adding duplications instead?

I don't follow.

> Meanwhile, shmem_opts right now is auto-free.  If we do this we don't need
> it to be auto-free anymore..

We need.
It can still be from g_strdup_printf().

What this patch change is that it will never be (again) "".

It is going to be NULL or a real string, like all the other options.
The real string is generated, so it needs to be auto_free.

Later, Juan.

>>                                   args->opts_target ? args->opts_target : "",
>>                                   ignore_stderr ? ignore_stderr : "");
>>      *to = qtest_init(cmd_target);
>> -- 
>> 2.40.1
>> 



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 11/42] migration-test: Update test_ignore_shared to use args
  2023-06-20 15:21   ` Peter Xu
@ 2023-06-21  9:58     ` Juan Quintela
  0 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-21  9:58 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

Peter Xu <peterx@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:12AM +0200, Juan Quintela wrote:
>> It missed this treatment:
>> 
>> commit 11f1a4ce14803f15d59cff42a4cfb7ac50d36bd0
>> Author: Juan Quintela <quintela@redhat.com>
>> Date:   Mon Nov 29 18:57:51 2021 +0100
>> 
>>     migration-test: Check for shared memory like for everything else
>> 
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>
> This is still under "#if 0" block.. and the old code doesn't even compile,
> but the change looks fine.

With the change it compiles O:-)

> Reviewed-by: Peter Xu <peterx@redhat.com>

Thanks. 



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 13/42] migration-test: Check for shared memory like for everything else
  2023-06-20 15:32   ` Peter Xu
@ 2023-06-21 10:07     ` Juan Quintela
  2023-06-21 13:14       ` Peter Xu
  0 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 10:07 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

Peter Xu <peterx@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:14AM +0200, Juan Quintela wrote:
>> Makes things easier and cleaner.
>> 
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>  tests/qtest/migration-test.c | 20 ++++++++++++--------
>>  1 file changed, 12 insertions(+), 8 deletions(-)
>> 
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index daaf5cd71a..5837060138 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -645,13 +645,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>      const char *arch = qtest_get_arch();
>>      const char *memory_size;
>>  
>> -    if (args->use_shmem) {
>> -        if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
>> -            g_test_skip("/dev/shm is not supported");
>> -            return -1;
>> -        }
>> -    }
>
> Maybe assert on: "!args->use_shmem || shm_supported()" here?

Nope.

We are being extra defensive in some tests.

It is tested here

>> -    qtest_add_func("/migration/ignore_shared", test_ignore_shared);
>> +    if (shm_supported()) {
>> +        qtest_add_func("/migration/ignore_shared", test_ignore_shared);
>> +    }

Checking (in the same code path) once in the same file looks like enough
to me.

Thanks, Juan.



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 02/42] migration-test: Make ignore_stderr regular with other options
  2023-06-20 14:59   ` Peter Xu
@ 2023-06-21 10:20     ` Juan Quintela
  0 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 10:20 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

Peter Xu <peterx@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:03AM +0200, Juan Quintela wrote:
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>  tests/qtest/migration-test.c | 10 ++++------
>>  1 file changed, 4 insertions(+), 6 deletions(-)
>> 
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index c5e0c69c6b..73b2f01427 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -602,7 +602,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>      g_autofree gchar *arch_target = NULL;
>>      g_autofree gchar *cmd_source = NULL;
>>      g_autofree gchar *cmd_target = NULL;
>> -    const gchar *ignore_stderr;
>> +    const gchar *ignore_stderr = NULL;
>>      g_autofree char *bootpath = NULL;
>>      g_autofree char *shmem_opts = NULL;
>>      g_autofree char *shmem_path = NULL;
>> @@ -672,10 +672,7 @@ 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 = "";
>
> Personally maybe I won't bother with such a patch as a whole..

I am trying that all the options are handled the same.
The whole idea here is that I have to split guest definition and guest
creation.  See GuestState later on the series.

If all the options are handled the same, it is much easier than if I
have to do "magic" for one vs others.

One thing that I wonder is that migration-test can't be the only test
that needs to redirect stderr, but that is a completely different issue.

> but if we do
> want to, we could also remove "#else" here and move comment above it.

Done.



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 16/42] migration-test: Create do_migrate()
  2023-06-20 15:53   ` Peter Xu
@ 2023-06-21 10:30     ` Juan Quintela
  0 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 10:30 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

Peter Xu <peterx@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:17AM +0200, Juan Quintela wrote:
>> We called migrate_qmp() in lot of places.  And there are tricks like
>> changing tcp address with the right port.
>> 
>> Only two callers remaining:
>> - postcopy resume: It needs to play with the qmp.
>> - baddest: We want to do a unvalid URI. For that we need to do it by
>>   hand.
>> -    uri = migrate_get_socket_address(to, "socket-address");
>> -
>> -    migrate_qmp(from, uri, "{}");
>> +    do_migrate(from, to, "127.0.0.1:0");
>
> I think this means migrating to "127.0.0.1:0".  Can this work?

You are right.

do_migrate(from, to, NULL)

Same for the next one.

Too many rebases trying to make things clearer.

Good catch.



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 13/42] migration-test: Check for shared memory like for everything else
  2023-06-21 10:07     ` Juan Quintela
@ 2023-06-21 13:14       ` Peter Xu
  2023-06-21 18:56         ` Juan Quintela
  0 siblings, 1 reply; 76+ messages in thread
From: Peter Xu @ 2023-06-21 13:14 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Wed, Jun 21, 2023 at 12:07:20PM +0200, Juan Quintela wrote:
> Peter Xu <peterx@redhat.com> wrote:
> > On Fri, Jun 09, 2023 at 12:49:14AM +0200, Juan Quintela wrote:
> >> Makes things easier and cleaner.
> >> 
> >> Signed-off-by: Juan Quintela <quintela@redhat.com>
> >> ---
> >>  tests/qtest/migration-test.c | 20 ++++++++++++--------
> >>  1 file changed, 12 insertions(+), 8 deletions(-)
> >> 
> >> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> >> index daaf5cd71a..5837060138 100644
> >> --- a/tests/qtest/migration-test.c
> >> +++ b/tests/qtest/migration-test.c
> >> @@ -645,13 +645,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
> >>      const char *arch = qtest_get_arch();
> >>      const char *memory_size;
> >>  
> >> -    if (args->use_shmem) {
> >> -        if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
> >> -            g_test_skip("/dev/shm is not supported");
> >> -            return -1;
> >> -        }
> >> -    }
> >
> > Maybe assert on: "!args->use_shmem || shm_supported()" here?
> 
> Nope.
> 
> We are being extra defensive in some tests.

This will protect a new test passing in use_shmem=true without checking
shm_supported().  It'll then fail at starting the VM I think otherwise.

> 
> It is tested here
> 
> >> -    qtest_add_func("/migration/ignore_shared", test_ignore_shared);
> >> +    if (shm_supported()) {
> >> +        qtest_add_func("/migration/ignore_shared", test_ignore_shared);
> >> +    }
> 
> Checking (in the same code path) once in the same file looks like enough
> to me.
> 
> Thanks, Juan.
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 03/42] migration-test: simplify shmem_opts handling
  2023-06-21  9:42     ` Juan Quintela
@ 2023-06-21 13:15       ` Peter Xu
  0 siblings, 0 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-21 13:15 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

On Wed, Jun 21, 2023 at 11:42:45AM +0200, Juan Quintela wrote:
> Peter Xu <peterx@redhat.com> wrote:
> > On Fri, Jun 09, 2023 at 12:49:04AM +0200, Juan Quintela wrote:
> >> Signed-off-by: Juan Quintela <quintela@redhat.com>
> >> ---
> >>  tests/qtest/migration-test.c | 9 ++++-----
> >>  1 file changed, 4 insertions(+), 5 deletions(-)
> >> 
> >> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> >> index 73b2f01427..95ccc9bce7 100644
> >> --- a/tests/qtest/migration-test.c
> >> +++ b/tests/qtest/migration-test.c
> >> @@ -681,9 +681,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
> >>              "-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 "
> >> @@ -696,7 +693,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
> >>                                   machine_opts ? " -machine " : "",
> >>                                   machine_opts ? machine_opts : "",
> >>                                   memory_size, tmpfs,
> >> -                                 arch_source, shmem_opts,
> >> +                                 arch_source,
> >> +                                 shmem_opts ? shmem_opts : "",
> >>                                   args->opts_source ? args->opts_source : "",
> >>                                   ignore_stderr ? ignore_stderr : "");
> >>  
> >> @@ -718,7 +716,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
> >>                                   machine_opts ? " -machine " : "",
> >>                                   machine_opts ? machine_opts : "",
> >>                                   memory_size, tmpfs, uri,
> >> -                                 arch_target, shmem_opts,
> >> +                                 arch_target,
> >> +                                 shmem_opts ? shmem_opts : "",
> >
> > Isn't this adding duplications instead?
> 
> I don't follow.
> 
> > Meanwhile, shmem_opts right now is auto-free.  If we do this we don't need
> > it to be auto-free anymore..
> 
> We need.
> It can still be from g_strdup_printf().
> 
> What this patch change is that it will never be (again) "".
> 
> It is going to be NULL or a real string, like all the other options.
> The real string is generated, so it needs to be auto_free.

Ah ok.. after I read some other reply I think I see what you mean.

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 13/42] migration-test: Check for shared memory like for everything else
  2023-06-21 13:14       ` Peter Xu
@ 2023-06-21 18:56         ` Juan Quintela
  0 siblings, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 18:56 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras

Peter Xu <peterx@redhat.com> wrote:
> On Wed, Jun 21, 2023 at 12:07:20PM +0200, Juan Quintela wrote:
>> Peter Xu <peterx@redhat.com> wrote:
>> > On Fri, Jun 09, 2023 at 12:49:14AM +0200, Juan Quintela wrote:
>> >> Makes things easier and cleaner.
>> >> 
>> >> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> >> ---
>> >>  tests/qtest/migration-test.c | 20 ++++++++++++--------
>> >>  1 file changed, 12 insertions(+), 8 deletions(-)
>> >> 
>> >> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> >> index daaf5cd71a..5837060138 100644
>> >> --- a/tests/qtest/migration-test.c
>> >> +++ b/tests/qtest/migration-test.c
>> >> @@ -645,13 +645,6 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>> >>      const char *arch = qtest_get_arch();
>> >>      const char *memory_size;
>> >>  
>> >> -    if (args->use_shmem) {
>> >> -        if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
>> >> -            g_test_skip("/dev/shm is not supported");
>> >> -            return -1;
>> >> -        }
>> >> -    }
>> >
>> > Maybe assert on: "!args->use_shmem || shm_supported()" here?
>> 
>> Nope.
>> 
>> We are being extra defensive in some tests.
>
> This will protect a new test passing in use_shmem=true without checking
> shm_supported().  It'll then fail at starting the VM I think otherwise.

Hi


As it should.
Test is wrong and it aborts.
It is not that it has found an error, it is that it is badly written.

And anyways, args->use_shmem dissapears later in the series O:-)

Later, Juan.



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 12/42] migration-test: Enable back ignore-shared test
  2023-06-20 15:27   ` Peter Xu
@ 2023-06-21 19:38     ` Juan Quintela
  2023-06-21 19:53       ` Peter Xu
  0 siblings, 1 reply; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 19:38 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras,
	Yury Kotov

Peter Xu <peterx@redhat.com> wrote:
> On Fri, Jun 09, 2023 at 12:49:13AM +0200, Juan Quintela wrote:
>> It failed on aarch64 tcg, lets see if that is still the case.
>> 
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>
> According to the history:
>
> https://lore.kernel.org/all/20190305180635.GA3803@work-vm/
>
> It's never enabled, and not sure whether Yury followed it up.  Juan: have
> you tried it out on aarch64 before enabling it again?  I assume we rely on
> the previous patch but that doesn't even sound like aarch64 specific.  I
> worry it'll just keep failing on aarch64.

Hi

I am resending this series.

I hard tested this time.  x86_64 host.
Two build directories:
- x86_64 (I just build qemu-system-x86_64, kvm)
- aarch64 (I just build qemu-system-aarch64, tcg)

Everything is run as:

while true; do $command || break; done

And run this:
- x86_64:
  * make check (nit: you can't run two make checks on the same
    directory)
  * 4 ./test/qtest/migration-test
  * 2 ./test/qtest/migration-test -p ./tests/qtest/migration-test -p /x86_64/migration/multifd/tcp/plain/cancel
  * 2 ./test/qtest/migration-test -p ./tests/qtest/migration-test -p /x86_64/migration/ignore_shared

- aarch64:
  The same with s/x86_64/aarch64/

And left it running for 6 hours.  No errors.
Machine has enough RAM for running this (128GB) and 18 cores (intel
i9900K).
Load of the machine while running this tests is around 50 (I really hope
that our CI hosts have less load).

A run master with the same configuration.  In less than 10 minutes I get
the dreaded:

# starting QEMU: exec ./qemu-system-aarch64 -qtest unix:/tmp/qtest-3264370.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-3264370.qmp,id=char0 -mon chardev=char0,mode=control -display none -accel kvm -accel tcg -machine virt,gic-version=max -name target,debug-threads=on -m 150M -serial file:/tmp/migration-test-1A1461/dest_serial -incoming defer -cpu max -kernel /tmp/migration-test-1A1461/bootsect    -accel qtest
Broken pipe
../../../../../mnt/code/qemu/multifd/tests/qtest/libqtest.c:195: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped)
Aborted (core dumped)
$

On multifd+cancel.

I have no been able to ever get ignore_shared to fail on my machine.
But I didn't tested aarch64 TCG in the past so hard, and in x86_64 it
has always worked for me.

Later, Juan.





^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 12/42] migration-test: Enable back ignore-shared test
  2023-06-21 19:38     ` Juan Quintela
@ 2023-06-21 19:53       ` Peter Xu
  2023-06-21 20:37         ` Juan Quintela
  2023-06-21 21:53         ` Juan Quintela
  0 siblings, 2 replies; 76+ messages in thread
From: Peter Xu @ 2023-06-21 19:53 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras,
	Yury Kotov

On Wed, Jun 21, 2023 at 09:38:08PM +0200, Juan Quintela wrote:
> Peter Xu <peterx@redhat.com> wrote:
> > On Fri, Jun 09, 2023 at 12:49:13AM +0200, Juan Quintela wrote:
> >> It failed on aarch64 tcg, lets see if that is still the case.
> >> 
> >> Signed-off-by: Juan Quintela <quintela@redhat.com>
> >
> > According to the history:
> >
> > https://lore.kernel.org/all/20190305180635.GA3803@work-vm/
> >
> > It's never enabled, and not sure whether Yury followed it up.  Juan: have
> > you tried it out on aarch64 before enabling it again?  I assume we rely on
> > the previous patch but that doesn't even sound like aarch64 specific.  I
> > worry it'll just keep failing on aarch64.
> 
> Hi
> 
> I am resending this series.
> 
> I hard tested this time.  x86_64 host.
> Two build directories:
> - x86_64 (I just build qemu-system-x86_64, kvm)
> - aarch64 (I just build qemu-system-aarch64, tcg)
> 
> Everything is run as:
> 
> while true; do $command || break; done
> 
> And run this:
> - x86_64:
>   * make check (nit: you can't run two make checks on the same
>     directory)
>   * 4 ./test/qtest/migration-test
>   * 2 ./test/qtest/migration-test -p ./tests/qtest/migration-test -p /x86_64/migration/multifd/tcp/plain/cancel
>   * 2 ./test/qtest/migration-test -p ./tests/qtest/migration-test -p /x86_64/migration/ignore_shared
> 
> - aarch64:
>   The same with s/x86_64/aarch64/
> 
> And left it running for 6 hours.  No errors.
> Machine has enough RAM for running this (128GB) and 18 cores (intel
> i9900K).
> Load of the machine while running this tests is around 50 (I really hope
> that our CI hosts have less load).
> 
> A run master with the same configuration.  In less than 10 minutes I get
> the dreaded:
> 
> # starting QEMU: exec ./qemu-system-aarch64 -qtest unix:/tmp/qtest-3264370.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-3264370.qmp,id=char0 -mon chardev=char0,mode=control -display none -accel kvm -accel tcg -machine virt,gic-version=max -name target,debug-threads=on -m 150M -serial file:/tmp/migration-test-1A1461/dest_serial -incoming defer -cpu max -kernel /tmp/migration-test-1A1461/bootsect    -accel qtest
> Broken pipe
> ../../../../../mnt/code/qemu/multifd/tests/qtest/libqtest.c:195: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped)
> Aborted (core dumped)
> $
> 
> On multifd+cancel.
> 
> I have no been able to ever get ignore_shared to fail on my machine.
> But I didn't tested aarch64 TCG in the past so hard, and in x86_64 it
> has always worked for me.

Thanks a lot, Juan.

Do you mean master is broken with QEMU_TEST_FLAKY_TESTS=1?  And after the
whole series applied we cannot trigger issue in the few hours test even
with it?

Shall we wait for another 1-2 days to see whether Yury would comment
(before you repost)?  Otherwise I agree if it survives your few-hours test
we should give it a try - at least according to Dave's comment before it
was failing easily, but it is not now on the test bed.

Maybe it's still just hidden, but in that case I also agree enabling it in
the repo is the simplest way to reproduce the failure again, if we still
ever want to enable it one day..

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 12/42] migration-test: Enable back ignore-shared test
  2023-06-21 19:53       ` Peter Xu
@ 2023-06-21 20:37         ` Juan Quintela
  2023-06-21 21:53         ` Juan Quintela
  1 sibling, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 20:37 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras,
	Yury Kotov

Peter Xu <peterx@redhat.com> wrote:
> On Wed, Jun 21, 2023 at 09:38:08PM +0200, Juan Quintela wrote:
>> Peter Xu <peterx@redhat.com> wrote:
>> > On Fri, Jun 09, 2023 at 12:49:13AM +0200, Juan Quintela wrote:
>> >> It failed on aarch64 tcg, lets see if that is still the case.
>> >> 
>> >> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> >
>> > According to the history:
>> >
>> > https://lore.kernel.org/all/20190305180635.GA3803@work-vm/
>> >
>> > It's never enabled, and not sure whether Yury followed it up.  Juan: have
>> > you tried it out on aarch64 before enabling it again?  I assume we rely on
>> > the previous patch but that doesn't even sound like aarch64 specific.  I
>> > worry it'll just keep failing on aarch64.

>> On multifd+cancel.
>> 
>> I have no been able to ever get ignore_shared to fail on my machine.
>> But I didn't tested aarch64 TCG in the past so hard, and in x86_64 it
>> has always worked for me.
>
> Thanks a lot, Juan.
>
> Do you mean master is broken with QEMU_TEST_FLAKY_TESTS=1?  And after the
> whole series applied we cannot trigger issue in the few hours test even
> with it?
>
> Shall we wait for another 1-2 days to see whether Yury would comment
> (before you repost)?  Otherwise I agree if it survives your few-hours test
> we should give it a try - at least according to Dave's comment before it
> was failing easily, but it is not now on the test bed.
>
> Maybe it's still just hidden, but in that case I also agree enabling it in
> the repo is the simplest way to reproduce the failure again, if we still
> ever want to enable it one day..

Sending v2.

In that serie both re-enablement of multifd+cancel and ingnore_shared
are the last two patches.

So I am going to wait until all other patches are in and that the people
that complained the most: Peter Maydell, Daniel and Thomas say/test on their
cases.  Hint, Hint.

Later, Juan.



^ permalink raw reply	[flat|nested] 76+ messages in thread

* Re: [PATCH 12/42] migration-test: Enable back ignore-shared test
  2023-06-21 19:53       ` Peter Xu
  2023-06-21 20:37         ` Juan Quintela
@ 2023-06-21 21:53         ` Juan Quintela
  1 sibling, 0 replies; 76+ messages in thread
From: Juan Quintela @ 2023-06-21 21:53 UTC (permalink / raw)
  To: Peter Xu
  Cc: qemu-devel, Paolo Bonzini, Laurent Vivier, Thomas Huth,
	Peter Maydell, Daniel P . Berrangé, Leonardo Bras,
	Yury Kotov

Peter Xu <peterx@redhat.com> wrote:
> On Wed, Jun 21, 2023 at 09:38:08PM +0200, Juan Quintela wrote:
>> Peter Xu <peterx@redhat.com> wrote:
>> > On Fri, Jun 09, 2023 at 12:49:13AM +0200, Juan Quintela wrote:
>> >> It failed on aarch64 tcg, lets see if that is still the case.
>> >> 
>> >> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> >
>> > According to the history:
>> >
>> > https://lore.kernel.org/all/20190305180635.GA3803@work-vm/
>> >
>> > It's never enabled, and not sure whether Yury followed it up.  Juan: have
>> > you tried it out on aarch64 before enabling it again?  I assume we rely on
>> > the previous patch but that doesn't even sound like aarch64 specific.  I
>> > worry it'll just keep failing on aarch64.
>> 
>> Hi
>> 
>> I am resending this series.
>> 
>> I hard tested this time.  x86_64 host.
>> Two build directories:
>> - x86_64 (I just build qemu-system-x86_64, kvm)
>> - aarch64 (I just build qemu-system-aarch64, tcg)
>> 
>> Everything is run as:
>> 
>> while true; do $command || break; done
>> 
>> And run this:
>> - x86_64:
>>   * make check (nit: you can't run two make checks on the same
>>     directory)
>>   * 4 ./test/qtest/migration-test
>>   * 2 ./test/qtest/migration-test -p ./tests/qtest/migration-test -p /x86_64/migration/multifd/tcp/plain/cancel
>>   * 2 ./test/qtest/migration-test -p ./tests/qtest/migration-test -p /x86_64/migration/ignore_shared
>> 
>> - aarch64:
>>   The same with s/x86_64/aarch64/
>> 
>> And left it running for 6 hours.  No errors.
>> Machine has enough RAM for running this (128GB) and 18 cores (intel
>> i9900K).
>> Load of the machine while running this tests is around 50 (I really hope
>> that our CI hosts have less load).
>> 
>> A run master with the same configuration.  In less than 10 minutes I get
>> the dreaded:
>> 
>> # starting QEMU: exec ./qemu-system-aarch64 -qtest unix:/tmp/qtest-3264370.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-3264370.qmp,id=char0 -mon chardev=char0,mode=control -display none -accel kvm -accel tcg -machine virt,gic-version=max -name target,debug-threads=on -m 150M -serial file:/tmp/migration-test-1A1461/dest_serial -incoming defer -cpu max -kernel /tmp/migration-test-1A1461/bootsect    -accel qtest
>> Broken pipe
>> ../../../../../mnt/code/qemu/multifd/tests/qtest/libqtest.c:195: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped)
>> Aborted (core dumped)
>> $
>> 
>> On multifd+cancel.
>> 
>> I have no been able to ever get ignore_shared to fail on my machine.
>> But I didn't tested aarch64 TCG in the past so hard, and in x86_64 it
>> has always worked for me.
>
> Thanks a lot, Juan.
>
> Do you mean master is broken with QEMU_TEST_FLAKY_TESTS=1?

Yeap.  I mean multifd+cancel.  That is the reason why we put the FLAKY
part.

> And after the
> whole series applied we cannot trigger issue in the few hours test even
> with it?

Yeap.

> Shall we wait for another 1-2 days to see whether Yury would comment
> (before you repost)?  Otherwise I agree if it survives your few-hours test
> we should give it a try - at least according to Dave's comment before it
> was failing easily, but it is not now on the test bed.

From the v2 series that I am about to post:

    migration-test: Re-enable multifd_cancel test

    Why?
    - migration/multifd: Protect accesses to migration_threads
      this patch fixed the problem about memory corruption
    - migration-test: Move serial to GuestState
      now we are using guest name as serial file name
      In the past there was a conflict between vm "to" and "to2" that used
      the same file name.
    - migration-test: Wait for first target to finish
      Now we wait from vm "to" to finish before launching "to2".  So we
      avoid similar problems in the future.

    Signed-off-by: Juan Quintela <quintela@redhat.com>


> Maybe it's still just hidden, but in that case I also agree enabling it in
> the repo is the simplest way to reproduce the failure again, if we still
> ever want to enable it one day..

We want.  If it still fails, we want to know why and fix it.

Later, Juan.



^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2023-06-21 21:54 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-08 22:49 [PATCH 00/42] Migration test refactoring Juan Quintela
2023-06-08 22:49 ` [PATCH 01/42] migration-test: Be consistent for ppc Juan Quintela
2023-06-20 14:54   ` Peter Xu
2023-06-20 19:27     ` Laurent Vivier
2023-06-20 19:42       ` Peter Xu
2023-06-08 22:49 ` [PATCH 02/42] migration-test: Make ignore_stderr regular with other options Juan Quintela
2023-06-20 14:59   ` Peter Xu
2023-06-21 10:20     ` Juan Quintela
2023-06-08 22:49 ` [PATCH 03/42] migration-test: simplify shmem_opts handling Juan Quintela
2023-06-20 15:02   ` Peter Xu
2023-06-21  9:42     ` Juan Quintela
2023-06-21 13:15       ` Peter Xu
2023-06-08 22:49 ` [PATCH 04/42] migration-test: Make machine_opts regular with other options Juan Quintela
2023-06-20 15:03   ` Peter Xu
2023-06-08 22:49 ` [PATCH 05/42] migration-test: Create arch_opts Juan Quintela
2023-06-20 15:06   ` Peter Xu
2023-06-08 22:49 ` [PATCH 06/42] migration-test: machine_opts is really arch specific Juan Quintela
2023-06-20 15:07   ` Peter Xu
2023-06-08 22:49 ` [PATCH 07/42] migration-test: Create kvm_opts Juan Quintela
2023-06-20 15:07   ` Peter Xu
2023-06-08 22:49 ` [PATCH 08/42] migration-test: bootpath is the same for all tests and for all archs Juan Quintela
2023-06-20 15:11   ` Peter Xu
2023-06-08 22:49 ` [PATCH 09/42] migration-test: Add bootfile_create/delete() functions Juan Quintela
2023-06-20 15:17   ` Peter Xu
2023-06-08 22:49 ` [PATCH 10/42] migration-test: dirtylimit checks for x86_64 arch before Juan Quintela
2023-06-20 15:18   ` Peter Xu
2023-06-08 22:49 ` [PATCH 11/42] migration-test: Update test_ignore_shared to use args Juan Quintela
2023-06-20 15:21   ` Peter Xu
2023-06-21  9:58     ` Juan Quintela
2023-06-08 22:49 ` [PATCH 12/42] migration-test: Enable back ignore-shared test Juan Quintela
2023-06-20 15:27   ` Peter Xu
2023-06-21 19:38     ` Juan Quintela
2023-06-21 19:53       ` Peter Xu
2023-06-21 20:37         ` Juan Quintela
2023-06-21 21:53         ` Juan Quintela
2023-06-08 22:49 ` [PATCH 13/42] migration-test: Check for shared memory like for everything else Juan Quintela
2023-06-20 15:32   ` Peter Xu
2023-06-21 10:07     ` Juan Quintela
2023-06-21 13:14       ` Peter Xu
2023-06-21 18:56         ` Juan Quintela
2023-06-08 22:49 ` [PATCH 14/42] migration-test: test_migrate_start() always return 0 Juan Quintela
2023-06-20 15:35   ` Peter Xu
2023-06-08 22:49 ` [PATCH 15/42] migration-test: migrate_postcopy_prepare() " Juan Quintela
2023-06-20 15:36   ` Peter Xu
2023-06-08 22:49 ` [PATCH 16/42] migration-test: Create do_migrate() Juan Quintela
2023-06-20 15:53   ` Peter Xu
2023-06-21 10:30     ` Juan Quintela
2023-06-08 22:49 ` [PATCH 17/42] migration-test: Introduce GuestState Juan Quintela
2023-06-08 22:49 ` [PATCH 18/42] migration-test: Create guest before calling do_test_validate_uuid() Juan Quintela
2023-06-08 22:49 ` [PATCH 19/42] migration-test: Create guest before calling test_precopy_common() Juan Quintela
2023-06-08 22:49 ` [PATCH 20/42] migration-test: Create guest before calling test_postcopy_common() Juan Quintela
2023-06-08 22:49 ` [PATCH 21/42] migration-test: Move common guest code to guest_create() Juan Quintela
2023-06-08 22:49 ` [PATCH 22/42] migration-test: Create guest_use_dirty_log() Juan Quintela
2023-06-08 22:49 ` [PATCH 23/42] migration-test: Move serial to GuestState Juan Quintela
2023-06-08 22:49 ` [PATCH 24/42] migration-test: Re-enable multifd_cancel test Juan Quintela
2023-06-09  7:53   ` Daniel P. Berrangé
2023-06-09 10:22     ` Juan Quintela
2023-06-09 10:40       ` Daniel P. Berrangé
2023-06-08 22:49 ` [PATCH 25/42] migration-test: We were not waiting for "target" to finish Juan Quintela
2023-06-08 22:49 ` [PATCH 26/42] migration-test: create guest_use_shmem() Juan Quintela
2023-06-08 22:49 ` [PATCH 27/42] migration-test: Create guest_extra_opts() Juan Quintela
2023-06-08 22:49 ` [PATCH 28/42] migration-test: Create guest_hide_stderr() Juan Quintela
2023-06-08 22:49 ` [PATCH 29/42] migration-test: Create the migration unix socket by guest Juan Quintela
2023-06-08 22:49 ` [PATCH 30/42] migration-test: Hooks also need GuestState Juan Quintela
2023-06-08 22:49 ` [PATCH 31/42] migration-test: Preffer to->uri to uri parameter for migration Juan Quintela
2023-06-08 22:49 ` [PATCH 32/42] migration-test: Create guest_set_uri() Juan Quintela
2023-06-08 22:49 ` [PATCH 33/42] migration-test: Remove connect_uri Juan Quintela
2023-06-08 22:49 ` [PATCH 34/42] migration-test: Use new schema for all tests that use unix sockets Juan Quintela
2023-06-08 22:49 ` [PATCH 35/42] migration-test: Set uri for tcp tests with guest_set_uri() Juan Quintela
2023-06-08 22:49 ` [PATCH 36/42] migration-test: Remove unused listen_uri Juan Quintela
2023-06-08 22:49 ` [PATCH 37/42] migration-test: Create get_event GuestState variable Juan Quintela
2023-06-08 22:49 ` [PATCH 38/42] migration-test: Create guest_realize() Juan Quintela
2023-06-08 22:49 ` [PATCH 39/42] migration-test: Unfold test_migrate_end() into three functions Juan Quintela
2023-06-08 22:49 ` [PATCH 40/42] migration-test: Create migrate_incoming() function Juan Quintela
2023-06-08 22:49 ` [PATCH 41/42] migration-test: Move functions to migration-helpers.c Juan Quintela
2023-06-08 22:49 ` [PATCH 42/42] migration-test: Split vcpu-dirty-limit-test Juan Quintela

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).