@samitouri / QOSamiQemu / commits / 18ff25e131

tests/qtest/dbus-vmstate: Bring the test up-to-date

The dbus-vmstate-test has been disabled for years. Here's the things that have changed in the meantime and how to update the test: - Migration tests got new headers. Update the includes. - migrate_qmp got new parameters. Update the caller. - migrate_incoming_qmp is now used instead of -incoming URL. Use -incoming defer. - Tests expecting failure should not check non-zero return code. Check for failed migration state instead. - The test result enum was introduced. Replace the migration_fail flag with the enum. - The DEVICE state was added. Replace wait_for_migration_complete with migration_event_wait, which won't trip on intermediary states. - Migration completion was reworked. Explicitly wait for the RESUME event before asserting runstate is RUNNING to avoid checking too quickly and seeing FINISH_MIGRATE instead. - The FAILING state was added. Wait for it before waiting for the RESUME event. - Sanity checks were added to migration_get_env(). Start calling that function in main. - qtest_add_func now has a wrapper. Replace qtest_add_func with migration_test_add. Update tests' signatures to take MigrationCommon, although it's unused. - meson now sets up G_TEST_DBUS_DAEMON. Remove the logic around it. Signed-off-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260429190550.20122-2-farosas@suse.de>

Fabiano Rosas committed Apr 29, 2026 at 16:05 UTC 18ff25e1315937f712354092be727aa7db0db127
2 files changed +46 -32
tests/qtest/dbus-vmstate-test.c
+41 -30
@@ -2,8 +2,8 @@
2 #include <glib/gstdio.h>
3 #include <gio/gio.h>
4 #include "libqtest.h"
5 +#include "migration/migration-qmp.h"
6 #include "dbus-vmstate1.h"
6 -#include "migration-helpers.h"
7
8 static char *workdir;
9
@@ -29,7 +29,7 @@ typedef struct TestServer {
29
30 typedef struct Test {
31 const char *id_list;
32 - bool migrate_fail;
32 + int result;
33 bool without_dst_b;
34 TestServer srcA;
35 TestServer dstA;
@@ -190,6 +190,7 @@ test_dbus_vmstate(Test *test)
190 g_autofree char *uri = NULL;
191 QTestState *src_qemu = NULL, *dst_qemu = NULL;
192 guint ownsrcA, ownsrcB, owndstA, owndstB;
193 + QTestMigrationState src_state = { };
194
195 uri = g_strdup_printf("unix:%s/migsocket", workdir);
196
@@ -224,17 +225,33 @@ test_dbus_vmstate(Test *test)
225
226 src_qemu = qtest_init(src_qemu_args);
227 dst_qemu = qtest_init(dst_qemu_args);
228 +
229 + migrate_set_capability(src_qemu, "events", true);
230 + qtest_qmp_set_event_callback(src_qemu, migrate_watch_for_events,
231 + &src_state);
232 +
233 set_id_list(test, src_qemu);
234 set_id_list(test, dst_qemu);
235
236 thread = g_thread_new("dbus-vmstate-thread", dbus_vmstate_thread, loop);
237
238 migrate_incoming_qmp(dst_qemu, uri, NULL, "{}");
233 - migrate_qmp(src_qemu, uri, "{}");
239 + migrate_ensure_converge(src_qemu);
240 + migrate_qmp(src_qemu, NULL, uri, NULL, "{}");
241 test->src_qemu = src_qemu;
235 - if (test->migrate_fail) {
236 - wait_for_migration_fail(src_qemu, true);
237 - qtest_set_expected_status(dst_qemu, EXIT_FAILURE);
242 +
243 + if (test->result != MIG_TEST_SUCCEED) {
244 + QDict *rsp;
245 +
246 + migration_event_wait(src_qemu, "failing");
247 + wait_for_resume(src_qemu, &src_state);
248 + migration_event_wait(src_qemu, "failed");
249 +
250 + rsp = qtest_qmp_assert_success_ref(src_qemu,
251 + "{ 'execute': 'query-status' }");
252 + g_assert(qdict_haskey(rsp, "running"));
253 + g_assert(qdict_get_bool(rsp, "running"));
254 + qobject_unref(rsp);
255 } else {
256 wait_for_migration_complete(src_qemu);
257 }
@@ -270,7 +287,7 @@ check_migrated(TestServer *s, TestServer *d)
287 }
288
289 static void
273 -test_dbus_vmstate_without_list(void)
290 +test_dbus_vmstate_without_list(char *name, MigrateCommon *args)
291 {
292 Test test = { 0, };
293
@@ -281,7 +298,7 @@ test_dbus_vmstate_without_list(void)
298 }
299
300 static void
284 -test_dbus_vmstate_with_list(void)
301 +test_dbus_vmstate_with_list(char *name, MigrateCommon *args)
302 {
303 Test test = { .id_list = "idA,idB" };
304
@@ -292,7 +309,7 @@ test_dbus_vmstate_with_list(void)
309 }
310
311 static void
295 -test_dbus_vmstate_only_a(void)
312 +test_dbus_vmstate_only_a(char *name, MigrateCommon *args)
313 {
314 Test test = { .id_list = "idA" };
315
@@ -303,9 +320,10 @@ test_dbus_vmstate_only_a(void)
320 }
321
322 static void
306 -test_dbus_vmstate_missing_src(void)
323 +test_dbus_vmstate_missing_src(char *name, MigrateCommon *args)
324 {
308 - Test test = { .id_list = "idA,idC", .migrate_fail = true };
325 + Test test = { .id_list = "idA,idC",
326 + .result = MIG_TEST_FAIL };
327
328 /* run in subprocess to silence QEMU error reporting */
329 if (g_test_subprocess()) {
@@ -320,11 +338,11 @@ test_dbus_vmstate_missing_src(void)
338 }
339
340 static void
323 -test_dbus_vmstate_missing_dst(void)
341 +test_dbus_vmstate_missing_dst(char *name, MigrateCommon *args)
342 {
343 Test test = { .id_list = "idA,idB",
344 .without_dst_b = true,
327 - .migrate_fail = true };
345 + .result = MIG_TEST_FAIL };
346
347 /* run in subprocess to silence QEMU error reporting */
348 if (g_test_subprocess()) {
@@ -343,15 +361,8 @@ int
361 main(int argc, char **argv)
362 {
363 GError *err = NULL;
346 - g_autofree char *dbus_daemon = NULL;
364 int ret;
365
349 - dbus_daemon = g_build_filename(G_STRINGIFY(SRCDIR),
350 - "tests",
351 - "dbus-vmstate-daemon.sh",
352 - NULL);
353 - g_setenv("G_TEST_DBUS_DAEMON", dbus_daemon, true);
354 -
366 g_test_init(&argc, &argv, NULL);
367
368 workdir = g_dir_make_tmp("dbus-vmstate-test-XXXXXX", &err);
@@ -362,16 +373,16 @@ main(int argc, char **argv)
373
374 g_setenv("DBUS_VMSTATE_TEST_TMPDIR", workdir, true);
375
365 - qtest_add_func("/dbus-vmstate/without-list",
366 - test_dbus_vmstate_without_list);
367 - qtest_add_func("/dbus-vmstate/with-list",
368 - test_dbus_vmstate_with_list);
369 - qtest_add_func("/dbus-vmstate/only-a",
370 - test_dbus_vmstate_only_a);
371 - qtest_add_func("/dbus-vmstate/missing-src",
372 - test_dbus_vmstate_missing_src);
373 - qtest_add_func("/dbus-vmstate/missing-dst",
374 - test_dbus_vmstate_missing_dst);
376 + migration_test_add("/dbus-vmstate/without-list",
377 + test_dbus_vmstate_without_list);
378 + migration_test_add("/dbus-vmstate/with-list",
379 + test_dbus_vmstate_with_list);
380 + migration_test_add("/dbus-vmstate/only-a",
381 + test_dbus_vmstate_only_a);
382 + migration_test_add("/dbus-vmstate/missing-src",
383 + test_dbus_vmstate_missing_src);
384 + migration_test_add("/dbus-vmstate/missing-dst",
385 + test_dbus_vmstate_missing_dst);
386
387 ret = g_test_run();
388
tests/qtest/meson.build
+5 -2
@@ -128,10 +128,12 @@ if dbus_daemon.found() and gdbus_codegen.found()
128 # Temporarily disabled due to Patchew failures:
129 #qtests_i386 += ['dbus-vmstate-test']
130 dbus_vmstate1 = custom_target('dbus-vmstate description',
131 - output: ['dbus-vmstate1.h', 'dbus-vmstate1.c'],
131 + build_by_default: true,
132 + output: [ 'dbus-vmstate1.h', 'dbus-vmstate1.c'],
133 input: meson.project_source_root() / 'backends/dbus-vmstate1.xml',
134 command: [gdbus_codegen, '@INPUT@',
135 '--interface-prefix', 'org.qemu',
136 + '--output-directory', meson.current_build_dir(),
137 '--generate-c-code', '@BASENAME@']).to_list()
138 else
139 dbus_vmstate1 = []
@@ -387,7 +389,8 @@ qtests = {
389 'bios-tables-test': [io, 'boot-sector.c', 'acpi-utils.c', 'tpm-emu.c'],
390 'cdrom-test': files('boot-sector.c'),
391 'dbus-vmstate-test': files('migration/migration-qmp.c',
390 - 'migration/migration-util.c') + dbus_vmstate1,
392 + 'migration/migration-util.c') + dbus_vmstate1 +
393 + [gio],
394 'erst-test': files('erst-test.c'),
395 'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'],
396 'migration-test': test_migration_files + migration_tls_files + migration_colo_files,