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