xref: /openbmc/qemu/tests/qtest/migration-test.c (revision 88cd34ee)
1 /*
2  * QTest testcase for migration
3  *
4  * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
5  *   based on the vhost-user-test.c that is:
6  *      Copyright (c) 2014 Virtual Open Systems Sarl.
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or later.
9  * See the COPYING file in the top-level directory.
10  *
11  */
12 
13 #include "qemu/osdep.h"
14 
15 #include "libqtest.h"
16 #include "qapi/qmp/qdict.h"
17 #include "qemu/module.h"
18 #include "qemu/option.h"
19 #include "qemu/range.h"
20 #include "qemu/sockets.h"
21 #include "chardev/char.h"
22 #include "qapi/qapi-visit-sockets.h"
23 #include "qapi/qobject-input-visitor.h"
24 #include "qapi/qobject-output-visitor.h"
25 
26 #include "migration-helpers.h"
27 #include "migration/migration-test.h"
28 
29 /* TODO actually test the results and get rid of this */
30 #define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
31 
32 unsigned start_address;
33 unsigned end_address;
34 static bool uffd_feature_thread_id;
35 
36 #if defined(__linux__)
37 #include <sys/syscall.h>
38 #include <sys/vfs.h>
39 #endif
40 
41 #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
42 #include <sys/eventfd.h>
43 #include <sys/ioctl.h>
44 #include <linux/userfaultfd.h>
45 
46 static bool ufd_version_check(void)
47 {
48     struct uffdio_api api_struct;
49     uint64_t ioctl_mask;
50 
51     int ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
52 
53     if (ufd == -1) {
54         g_test_message("Skipping test: userfaultfd not available");
55         return false;
56     }
57 
58     api_struct.api = UFFD_API;
59     api_struct.features = 0;
60     if (ioctl(ufd, UFFDIO_API, &api_struct)) {
61         g_test_message("Skipping test: UFFDIO_API failed");
62         return false;
63     }
64     uffd_feature_thread_id = api_struct.features & UFFD_FEATURE_THREAD_ID;
65 
66     ioctl_mask = (__u64)1 << _UFFDIO_REGISTER |
67                  (__u64)1 << _UFFDIO_UNREGISTER;
68     if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) {
69         g_test_message("Skipping test: Missing userfault feature");
70         return false;
71     }
72 
73     return true;
74 }
75 
76 #else
77 static bool ufd_version_check(void)
78 {
79     g_test_message("Skipping test: Userfault not available (builtdtime)");
80     return false;
81 }
82 
83 #endif
84 
85 static const char *tmpfs;
86 
87 /* The boot file modifies memory area in [start_address, end_address)
88  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
89  */
90 #include "tests/migration/i386/a-b-bootblock.h"
91 #include "tests/migration/aarch64/a-b-kernel.h"
92 #include "tests/migration/s390x/a-b-bios.h"
93 
94 static void init_bootfile(const char *bootpath, void *content, size_t len)
95 {
96     FILE *bootfile = fopen(bootpath, "wb");
97 
98     g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
99     fclose(bootfile);
100 }
101 
102 /*
103  * Wait for some output in the serial output file,
104  * we get an 'A' followed by an endless string of 'B's
105  * but on the destination we won't have the A.
106  */
107 static void wait_for_serial(const char *side)
108 {
109     char *serialpath = g_strdup_printf("%s/%s", tmpfs, side);
110     FILE *serialfile = fopen(serialpath, "r");
111     const char *arch = qtest_get_arch();
112     int started = (strcmp(side, "src_serial") == 0 &&
113                    strcmp(arch, "ppc64") == 0) ? 0 : 1;
114 
115     g_free(serialpath);
116     do {
117         int readvalue = fgetc(serialfile);
118 
119         if (!started) {
120             /* SLOF prints its banner before starting test,
121              * to ignore it, mark the start of the test with '_',
122              * ignore all characters until this marker
123              */
124             switch (readvalue) {
125             case '_':
126                 started = 1;
127                 break;
128             case EOF:
129                 fseek(serialfile, 0, SEEK_SET);
130                 usleep(1000);
131                 break;
132             }
133             continue;
134         }
135         switch (readvalue) {
136         case 'A':
137             /* Fine */
138             break;
139 
140         case 'B':
141             /* It's alive! */
142             fclose(serialfile);
143             return;
144 
145         case EOF:
146             started = (strcmp(side, "src_serial") == 0 &&
147                        strcmp(arch, "ppc64") == 0) ? 0 : 1;
148             fseek(serialfile, 0, SEEK_SET);
149             usleep(1000);
150             break;
151 
152         default:
153             fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, side);
154             g_assert_not_reached();
155         }
156     } while (true);
157 }
158 
159 /*
160  * It's tricky to use qemu's migration event capability with qtest,
161  * events suddenly appearing confuse the qmp()/hmp() responses.
162  */
163 
164 static int64_t read_ram_property_int(QTestState *who, const char *property)
165 {
166     QDict *rsp_return, *rsp_ram;
167     int64_t result;
168 
169     rsp_return = migrate_query(who);
170     if (!qdict_haskey(rsp_return, "ram")) {
171         /* Still in setup */
172         result = 0;
173     } else {
174         rsp_ram = qdict_get_qdict(rsp_return, "ram");
175         result = qdict_get_try_int(rsp_ram, property, 0);
176     }
177     qobject_unref(rsp_return);
178     return result;
179 }
180 
181 static int64_t read_migrate_property_int(QTestState *who, const char *property)
182 {
183     QDict *rsp_return;
184     int64_t result;
185 
186     rsp_return = migrate_query(who);
187     result = qdict_get_try_int(rsp_return, property, 0);
188     qobject_unref(rsp_return);
189     return result;
190 }
191 
192 static uint64_t get_migration_pass(QTestState *who)
193 {
194     return read_ram_property_int(who, "dirty-sync-count");
195 }
196 
197 static void read_blocktime(QTestState *who)
198 {
199     QDict *rsp_return;
200 
201     rsp_return = migrate_query(who);
202     g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
203     qobject_unref(rsp_return);
204 }
205 
206 static void wait_for_migration_pass(QTestState *who)
207 {
208     uint64_t initial_pass = get_migration_pass(who);
209     uint64_t pass;
210 
211     /* Wait for the 1st sync */
212     while (!got_stop && !initial_pass) {
213         usleep(1000);
214         initial_pass = get_migration_pass(who);
215     }
216 
217     do {
218         usleep(1000);
219         pass = get_migration_pass(who);
220     } while (pass == initial_pass && !got_stop);
221 }
222 
223 static void check_guests_ram(QTestState *who)
224 {
225     /* Our ASM test will have been incrementing one byte from each page from
226      * start_address to < end_address in order. This gives us a constraint
227      * that any page's byte should be equal or less than the previous pages
228      * byte (mod 256); and they should all be equal except for one transition
229      * at the point where we meet the incrementer. (We're running this with
230      * the guest stopped).
231      */
232     unsigned address;
233     uint8_t first_byte;
234     uint8_t last_byte;
235     bool hit_edge = false;
236     int bad = 0;
237 
238     qtest_memread(who, start_address, &first_byte, 1);
239     last_byte = first_byte;
240 
241     for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
242          address += TEST_MEM_PAGE_SIZE)
243     {
244         uint8_t b;
245         qtest_memread(who, address, &b, 1);
246         if (b != last_byte) {
247             if (((b + 1) % 256) == last_byte && !hit_edge) {
248                 /* This is OK, the guest stopped at the point of
249                  * incrementing the previous page but didn't get
250                  * to us yet.
251                  */
252                 hit_edge = true;
253                 last_byte = b;
254             } else {
255                 bad++;
256                 if (bad <= 10) {
257                     fprintf(stderr, "Memory content inconsistency at %x"
258                             " first_byte = %x last_byte = %x current = %x"
259                             " hit_edge = %x\n",
260                             address, first_byte, last_byte, b, hit_edge);
261                 }
262             }
263         }
264     }
265     if (bad >= 10) {
266         fprintf(stderr, "and in another %d pages", bad - 10);
267     }
268     g_assert(bad == 0);
269 }
270 
271 static void cleanup(const char *filename)
272 {
273     char *path = g_strdup_printf("%s/%s", tmpfs, filename);
274 
275     unlink(path);
276     g_free(path);
277 }
278 
279 static char *SocketAddress_to_str(SocketAddress *addr)
280 {
281     switch (addr->type) {
282     case SOCKET_ADDRESS_TYPE_INET:
283         return g_strdup_printf("tcp:%s:%s",
284                                addr->u.inet.host,
285                                addr->u.inet.port);
286     case SOCKET_ADDRESS_TYPE_UNIX:
287         return g_strdup_printf("unix:%s",
288                                addr->u.q_unix.path);
289     case SOCKET_ADDRESS_TYPE_FD:
290         return g_strdup_printf("fd:%s", addr->u.fd.str);
291     case SOCKET_ADDRESS_TYPE_VSOCK:
292         return g_strdup_printf("tcp:%s:%s",
293                                addr->u.vsock.cid,
294                                addr->u.vsock.port);
295     default:
296         return g_strdup("unknown address type");
297     }
298 }
299 
300 static char *migrate_get_socket_address(QTestState *who, const char *parameter)
301 {
302     QDict *rsp;
303     char *result;
304     Error *local_err = NULL;
305     SocketAddressList *addrs;
306     Visitor *iv = NULL;
307     QObject *object;
308 
309     rsp = migrate_query(who);
310     object = qdict_get(rsp, parameter);
311 
312     iv = qobject_input_visitor_new(object);
313     visit_type_SocketAddressList(iv, NULL, &addrs, &local_err);
314     visit_free(iv);
315 
316     /* we are only using a single address */
317     result = SocketAddress_to_str(addrs->value);
318 
319     qapi_free_SocketAddressList(addrs);
320     qobject_unref(rsp);
321     return result;
322 }
323 
324 static long long migrate_get_parameter_int(QTestState *who,
325                                            const char *parameter)
326 {
327     QDict *rsp;
328     long long result;
329 
330     rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
331     result = qdict_get_int(rsp, parameter);
332     qobject_unref(rsp);
333     return result;
334 }
335 
336 static void migrate_check_parameter_int(QTestState *who, const char *parameter,
337                                         long long value)
338 {
339     long long result;
340 
341     result = migrate_get_parameter_int(who, parameter);
342     g_assert_cmpint(result, ==, value);
343 }
344 
345 static void migrate_set_parameter_int(QTestState *who, const char *parameter,
346                                       long long value)
347 {
348     QDict *rsp;
349 
350     rsp = qtest_qmp(who,
351                     "{ 'execute': 'migrate-set-parameters',"
352                     "'arguments': { %s: %lld } }",
353                     parameter, value);
354     g_assert(qdict_haskey(rsp, "return"));
355     qobject_unref(rsp);
356     migrate_check_parameter_int(who, parameter, value);
357 }
358 
359 static char *migrate_get_parameter_str(QTestState *who,
360                                        const char *parameter)
361 {
362     QDict *rsp;
363     char *result;
364 
365     rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
366     result = g_strdup(qdict_get_str(rsp, parameter));
367     qobject_unref(rsp);
368     return result;
369 }
370 
371 static void migrate_check_parameter_str(QTestState *who, const char *parameter,
372                                         const char *value)
373 {
374     char *result;
375 
376     result = migrate_get_parameter_str(who, parameter);
377     g_assert_cmpstr(result, ==, value);
378     g_free(result);
379 }
380 
381 __attribute__((unused))
382 static void migrate_set_parameter_str(QTestState *who, const char *parameter,
383                                       const char *value)
384 {
385     QDict *rsp;
386 
387     rsp = qtest_qmp(who,
388                     "{ 'execute': 'migrate-set-parameters',"
389                     "'arguments': { %s: %s } }",
390                     parameter, value);
391     g_assert(qdict_haskey(rsp, "return"));
392     qobject_unref(rsp);
393     migrate_check_parameter_str(who, parameter, value);
394 }
395 
396 static void migrate_pause(QTestState *who)
397 {
398     QDict *rsp;
399 
400     rsp = wait_command(who, "{ 'execute': 'migrate-pause' }");
401     qobject_unref(rsp);
402 }
403 
404 static void migrate_continue(QTestState *who, const char *state)
405 {
406     QDict *rsp;
407 
408     rsp = wait_command(who,
409                        "{ 'execute': 'migrate-continue',"
410                        "  'arguments': { 'state': %s } }",
411                        state);
412     qobject_unref(rsp);
413 }
414 
415 static void migrate_recover(QTestState *who, const char *uri)
416 {
417     QDict *rsp;
418 
419     rsp = wait_command(who,
420                        "{ 'execute': 'migrate-recover', "
421                        "  'id': 'recover-cmd', "
422                        "  'arguments': { 'uri': %s } }",
423                        uri);
424     qobject_unref(rsp);
425 }
426 
427 static void migrate_cancel(QTestState *who)
428 {
429     QDict *rsp;
430 
431     rsp = wait_command(who, "{ 'execute': 'migrate_cancel' }");
432     qobject_unref(rsp);
433 }
434 
435 static void migrate_set_capability(QTestState *who, const char *capability,
436                                    bool value)
437 {
438     QDict *rsp;
439 
440     rsp = qtest_qmp(who,
441                     "{ 'execute': 'migrate-set-capabilities',"
442                     "'arguments': { "
443                     "'capabilities': [ { "
444                     "'capability': %s, 'state': %i } ] } }",
445                     capability, value);
446     g_assert(qdict_haskey(rsp, "return"));
447     qobject_unref(rsp);
448 }
449 
450 static void migrate_postcopy_start(QTestState *from, QTestState *to)
451 {
452     QDict *rsp;
453 
454     rsp = wait_command(from, "{ 'execute': 'migrate-start-postcopy' }");
455     qobject_unref(rsp);
456 
457     if (!got_stop) {
458         qtest_qmp_eventwait(from, "STOP");
459     }
460 
461     qtest_qmp_eventwait(to, "RESUME");
462 }
463 
464 typedef struct {
465     bool hide_stderr;
466     bool use_shmem;
467     /* only launch the target process */
468     bool only_target;
469     char *opts_source;
470     char *opts_target;
471 } MigrateStart;
472 
473 static MigrateStart *migrate_start_new(void)
474 {
475     MigrateStart *args = g_new0(MigrateStart, 1);
476 
477     args->opts_source = g_strdup("");
478     args->opts_target = g_strdup("");
479     return args;
480 }
481 
482 static void migrate_start_destroy(MigrateStart *args)
483 {
484     g_free(args->opts_source);
485     g_free(args->opts_target);
486     g_free(args);
487 }
488 
489 static int test_migrate_start(QTestState **from, QTestState **to,
490                               const char *uri, MigrateStart *args)
491 {
492     gchar *arch_source, *arch_target;
493     gchar *cmd_source, *cmd_target;
494     const gchar *ignore_stderr;
495     char *bootpath = NULL;
496     char *shmem_opts;
497     char *shmem_path;
498     const char *arch = qtest_get_arch();
499     const char *machine_opts = NULL;
500     const char *memory_size;
501     int ret = 0;
502 
503     if (args->use_shmem) {
504         if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
505             g_test_skip("/dev/shm is not supported");
506             ret = -1;
507             goto out;
508         }
509     }
510 
511     got_stop = false;
512     bootpath = g_strdup_printf("%s/bootsect", tmpfs);
513     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
514         /* the assembled x86 boot sector should be exactly one sector large */
515         assert(sizeof(x86_bootsect) == 512);
516         init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect));
517         memory_size = "150M";
518         arch_source = g_strdup_printf("-drive file=%s,format=raw", bootpath);
519         arch_target = g_strdup(arch_source);
520         start_address = X86_TEST_MEM_START;
521         end_address = X86_TEST_MEM_END;
522     } else if (g_str_equal(arch, "s390x")) {
523         init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf));
524         memory_size = "128M";
525         arch_source = g_strdup_printf("-bios %s", bootpath);
526         arch_target = g_strdup(arch_source);
527         start_address = S390_TEST_MEM_START;
528         end_address = S390_TEST_MEM_END;
529     } else if (strcmp(arch, "ppc64") == 0) {
530         machine_opts = "vsmt=8";
531         memory_size = "256M";
532         start_address = PPC_TEST_MEM_START;
533         end_address = PPC_TEST_MEM_END;
534         arch_source = g_strdup_printf("-nodefaults "
535                                       "-prom-env 'use-nvramrc?=true' -prom-env "
536                                       "'nvramrc=hex .\" _\" begin %x %x "
537                                       "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
538                                       "until'", end_address, start_address);
539         arch_target = g_strdup("");
540     } else if (strcmp(arch, "aarch64") == 0) {
541         init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
542         machine_opts = "virt,gic-version=max";
543         memory_size = "150M";
544         arch_source = g_strdup_printf("-cpu max "
545                                       "-kernel %s",
546                                       bootpath);
547         arch_target = g_strdup(arch_source);
548         start_address = ARM_TEST_MEM_START;
549         end_address = ARM_TEST_MEM_END;
550 
551         g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
552     } else {
553         g_assert_not_reached();
554     }
555 
556     g_free(bootpath);
557 
558     if (args->hide_stderr) {
559         ignore_stderr = "2>/dev/null";
560     } else {
561         ignore_stderr = "";
562     }
563 
564     if (args->use_shmem) {
565         shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid());
566         shmem_opts = g_strdup_printf(
567             "-object memory-backend-file,id=mem0,size=%s"
568             ",mem-path=%s,share=on -numa node,memdev=mem0",
569             memory_size, shmem_path);
570     } else {
571         shmem_path = NULL;
572         shmem_opts = g_strdup("");
573     }
574 
575     cmd_source = g_strdup_printf("-accel kvm -accel tcg%s%s "
576                                  "-name source,debug-threads=on "
577                                  "-m %s "
578                                  "-serial file:%s/src_serial "
579                                  "%s %s %s %s",
580                                  machine_opts ? " -machine " : "",
581                                  machine_opts ? machine_opts : "",
582                                  memory_size, tmpfs,
583                                  arch_source, shmem_opts, args->opts_source,
584                                  ignore_stderr);
585     g_free(arch_source);
586     if (!args->only_target) {
587         *from = qtest_init(cmd_source);
588     }
589     g_free(cmd_source);
590 
591     cmd_target = g_strdup_printf("-accel kvm -accel tcg%s%s "
592                                  "-name target,debug-threads=on "
593                                  "-m %s "
594                                  "-serial file:%s/dest_serial "
595                                  "-incoming %s "
596                                  "%s %s %s %s",
597                                  machine_opts ? " -machine " : "",
598                                  machine_opts ? machine_opts : "",
599                                  memory_size, tmpfs, uri,
600                                  arch_target, shmem_opts,
601                                  args->opts_target, ignore_stderr);
602     g_free(arch_target);
603     *to = qtest_init(cmd_target);
604     g_free(cmd_target);
605 
606     g_free(shmem_opts);
607     /*
608      * Remove shmem file immediately to avoid memory leak in test failed case.
609      * It's valid becase QEMU has already opened this file
610      */
611     if (args->use_shmem) {
612         unlink(shmem_path);
613         g_free(shmem_path);
614     }
615 
616 out:
617     migrate_start_destroy(args);
618     return ret;
619 }
620 
621 static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
622 {
623     unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
624 
625     qtest_quit(from);
626 
627     if (test_dest) {
628         qtest_memread(to, start_address, &dest_byte_a, 1);
629 
630         /* Destination still running, wait for a byte to change */
631         do {
632             qtest_memread(to, start_address, &dest_byte_b, 1);
633             usleep(1000 * 10);
634         } while (dest_byte_a == dest_byte_b);
635 
636         qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}");
637 
638         /* With it stopped, check nothing changes */
639         qtest_memread(to, start_address, &dest_byte_c, 1);
640         usleep(1000 * 200);
641         qtest_memread(to, start_address, &dest_byte_d, 1);
642         g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
643 
644         check_guests_ram(to);
645     }
646 
647     qtest_quit(to);
648 
649     cleanup("bootsect");
650     cleanup("migsocket");
651     cleanup("src_serial");
652     cleanup("dest_serial");
653 }
654 
655 static void deprecated_set_downtime(QTestState *who, const double value)
656 {
657     QDict *rsp;
658 
659     rsp = qtest_qmp(who,
660                     "{ 'execute': 'migrate_set_downtime',"
661                     " 'arguments': { 'value': %f } }", value);
662     g_assert(qdict_haskey(rsp, "return"));
663     qobject_unref(rsp);
664     migrate_check_parameter_int(who, "downtime-limit", value * 1000);
665 }
666 
667 static void deprecated_set_speed(QTestState *who, long long value)
668 {
669     QDict *rsp;
670 
671     rsp = qtest_qmp(who, "{ 'execute': 'migrate_set_speed',"
672                           "'arguments': { 'value': %lld } }", value);
673     g_assert(qdict_haskey(rsp, "return"));
674     qobject_unref(rsp);
675     migrate_check_parameter_int(who, "max-bandwidth", value);
676 }
677 
678 static void deprecated_set_cache_size(QTestState *who, long long value)
679 {
680     QDict *rsp;
681 
682     rsp = qtest_qmp(who, "{ 'execute': 'migrate-set-cache-size',"
683                          "'arguments': { 'value': %lld } }", value);
684     g_assert(qdict_haskey(rsp, "return"));
685     qobject_unref(rsp);
686     migrate_check_parameter_int(who, "xbzrle-cache-size", value);
687 }
688 
689 static void test_deprecated(void)
690 {
691     QTestState *from;
692 
693     from = qtest_init("-machine none");
694 
695     deprecated_set_downtime(from, 0.12345);
696     deprecated_set_speed(from, 12345);
697     deprecated_set_cache_size(from, 4096);
698 
699     qtest_quit(from);
700 }
701 
702 static int migrate_postcopy_prepare(QTestState **from_ptr,
703                                     QTestState **to_ptr,
704                                     MigrateStart *args)
705 {
706     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
707     QTestState *from, *to;
708 
709     if (test_migrate_start(&from, &to, uri, args)) {
710         return -1;
711     }
712 
713     migrate_set_capability(from, "postcopy-ram", true);
714     migrate_set_capability(to, "postcopy-ram", true);
715     migrate_set_capability(to, "postcopy-blocktime", true);
716 
717     /* We want to pick a speed slow enough that the test completes
718      * quickly, but that it doesn't complete precopy even on a slow
719      * machine, so also set the downtime.
720      */
721     migrate_set_parameter_int(from, "max-bandwidth", 30000000);
722     migrate_set_parameter_int(from, "downtime-limit", 1);
723 
724     /* Wait for the first serial output from the source */
725     wait_for_serial("src_serial");
726 
727     migrate_qmp(from, uri, "{}");
728     g_free(uri);
729 
730     wait_for_migration_pass(from);
731 
732     *from_ptr = from;
733     *to_ptr = to;
734 
735     return 0;
736 }
737 
738 static void migrate_postcopy_complete(QTestState *from, QTestState *to)
739 {
740     wait_for_migration_complete(from);
741 
742     /* Make sure we get at least one "B" on destination */
743     wait_for_serial("dest_serial");
744 
745     if (uffd_feature_thread_id) {
746         read_blocktime(to);
747     }
748 
749     test_migrate_end(from, to, true);
750 }
751 
752 static void test_postcopy(void)
753 {
754     MigrateStart *args = migrate_start_new();
755     QTestState *from, *to;
756 
757     if (migrate_postcopy_prepare(&from, &to, args)) {
758         return;
759     }
760     migrate_postcopy_start(from, to);
761     migrate_postcopy_complete(from, to);
762 }
763 
764 static void test_postcopy_recovery(void)
765 {
766     MigrateStart *args = migrate_start_new();
767     QTestState *from, *to;
768     char *uri;
769 
770     args->hide_stderr = true;
771 
772     if (migrate_postcopy_prepare(&from, &to, args)) {
773         return;
774     }
775 
776     /* Turn postcopy speed down, 4K/s is slow enough on any machines */
777     migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096);
778 
779     /* Now we start the postcopy */
780     migrate_postcopy_start(from, to);
781 
782     /*
783      * Wait until postcopy is really started; we can only run the
784      * migrate-pause command during a postcopy
785      */
786     wait_for_migration_status(from, "postcopy-active", NULL);
787 
788     /*
789      * Manually stop the postcopy migration. This emulates a network
790      * failure with the migration socket
791      */
792     migrate_pause(from);
793 
794     /*
795      * Wait for destination side to reach postcopy-paused state.  The
796      * migrate-recover command can only succeed if destination machine
797      * is in the paused state
798      */
799     wait_for_migration_status(to, "postcopy-paused",
800                               (const char * []) { "failed", "active",
801                                                   "completed", NULL });
802 
803     /*
804      * Create a new socket to emulate a new channel that is different
805      * from the broken migration channel; tell the destination to
806      * listen to the new port
807      */
808     uri = g_strdup_printf("unix:%s/migsocket-recover", tmpfs);
809     migrate_recover(to, uri);
810 
811     /*
812      * Try to rebuild the migration channel using the resume flag and
813      * the newly created channel
814      */
815     wait_for_migration_status(from, "postcopy-paused",
816                               (const char * []) { "failed", "active",
817                                                   "completed", NULL });
818     migrate_qmp(from, uri, "{'resume': true}");
819     g_free(uri);
820 
821     /* Restore the postcopy bandwidth to unlimited */
822     migrate_set_parameter_int(from, "max-postcopy-bandwidth", 0);
823 
824     migrate_postcopy_complete(from, to);
825 }
826 
827 static void test_baddest(void)
828 {
829     MigrateStart *args = migrate_start_new();
830     QTestState *from, *to;
831 
832     args->hide_stderr = true;
833 
834     if (test_migrate_start(&from, &to, "tcp:0:0", args)) {
835         return;
836     }
837     migrate_qmp(from, "tcp:0:0", "{}");
838     wait_for_migration_fail(from, false);
839     test_migrate_end(from, to, false);
840 }
841 
842 static void test_precopy_unix(void)
843 {
844     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
845     MigrateStart *args = migrate_start_new();
846     QTestState *from, *to;
847 
848     if (test_migrate_start(&from, &to, uri, args)) {
849         return;
850     }
851 
852     /* We want to pick a speed slow enough that the test completes
853      * quickly, but that it doesn't complete precopy even on a slow
854      * machine, so also set the downtime.
855      */
856     /* 1 ms should make it not converge*/
857     migrate_set_parameter_int(from, "downtime-limit", 1);
858     /* 1GB/s */
859     migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
860 
861     /* Wait for the first serial output from the source */
862     wait_for_serial("src_serial");
863 
864     migrate_qmp(from, uri, "{}");
865 
866     wait_for_migration_pass(from);
867 
868     /* 300 ms should converge */
869     migrate_set_parameter_int(from, "downtime-limit", 300);
870 
871     if (!got_stop) {
872         qtest_qmp_eventwait(from, "STOP");
873     }
874 
875     qtest_qmp_eventwait(to, "RESUME");
876 
877     wait_for_serial("dest_serial");
878     wait_for_migration_complete(from);
879 
880     test_migrate_end(from, to, true);
881     g_free(uri);
882 }
883 
884 #if 0
885 /* Currently upset on aarch64 TCG */
886 static void test_ignore_shared(void)
887 {
888     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
889     QTestState *from, *to;
890 
891     if (test_migrate_start(&from, &to, uri, false, true, NULL, NULL)) {
892         return;
893     }
894 
895     migrate_set_capability(from, "x-ignore-shared", true);
896     migrate_set_capability(to, "x-ignore-shared", true);
897 
898     /* Wait for the first serial output from the source */
899     wait_for_serial("src_serial");
900 
901     migrate_qmp(from, uri, "{}");
902 
903     wait_for_migration_pass(from);
904 
905     if (!got_stop) {
906         qtest_qmp_eventwait(from, "STOP");
907     }
908 
909     qtest_qmp_eventwait(to, "RESUME");
910 
911     wait_for_serial("dest_serial");
912     wait_for_migration_complete(from);
913 
914     /* Check whether shared RAM has been really skipped */
915     g_assert_cmpint(read_ram_property_int(from, "transferred"), <, 1024 * 1024);
916 
917     test_migrate_end(from, to, true);
918     g_free(uri);
919 }
920 #endif
921 
922 static void test_xbzrle(const char *uri)
923 {
924     MigrateStart *args = migrate_start_new();
925     QTestState *from, *to;
926 
927     if (test_migrate_start(&from, &to, uri, args)) {
928         return;
929     }
930 
931     /*
932      * We want to pick a speed slow enough that the test completes
933      * quickly, but that it doesn't complete precopy even on a slow
934      * machine, so also set the downtime.
935      */
936     /* 1 ms should make it not converge*/
937     migrate_set_parameter_int(from, "downtime-limit", 1);
938     /* 1GB/s */
939     migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
940 
941     migrate_set_parameter_int(from, "xbzrle-cache-size", 33554432);
942 
943     migrate_set_capability(from, "xbzrle", "true");
944     migrate_set_capability(to, "xbzrle", "true");
945     /* Wait for the first serial output from the source */
946     wait_for_serial("src_serial");
947 
948     migrate_qmp(from, uri, "{}");
949 
950     wait_for_migration_pass(from);
951 
952     /* 300ms should converge */
953     migrate_set_parameter_int(from, "downtime-limit", 300);
954 
955     if (!got_stop) {
956         qtest_qmp_eventwait(from, "STOP");
957     }
958     qtest_qmp_eventwait(to, "RESUME");
959 
960     wait_for_serial("dest_serial");
961     wait_for_migration_complete(from);
962 
963     test_migrate_end(from, to, true);
964 }
965 
966 static void test_xbzrle_unix(void)
967 {
968     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
969 
970     test_xbzrle(uri);
971     g_free(uri);
972 }
973 
974 static void test_precopy_tcp(void)
975 {
976     MigrateStart *args = migrate_start_new();
977     char *uri;
978     QTestState *from, *to;
979 
980     if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", args)) {
981         return;
982     }
983 
984     /*
985      * We want to pick a speed slow enough that the test completes
986      * quickly, but that it doesn't complete precopy even on a slow
987      * machine, so also set the downtime.
988      */
989     /* 1 ms should make it not converge*/
990     migrate_set_parameter_int(from, "downtime-limit", 1);
991     /* 1GB/s */
992     migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
993 
994     /* Wait for the first serial output from the source */
995     wait_for_serial("src_serial");
996 
997     uri = migrate_get_socket_address(to, "socket-address");
998 
999     migrate_qmp(from, uri, "{}");
1000 
1001     wait_for_migration_pass(from);
1002 
1003     /* 300ms should converge */
1004     migrate_set_parameter_int(from, "downtime-limit", 300);
1005 
1006     if (!got_stop) {
1007         qtest_qmp_eventwait(from, "STOP");
1008     }
1009     qtest_qmp_eventwait(to, "RESUME");
1010 
1011     wait_for_serial("dest_serial");
1012     wait_for_migration_complete(from);
1013 
1014     test_migrate_end(from, to, true);
1015     g_free(uri);
1016 }
1017 
1018 static void test_migrate_fd_proto(void)
1019 {
1020     MigrateStart *args = migrate_start_new();
1021     QTestState *from, *to;
1022     int ret;
1023     int pair[2];
1024     QDict *rsp;
1025     const char *error_desc;
1026 
1027     if (test_migrate_start(&from, &to, "defer", args)) {
1028         return;
1029     }
1030 
1031     /*
1032      * We want to pick a speed slow enough that the test completes
1033      * quickly, but that it doesn't complete precopy even on a slow
1034      * machine, so also set the downtime.
1035      */
1036     /* 1 ms should make it not converge */
1037     migrate_set_parameter_int(from, "downtime-limit", 1);
1038     /* 1GB/s */
1039     migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
1040 
1041     /* Wait for the first serial output from the source */
1042     wait_for_serial("src_serial");
1043 
1044     /* Create two connected sockets for migration */
1045     ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair);
1046     g_assert_cmpint(ret, ==, 0);
1047 
1048     /* Send the 1st socket to the target */
1049     rsp = wait_command_fd(to, pair[0],
1050                           "{ 'execute': 'getfd',"
1051                           "  'arguments': { 'fdname': 'fd-mig' }}");
1052     qobject_unref(rsp);
1053     close(pair[0]);
1054 
1055     /* Start incoming migration from the 1st socket */
1056     rsp = wait_command(to, "{ 'execute': 'migrate-incoming',"
1057                            "  'arguments': { 'uri': 'fd:fd-mig' }}");
1058     qobject_unref(rsp);
1059 
1060     /* Send the 2nd socket to the target */
1061     rsp = wait_command_fd(from, pair[1],
1062                           "{ 'execute': 'getfd',"
1063                           "  'arguments': { 'fdname': 'fd-mig' }}");
1064     qobject_unref(rsp);
1065     close(pair[1]);
1066 
1067     /* Start migration to the 2nd socket*/
1068     migrate_qmp(from, "fd:fd-mig", "{}");
1069 
1070     wait_for_migration_pass(from);
1071 
1072     /* 300ms should converge */
1073     migrate_set_parameter_int(from, "downtime-limit", 300);
1074 
1075     if (!got_stop) {
1076         qtest_qmp_eventwait(from, "STOP");
1077     }
1078     qtest_qmp_eventwait(to, "RESUME");
1079 
1080     /* Test closing fds */
1081     /* We assume, that QEMU removes named fd from its list,
1082      * so this should fail */
1083     rsp = qtest_qmp(from, "{ 'execute': 'closefd',"
1084                           "  'arguments': { 'fdname': 'fd-mig' }}");
1085     g_assert_true(qdict_haskey(rsp, "error"));
1086     error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
1087     g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
1088     qobject_unref(rsp);
1089 
1090     rsp = qtest_qmp(to, "{ 'execute': 'closefd',"
1091                         "  'arguments': { 'fdname': 'fd-mig' }}");
1092     g_assert_true(qdict_haskey(rsp, "error"));
1093     error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
1094     g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
1095     qobject_unref(rsp);
1096 
1097     /* Complete migration */
1098     wait_for_serial("dest_serial");
1099     wait_for_migration_complete(from);
1100     test_migrate_end(from, to, true);
1101 }
1102 
1103 static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
1104 {
1105     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
1106     QTestState *from, *to;
1107 
1108     if (test_migrate_start(&from, &to, uri, args)) {
1109         return;
1110     }
1111 
1112     /*
1113      * UUID validation is at the begin of migration. So, the main process of
1114      * migration is not interesting for us here. Thus, set huge downtime for
1115      * very fast migration.
1116      */
1117     migrate_set_parameter_int(from, "downtime-limit", 1000000);
1118     migrate_set_capability(from, "validate-uuid", true);
1119 
1120     /* Wait for the first serial output from the source */
1121     wait_for_serial("src_serial");
1122 
1123     migrate_qmp(from, uri, "{}");
1124 
1125     if (should_fail) {
1126         qtest_set_expected_status(to, 1);
1127         wait_for_migration_fail(from, true);
1128     } else {
1129         wait_for_migration_complete(from);
1130     }
1131 
1132     test_migrate_end(from, to, false);
1133     g_free(uri);
1134 }
1135 
1136 static void test_validate_uuid(void)
1137 {
1138     MigrateStart *args = migrate_start_new();
1139 
1140     g_free(args->opts_source);
1141     g_free(args->opts_target);
1142     args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111");
1143     args->opts_target = g_strdup("-uuid 11111111-1111-1111-1111-111111111111");
1144     do_test_validate_uuid(args, false);
1145 }
1146 
1147 static void test_validate_uuid_error(void)
1148 {
1149     MigrateStart *args = migrate_start_new();
1150 
1151     g_free(args->opts_source);
1152     g_free(args->opts_target);
1153     args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111");
1154     args->opts_target = g_strdup("-uuid 22222222-2222-2222-2222-222222222222");
1155     args->hide_stderr = true;
1156     do_test_validate_uuid(args, true);
1157 }
1158 
1159 static void test_validate_uuid_src_not_set(void)
1160 {
1161     MigrateStart *args = migrate_start_new();
1162 
1163     g_free(args->opts_target);
1164     args->opts_target = g_strdup("-uuid 22222222-2222-2222-2222-222222222222");
1165     args->hide_stderr = true;
1166     do_test_validate_uuid(args, false);
1167 }
1168 
1169 static void test_validate_uuid_dst_not_set(void)
1170 {
1171     MigrateStart *args = migrate_start_new();
1172 
1173     g_free(args->opts_source);
1174     args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111");
1175     args->hide_stderr = true;
1176     do_test_validate_uuid(args, false);
1177 }
1178 
1179 static void test_migrate_auto_converge(void)
1180 {
1181     char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
1182     MigrateStart *args = migrate_start_new();
1183     QTestState *from, *to;
1184     int64_t remaining, percentage;
1185 
1186     /*
1187      * We want the test to be stable and as fast as possible.
1188      * E.g., with 1Gb/s bandwith migration may pass without throttling,
1189      * so we need to decrease a bandwidth.
1190      */
1191     const int64_t init_pct = 5, inc_pct = 50, max_pct = 95;
1192     const int64_t max_bandwidth = 400000000; /* ~400Mb/s */
1193     const int64_t downtime_limit = 250; /* 250ms */
1194     /*
1195      * We migrate through unix-socket (> 500Mb/s).
1196      * Thus, expected migration speed ~= bandwidth limit (< 500Mb/s).
1197      * So, we can predict expected_threshold
1198      */
1199     const int64_t expected_threshold = max_bandwidth * downtime_limit / 1000;
1200 
1201     if (test_migrate_start(&from, &to, uri, args)) {
1202         return;
1203     }
1204 
1205     migrate_set_capability(from, "auto-converge", true);
1206     migrate_set_parameter_int(from, "cpu-throttle-initial", init_pct);
1207     migrate_set_parameter_int(from, "cpu-throttle-increment", inc_pct);
1208     migrate_set_parameter_int(from, "max-cpu-throttle", max_pct);
1209 
1210     /*
1211      * Set the initial parameters so that the migration could not converge
1212      * without throttling.
1213      */
1214     migrate_set_parameter_int(from, "downtime-limit", 1);
1215     migrate_set_parameter_int(from, "max-bandwidth", 100000000); /* ~100Mb/s */
1216 
1217     /* To check remaining size after precopy */
1218     migrate_set_capability(from, "pause-before-switchover", true);
1219 
1220     /* Wait for the first serial output from the source */
1221     wait_for_serial("src_serial");
1222 
1223     migrate_qmp(from, uri, "{}");
1224 
1225     /* Wait for throttling begins */
1226     percentage = 0;
1227     while (percentage == 0) {
1228         percentage = read_migrate_property_int(from, "cpu-throttle-percentage");
1229         usleep(100);
1230         g_assert_false(got_stop);
1231     }
1232     /* The first percentage of throttling should be equal to init_pct */
1233     g_assert_cmpint(percentage, ==, init_pct);
1234     /* Now, when we tested that throttling works, let it converge */
1235     migrate_set_parameter_int(from, "downtime-limit", downtime_limit);
1236     migrate_set_parameter_int(from, "max-bandwidth", max_bandwidth);
1237 
1238     /*
1239      * Wait for pre-switchover status to check last throttle percentage
1240      * and remaining. These values will be zeroed later
1241      */
1242     wait_for_migration_status(from, "pre-switchover", NULL);
1243 
1244     /* The final percentage of throttling shouldn't be greater than max_pct */
1245     percentage = read_migrate_property_int(from, "cpu-throttle-percentage");
1246     g_assert_cmpint(percentage, <=, max_pct);
1247 
1248     remaining = read_ram_property_int(from, "remaining");
1249     g_assert_cmpint(remaining, <,
1250                     (expected_threshold + expected_threshold / 100));
1251 
1252     migrate_continue(from, "pre-switchover");
1253 
1254     qtest_qmp_eventwait(to, "RESUME");
1255 
1256     wait_for_serial("dest_serial");
1257     wait_for_migration_complete(from);
1258 
1259     g_free(uri);
1260 
1261     test_migrate_end(from, to, true);
1262 }
1263 
1264 static void test_multifd_tcp(void)
1265 {
1266     MigrateStart *args = migrate_start_new();
1267     QTestState *from, *to;
1268     QDict *rsp;
1269     char *uri;
1270 
1271     if (test_migrate_start(&from, &to, "defer", args)) {
1272         return;
1273     }
1274 
1275     /*
1276      * We want to pick a speed slow enough that the test completes
1277      * quickly, but that it doesn't complete precopy even on a slow
1278      * machine, so also set the downtime.
1279      */
1280     /* 1 ms should make it not converge*/
1281     migrate_set_parameter_int(from, "downtime-limit", 1);
1282     /* 1GB/s */
1283     migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
1284 
1285     migrate_set_parameter_int(from, "multifd-channels", 16);
1286     migrate_set_parameter_int(to, "multifd-channels", 16);
1287 
1288     migrate_set_capability(from, "multifd", "true");
1289     migrate_set_capability(to, "multifd", "true");
1290 
1291     /* Start incoming migration from the 1st socket */
1292     rsp = wait_command(to, "{ 'execute': 'migrate-incoming',"
1293                            "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
1294     qobject_unref(rsp);
1295 
1296     /* Wait for the first serial output from the source */
1297     wait_for_serial("src_serial");
1298 
1299     uri = migrate_get_socket_address(to, "socket-address");
1300 
1301     migrate_qmp(from, uri, "{}");
1302 
1303     wait_for_migration_pass(from);
1304 
1305     /* 300ms it should converge */
1306     migrate_set_parameter_int(from, "downtime-limit", 300);
1307 
1308     if (!got_stop) {
1309         qtest_qmp_eventwait(from, "STOP");
1310     }
1311     qtest_qmp_eventwait(to, "RESUME");
1312 
1313     wait_for_serial("dest_serial");
1314     wait_for_migration_complete(from);
1315     test_migrate_end(from, to, true);
1316     g_free(uri);
1317 }
1318 
1319 /*
1320  * This test does:
1321  *  source               target
1322  *                       migrate_incoming
1323  *     migrate
1324  *     migrate_cancel
1325  *                       launch another target
1326  *     migrate
1327  *
1328  *  And see that it works
1329  */
1330 
1331 static void test_multifd_tcp_cancel(void)
1332 {
1333     MigrateStart *args = migrate_start_new();
1334     QTestState *from, *to, *to2;
1335     QDict *rsp;
1336     char *uri;
1337 
1338     args->hide_stderr = true;
1339 
1340     if (test_migrate_start(&from, &to, "defer", args)) {
1341         return;
1342     }
1343 
1344     /*
1345      * We want to pick a speed slow enough that the test completes
1346      * quickly, but that it doesn't complete precopy even on a slow
1347      * machine, so also set the downtime.
1348      */
1349     /* 1 ms should make it not converge*/
1350     migrate_set_parameter_int(from, "downtime-limit", 1);
1351     /* 300MB/s */
1352     migrate_set_parameter_int(from, "max-bandwidth", 30000000);
1353 
1354     migrate_set_parameter_int(from, "multifd-channels", 16);
1355     migrate_set_parameter_int(to, "multifd-channels", 16);
1356 
1357     migrate_set_capability(from, "multifd", "true");
1358     migrate_set_capability(to, "multifd", "true");
1359 
1360     /* Start incoming migration from the 1st socket */
1361     rsp = wait_command(to, "{ 'execute': 'migrate-incoming',"
1362                            "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
1363     qobject_unref(rsp);
1364 
1365     /* Wait for the first serial output from the source */
1366     wait_for_serial("src_serial");
1367 
1368     uri = migrate_get_socket_address(to, "socket-address");
1369 
1370     migrate_qmp(from, uri, "{}");
1371 
1372     wait_for_migration_pass(from);
1373 
1374     migrate_cancel(from);
1375 
1376     args = migrate_start_new();
1377     args->only_target = true;
1378 
1379     if (test_migrate_start(&from, &to2, "defer", args)) {
1380         return;
1381     }
1382 
1383     migrate_set_parameter_int(to2, "multifd-channels", 16);
1384 
1385     migrate_set_capability(to2, "multifd", "true");
1386 
1387     /* Start incoming migration from the 1st socket */
1388     rsp = wait_command(to2, "{ 'execute': 'migrate-incoming',"
1389                             "  'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
1390     qobject_unref(rsp);
1391 
1392     g_free(uri);
1393     uri = migrate_get_socket_address(to2, "socket-address");
1394 
1395     wait_for_migration_status(from, "cancelled", NULL);
1396 
1397     /* 300ms it should converge */
1398     migrate_set_parameter_int(from, "downtime-limit", 300);
1399     /* 1GB/s */
1400     migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
1401 
1402     migrate_qmp(from, uri, "{}");
1403 
1404     wait_for_migration_pass(from);
1405 
1406     if (!got_stop) {
1407         qtest_qmp_eventwait(from, "STOP");
1408     }
1409     qtest_qmp_eventwait(to2, "RESUME");
1410 
1411     wait_for_serial("dest_serial");
1412     wait_for_migration_complete(from);
1413     test_migrate_end(from, to2, true);
1414     g_free(uri);
1415 }
1416 
1417 int main(int argc, char **argv)
1418 {
1419     char template[] = "/tmp/migration-test-XXXXXX";
1420     int ret;
1421 
1422     g_test_init(&argc, &argv, NULL);
1423 
1424     if (!ufd_version_check()) {
1425         return g_test_run();
1426     }
1427 
1428     /*
1429      * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
1430      * is touchy due to race conditions on dirty bits (especially on PPC for
1431      * some reason)
1432      */
1433     if (g_str_equal(qtest_get_arch(), "ppc64") &&
1434         (access("/sys/module/kvm_hv", F_OK) ||
1435          access("/dev/kvm", R_OK | W_OK))) {
1436         g_test_message("Skipping test: kvm_hv not available");
1437         return g_test_run();
1438     }
1439 
1440     /*
1441      * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
1442      * there until the problems are resolved
1443      */
1444     if (g_str_equal(qtest_get_arch(), "s390x")) {
1445 #if defined(HOST_S390X)
1446         if (access("/dev/kvm", R_OK | W_OK)) {
1447             g_test_message("Skipping test: kvm not available");
1448             return g_test_run();
1449         }
1450 #else
1451         g_test_message("Skipping test: Need s390x host to work properly");
1452         return g_test_run();
1453 #endif
1454     }
1455 
1456     tmpfs = mkdtemp(template);
1457     if (!tmpfs) {
1458         g_test_message("mkdtemp on path (%s): %s", template, strerror(errno));
1459     }
1460     g_assert(tmpfs);
1461 
1462     module_call_init(MODULE_INIT_QOM);
1463 
1464     qtest_add_func("/migration/postcopy/unix", test_postcopy);
1465     qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery);
1466     qtest_add_func("/migration/deprecated", test_deprecated);
1467     qtest_add_func("/migration/bad_dest", test_baddest);
1468     qtest_add_func("/migration/precopy/unix", test_precopy_unix);
1469     qtest_add_func("/migration/precopy/tcp", test_precopy_tcp);
1470     /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
1471     qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix);
1472     qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
1473     qtest_add_func("/migration/validate_uuid", test_validate_uuid);
1474     qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error);
1475     qtest_add_func("/migration/validate_uuid_src_not_set",
1476                    test_validate_uuid_src_not_set);
1477     qtest_add_func("/migration/validate_uuid_dst_not_set",
1478                    test_validate_uuid_dst_not_set);
1479 
1480     qtest_add_func("/migration/auto_converge", test_migrate_auto_converge);
1481     qtest_add_func("/migration/multifd/tcp", test_multifd_tcp);
1482     qtest_add_func("/migration/multifd/tcp/cancel", test_multifd_tcp_cancel);
1483 
1484     ret = g_test_run();
1485 
1486     g_assert_cmpint(ret, ==, 0);
1487 
1488     ret = rmdir(tmpfs);
1489     if (ret != 0) {
1490         g_test_message("unable to rmdir: path (%s): %s",
1491                        tmpfs, strerror(errno));
1492     }
1493 
1494     return ret;
1495 }
1496