From nobody Sun Nov 2 16:37:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509004821435766.4366571390557; Thu, 26 Oct 2017 01:00:21 -0700 (PDT) Received: from localhost ([::1]:51503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7d58-0001lt-U7 for importer@patchew.org; Thu, 26 Oct 2017 04:00:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7cxu-0004en-GG for qemu-devel@nongnu.org; Thu, 26 Oct 2017 03:52:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7cxt-0007yr-Ea for qemu-devel@nongnu.org; Thu, 26 Oct 2017 03:52:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27153) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e7cxt-0007yC-6W for qemu-devel@nongnu.org; Thu, 26 Oct 2017 03:52:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 313F780B2A for ; Thu, 26 Oct 2017 07:52:32 +0000 (UTC) Received: from secure.mitica (ovpn-116-124.ams2.redhat.com [10.36.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id D55847B533; Thu, 26 Oct 2017 07:52:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 313F780B2A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 26 Oct 2017 09:52:15 +0200 Message-Id: <20171026075222.27798-4-quintela@redhat.com> In-Reply-To: <20171026075222.27798-1-quintela@redhat.com> References: <20171026075222.27798-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 26 Oct 2017 07:52:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 03/10] tests: Factorize out migrate_test_start/end X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We fix global_test users left and right Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- 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 =3D=3D initial_pass && !got_stop); } =20 -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 fr= om * 1MB to <100MB in order. @@ -316,13 +316,13 @@ static void check_guests_ram(void) bool hit_edge =3D false; bool bad =3D false; =20 - qtest_memread(global_qtest, start_address, &first_byte, 1); + qtest_memread(who, start_address, &first_byte, 1); last_byte =3D first_byte; =20 for (address =3D start_address + 4096; address < end_address; address = +=3D 4096) { uint8_t b; - qtest_memread(global_qtest, address, &b, 1); + qtest_memread(who, address, &b, 1); if (b !=3D last_byte) { if (((b + 1) % 256) =3D=3D 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); } =20 -static void test_migrate(void) +static void test_migrate_start(QTestState **from, QTestState **to, + const char *uri) { - char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); - QTestState *global =3D 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 =3D g_strdup_printf("%s/bootsect", tmpfs); const char *arch =3D qtest_get_arch(); =20 @@ -456,11 +452,51 @@ static void test_migrate(void) =20 g_free(bootpath); =20 - from =3D qtest_start(cmd_src); + *from =3D qtest_start(cmd_src); g_free(cmd_src); =20 - to =3D qtest_init(cmd_dst); + *to =3D 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 =3D=3D 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, =3D=3D, 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 =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + QTestState *global =3D global_qtest, *from, *to; + QDict *rsp; + + test_migrate_start(&from, &to, uri); =20 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 =3D from; wait_for_migration_complete(); =20 - qtest_quit(from); - - global_qtest =3D 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 =3D=3D 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, =3D=3D, dest_byte_d); - - check_guests_ram(); - - qtest_quit(to); g_free(uri); - global_qtest =3D global; =20 - cleanup("bootsect"); - cleanup("migsocket"); - cleanup("src_serial"); - cleanup("dest_serial"); + test_migrate_end(from, to); } =20 int main(int argc, char **argv) --=20 2.13.6