All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: dgilbert@redhat.com, lvivier@redhat.com, peterx@redhat.com
Subject: [Qemu-devel] [PATCH v2 03/10] tests: Factorize out migrate_test_start/end
Date: Thu, 26 Oct 2017 09:52:15 +0200	[thread overview]
Message-ID: <20171026075222.27798-4-quintela@redhat.com> (raw)
In-Reply-To: <20171026075222.27798-1-quintela@redhat.com>

We fix global_test users left and right

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

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 19a1445076..91fb0277d6 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -301,7 +301,7 @@ static void wait_for_migration_pass(void)
     } while (pass == initial_pass && !got_stop);
 }
 
-static void check_guests_ram(void)
+static void check_guests_ram(QTestState *who)
 {
     /* Our ASM test will have been incrementing one byte from each page from
      * 1MB to <100MB in order.
@@ -316,13 +316,13 @@ static void check_guests_ram(void)
     bool hit_edge = false;
     bool bad = false;
 
-    qtest_memread(global_qtest, start_address, &first_byte, 1);
+    qtest_memread(who, start_address, &first_byte, 1);
     last_byte = first_byte;
 
     for (address = start_address + 4096; address < end_address; address += 4096)
     {
         uint8_t b;
-        qtest_memread(global_qtest, address, &b, 1);
+        qtest_memread(who, 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
@@ -408,14 +408,10 @@ static void migrate(QTestState *who, const char *uri)
     QDECREF(rsp);
 }
 
-static void test_migrate(void)
+static void test_migrate_start(QTestState **from, QTestState **to,
+                               const char *uri)
 {
-    char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
-    QTestState *global = global_qtest, *from, *to;
-    unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
     gchar *cmd_src, *cmd_dst;
-    QDict *rsp;
-
     char *bootpath = g_strdup_printf("%s/bootsect", tmpfs);
     const char *arch = qtest_get_arch();
 
@@ -456,11 +452,51 @@ static void test_migrate(void)
 
     g_free(bootpath);
 
-    from = qtest_start(cmd_src);
+    *from = qtest_start(cmd_src);
     g_free(cmd_src);
 
-    to = qtest_init(cmd_dst);
+    *to = qtest_init(cmd_dst);
     g_free(cmd_dst);
+}
+
+static void test_migrate_end(QTestState *from, QTestState *to)
+{
+    unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
+
+    qtest_quit(from);
+
+    qtest_memread(to, 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);
+        usleep(10 * 1000);
+    } while (dest_byte_a == dest_byte_b);
+
+    qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}");
+    /* With it stopped, check nothing changes */
+    qtest_memread(to, start_address, &dest_byte_c, 1);
+    sleep(1);
+    qtest_memread(to, start_address, &dest_byte_d, 1);
+    g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
+
+    check_guests_ram(to);
+
+    qtest_quit(to);
+
+    cleanup("bootsect");
+    cleanup("migsocket");
+    cleanup("src_serial");
+    cleanup("dest_serial");
+}
+
+static void test_migrate(void)
+{
+    char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    QTestState *global = global_qtest, *from, *to;
+    QDict *rsp;
+
+    test_migrate_start(&from, &to, uri);
 
     migrate_set_capability(from, "postcopy-ram", "true");
     migrate_set_capability(to, "postcopy-ram", "true");
@@ -495,36 +531,10 @@ static void test_migrate(void)
     global_qtest = from;
     wait_for_migration_complete();
 
-    qtest_quit(from);
-
-    global_qtest = to;
-
-    qtest_memread(to, 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);
-        usleep(10 * 1000);
-    } while (dest_byte_a == dest_byte_b);
-
-    qmp_discard_response("{ 'execute' : 'stop'}");
-    /* With it stopped, check nothing changes */
-    qtest_memread(to, start_address, &dest_byte_c, 1);
-    sleep(1);
-    qtest_memread(to, start_address, &dest_byte_d, 1);
-    g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
-
-    check_guests_ram();
-
-    qtest_quit(to);
     g_free(uri);
-
     global_qtest = global;
 
-    cleanup("bootsect");
-    cleanup("migsocket");
-    cleanup("src_serial");
-    cleanup("dest_serial");
+    test_migrate_end(from, to);
 }
 
 int main(int argc, char **argv)
-- 
2.13.6

  parent reply	other threads:[~2017-10-26  7:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-26  7:52 [Qemu-devel] [PATCH v2 00/10] Add make check tests for Migration Juan Quintela
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 01/10] tests: rename postcopy-test to migration-test Juan Quintela
2017-10-27  1:50   ` Dr. David Alan Gilbert
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 02/10] tests: Refactor setting of parameters/capabilities Juan Quintela
2017-10-27  1:54   ` Dr. David Alan Gilbert
2017-10-26  7:52 ` Juan Quintela [this message]
2017-10-27  2:15   ` [Qemu-devel] [PATCH v2 03/10] tests: Factorize out migrate_test_start/end Dr. David Alan Gilbert
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 04/10] tests: Don't abuse global_qtest Juan Quintela
2017-10-27  2:37   ` Dr. David Alan Gilbert
2017-10-29  8:29     ` Juan Quintela
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 05/10] tests: check that migration parameters are really assigned Juan Quintela
2017-10-27  3:47   ` Dr. David Alan Gilbert
2017-10-29  8:30     ` Juan Quintela
2017-10-29 13:24   ` Peter Xu
2017-10-30 13:28     ` Juan Quintela
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 06/10] tests: Add migration precopy test Juan Quintela
2017-10-29 13:56   ` Peter Xu
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 07/10] tests: Add basic migration precopy tcp test Juan Quintela
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 08/10] tests: Add precopy test using deprecated commands Juan Quintela
2017-10-29 13:40   ` Peter Xu
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 09/10] tests: Add migration xbzrle test Juan Quintela
2017-10-26  7:52 ` [Qemu-devel] [PATCH v2 10/10] [RFH] tests: Add migration compress threads tests Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171026075222.27798-4-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.