tests/qtest: migration events
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 <steven.sistare@oracle.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: "Daniel P. Berrangé" <berrange@redhat.com> Link: https://lore.kernel.org/r/1704312341-66640-10-git-send-email-steven.sistare@oracle.com Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
parent
49a5020697
commit
f0649758be
@ -24,26 +24,16 @@
|
|||||||
*/
|
*/
|
||||||
#define MIGRATION_STATUS_WAIT_TIMEOUT 120
|
#define MIGRATION_STATUS_WAIT_TIMEOUT 120
|
||||||
|
|
||||||
bool migrate_watch_for_stop(QTestState *who, const char *name,
|
bool migrate_watch_for_events(QTestState *who, const char *name,
|
||||||
QDict *event, void *opaque)
|
QDict *event, void *opaque)
|
||||||
{
|
{
|
||||||
bool *seen = opaque;
|
QTestMigrationState *state = opaque;
|
||||||
|
|
||||||
if (g_str_equal(name, "STOP")) {
|
if (g_str_equal(name, "STOP")) {
|
||||||
*seen = true;
|
state->stop_seen = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (g_str_equal(name, "RESUME")) {
|
||||||
|
state->resume_seen = true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool migrate_watch_for_resume(QTestState *who, const char *name,
|
|
||||||
QDict *event, void *opaque)
|
|
||||||
{
|
|
||||||
bool *seen = opaque;
|
|
||||||
|
|
||||||
if (g_str_equal(name, "RESUME")) {
|
|
||||||
*seen = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,12 @@
|
|||||||
|
|
||||||
#include "libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
bool migrate_watch_for_stop(QTestState *who, const char *name,
|
typedef struct QTestMigrationState {
|
||||||
QDict *event, void *opaque);
|
bool stop_seen;
|
||||||
bool migrate_watch_for_resume(QTestState *who, const char *name,
|
bool resume_seen;
|
||||||
|
} QTestMigrationState;
|
||||||
|
|
||||||
|
bool migrate_watch_for_events(QTestState *who, const char *name,
|
||||||
QDict *event, void *opaque);
|
QDict *event, void *opaque);
|
||||||
|
|
||||||
G_GNUC_PRINTF(3, 4)
|
G_GNUC_PRINTF(3, 4)
|
||||||
|
@ -43,8 +43,8 @@
|
|||||||
unsigned start_address;
|
unsigned start_address;
|
||||||
unsigned end_address;
|
unsigned end_address;
|
||||||
static bool uffd_feature_thread_id;
|
static bool uffd_feature_thread_id;
|
||||||
static bool got_src_stop;
|
static QTestMigrationState src_state;
|
||||||
static bool got_dst_resume;
|
static QTestMigrationState dst_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An initial 3 MB offset is used as that corresponds
|
* An initial 3 MB offset is used as that corresponds
|
||||||
@ -230,6 +230,20 @@ static void wait_for_serial(const char *side)
|
|||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
* It's tricky to use qemu's migration event capability with qtest,
|
||||||
* events suddenly appearing confuse the qmp()/hmp() responses.
|
* events suddenly appearing confuse the qmp()/hmp() responses.
|
||||||
@ -277,21 +291,19 @@ static void read_blocktime(QTestState *who)
|
|||||||
qobject_unref(rsp_return);
|
qobject_unref(rsp_return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait for two changes in the migration pass count, but bail if we stop.
|
||||||
|
*/
|
||||||
static void wait_for_migration_pass(QTestState *who)
|
static void wait_for_migration_pass(QTestState *who)
|
||||||
{
|
{
|
||||||
uint64_t initial_pass = get_migration_pass(who);
|
uint64_t pass, prev_pass = 0, changes = 0;
|
||||||
uint64_t pass;
|
|
||||||
|
|
||||||
/* Wait for the 1st sync */
|
while (changes < 2 && !src_state.stop_seen) {
|
||||||
while (!got_src_stop && !initial_pass) {
|
|
||||||
usleep(1000);
|
|
||||||
initial_pass = get_migration_pass(who);
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
pass = get_migration_pass(who);
|
pass = get_migration_pass(who);
|
||||||
} while (pass == initial_pass && !got_src_stop);
|
changes += (pass != prev_pass);
|
||||||
|
prev_pass = pass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_guests_ram(QTestState *who)
|
static void check_guests_ram(QTestState *who)
|
||||||
@ -617,10 +629,7 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to)
|
|||||||
{
|
{
|
||||||
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
|
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
|
||||||
|
|
||||||
if (!got_src_stop) {
|
wait_for_stop(from, &src_state);
|
||||||
qtest_qmp_eventwait(from, "STOP");
|
|
||||||
}
|
|
||||||
|
|
||||||
qtest_qmp_eventwait(to, "RESUME");
|
qtest_qmp_eventwait(to, "RESUME");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -756,8 +765,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
got_src_stop = false;
|
dst_state = (QTestMigrationState) { };
|
||||||
got_dst_resume = false;
|
src_state = (QTestMigrationState) { };
|
||||||
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
||||||
memory_size = "150M";
|
memory_size = "150M";
|
||||||
|
|
||||||
@ -848,8 +857,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
|
|||||||
if (!args->only_target) {
|
if (!args->only_target) {
|
||||||
*from = qtest_init_with_env(QEMU_ENV_SRC, cmd_source);
|
*from = qtest_init_with_env(QEMU_ENV_SRC, cmd_source);
|
||||||
qtest_qmp_set_event_callback(*from,
|
qtest_qmp_set_event_callback(*from,
|
||||||
migrate_watch_for_stop,
|
migrate_watch_for_events,
|
||||||
&got_src_stop);
|
&src_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
|
cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
|
||||||
@ -869,8 +878,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
|
|||||||
ignore_stderr);
|
ignore_stderr);
|
||||||
*to = qtest_init_with_env(QEMU_ENV_DST, cmd_target);
|
*to = qtest_init_with_env(QEMU_ENV_DST, cmd_target);
|
||||||
qtest_qmp_set_event_callback(*to,
|
qtest_qmp_set_event_callback(*to,
|
||||||
migrate_watch_for_resume,
|
migrate_watch_for_events,
|
||||||
&got_dst_resume);
|
&dst_state);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove shmem file immediately to avoid memory leak in test failed case.
|
* Remove shmem file immediately to avoid memory leak in test failed case.
|
||||||
@ -1717,9 +1726,7 @@ static void test_precopy_common(MigrateCommon *args)
|
|||||||
*/
|
*/
|
||||||
if (args->result == MIG_TEST_SUCCEED) {
|
if (args->result == MIG_TEST_SUCCEED) {
|
||||||
qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
|
qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
|
||||||
if (!got_src_stop) {
|
wait_for_stop(from, &src_state);
|
||||||
qtest_qmp_eventwait(from, "STOP");
|
|
||||||
}
|
|
||||||
migrate_ensure_converge(from);
|
migrate_ensure_converge(from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1765,9 +1772,8 @@ static void test_precopy_common(MigrateCommon *args)
|
|||||||
*/
|
*/
|
||||||
wait_for_migration_complete(from);
|
wait_for_migration_complete(from);
|
||||||
|
|
||||||
if (!got_src_stop) {
|
wait_for_stop(from, &src_state);
|
||||||
qtest_qmp_eventwait(from, "STOP");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
wait_for_migration_complete(from);
|
wait_for_migration_complete(from);
|
||||||
/*
|
/*
|
||||||
@ -1780,9 +1786,7 @@ static void test_precopy_common(MigrateCommon *args)
|
|||||||
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
|
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!got_dst_resume) {
|
wait_for_resume(to, &dst_state);
|
||||||
qtest_qmp_eventwait(to, "RESUME");
|
|
||||||
}
|
|
||||||
|
|
||||||
wait_for_serial("dest_serial");
|
wait_for_serial("dest_serial");
|
||||||
}
|
}
|
||||||
@ -1821,9 +1825,7 @@ static void test_file_common(MigrateCommon *args, bool stop_src)
|
|||||||
|
|
||||||
if (stop_src) {
|
if (stop_src) {
|
||||||
qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
|
qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
|
||||||
if (!got_src_stop) {
|
wait_for_stop(from, &src_state);
|
||||||
qtest_qmp_eventwait(from, "STOP");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->result == MIG_TEST_QMP_ERROR) {
|
if (args->result == MIG_TEST_QMP_ERROR) {
|
||||||
@ -1844,10 +1846,7 @@ static void test_file_common(MigrateCommon *args, bool stop_src)
|
|||||||
if (stop_src) {
|
if (stop_src) {
|
||||||
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
|
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
|
||||||
}
|
}
|
||||||
|
wait_for_resume(to, &dst_state);
|
||||||
if (!got_dst_resume) {
|
|
||||||
qtest_qmp_eventwait(to, "RESUME");
|
|
||||||
}
|
|
||||||
|
|
||||||
wait_for_serial("dest_serial");
|
wait_for_serial("dest_serial");
|
||||||
|
|
||||||
@ -1966,9 +1965,7 @@ static void test_ignore_shared(void)
|
|||||||
|
|
||||||
migrate_wait_for_dirty_mem(from, to);
|
migrate_wait_for_dirty_mem(from, to);
|
||||||
|
|
||||||
if (!got_src_stop) {
|
wait_for_stop(from, &src_state);
|
||||||
qtest_qmp_eventwait(from, "STOP");
|
|
||||||
}
|
|
||||||
|
|
||||||
qtest_qmp_eventwait(to, "RESUME");
|
qtest_qmp_eventwait(to, "RESUME");
|
||||||
|
|
||||||
@ -2503,7 +2500,7 @@ static void test_migrate_auto_converge(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
usleep(20);
|
usleep(20);
|
||||||
g_assert_false(got_src_stop);
|
g_assert_false(src_state.stop_seen);
|
||||||
} while (true);
|
} while (true);
|
||||||
/* The first percentage of throttling should be at least init_pct */
|
/* The first percentage of throttling should be at least init_pct */
|
||||||
g_assert_cmpint(percentage, >=, init_pct);
|
g_assert_cmpint(percentage, >=, init_pct);
|
||||||
@ -2842,9 +2839,7 @@ static void test_multifd_tcp_cancel(void)
|
|||||||
|
|
||||||
migrate_ensure_converge(from);
|
migrate_ensure_converge(from);
|
||||||
|
|
||||||
if (!got_src_stop) {
|
wait_for_stop(from, &src_state);
|
||||||
qtest_qmp_eventwait(from, "STOP");
|
|
||||||
}
|
|
||||||
qtest_qmp_eventwait(to2, "RESUME");
|
qtest_qmp_eventwait(to2, "RESUME");
|
||||||
|
|
||||||
wait_for_serial("dest_serial");
|
wait_for_serial("dest_serial");
|
||||||
@ -3177,7 +3172,7 @@ static void test_migrate_dirty_limit(void)
|
|||||||
throttle_us_per_full =
|
throttle_us_per_full =
|
||||||
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
|
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
|
||||||
usleep(100);
|
usleep(100);
|
||||||
g_assert_false(got_src_stop);
|
g_assert_false(src_state.stop_seen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now cancel migrate and wait for dirty limit throttle switch off */
|
/* 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 =
|
throttle_us_per_full =
|
||||||
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
|
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
|
||||||
usleep(100);
|
usleep(100);
|
||||||
g_assert_false(got_src_stop);
|
g_assert_false(src_state.stop_seen);
|
||||||
} while (throttle_us_per_full != 0 && --max_try_count);
|
} while (throttle_us_per_full != 0 && --max_try_count);
|
||||||
|
|
||||||
/* Assert dirty limit is not in service */
|
/* Assert dirty limit is not in service */
|
||||||
@ -3218,7 +3213,7 @@ static void test_migrate_dirty_limit(void)
|
|||||||
throttle_us_per_full =
|
throttle_us_per_full =
|
||||||
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
|
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
|
||||||
usleep(100);
|
usleep(100);
|
||||||
g_assert_false(got_src_stop);
|
g_assert_false(src_state.stop_seen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user