From nobody Fri Oct 24 20:19:14 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 1519747450865640.0993757657346; Tue, 27 Feb 2018 08:04:10 -0800 (PST) Received: from localhost ([::1]:38328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqhjW-0008Lf-Eb for importer@patchew.org; Tue, 27 Feb 2018 11:04:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqdss-0000P2-IG for qemu-devel@nongnu.org; Tue, 27 Feb 2018 06:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqdsr-0000C7-5m for qemu-devel@nongnu.org; Tue, 27 Feb 2018 06:57:26 -0500 Received: from mx2.suse.de ([195.135.220.15]:60233) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eqdsk-00007l-O1; Tue, 27 Feb 2018 06:57:19 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A4246ADCA; Tue, 27 Feb 2018 11:57:16 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Richard Palethorpe To: qemu-devel@nongnu.org Date: Tue, 27 Feb 2018 12:56:51 +0100 Message-Id: <20180227115651.30762-3-rpalethorpe@suse.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180227115651.30762-1-rpalethorpe@suse.com> References: <20180227115651.30762-1-rpalethorpe@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 X-Mailman-Approved-At: Tue, 27 Feb 2018 10:58:35 -0500 Subject: [Qemu-devel] [RFC PATCH 2/2] migrate: Tests for migrating to an already used QEMU 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: qemu-block@nongnu.org, quintela@redhat.com, armbru@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, Richard Palethorpe 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" Currently this appears to work for X86_64, but PPC64 fails due to some unexpected data on the serial port after migration. This probably requires quite a bit more work. --- tests/migration-test.c | 113 +++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 74f9361bdd..8217d2e83e 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -125,19 +125,17 @@ static void init_bootfile_ppc(const char *bootpath) * 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(const char *side, gboolean started) { char *serialpath =3D g_strdup_printf("%s/%s", tmpfs, side); FILE *serialfile =3D fopen(serialpath, "r"); const char *arch =3D qtest_get_arch(); - int started =3D (strcmp(side, "src_serial") =3D=3D 0 && - strcmp(arch, "ppc64") =3D=3D 0) ? 0 : 1; =20 g_free(serialpath); do { int readvalue =3D fgetc(serialfile); =20 - if (!started) { + if (!started && !strcmp(arch, "ppc64")) { /* SLOF prints its banner before starting test, * to ignore it, mark the start of the test with '_', * ignore all characters until this marker @@ -358,16 +356,21 @@ static void migrate_set_capability(QTestState *who, c= onst char *capability, QDECREF(rsp); } =20 -static void migrate(QTestState *who, const char *uri) +static void migrate(QTestState *who, const char *uri, gboolean incoming) { QDict *rsp; + const gchar *cmd_name =3D incoming ? "migrate-incoming" : "migrate"; gchar *cmd; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," + cmd =3D g_strdup_printf("{ 'execute': '%s'," "'arguments': { 'uri': '%s' } }", - uri); + cmd_name, uri); rsp =3D qtest_qmp(who, cmd); g_free(cmd); + while (qdict_haskey(rsp, "event")) { + QDECREF(rsp); + rsp =3D qtest_qmp_receive(who); + } g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); } @@ -382,15 +385,22 @@ static void migrate_start_postcopy(QTestState *who) } =20 static void test_migrate_start(QTestState **from, QTestState **to, - const char *uri) + const char *uri, gboolean incoming) { - gchar *cmd_src, *cmd_dst; + gchar *cmd_src; + GString *cmd_dst =3D g_string_new(NULL); char *bootpath =3D g_strdup_printf("%s/bootsect", tmpfs); + char *bootpath_dst; const char *arch =3D qtest_get_arch(); const char *accel =3D "kvm:tcg"; =20 got_stop =3D false; =20 + if (incoming) + bootpath_dst =3D bootpath; + else + bootpath_dst =3D g_strdup_printf("%s/bootsect_dst", tmpfs); + if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { init_bootfile_x86(bootpath); cmd_src =3D g_strdup_printf("-machine accel=3D%s -m 150M" @@ -398,12 +408,14 @@ static void test_migrate_start(QTestState **from, QTe= stState **to, " -serial file:%s/src_serial" " -drive file=3D%s,format=3Draw", accel, tmpfs, bootpath); - cmd_dst =3D g_strdup_printf("-machine accel=3D%s -m 150M" - " -name target,debug-threads=3Don" - " -serial file:%s/dest_serial" - " -drive file=3D%s,format=3Draw" - " -incoming %s", - accel, tmpfs, bootpath, uri); + if (!incoming) + init_bootfile_x86(bootpath_dst); + + g_string_printf(cmd_dst, "-machine accel=3D%s -m 150M" + " -name target,debug-threads=3Don" + " -serial file:%s/dest_serial" + " -drive file=3D%s,format=3Draw", + accel, tmpfs, bootpath_dst); } else if (strcmp(arch, "ppc64") =3D=3D 0) { =20 /* On ppc64, the test only works with kvm-hv, but not with kvm-pr = */ @@ -416,22 +428,29 @@ static void test_migrate_start(QTestState **from, QTe= stState **to, " -serial file:%s/src_serial" " -drive file=3D%s,if=3Dpflash,format=3D= raw", accel, tmpfs, bootpath); - cmd_dst =3D g_strdup_printf("-machine accel=3D%s -m 256M" - " -name target,debug-threads=3Don" - " -serial file:%s/dest_serial" - " -incoming %s", - accel, tmpfs, uri); + g_string_printf(cmd_dst, "-machine accel=3D%s -m 256M" + " -name target,debug-threads=3Don" + " -serial file:%s/dest_serial", + accel, tmpfs); + if (!incoming) { + g_string_append_printf(cmd_dst, + " -drive file=3D%s,if=3Dpflash,format= =3Draw", + bootpath); + } } else { g_assert_not_reached(); } =20 + if (incoming) + g_string_append_printf(cmd_dst, " -incoming %s", uri); + g_free(bootpath); =20 *from =3D qtest_start(cmd_src); g_free(cmd_src); =20 - *to =3D qtest_init(cmd_dst); - g_free(cmd_dst); + *to =3D qtest_init(cmd_dst->str); + g_string_free(cmd_dst, TRUE); } =20 static void test_migrate_end(QTestState *from, QTestState *to, bool test_d= est) @@ -518,7 +537,7 @@ static void test_migrate(void) char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; =20 - test_migrate_start(&from, &to, uri); + test_migrate_start(&from, &to, uri, TRUE); =20 migrate_set_capability(from, "postcopy-ram", "true"); migrate_set_capability(to, "postcopy-ram", "true"); @@ -531,9 +550,9 @@ static void test_migrate(void) migrate_set_parameter(from, "downtime-limit", "1"); =20 /* Wait for the first serial output from the source */ - wait_for_serial("src_serial"); + wait_for_serial("src_serial", FALSE); =20 - migrate(from, uri); + migrate(from, uri, FALSE); =20 wait_for_migration_pass(from); =20 @@ -545,7 +564,7 @@ static void test_migrate(void) =20 qtest_qmp_eventwait(to, "RESUME"); =20 - wait_for_serial("dest_serial"); + wait_for_serial("dest_serial", TRUE); wait_for_migration_complete(from); =20 g_free(uri); @@ -560,8 +579,8 @@ static void test_baddest(void) const char *status; bool failed; =20 - test_migrate_start(&from, &to, "tcp:0:0"); - migrate(from, "tcp:0:0"); + test_migrate_start(&from, &to, "tcp:0:0", TRUE); + migrate(from, "tcp:0:0", FALSE); do { rsp =3D wait_command(from, "{ 'execute': 'query-migrate' }"); rsp_return =3D qdict_get_qdict(rsp, "return"); @@ -584,6 +603,43 @@ static void test_baddest(void) test_migrate_end(from, to, false); } =20 +static void test_migrate_to_used(void) +{ + char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + QTestState *from, *to; + + test_migrate_start(&from, &to, uri, FALSE); + + migrate_set_capability(from, "postcopy-ram", "true"); + migrate_set_capability(to, "postcopy-ram", "true"); + + migrate_set_parameter(from, "max-bandwidth", "100000000"); + migrate_set_parameter(from, "downtime-limit", "1"); + + wait_for_serial("dest_serial", FALSE); + migrate(to, uri, TRUE); + + wait_for_serial("src_serial", FALSE); + migrate(from, uri, FALSE); + + wait_for_migration_pass(from); + + migrate_start_postcopy(from); + + if (!got_stop) { + qtest_qmp_eventwait(from, "STOP"); + } + + qtest_qmp_eventwait(to, "RESUME"); + + wait_for_serial("dest_serial", TRUE); + wait_for_migration_complete(from); + + g_free(uri); + + test_migrate_end(from, to, true); +} + int main(int argc, char **argv) { char template[] =3D "/tmp/migration-test-XXXXXX"; @@ -604,6 +660,7 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QOM); =20 qtest_add_func("/migration/postcopy/unix", test_migrate); + qtest_add_func("/migration/postcopy/to_used", test_migrate_to_used); qtest_add_func("/migration/deprecated", test_deprecated); qtest_add_func("/migration/bad_dest", test_baddest); =20 --=20 2.16.2