From nobody Tue Nov 26 22:41:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704342998; cv=none; d=zohomail.com; s=zohoarc; b=Bnuux1DoxfT+T4IAQpYJSql/3Z3bSE39ooG9UK5bTtdW9LBNx7xd8qbQtkgLWfdK7gIZQAQhYNPLB4YnS4Efoo+uObgQos/MhRWg/ZqKIqp7/TeuRpVnY9mi3/5fXvBA8uXnXhfyA7wzeOncUDn6dy+mDhXXApZWovfoPY6l3qg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704342998; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gNoIPqx89KwEEiI+qbI/WDuicixEzT9Crv1KraL+/p4=; b=ai0+ErMNbS/RwIue7xsX5EAo6mkVObE0jtwYi8NyWY7cgHfbGSnuOR/dpAYSc64LtQHDClkiocp7G7Us5DYcNJBdMb3A2zynkNfLjk/GAH9HMtYZ+QV21frGTRE3jhh7AjM0xbVPs8ziFYOJ/8y2R14lMibUqMLOqfr1tWn3ie4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704342998165252.89433561646524; Wed, 3 Jan 2024 20:36:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLFQ4-0000zG-JM; Wed, 03 Jan 2024 23:33:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLFQ2-0000ob-S2 for qemu-devel@nongnu.org; Wed, 03 Jan 2024 23:33:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLFQ0-0006cz-SD for qemu-devel@nongnu.org; Wed, 03 Jan 2024 23:33:22 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-49-XJDPvUa5Mn-0gPH-UJ5qNw-1; Wed, 03 Jan 2024 23:33:15 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 986B5185A780; Thu, 4 Jan 2024 04:33:14 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BA70C15968; Thu, 4 Jan 2024 04:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704342800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gNoIPqx89KwEEiI+qbI/WDuicixEzT9Crv1KraL+/p4=; b=fIwo62H/EWuPBtCEaaWlaYhty+OxNUtrXjeL3MvBOZUNB9KUCw/86CJHaenakDTI1v1iat eeyDCw/YI3DJSJ5CKKywhD25skT+d1nX7xavFLdiy4jEDwSuwpK6uPaO8/ngDkOarMZQpg HonaYoKIpxAOiMeAI/mlcXv/sMkCtQA= X-MC-Unique: XJDPvUa5Mn-0gPH-UJ5qNw-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fabiano Rosas , Steve Sistare , Juan Quintela , peterx@redhat.com, Leonardo Bras Soares Passos , Avihai Horon , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 11/26] tests/qtest: migration events Date: Thu, 4 Jan 2024 12:31:56 +0800 Message-ID: <20240104043213.431566-12-peterx@redhat.com> In-Reply-To: <20240104043213.431566-1-peterx@redhat.com> References: <20240104043213.431566-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.601, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1704343000241100010 From: Steve Sistare Define a state object to capture events seen by migration tests, to allow more events to be captured in a subsequent patch, and simplify event checking in wait_for_migration_pass. No functional change. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Reviewed-by: "Daniel P. Berrang=C3=A9" Link: https://lore.kernel.org/r/1704312341-66640-10-git-send-email-steven.s= istare@oracle.com Signed-off-by: Peter Xu --- tests/qtest/migration-helpers.h | 9 ++-- tests/qtest/migration-helpers.c | 22 +++----- tests/qtest/migration-test.c | 91 ++++++++++++++++----------------- 3 files changed, 55 insertions(+), 67 deletions(-) diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helper= s.h index e31dc85cc7..3d32699c45 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -15,9 +15,12 @@ =20 #include "libqtest.h" =20 -bool migrate_watch_for_stop(QTestState *who, const char *name, - QDict *event, void *opaque); -bool migrate_watch_for_resume(QTestState *who, const char *name, +typedef struct QTestMigrationState { + bool stop_seen; + bool resume_seen; +} QTestMigrationState; + +bool migrate_watch_for_events(QTestState *who, const char *name, QDict *event, void *opaque); =20 G_GNUC_PRINTF(3, 4) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 24fb7b3525..fd3b94efa2 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -24,26 +24,16 @@ */ #define MIGRATION_STATUS_WAIT_TIMEOUT 120 =20 -bool migrate_watch_for_stop(QTestState *who, const char *name, - QDict *event, void *opaque) +bool migrate_watch_for_events(QTestState *who, const char *name, + QDict *event, void *opaque) { - bool *seen =3D opaque; + QTestMigrationState *state =3D opaque; =20 if (g_str_equal(name, "STOP")) { - *seen =3D true; + state->stop_seen =3D true; return true; - } - - return false; -} - -bool migrate_watch_for_resume(QTestState *who, const char *name, - QDict *event, void *opaque) -{ - bool *seen =3D opaque; - - if (g_str_equal(name, "RESUME")) { - *seen =3D true; + } else if (g_str_equal(name, "RESUME")) { + state->resume_seen =3D true; return true; } =20 diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index d520c587f7..41fc837f36 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -43,8 +43,8 @@ unsigned start_address; unsigned end_address; static bool uffd_feature_thread_id; -static bool got_src_stop; -static bool got_dst_resume; +static QTestMigrationState src_state; +static QTestMigrationState dst_state; =20 /* * An initial 3 MB offset is used as that corresponds @@ -230,6 +230,20 @@ static void wait_for_serial(const char *side) } while (true); } =20 +static void wait_for_stop(QTestState *who, QTestMigrationState *state) +{ + if (!state->stop_seen) { + qtest_qmp_eventwait(who, "STOP"); + } +} + +static void wait_for_resume(QTestState *who, QTestMigrationState *state) +{ + if (!state->resume_seen) { + qtest_qmp_eventwait(who, "RESUME"); + } +} + /* * It's tricky to use qemu's migration event capability with qtest, * events suddenly appearing confuse the qmp()/hmp() responses. @@ -277,21 +291,19 @@ static void read_blocktime(QTestState *who) qobject_unref(rsp_return); } =20 +/* + * Wait for two changes in the migration pass count, but bail if we stop. + */ static void wait_for_migration_pass(QTestState *who) { - uint64_t initial_pass =3D get_migration_pass(who); - uint64_t pass; - - /* Wait for the 1st sync */ - while (!got_src_stop && !initial_pass) { - usleep(1000); - initial_pass =3D get_migration_pass(who); - } + uint64_t pass, prev_pass =3D 0, changes =3D 0; =20 - do { + while (changes < 2 && !src_state.stop_seen) { usleep(1000); pass =3D get_migration_pass(who); - } while (pass =3D=3D initial_pass && !got_src_stop); + changes +=3D (pass !=3D prev_pass); + prev_pass =3D pass; + } } =20 static void check_guests_ram(QTestState *who) @@ -617,10 +629,7 @@ static void migrate_postcopy_start(QTestState *from, Q= TestState *to) { qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' = }"); =20 - if (!got_src_stop) { - qtest_qmp_eventwait(from, "STOP"); - } - + wait_for_stop(from, &src_state); qtest_qmp_eventwait(to, "RESUME"); } =20 @@ -756,8 +765,8 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, } } =20 - got_src_stop =3D false; - got_dst_resume =3D false; + dst_state =3D (QTestMigrationState) { }; + src_state =3D (QTestMigrationState) { }; if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { memory_size =3D "150M"; =20 @@ -848,8 +857,8 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, if (!args->only_target) { *from =3D qtest_init_with_env(QEMU_ENV_SRC, cmd_source); qtest_qmp_set_event_callback(*from, - migrate_watch_for_stop, - &got_src_stop); + migrate_watch_for_events, + &src_state); } =20 cmd_target =3D g_strdup_printf("-accel kvm%s -accel tcg " @@ -869,8 +878,8 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, ignore_stderr); *to =3D qtest_init_with_env(QEMU_ENV_DST, cmd_target); qtest_qmp_set_event_callback(*to, - migrate_watch_for_resume, - &got_dst_resume); + migrate_watch_for_events, + &dst_state); =20 /* * Remove shmem file immediately to avoid memory leak in test failed c= ase. @@ -1717,9 +1726,7 @@ static void test_precopy_common(MigrateCommon *args) */ if (args->result =3D=3D MIG_TEST_SUCCEED) { qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}"); - if (!got_src_stop) { - qtest_qmp_eventwait(from, "STOP"); - } + wait_for_stop(from, &src_state); migrate_ensure_converge(from); } } @@ -1765,9 +1772,8 @@ static void test_precopy_common(MigrateCommon *args) */ wait_for_migration_complete(from); =20 - if (!got_src_stop) { - qtest_qmp_eventwait(from, "STOP"); - } + wait_for_stop(from, &src_state); + } else { wait_for_migration_complete(from); /* @@ -1780,9 +1786,7 @@ static void test_precopy_common(MigrateCommon *args) qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}"); } =20 - if (!got_dst_resume) { - qtest_qmp_eventwait(to, "RESUME"); - } + wait_for_resume(to, &dst_state); =20 wait_for_serial("dest_serial"); } @@ -1821,9 +1825,7 @@ static void test_file_common(MigrateCommon *args, boo= l stop_src) =20 if (stop_src) { qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}"); - if (!got_src_stop) { - qtest_qmp_eventwait(from, "STOP"); - } + wait_for_stop(from, &src_state); } =20 if (args->result =3D=3D MIG_TEST_QMP_ERROR) { @@ -1844,10 +1846,7 @@ static void test_file_common(MigrateCommon *args, bo= ol stop_src) if (stop_src) { qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}"); } - - if (!got_dst_resume) { - qtest_qmp_eventwait(to, "RESUME"); - } + wait_for_resume(to, &dst_state); =20 wait_for_serial("dest_serial"); =20 @@ -1966,9 +1965,7 @@ static void test_ignore_shared(void) =20 migrate_wait_for_dirty_mem(from, to); =20 - if (!got_src_stop) { - qtest_qmp_eventwait(from, "STOP"); - } + wait_for_stop(from, &src_state); =20 qtest_qmp_eventwait(to, "RESUME"); =20 @@ -2503,7 +2500,7 @@ static void test_migrate_auto_converge(void) break; } usleep(20); - g_assert_false(got_src_stop); + g_assert_false(src_state.stop_seen); } while (true); /* The first percentage of throttling should be at least init_pct */ g_assert_cmpint(percentage, >=3D, init_pct); @@ -2842,9 +2839,7 @@ static void test_multifd_tcp_cancel(void) =20 migrate_ensure_converge(from); =20 - if (!got_src_stop) { - qtest_qmp_eventwait(from, "STOP"); - } + wait_for_stop(from, &src_state); qtest_qmp_eventwait(to2, "RESUME"); =20 wait_for_serial("dest_serial"); @@ -3177,7 +3172,7 @@ static void test_migrate_dirty_limit(void) throttle_us_per_full =3D read_migrate_property_int(from, "dirty-limit-throttle-time-per-rou= nd"); usleep(100); - g_assert_false(got_src_stop); + g_assert_false(src_state.stop_seen); } =20 /* Now cancel migrate and wait for dirty limit throttle switch off */ @@ -3189,7 +3184,7 @@ static void test_migrate_dirty_limit(void) throttle_us_per_full =3D read_migrate_property_int(from, "dirty-limit-throttle-time-per-rou= nd"); usleep(100); - g_assert_false(got_src_stop); + g_assert_false(src_state.stop_seen); } while (throttle_us_per_full !=3D 0 && --max_try_count); =20 /* Assert dirty limit is not in service */ @@ -3218,7 +3213,7 @@ static void test_migrate_dirty_limit(void) throttle_us_per_full =3D read_migrate_property_int(from, "dirty-limit-throttle-time-per-rou= nd"); usleep(100); - g_assert_false(got_src_stop); + g_assert_false(src_state.stop_seen); } =20 /* --=20 2.41.0