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;
/*
* An initial 3 MB offset is used as that corresponds
} 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,
* events suddenly appearing confuse the qmp()/hmp() responses.
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)
{
- uint64_t initial_pass = get_migration_pass(who);
- uint64_t pass;
-
- /* Wait for the 1st sync */
- while (!got_src_stop && !initial_pass) {
- usleep(1000);
- initial_pass = get_migration_pass(who);
- }
+ uint64_t pass, prev_pass = 0, changes = 0;
- do {
+ while (changes < 2 && !src_state.stop_seen) {
usleep(1000);
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)
{
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
-
+ wait_for_stop(from, &src_state);
qtest_qmp_eventwait(to, "RESUME");
}
}
}
- got_src_stop = false;
- got_dst_resume = false;
+ dst_state = (QTestMigrationState) { };
+ src_state = (QTestMigrationState) { };
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
memory_size = "150M";
if (!args->only_target) {
*from = 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);
}
cmd_target = g_strdup_printf("-accel kvm%s -accel tcg "
ignore_stderr);
*to = 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);
/*
* Remove shmem file immediately to avoid memory leak in test failed case.
*/
if (args->result == 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);
}
}
*/
wait_for_migration_complete(from);
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
+
} else {
wait_for_migration_complete(from);
/*
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
}
- if (!got_dst_resume) {
- qtest_qmp_eventwait(to, "RESUME");
- }
+ wait_for_resume(to, &dst_state);
wait_for_serial("dest_serial");
}
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);
}
if (args->result == MIG_TEST_QMP_ERROR) {
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);
wait_for_serial("dest_serial");
migrate_wait_for_dirty_mem(from, to);
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
qtest_qmp_eventwait(to, "RESUME");
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, >=, init_pct);
migrate_ensure_converge(from);
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
qtest_qmp_eventwait(to2, "RESUME");
wait_for_serial("dest_serial");
throttle_us_per_full =
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
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 */
throttle_us_per_full =
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
usleep(100);
- g_assert_false(got_src_stop);
+ g_assert_false(src_state.stop_seen);
} while (throttle_us_per_full != 0 && --max_try_count);
/* Assert dirty limit is not in service */
throttle_us_per_full =
read_migrate_property_int(from, "dirty-limit-throttle-time-per-round");
usleep(100);
- g_assert_false(got_src_stop);
+ g_assert_false(src_state.stop_seen);
}
/*