@samitouri / QOSamiQemu / commits / ced4b9dfde

tests/qtest/migration: Unify URIs

The migration tests have always used localhost migration and therefore the same URI for both sides of migration. Change the listen_uri and connect_uri into a single uri variable. For migrations using sockets, there's the possibility of detecting the socket address the destination side is using. For those, keep using different variables for migrate_qmp and migrate_incoming_qmp. Signed-off-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Lukas Straub <lukasstraub2@web.de> Tested-by: Lukas Straub <lukasstraub2@web.de> Reviewed-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/r/20260505160915.25558-16-farosas@suse.de Signed-off-by: Peter Xu <peterx@redhat.com>

Fabiano Rosas committed May 5, 2026 at 13:09 UTC ced4b9dfde227417bab5df96132814a301cfac1f
8 files changed +40 -50
tests/qtest/migration/colo-tests.c
+4 -4
@@ -55,12 +55,12 @@ static int test_colo_common(MigrateCommon *args,
55 data_hook = args->start_hook(from, to);
56 }
57
58 - migrate_incoming_qmp(to, args->listen_uri, NULL, "{}");
58 + migrate_incoming_qmp(to, args->uri, NULL, "{}");
59
60 migrate_ensure_converge(from);
61 wait_for_serial("src_serial");
62
63 - migrate_qmp(from, to, args->connect_uri, NULL, "{}");
63 + migrate_qmp(from, to, NULL, NULL, "{}");
64
65 wait_for_migration_status(from, "colo", NULL);
66 wait_for_resume(to, get_dst());
@@ -105,7 +105,7 @@ static void test_colo_plain_common(MigrateCommon *args,
105 bool failover_during_checkpoint,
106 bool primary_failover)
107 {
108 - args->listen_uri = "tcp:127.0.0.1:0";
108 + args->uri = "tcp:127.0.0.1:0";
109 test_colo_common(args, failover_during_checkpoint, primary_failover);
110 }
111
@@ -113,7 +113,7 @@ static void test_colo_multifd_common(MigrateCommon *args,
113 bool failover_during_checkpoint,
114 bool primary_failover)
115 {
116 - args->listen_uri = "tcp:127.0.0.1:0";
116 + args->uri = "tcp:127.0.0.1:0";
117 args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
118 test_colo_common(args, failover_during_checkpoint, primary_failover);
119 }
tests/qtest/migration/cpr-tests.c
+3 -3
@@ -35,7 +35,7 @@ static void test_mode_reboot(char *name, MigrateCommon *args)
35 g_autofree char *uri = g_strdup_printf("file:%s/%s", tmpfs,
36 FILE_TEST_FILENAME);
37
38 - args->connect_uri = uri;
38 + args->uri = uri;
39 args->start_hook = migrate_hook_start_mode_reboot;
40
41 args->start.mem_type = MEM_TYPE_SHMEM;
@@ -226,7 +226,7 @@ static void test_cpr_exec(MigrateCommon *args)
226 {
227 QTestState *from, *to;
228 void *data_hook = NULL;
229 - g_autofree char *connect_uri = g_strdup(args->connect_uri);
229 + g_autofree char *connect_uri = g_strdup(args->uri);
230 g_autofree char *filename = g_strdup_printf("%s/%s", tmpfs,
231 FILE_TEST_FILENAME);
232
@@ -280,7 +280,7 @@ static void test_mode_exec(char *name, MigrateCommon *args)
280 {
281 g_autofree char *uri = g_strdup_printf("file:%s/%s", tmpfs,
282 FILE_TEST_FILENAME);
283 - args->connect_uri = uri;
283 + args->uri = uri;
284 args->start_hook = test_mode_exec_start;
285
286 args->start.only_source = true;
tests/qtest/migration/file-tests.c
+5 -5
@@ -107,7 +107,7 @@ static void test_precopy_file_offset_fdset(char *name, MigrateCommon *args)
107 {
108 g_autofree char *uri = g_strdup_printf("file:/dev/fdset/1,offset=%d",
109 FILE_TEST_OFFSET);
110 - args->connect_uri = uri;
110 + args->uri = uri;
111 args->start_hook = migrate_hook_start_file_offset_fdset;
112
113 test_file_common(args, false);
@@ -120,7 +120,7 @@ static void test_precopy_file_offset(char *name, MigrateCommon *args)
120 FILE_TEST_FILENAME,
121 FILE_TEST_OFFSET);
122
123 - args->connect_uri = uri;
123 + args->uri = uri;
124 test_file_common(args, false);
125 }
126
@@ -130,7 +130,7 @@ static void test_precopy_file_offset_bad(char *name, MigrateCommon *args)
130 g_autofree char *uri = g_strdup_printf("file:%s/%s,offset=0x20M",
131 tmpfs, FILE_TEST_FILENAME);
132
133 - args->connect_uri = uri;
133 + args->uri = uri;
134 args->result = MIG_TEST_QMP_ERROR;
135
136 test_file_common(args, false);
@@ -247,7 +247,7 @@ static void test_multifd_file_mapped_ram_fdset(char *name, MigrateCommon *args)
247 g_autofree char *uri = g_strdup_printf("file:/dev/fdset/1,offset=%d",
248 FILE_TEST_OFFSET);
249
250 - args->connect_uri = uri;
250 + args->uri = uri;
251 args->start_hook = migrate_hook_start_multifd_mapped_ram_fdset;
252 args->end_hook = migrate_hook_end_multifd_mapped_ram_fdset;
253
@@ -262,7 +262,7 @@ static void test_multifd_file_mapped_ram_fdset_dio(char *name,
262 {
263 g_autofree char *uri = g_strdup_printf("file:/dev/fdset/1,offset=%d",
264 FILE_TEST_OFFSET);
265 - args->connect_uri = uri;
265 + args->uri = uri;
266 args->start_hook = migrate_hook_start_multifd_mapped_ram_fdset_dio;
267 args->end_hook = migrate_hook_end_multifd_mapped_ram_fdset;
268
tests/qtest/migration/framework.c
+11 -18
@@ -832,14 +832,7 @@ int test_precopy_common(MigrateCommon *args)
832 QTestState *from, *to;
833 void *data_hook = NULL;
834 QObject *channels = NULL;
835 -
836 - assert(!args->connect_uri);
837 -
838 - if (args->listen_uri) {
839 - args->connect_uri = args->listen_uri;
840 - } else {
841 - args->listen_uri = "tcp:127.0.0.1:0";
842 - }
835 + const char *listen_uri = args->uri ?: "tcp:127.0.0.1:0";
836
837 if (migrate_start(&from, &to, &args->start)) {
838 return -1;
@@ -849,7 +842,7 @@ int test_precopy_common(MigrateCommon *args)
842 data_hook = args->start_hook(from, to);
843 }
844
852 - migrate_incoming_qmp(to, args->listen_uri, NULL, "{}");
845 + migrate_incoming_qmp(to, listen_uri, NULL, "{}");
846
847 /* Wait for the first serial output from the source */
848 if (args->result == MIG_TEST_SUCCEED) {
@@ -879,11 +872,11 @@ int test_precopy_common(MigrateCommon *args)
872 }
873
874 if (args->result == MIG_TEST_QMP_ERROR) {
882 - migrate_qmp_fail(from, args->connect_uri, channels, "{}");
875 + migrate_qmp_fail(from, args->uri, channels, "{}");
876 goto finish;
877 }
878
886 - migrate_qmp(from, to, args->connect_uri, channels, "{}");
879 + migrate_qmp(from, to, args->uri, channels, "{}");
880
881 if (args->result != MIG_TEST_SUCCEED) {
882 bool allow_active = args->result == MIG_TEST_FAIL;
@@ -947,7 +940,7 @@ void test_precopy_unix_common(MigrateCommon *args)
940 {
941 g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
942
950 - args->listen_uri = uri;
943 + args->uri = uri;
944 test_precopy_common(args);
945 }
946
@@ -994,9 +987,9 @@ void test_file_common(MigrateCommon *args, bool stop_src)
987 return;
988 }
989
997 - if (!args->connect_uri) {
990 + if (!args->uri) {
991 uri = g_strdup_printf("file:%s/%s", tmpfs, FILE_TEST_FILENAME);
999 - args->connect_uri = uri;
992 + args->uri = uri;
993 }
994
995 /*
@@ -1006,7 +999,7 @@ void test_file_common(MigrateCommon *args, bool stop_src)
999 */
1000 g_assert_false(args->live);
1001
1009 - if (g_strrstr(args->connect_uri, "offset=")) {
1002 + if (g_strrstr(args->uri, "offset=")) {
1003 check_offset = true;
1004 /*
1005 * This comes before the start_hook because it's equivalent to
@@ -1029,18 +1022,18 @@ void test_file_common(MigrateCommon *args, bool stop_src)
1022 }
1023
1024 if (args->result == MIG_TEST_QMP_ERROR) {
1032 - migrate_qmp_fail(from, args->connect_uri, NULL, "{}");
1025 + migrate_qmp_fail(from, args->uri, NULL, "{}");
1026 goto finish;
1027 }
1028
1036 - migrate_qmp(from, to, args->connect_uri, NULL, "{}");
1029 + migrate_qmp(from, to, args->uri, NULL, "{}");
1030 wait_for_migration_complete(from);
1031
1032 /*
1033 * We need to wait for the source to finish before starting the
1034 * destination.
1035 */
1043 - migrate_incoming_qmp(to, args->connect_uri, NULL, "{}");
1036 + migrate_incoming_qmp(to, args->uri, NULL, "{}");
1037 wait_for_migration_complete(to);
1038
1039 if (stop_src) {
tests/qtest/migration/framework.h
+6 -8
@@ -163,16 +163,14 @@ typedef struct {
163 /* Optional: fine tune start parameters */
164 MigrateStart start;
165
166 - /* Required: the URI for the dst QEMU to listen on */
167 - const char *listen_uri;
168 -
166 /*
170 - * Optional: the URI for the src QEMU to connect to
171 - * If NULL, then it will query the dst QEMU for its actual
172 - * listening address and use that as the connect address.
173 - * This allows for dynamically picking a free TCP port.
167 + * Optional: the migration URI. If NULL, the common code should
168 + * provide a default. For socket migration, the source QEMU may
169 + * query the dst QEMU for the listening address and use that as
170 + * the connection address. This allows for dynamically picking a
171 + * free TCP port.
172 */
175 - const char *connect_uri;
173 + const char *uri;
174
175 /*
176 * Optional: JSON-formatted list of src QEMU URIs. If a port is
tests/qtest/migration/misc-tests.c
+2 -2
@@ -196,7 +196,7 @@ static void do_test_validate_uri_channel(MigrateCommon *args)
196 channels = args->connect_channels ?
197 qobject_from_json(args->connect_channels, &error_abort) :
198 NULL;
199 - migrate_qmp_fail(from, args->connect_uri, channels, "{}");
199 + migrate_qmp_fail(from, args->uri, channels, "{}");
200
201 migrate_end(from, to, false);
202 }
@@ -252,7 +252,7 @@ static void test_validate_caps_pair(char *test_path, MigrateCommon *args)
252
253 static void test_validate_uri_channels_both_set(char *name, MigrateCommon *args)
254 {
255 - args->connect_uri = "tcp:127.0.0.1:0",
255 + args->uri = "tcp:127.0.0.1:0",
256 args->connect_channels = ("[ { ""'channel-type': 'main',"
257 " 'addr': { 'transport': 'socket',"
258 " 'type': 'inet',"
tests/qtest/migration/precopy-tests.c
+8 -9
@@ -161,7 +161,7 @@ static void __test_precopy_rdma_plain(MigrateCommon *args, bool ipv6)
161 **/
162 g_autofree char *uri = g_strdup_printf("rdma:%s:29200", buffer);
163
164 - args->listen_uri = uri;
164 + args->uri = uri;
165
166 test_precopy_common(args);
167 }
@@ -253,7 +253,7 @@ static void migrate_hook_end_fd(QTestState *from,
253
254 static void test_precopy_fd_socket(char *name, MigrateCommon *args)
255 {
256 - args->listen_uri = "fd:fd-mig";
256 + args->uri = "fd:fd-mig";
257 args->start_hook = migrate_hook_start_fd;
258 args->end_hook = migrate_hook_end_fd;
259
@@ -970,7 +970,7 @@ static void test_dirty_limit(char *name, MigrateCommon *args)
970 args->start.hide_stderr = true;
971 args->start.use_dirty_ring = true;
972
973 - args->connect_uri = uri;
973 + args->uri = uri;
974
975 /* Start src, dst vm */
976 if (migrate_start(&from, &to, &args->start)) {
@@ -981,8 +981,8 @@ static void test_dirty_limit(char *name, MigrateCommon *args)
981 migrate_dirty_limit_wait_showup(from, dirtylimit_period, dirtylimit_value);
982
983 /* Start migrate */
984 - migrate_incoming_qmp(to, args->connect_uri, NULL, "{}");
985 - migrate_qmp(from, to, args->connect_uri, NULL, "{}");
984 + migrate_incoming_qmp(to, args->uri, NULL, "{}");
985 + migrate_qmp(from, to, args->uri, NULL, "{}");
986
987 /* Wait for dirty limit throttle begin */
988 throttle_us_per_full = 0;
@@ -1014,8 +1014,7 @@ static void test_dirty_limit(char *name, MigrateCommon *args)
1014 /* Assert dirty limit is not in service */
1015 g_assert_cmpint(throttle_us_per_full, ==, 0);
1016
1017 - args->listen_uri = uri;
1018 - args->connect_uri = uri;
1017 + args->uri = uri;
1018
1019 args->start.only_target = true;
1020 args->start.use_dirty_ring = true;
@@ -1026,8 +1025,8 @@ static void test_dirty_limit(char *name, MigrateCommon *args)
1025 }
1026
1027 /* Start migrate */
1029 - migrate_incoming_qmp(to, args->listen_uri, NULL, "{}");
1030 - migrate_qmp(from, to, args->connect_uri, NULL, "{}");
1028 + migrate_incoming_qmp(to, args->uri, NULL, "{}");
1029 + migrate_qmp(from, to, args->uri, NULL, "{}");
1030
1031 /* Wait for dirty limit throttle begin */
1032 throttle_us_per_full = 0;
tests/qtest/migration/tls-tests.c
+1 -1
@@ -436,7 +436,7 @@ static void test_precopy_unix_tls_x509_default_host(char *name,
436 {
437 g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
438
439 - args->listen_uri = uri;
439 + args->uri = uri;
440 args->start_hook = migrate_hook_start_tls_x509_default_host;
441 args->end_hook = migrate_hook_end_tls_x509;
442 args->result = MIG_TEST_FAIL;