2 * QTest testcase for migration
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.
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.
13 #include "qemu/osdep.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 #include "crypto/tlscredspsk.h"
27 #include "qapi/qmp/qlist.h"
29 #include "migration-helpers.h"
30 #include "tests/migration/migration-test.h"
32 # include "tests/unit/crypto-tls-psk-helpers.h"
34 # include "tests/unit/crypto-tls-x509-helpers.h"
35 # endif /* CONFIG_TASN1 */
36 #endif /* CONFIG_GNUTLS */
38 /* For dirty ring test; so far only x86_64 is supported */
39 #if defined(__linux__) && defined(HOST_X86_64)
40 #include "linux/kvm.h"
43 unsigned start_address
;
45 static bool uffd_feature_thread_id
;
49 * Dirtylimit stop working if dirty page rate error
50 * value less than DIRTYLIMIT_TOLERANCE_RANGE
52 #define DIRTYLIMIT_TOLERANCE_RANGE 25 /* MB/s */
54 #if defined(__linux__)
55 #include <sys/syscall.h>
59 #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
60 #include <sys/eventfd.h>
61 #include <sys/ioctl.h>
62 #include "qemu/userfaultfd.h"
64 static bool ufd_version_check(void)
66 struct uffdio_api api_struct
;
69 int ufd
= uffd_open(O_CLOEXEC
);
72 g_test_message("Skipping test: userfaultfd not available");
76 api_struct
.api
= UFFD_API
;
77 api_struct
.features
= 0;
78 if (ioctl(ufd
, UFFDIO_API
, &api_struct
)) {
79 g_test_message("Skipping test: UFFDIO_API failed");
82 uffd_feature_thread_id
= api_struct
.features
& UFFD_FEATURE_THREAD_ID
;
84 ioctl_mask
= (__u64
)1 << _UFFDIO_REGISTER
|
85 (__u64
)1 << _UFFDIO_UNREGISTER
;
86 if ((api_struct
.ioctls
& ioctl_mask
) != ioctl_mask
) {
87 g_test_message("Skipping test: Missing userfault feature");
95 static bool ufd_version_check(void)
97 g_test_message("Skipping test: Userfault not available (builtdtime)");
105 /* The boot file modifies memory area in [start_address, end_address)
106 * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
108 #include "tests/migration/i386/a-b-bootblock.h"
109 #include "tests/migration/aarch64/a-b-kernel.h"
110 #include "tests/migration/s390x/a-b-bios.h"
112 static void init_bootfile(const char *bootpath
, void *content
, size_t len
)
114 FILE *bootfile
= fopen(bootpath
, "wb");
116 g_assert_cmpint(fwrite(content
, len
, 1, bootfile
), ==, 1);
121 * Wait for some output in the serial output file,
122 * we get an 'A' followed by an endless string of 'B's
123 * but on the destination we won't have the A.
125 static void wait_for_serial(const char *side
)
127 g_autofree
char *serialpath
= g_strdup_printf("%s/%s", tmpfs
, side
);
128 FILE *serialfile
= fopen(serialpath
, "r");
129 const char *arch
= qtest_get_arch();
130 int started
= (strcmp(side
, "src_serial") == 0 &&
131 strcmp(arch
, "ppc64") == 0) ? 0 : 1;
134 int readvalue
= fgetc(serialfile
);
137 /* SLOF prints its banner before starting test,
138 * to ignore it, mark the start of the test with '_',
139 * ignore all characters until this marker
146 fseek(serialfile
, 0, SEEK_SET
);
163 started
= (strcmp(side
, "src_serial") == 0 &&
164 strcmp(arch
, "ppc64") == 0) ? 0 : 1;
165 fseek(serialfile
, 0, SEEK_SET
);
170 fprintf(stderr
, "Unexpected %d on %s serial\n", readvalue
, side
);
171 g_assert_not_reached();
177 * It's tricky to use qemu's migration event capability with qtest,
178 * events suddenly appearing confuse the qmp()/hmp() responses.
181 static int64_t read_ram_property_int(QTestState
*who
, const char *property
)
183 QDict
*rsp_return
, *rsp_ram
;
186 rsp_return
= migrate_query_not_failed(who
);
187 if (!qdict_haskey(rsp_return
, "ram")) {
191 rsp_ram
= qdict_get_qdict(rsp_return
, "ram");
192 result
= qdict_get_try_int(rsp_ram
, property
, 0);
194 qobject_unref(rsp_return
);
198 static int64_t read_migrate_property_int(QTestState
*who
, const char *property
)
203 rsp_return
= migrate_query_not_failed(who
);
204 result
= qdict_get_try_int(rsp_return
, property
, 0);
205 qobject_unref(rsp_return
);
209 static uint64_t get_migration_pass(QTestState
*who
)
211 return read_ram_property_int(who
, "dirty-sync-count");
214 static void read_blocktime(QTestState
*who
)
218 rsp_return
= migrate_query_not_failed(who
);
219 g_assert(qdict_haskey(rsp_return
, "postcopy-blocktime"));
220 qobject_unref(rsp_return
);
223 static void wait_for_migration_pass(QTestState
*who
)
225 uint64_t initial_pass
= get_migration_pass(who
);
228 /* Wait for the 1st sync */
229 while (!got_stop
&& !initial_pass
) {
231 initial_pass
= get_migration_pass(who
);
236 pass
= get_migration_pass(who
);
237 } while (pass
== initial_pass
&& !got_stop
);
240 static void check_guests_ram(QTestState
*who
)
242 /* Our ASM test will have been incrementing one byte from each page from
243 * start_address to < end_address in order. This gives us a constraint
244 * that any page's byte should be equal or less than the previous pages
245 * byte (mod 256); and they should all be equal except for one transition
246 * at the point where we meet the incrementer. (We're running this with
247 * the guest stopped).
252 bool hit_edge
= false;
255 qtest_memread(who
, start_address
, &first_byte
, 1);
256 last_byte
= first_byte
;
258 for (address
= start_address
+ TEST_MEM_PAGE_SIZE
; address
< end_address
;
259 address
+= TEST_MEM_PAGE_SIZE
)
262 qtest_memread(who
, address
, &b
, 1);
263 if (b
!= last_byte
) {
264 if (((b
+ 1) % 256) == last_byte
&& !hit_edge
) {
265 /* This is OK, the guest stopped at the point of
266 * incrementing the previous page but didn't get
274 fprintf(stderr
, "Memory content inconsistency at %x"
275 " first_byte = %x last_byte = %x current = %x"
277 address
, first_byte
, last_byte
, b
, hit_edge
);
283 fprintf(stderr
, "and in another %d pages", bad
- 10);
288 static void cleanup(const char *filename
)
290 g_autofree
char *path
= g_strdup_printf("%s/%s", tmpfs
, filename
);
295 static char *SocketAddress_to_str(SocketAddress
*addr
)
297 switch (addr
->type
) {
298 case SOCKET_ADDRESS_TYPE_INET
:
299 return g_strdup_printf("tcp:%s:%s",
302 case SOCKET_ADDRESS_TYPE_UNIX
:
303 return g_strdup_printf("unix:%s",
304 addr
->u
.q_unix
.path
);
305 case SOCKET_ADDRESS_TYPE_FD
:
306 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
307 case SOCKET_ADDRESS_TYPE_VSOCK
:
308 return g_strdup_printf("tcp:%s:%s",
312 return g_strdup("unknown address type");
316 static char *migrate_get_socket_address(QTestState
*who
, const char *parameter
)
320 SocketAddressList
*addrs
;
324 rsp
= migrate_query(who
);
325 object
= qdict_get(rsp
, parameter
);
327 iv
= qobject_input_visitor_new(object
);
328 visit_type_SocketAddressList(iv
, NULL
, &addrs
, &error_abort
);
331 /* we are only using a single address */
332 result
= SocketAddress_to_str(addrs
->value
);
334 qapi_free_SocketAddressList(addrs
);
339 static long long migrate_get_parameter_int(QTestState
*who
,
340 const char *parameter
)
345 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
346 result
= qdict_get_int(rsp
, parameter
);
351 static void migrate_check_parameter_int(QTestState
*who
, const char *parameter
,
356 result
= migrate_get_parameter_int(who
, parameter
);
357 g_assert_cmpint(result
, ==, value
);
360 static void migrate_set_parameter_int(QTestState
*who
, const char *parameter
,
363 qtest_qmp_assert_success(who
,
364 "{ 'execute': 'migrate-set-parameters',"
365 "'arguments': { %s: %lld } }",
367 migrate_check_parameter_int(who
, parameter
, value
);
370 static char *migrate_get_parameter_str(QTestState
*who
,
371 const char *parameter
)
376 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
377 result
= g_strdup(qdict_get_str(rsp
, parameter
));
382 static void migrate_check_parameter_str(QTestState
*who
, const char *parameter
,
385 g_autofree
char *result
= migrate_get_parameter_str(who
, parameter
);
386 g_assert_cmpstr(result
, ==, value
);
389 static void migrate_set_parameter_str(QTestState
*who
, const char *parameter
,
392 qtest_qmp_assert_success(who
,
393 "{ 'execute': 'migrate-set-parameters',"
394 "'arguments': { %s: %s } }",
396 migrate_check_parameter_str(who
, parameter
, value
);
399 static long long migrate_get_parameter_bool(QTestState
*who
,
400 const char *parameter
)
405 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
406 result
= qdict_get_bool(rsp
, parameter
);
411 static void migrate_check_parameter_bool(QTestState
*who
, const char *parameter
,
416 result
= migrate_get_parameter_bool(who
, parameter
);
417 g_assert_cmpint(result
, ==, value
);
420 static void migrate_set_parameter_bool(QTestState
*who
, const char *parameter
,
423 qtest_qmp_assert_success(who
,
424 "{ 'execute': 'migrate-set-parameters',"
425 "'arguments': { %s: %i } }",
427 migrate_check_parameter_bool(who
, parameter
, value
);
430 static void migrate_ensure_non_converge(QTestState
*who
)
432 /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
433 migrate_set_parameter_int(who
, "max-bandwidth", 3 * 1000 * 1000);
434 migrate_set_parameter_int(who
, "downtime-limit", 1);
437 static void migrate_ensure_converge(QTestState
*who
)
439 /* Should converge with 30s downtime + 1 gbs bandwidth limit */
440 migrate_set_parameter_int(who
, "max-bandwidth", 1 * 1000 * 1000 * 1000);
441 migrate_set_parameter_int(who
, "downtime-limit", 30 * 1000);
444 static void migrate_pause(QTestState
*who
)
448 rsp
= wait_command(who
, "{ 'execute': 'migrate-pause' }");
452 static void migrate_continue(QTestState
*who
, const char *state
)
456 rsp
= wait_command(who
,
457 "{ 'execute': 'migrate-continue',"
458 " 'arguments': { 'state': %s } }",
463 static void migrate_recover(QTestState
*who
, const char *uri
)
467 rsp
= wait_command(who
,
468 "{ 'execute': 'migrate-recover', "
469 " 'id': 'recover-cmd', "
470 " 'arguments': { 'uri': %s } }",
475 static void migrate_cancel(QTestState
*who
)
479 rsp
= wait_command(who
, "{ 'execute': 'migrate_cancel' }");
483 static void migrate_set_capability(QTestState
*who
, const char *capability
,
486 qtest_qmp_assert_success(who
,
487 "{ 'execute': 'migrate-set-capabilities',"
489 "'capabilities': [ { "
490 "'capability': %s, 'state': %i } ] } }",
494 static void migrate_postcopy_start(QTestState
*from
, QTestState
*to
)
498 rsp
= wait_command(from
, "{ 'execute': 'migrate-start-postcopy' }");
502 qtest_qmp_eventwait(from
, "STOP");
505 qtest_qmp_eventwait(to
, "RESUME");
510 * QTEST_LOG=1 may override this. When QTEST_LOG=1, we always dump errors
511 * unconditionally, because it means the user would like to be verbose.
515 /* only launch the target process */
517 /* Use dirty ring if true; dirty logging otherwise */
519 const char *opts_source
;
520 const char *opts_target
;
524 * A hook that runs after the src and dst QEMUs have been
525 * created, but before the migration is started. This can
526 * be used to set migration parameters and capabilities.
528 * Returns: NULL, or a pointer to opaque state to be
529 * later passed to the TestMigrateFinishHook
531 typedef void * (*TestMigrateStartHook
)(QTestState
*from
,
535 * A hook that runs after the migration has finished,
536 * regardless of whether it succeeded or failed, but
537 * before QEMU has terminated (unless it self-terminated
538 * due to migration error)
540 * @opaque is a pointer to state previously returned
541 * by the TestMigrateStartHook if any, or NULL.
543 typedef void (*TestMigrateFinishHook
)(QTestState
*from
,
548 /* Optional: fine tune start parameters */
551 /* Required: the URI for the dst QEMU to listen on */
552 const char *listen_uri
;
555 * Optional: the URI for the src QEMU to connect to
556 * If NULL, then it will query the dst QEMU for its actual
557 * listening address and use that as the connect address.
558 * This allows for dynamically picking a free TCP port.
560 const char *connect_uri
;
562 /* Optional: callback to run at start to set migration parameters */
563 TestMigrateStartHook start_hook
;
564 /* Optional: callback to run at finish to cleanup */
565 TestMigrateFinishHook finish_hook
;
568 * Optional: normally we expect the migration process to complete.
570 * There can be a variety of reasons and stages in which failure
571 * can happen during tests.
573 * If a failure is expected to happen at time of establishing
574 * the connection, then MIG_TEST_FAIL will indicate that the dst
575 * QEMU is expected to stay running and accept future migration
578 * If a failure is expected to happen while processing the
579 * migration stream, then MIG_TEST_FAIL_DEST_QUIT_ERR will indicate
580 * that the dst QEMU is expected to quit with non-zero exit status
583 /* This test should succeed, the default */
584 MIG_TEST_SUCCEED
= 0,
585 /* This test should fail, dest qemu should keep alive */
587 /* This test should fail, dest qemu should fail with abnormal status */
588 MIG_TEST_FAIL_DEST_QUIT_ERR
,
591 /* Optional: set number of migration passes to wait for */
592 unsigned int iterations
;
594 /* Postcopy specific fields */
596 bool postcopy_preempt
;
599 static int test_migrate_start(QTestState
**from
, QTestState
**to
,
600 const char *uri
, MigrateStart
*args
)
602 g_autofree gchar
*arch_source
= NULL
;
603 g_autofree gchar
*arch_target
= NULL
;
604 g_autofree gchar
*cmd_source
= NULL
;
605 g_autofree gchar
*cmd_target
= NULL
;
606 const gchar
*ignore_stderr
;
607 g_autofree
char *bootpath
= NULL
;
608 g_autofree
char *shmem_opts
= NULL
;
609 g_autofree
char *shmem_path
= NULL
;
610 const char *arch
= qtest_get_arch();
611 const char *machine_opts
= NULL
;
612 const char *memory_size
;
614 if (args
->use_shmem
) {
615 if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR
)) {
616 g_test_skip("/dev/shm is not supported");
622 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
623 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
624 /* the assembled x86 boot sector should be exactly one sector large */
625 assert(sizeof(x86_bootsect
) == 512);
626 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
627 memory_size
= "150M";
628 arch_source
= g_strdup_printf("-drive file=%s,format=raw", bootpath
);
629 arch_target
= g_strdup(arch_source
);
630 start_address
= X86_TEST_MEM_START
;
631 end_address
= X86_TEST_MEM_END
;
632 } else if (g_str_equal(arch
, "s390x")) {
633 init_bootfile(bootpath
, s390x_elf
, sizeof(s390x_elf
));
634 memory_size
= "128M";
635 arch_source
= g_strdup_printf("-bios %s", bootpath
);
636 arch_target
= g_strdup(arch_source
);
637 start_address
= S390_TEST_MEM_START
;
638 end_address
= S390_TEST_MEM_END
;
639 } else if (strcmp(arch
, "ppc64") == 0) {
640 machine_opts
= "vsmt=8";
641 memory_size
= "256M";
642 start_address
= PPC_TEST_MEM_START
;
643 end_address
= PPC_TEST_MEM_END
;
644 arch_source
= g_strdup_printf("-nodefaults "
645 "-prom-env 'use-nvramrc?=true' -prom-env "
646 "'nvramrc=hex .\" _\" begin %x %x "
647 "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
648 "until'", end_address
, start_address
);
649 arch_target
= g_strdup("");
650 } else if (strcmp(arch
, "aarch64") == 0) {
651 init_bootfile(bootpath
, aarch64_kernel
, sizeof(aarch64_kernel
));
652 machine_opts
= "virt,gic-version=max";
653 memory_size
= "150M";
654 arch_source
= g_strdup_printf("-cpu max "
657 arch_target
= g_strdup(arch_source
);
658 start_address
= ARM_TEST_MEM_START
;
659 end_address
= ARM_TEST_MEM_END
;
661 g_assert(sizeof(aarch64_kernel
) <= ARM_TEST_MAX_KERNEL_SIZE
);
663 g_assert_not_reached();
666 if (!getenv("QTEST_LOG") && args
->hide_stderr
) {
668 ignore_stderr
= "2>/dev/null";
671 * On Windows the QEMU executable is created via CreateProcess() and
672 * IO redirection does not work, so don't bother adding IO redirection
673 * to the command line.
681 if (args
->use_shmem
) {
682 shmem_path
= g_strdup_printf("/dev/shm/qemu-%d", getpid());
683 shmem_opts
= g_strdup_printf(
684 "-object memory-backend-file,id=mem0,size=%s"
685 ",mem-path=%s,share=on -numa node,memdev=mem0",
686 memory_size
, shmem_path
);
689 shmem_opts
= g_strdup("");
692 cmd_source
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
693 "-name source,debug-threads=on "
695 "-serial file:%s/src_serial "
697 args
->use_dirty_ring
?
698 ",dirty-ring-size=4096" : "",
699 machine_opts
? " -machine " : "",
700 machine_opts
? machine_opts
: "",
702 arch_source
, shmem_opts
,
703 args
->opts_source
? args
->opts_source
: "",
705 if (!args
->only_target
) {
706 *from
= qtest_init(cmd_source
);
707 qtest_qmp_set_event_callback(*from
,
708 migrate_watch_for_stop
,
712 cmd_target
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
713 "-name target,debug-threads=on "
715 "-serial file:%s/dest_serial "
718 args
->use_dirty_ring
?
719 ",dirty-ring-size=4096" : "",
720 machine_opts
? " -machine " : "",
721 machine_opts
? machine_opts
: "",
722 memory_size
, tmpfs
, uri
,
723 arch_target
, shmem_opts
,
724 args
->opts_target
? args
->opts_target
: "",
726 *to
= qtest_init(cmd_target
);
729 * Remove shmem file immediately to avoid memory leak in test failed case.
730 * It's valid becase QEMU has already opened this file
732 if (args
->use_shmem
) {
739 static void test_migrate_end(QTestState
*from
, QTestState
*to
, bool test_dest
)
741 unsigned char dest_byte_a
, dest_byte_b
, dest_byte_c
, dest_byte_d
;
746 qtest_memread(to
, start_address
, &dest_byte_a
, 1);
748 /* Destination still running, wait for a byte to change */
750 qtest_memread(to
, start_address
, &dest_byte_b
, 1);
752 } while (dest_byte_a
== dest_byte_b
);
754 qtest_qmp_assert_success(to
, "{ 'execute' : 'stop'}");
756 /* With it stopped, check nothing changes */
757 qtest_memread(to
, start_address
, &dest_byte_c
, 1);
759 qtest_memread(to
, start_address
, &dest_byte_d
, 1);
760 g_assert_cmpint(dest_byte_c
, ==, dest_byte_d
);
762 check_guests_ram(to
);
768 cleanup("migsocket");
769 cleanup("src_serial");
770 cleanup("dest_serial");
774 struct TestMigrateTLSPSKData
{
782 test_migrate_tls_psk_start_common(QTestState
*from
,
786 struct TestMigrateTLSPSKData
*data
=
787 g_new0(struct TestMigrateTLSPSKData
, 1);
790 data
->workdir
= g_strdup_printf("%s/tlscredspsk0", tmpfs
);
791 data
->pskfile
= g_strdup_printf("%s/%s", data
->workdir
,
792 QCRYPTO_TLS_CREDS_PSKFILE
);
793 g_mkdir_with_parents(data
->workdir
, 0700);
794 test_tls_psk_init(data
->pskfile
);
797 data
->workdiralt
= g_strdup_printf("%s/tlscredspskalt0", tmpfs
);
798 data
->pskfilealt
= g_strdup_printf("%s/%s", data
->workdiralt
,
799 QCRYPTO_TLS_CREDS_PSKFILE
);
800 g_mkdir_with_parents(data
->workdiralt
, 0700);
801 test_tls_psk_init_alt(data
->pskfilealt
);
804 rsp
= wait_command(from
,
805 "{ 'execute': 'object-add',"
806 " 'arguments': { 'qom-type': 'tls-creds-psk',"
807 " 'id': 'tlscredspsk0',"
808 " 'endpoint': 'client',"
810 " 'username': 'qemu'} }",
814 rsp
= wait_command(to
,
815 "{ 'execute': 'object-add',"
816 " 'arguments': { 'qom-type': 'tls-creds-psk',"
817 " 'id': 'tlscredspsk0',"
818 " 'endpoint': 'server',"
820 mismatch
? data
->workdiralt
: data
->workdir
);
823 migrate_set_parameter_str(from
, "tls-creds", "tlscredspsk0");
824 migrate_set_parameter_str(to
, "tls-creds", "tlscredspsk0");
830 test_migrate_tls_psk_start_match(QTestState
*from
,
833 return test_migrate_tls_psk_start_common(from
, to
, false);
837 test_migrate_tls_psk_start_mismatch(QTestState
*from
,
840 return test_migrate_tls_psk_start_common(from
, to
, true);
844 test_migrate_tls_psk_finish(QTestState
*from
,
848 struct TestMigrateTLSPSKData
*data
= opaque
;
850 test_tls_psk_cleanup(data
->pskfile
);
851 if (data
->pskfilealt
) {
852 test_tls_psk_cleanup(data
->pskfilealt
);
854 rmdir(data
->workdir
);
855 if (data
->workdiralt
) {
856 rmdir(data
->workdiralt
);
859 g_free(data
->workdiralt
);
860 g_free(data
->pskfilealt
);
861 g_free(data
->workdir
);
862 g_free(data
->pskfile
);
875 } TestMigrateTLSX509Data
;
882 const char *certhostname
;
883 const char *certipaddr
;
884 } TestMigrateTLSX509
;
887 test_migrate_tls_x509_start_common(QTestState
*from
,
889 TestMigrateTLSX509
*args
)
891 TestMigrateTLSX509Data
*data
= g_new0(TestMigrateTLSX509Data
, 1);
894 data
->workdir
= g_strdup_printf("%s/tlscredsx5090", tmpfs
);
895 data
->keyfile
= g_strdup_printf("%s/key.pem", data
->workdir
);
897 data
->cacert
= g_strdup_printf("%s/ca-cert.pem", data
->workdir
);
898 data
->serverkey
= g_strdup_printf("%s/server-key.pem", data
->workdir
);
899 data
->servercert
= g_strdup_printf("%s/server-cert.pem", data
->workdir
);
900 if (args
->clientcert
) {
901 data
->clientkey
= g_strdup_printf("%s/client-key.pem", data
->workdir
);
902 data
->clientcert
= g_strdup_printf("%s/client-cert.pem", data
->workdir
);
905 g_mkdir_with_parents(data
->workdir
, 0700);
907 test_tls_init(data
->keyfile
);
909 g_assert(link(data
->keyfile
, data
->serverkey
) == 0);
911 g_assert(CreateHardLink(data
->serverkey
, data
->keyfile
, NULL
) != 0);
913 if (args
->clientcert
) {
915 g_assert(link(data
->keyfile
, data
->clientkey
) == 0);
917 g_assert(CreateHardLink(data
->clientkey
, data
->keyfile
, NULL
) != 0);
921 TLS_ROOT_REQ_SIMPLE(cacertreq
, data
->cacert
);
922 if (args
->clientcert
) {
923 TLS_CERT_REQ_SIMPLE_CLIENT(servercertreq
, cacertreq
,
924 args
->hostileclient
?
925 QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME
:
926 QCRYPTO_TLS_TEST_CLIENT_NAME
,
930 TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq
, cacertreq
,
935 rsp
= wait_command(from
,
936 "{ 'execute': 'object-add',"
937 " 'arguments': { 'qom-type': 'tls-creds-x509',"
938 " 'id': 'tlscredsx509client0',"
939 " 'endpoint': 'client',"
941 " 'sanity-check': true,"
942 " 'verify-peer': true} }",
945 migrate_set_parameter_str(from
, "tls-creds", "tlscredsx509client0");
946 if (args
->certhostname
) {
947 migrate_set_parameter_str(from
, "tls-hostname", args
->certhostname
);
950 rsp
= wait_command(to
,
951 "{ 'execute': 'object-add',"
952 " 'arguments': { 'qom-type': 'tls-creds-x509',"
953 " 'id': 'tlscredsx509server0',"
954 " 'endpoint': 'server',"
956 " 'sanity-check': true,"
957 " 'verify-peer': %i} }",
958 data
->workdir
, args
->verifyclient
);
960 migrate_set_parameter_str(to
, "tls-creds", "tlscredsx509server0");
962 if (args
->authzclient
) {
963 rsp
= wait_command(to
,
964 "{ 'execute': 'object-add',"
965 " 'arguments': { 'qom-type': 'authz-simple',"
966 " 'id': 'tlsauthz0',"
967 " 'identity': %s} }",
968 "CN=" QCRYPTO_TLS_TEST_CLIENT_NAME
);
969 migrate_set_parameter_str(to
, "tls-authz", "tlsauthz0");
976 * The normal case: match server's cert hostname against
977 * whatever host we were telling QEMU to connect to (if any)
980 test_migrate_tls_x509_start_default_host(QTestState
*from
,
983 TestMigrateTLSX509 args
= {
984 .verifyclient
= true,
986 .certipaddr
= "127.0.0.1"
988 return test_migrate_tls_x509_start_common(from
, to
, &args
);
992 * The unusual case: the server's cert is different from
993 * the address we're telling QEMU to connect to (if any),
994 * so we must give QEMU an explicit hostname to validate
997 test_migrate_tls_x509_start_override_host(QTestState
*from
,
1000 TestMigrateTLSX509 args
= {
1001 .verifyclient
= true,
1003 .certhostname
= "qemu.org",
1005 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1009 * The unusual case: the server's cert is different from
1010 * the address we're telling QEMU to connect to, and so we
1011 * expect the client to reject the server
1014 test_migrate_tls_x509_start_mismatch_host(QTestState
*from
,
1017 TestMigrateTLSX509 args
= {
1018 .verifyclient
= true,
1020 .certipaddr
= "10.0.0.1",
1022 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1026 test_migrate_tls_x509_start_friendly_client(QTestState
*from
,
1029 TestMigrateTLSX509 args
= {
1030 .verifyclient
= true,
1032 .authzclient
= true,
1033 .certipaddr
= "127.0.0.1",
1035 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1039 test_migrate_tls_x509_start_hostile_client(QTestState
*from
,
1042 TestMigrateTLSX509 args
= {
1043 .verifyclient
= true,
1045 .hostileclient
= true,
1046 .authzclient
= true,
1047 .certipaddr
= "127.0.0.1",
1049 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1053 * The case with no client certificate presented,
1054 * and no server verification
1057 test_migrate_tls_x509_start_allow_anon_client(QTestState
*from
,
1060 TestMigrateTLSX509 args
= {
1061 .certipaddr
= "127.0.0.1",
1063 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1067 * The case with no client certificate presented,
1068 * and server verification rejecting
1071 test_migrate_tls_x509_start_reject_anon_client(QTestState
*from
,
1074 TestMigrateTLSX509 args
= {
1075 .verifyclient
= true,
1076 .certipaddr
= "127.0.0.1",
1078 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1082 test_migrate_tls_x509_finish(QTestState
*from
,
1086 TestMigrateTLSX509Data
*data
= opaque
;
1088 test_tls_cleanup(data
->keyfile
);
1089 g_free(data
->keyfile
);
1091 unlink(data
->cacert
);
1092 g_free(data
->cacert
);
1093 unlink(data
->servercert
);
1094 g_free(data
->servercert
);
1095 unlink(data
->serverkey
);
1096 g_free(data
->serverkey
);
1098 if (data
->clientcert
) {
1099 unlink(data
->clientcert
);
1100 g_free(data
->clientcert
);
1102 if (data
->clientkey
) {
1103 unlink(data
->clientkey
);
1104 g_free(data
->clientkey
);
1107 rmdir(data
->workdir
);
1108 g_free(data
->workdir
);
1112 #endif /* CONFIG_TASN1 */
1113 #endif /* CONFIG_GNUTLS */
1116 test_migrate_compress_start(QTestState
*from
,
1119 migrate_set_parameter_int(from
, "compress-level", 1);
1120 migrate_set_parameter_int(from
, "compress-threads", 4);
1121 migrate_set_parameter_bool(from
, "compress-wait-thread", true);
1122 migrate_set_parameter_int(to
, "decompress-threads", 4);
1124 migrate_set_capability(from
, "compress", true);
1125 migrate_set_capability(to
, "compress", true);
1131 test_migrate_compress_nowait_start(QTestState
*from
,
1134 migrate_set_parameter_int(from
, "compress-level", 9);
1135 migrate_set_parameter_int(from
, "compress-threads", 1);
1136 migrate_set_parameter_bool(from
, "compress-wait-thread", false);
1137 migrate_set_parameter_int(to
, "decompress-threads", 1);
1139 migrate_set_capability(from
, "compress", true);
1140 migrate_set_capability(to
, "compress", true);
1145 static int migrate_postcopy_prepare(QTestState
**from_ptr
,
1146 QTestState
**to_ptr
,
1147 MigrateCommon
*args
)
1149 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1150 QTestState
*from
, *to
;
1152 if (test_migrate_start(&from
, &to
, uri
, &args
->start
)) {
1156 if (args
->start_hook
) {
1157 args
->postcopy_data
= args
->start_hook(from
, to
);
1160 migrate_set_capability(from
, "postcopy-ram", true);
1161 migrate_set_capability(to
, "postcopy-ram", true);
1162 migrate_set_capability(to
, "postcopy-blocktime", true);
1164 if (args
->postcopy_preempt
) {
1165 migrate_set_capability(from
, "postcopy-preempt", true);
1166 migrate_set_capability(to
, "postcopy-preempt", true);
1169 migrate_ensure_non_converge(from
);
1171 /* Wait for the first serial output from the source */
1172 wait_for_serial("src_serial");
1174 migrate_qmp(from
, uri
, "{}");
1176 wait_for_migration_pass(from
);
1184 static void migrate_postcopy_complete(QTestState
*from
, QTestState
*to
,
1185 MigrateCommon
*args
)
1187 wait_for_migration_complete(from
);
1189 /* Make sure we get at least one "B" on destination */
1190 wait_for_serial("dest_serial");
1192 if (uffd_feature_thread_id
) {
1196 if (args
->finish_hook
) {
1197 args
->finish_hook(from
, to
, args
->postcopy_data
);
1198 args
->postcopy_data
= NULL
;
1201 test_migrate_end(from
, to
, true);
1204 static void test_postcopy_common(MigrateCommon
*args
)
1206 QTestState
*from
, *to
;
1208 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1211 migrate_postcopy_start(from
, to
);
1212 migrate_postcopy_complete(from
, to
, args
);
1215 static void test_postcopy(void)
1217 MigrateCommon args
= { };
1219 test_postcopy_common(&args
);
1222 static void test_postcopy_compress(void)
1224 MigrateCommon args
= {
1225 .start_hook
= test_migrate_compress_start
1228 test_postcopy_common(&args
);
1231 static void test_postcopy_preempt(void)
1233 MigrateCommon args
= {
1234 .postcopy_preempt
= true,
1237 test_postcopy_common(&args
);
1240 #ifdef CONFIG_GNUTLS
1241 static void test_postcopy_tls_psk(void)
1243 MigrateCommon args
= {
1244 .start_hook
= test_migrate_tls_psk_start_match
,
1245 .finish_hook
= test_migrate_tls_psk_finish
,
1248 test_postcopy_common(&args
);
1251 static void test_postcopy_preempt_tls_psk(void)
1253 MigrateCommon args
= {
1254 .postcopy_preempt
= true,
1255 .start_hook
= test_migrate_tls_psk_start_match
,
1256 .finish_hook
= test_migrate_tls_psk_finish
,
1259 test_postcopy_common(&args
);
1263 static void test_postcopy_recovery_common(MigrateCommon
*args
)
1265 QTestState
*from
, *to
;
1266 g_autofree
char *uri
= NULL
;
1268 /* Always hide errors for postcopy recover tests since they're expected */
1269 args
->start
.hide_stderr
= true;
1271 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1275 /* Turn postcopy speed down, 4K/s is slow enough on any machines */
1276 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 4096);
1278 /* Now we start the postcopy */
1279 migrate_postcopy_start(from
, to
);
1282 * Wait until postcopy is really started; we can only run the
1283 * migrate-pause command during a postcopy
1285 wait_for_migration_status(from
, "postcopy-active", NULL
);
1288 * Manually stop the postcopy migration. This emulates a network
1289 * failure with the migration socket
1291 migrate_pause(from
);
1294 * Wait for destination side to reach postcopy-paused state. The
1295 * migrate-recover command can only succeed if destination machine
1296 * is in the paused state
1298 wait_for_migration_status(to
, "postcopy-paused",
1299 (const char * []) { "failed", "active",
1300 "completed", NULL
});
1303 * Create a new socket to emulate a new channel that is different
1304 * from the broken migration channel; tell the destination to
1305 * listen to the new port
1307 uri
= g_strdup_printf("unix:%s/migsocket-recover", tmpfs
);
1308 migrate_recover(to
, uri
);
1311 * Try to rebuild the migration channel using the resume flag and
1312 * the newly created channel
1314 wait_for_migration_status(from
, "postcopy-paused",
1315 (const char * []) { "failed", "active",
1316 "completed", NULL
});
1317 migrate_qmp(from
, uri
, "{'resume': true}");
1319 /* Restore the postcopy bandwidth to unlimited */
1320 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 0);
1322 migrate_postcopy_complete(from
, to
, args
);
1325 static void test_postcopy_recovery(void)
1327 MigrateCommon args
= { };
1329 test_postcopy_recovery_common(&args
);
1332 static void test_postcopy_recovery_compress(void)
1334 MigrateCommon args
= {
1335 .start_hook
= test_migrate_compress_start
1338 test_postcopy_recovery_common(&args
);
1341 #ifdef CONFIG_GNUTLS
1342 static void test_postcopy_recovery_tls_psk(void)
1344 MigrateCommon args
= {
1345 .start_hook
= test_migrate_tls_psk_start_match
,
1346 .finish_hook
= test_migrate_tls_psk_finish
,
1349 test_postcopy_recovery_common(&args
);
1353 static void test_postcopy_preempt_recovery(void)
1355 MigrateCommon args
= {
1356 .postcopy_preempt
= true,
1359 test_postcopy_recovery_common(&args
);
1362 #ifdef CONFIG_GNUTLS
1363 /* This contains preempt+recovery+tls test altogether */
1364 static void test_postcopy_preempt_all(void)
1366 MigrateCommon args
= {
1367 .postcopy_preempt
= true,
1368 .start_hook
= test_migrate_tls_psk_start_match
,
1369 .finish_hook
= test_migrate_tls_psk_finish
,
1372 test_postcopy_recovery_common(&args
);
1377 static void test_baddest(void)
1379 MigrateStart args
= {
1382 QTestState
*from
, *to
;
1384 if (test_migrate_start(&from
, &to
, "tcp:127.0.0.1:0", &args
)) {
1387 migrate_qmp(from
, "tcp:127.0.0.1:0", "{}");
1388 wait_for_migration_fail(from
, false);
1389 test_migrate_end(from
, to
, false);
1392 static void test_precopy_common(MigrateCommon
*args
)
1394 QTestState
*from
, *to
;
1395 void *data_hook
= NULL
;
1397 if (test_migrate_start(&from
, &to
, args
->listen_uri
, &args
->start
)) {
1401 migrate_ensure_non_converge(from
);
1403 if (args
->start_hook
) {
1404 data_hook
= args
->start_hook(from
, to
);
1407 /* Wait for the first serial output from the source */
1408 if (args
->result
== MIG_TEST_SUCCEED
) {
1409 wait_for_serial("src_serial");
1412 if (!args
->connect_uri
) {
1413 g_autofree
char *local_connect_uri
=
1414 migrate_get_socket_address(to
, "socket-address");
1415 migrate_qmp(from
, local_connect_uri
, "{}");
1417 migrate_qmp(from
, args
->connect_uri
, "{}");
1421 if (args
->result
!= MIG_TEST_SUCCEED
) {
1422 bool allow_active
= args
->result
== MIG_TEST_FAIL
;
1423 wait_for_migration_fail(from
, allow_active
);
1425 if (args
->result
== MIG_TEST_FAIL_DEST_QUIT_ERR
) {
1426 qtest_set_expected_status(to
, EXIT_FAILURE
);
1429 if (args
->iterations
) {
1430 while (args
->iterations
--) {
1431 wait_for_migration_pass(from
);
1434 wait_for_migration_pass(from
);
1437 migrate_ensure_converge(from
);
1439 /* We do this first, as it has a timeout to stop us
1440 * hanging forever if migration didn't converge */
1441 wait_for_migration_complete(from
);
1444 qtest_qmp_eventwait(from
, "STOP");
1447 qtest_qmp_eventwait(to
, "RESUME");
1449 wait_for_serial("dest_serial");
1452 if (args
->finish_hook
) {
1453 args
->finish_hook(from
, to
, data_hook
);
1456 test_migrate_end(from
, to
, args
->result
== MIG_TEST_SUCCEED
);
1459 static void test_precopy_unix_plain(void)
1461 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1462 MigrateCommon args
= {
1467 test_precopy_common(&args
);
1471 static void test_precopy_unix_dirty_ring(void)
1473 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1474 MigrateCommon args
= {
1476 .use_dirty_ring
= true,
1482 test_precopy_common(&args
);
1485 #ifdef CONFIG_GNUTLS
1486 static void test_precopy_unix_tls_psk(void)
1488 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1489 MigrateCommon args
= {
1492 .start_hook
= test_migrate_tls_psk_start_match
,
1493 .finish_hook
= test_migrate_tls_psk_finish
,
1496 test_precopy_common(&args
);
1500 static void test_precopy_unix_tls_x509_default_host(void)
1502 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1503 MigrateCommon args
= {
1505 .hide_stderr
= true,
1509 .start_hook
= test_migrate_tls_x509_start_default_host
,
1510 .finish_hook
= test_migrate_tls_x509_finish
,
1511 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1514 test_precopy_common(&args
);
1517 static void test_precopy_unix_tls_x509_override_host(void)
1519 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1520 MigrateCommon args
= {
1523 .start_hook
= test_migrate_tls_x509_start_override_host
,
1524 .finish_hook
= test_migrate_tls_x509_finish
,
1527 test_precopy_common(&args
);
1529 #endif /* CONFIG_TASN1 */
1530 #endif /* CONFIG_GNUTLS */
1533 /* Currently upset on aarch64 TCG */
1534 static void test_ignore_shared(void)
1536 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1537 QTestState
*from
, *to
;
1539 if (test_migrate_start(&from
, &to
, uri
, false, true, NULL
, NULL
)) {
1543 migrate_set_capability(from
, "x-ignore-shared", true);
1544 migrate_set_capability(to
, "x-ignore-shared", true);
1546 /* Wait for the first serial output from the source */
1547 wait_for_serial("src_serial");
1549 migrate_qmp(from
, uri
, "{}");
1551 wait_for_migration_pass(from
);
1554 qtest_qmp_eventwait(from
, "STOP");
1557 qtest_qmp_eventwait(to
, "RESUME");
1559 wait_for_serial("dest_serial");
1560 wait_for_migration_complete(from
);
1562 /* Check whether shared RAM has been really skipped */
1563 g_assert_cmpint(read_ram_property_int(from
, "transferred"), <, 1024 * 1024);
1565 test_migrate_end(from
, to
, true);
1570 test_migrate_xbzrle_start(QTestState
*from
,
1573 migrate_set_parameter_int(from
, "xbzrle-cache-size", 33554432);
1575 migrate_set_capability(from
, "xbzrle", true);
1576 migrate_set_capability(to
, "xbzrle", true);
1581 static void test_precopy_unix_xbzrle(void)
1583 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1584 MigrateCommon args
= {
1588 .start_hook
= test_migrate_xbzrle_start
,
1593 test_precopy_common(&args
);
1596 static void test_precopy_unix_compress(void)
1598 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1599 MigrateCommon args
= {
1602 .start_hook
= test_migrate_compress_start
,
1604 * Test that no invalid thread state is left over from
1605 * the previous iteration.
1610 test_precopy_common(&args
);
1613 static void test_precopy_unix_compress_nowait(void)
1615 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1616 MigrateCommon args
= {
1619 .start_hook
= test_migrate_compress_nowait_start
,
1621 * Test that no invalid thread state is left over from
1622 * the previous iteration.
1627 test_precopy_common(&args
);
1630 static void test_precopy_tcp_plain(void)
1632 MigrateCommon args
= {
1633 .listen_uri
= "tcp:127.0.0.1:0",
1636 test_precopy_common(&args
);
1639 #ifdef CONFIG_GNUTLS
1640 static void test_precopy_tcp_tls_psk_match(void)
1642 MigrateCommon args
= {
1643 .listen_uri
= "tcp:127.0.0.1:0",
1644 .start_hook
= test_migrate_tls_psk_start_match
,
1645 .finish_hook
= test_migrate_tls_psk_finish
,
1648 test_precopy_common(&args
);
1651 static void test_precopy_tcp_tls_psk_mismatch(void)
1653 MigrateCommon args
= {
1655 .hide_stderr
= true,
1657 .listen_uri
= "tcp:127.0.0.1:0",
1658 .start_hook
= test_migrate_tls_psk_start_mismatch
,
1659 .finish_hook
= test_migrate_tls_psk_finish
,
1660 .result
= MIG_TEST_FAIL
,
1663 test_precopy_common(&args
);
1667 static void test_precopy_tcp_tls_x509_default_host(void)
1669 MigrateCommon args
= {
1670 .listen_uri
= "tcp:127.0.0.1:0",
1671 .start_hook
= test_migrate_tls_x509_start_default_host
,
1672 .finish_hook
= test_migrate_tls_x509_finish
,
1675 test_precopy_common(&args
);
1678 static void test_precopy_tcp_tls_x509_override_host(void)
1680 MigrateCommon args
= {
1681 .listen_uri
= "tcp:127.0.0.1:0",
1682 .start_hook
= test_migrate_tls_x509_start_override_host
,
1683 .finish_hook
= test_migrate_tls_x509_finish
,
1686 test_precopy_common(&args
);
1689 static void test_precopy_tcp_tls_x509_mismatch_host(void)
1691 MigrateCommon args
= {
1693 .hide_stderr
= true,
1695 .listen_uri
= "tcp:127.0.0.1:0",
1696 .start_hook
= test_migrate_tls_x509_start_mismatch_host
,
1697 .finish_hook
= test_migrate_tls_x509_finish
,
1698 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1701 test_precopy_common(&args
);
1704 static void test_precopy_tcp_tls_x509_friendly_client(void)
1706 MigrateCommon args
= {
1707 .listen_uri
= "tcp:127.0.0.1:0",
1708 .start_hook
= test_migrate_tls_x509_start_friendly_client
,
1709 .finish_hook
= test_migrate_tls_x509_finish
,
1712 test_precopy_common(&args
);
1715 static void test_precopy_tcp_tls_x509_hostile_client(void)
1717 MigrateCommon args
= {
1719 .hide_stderr
= true,
1721 .listen_uri
= "tcp:127.0.0.1:0",
1722 .start_hook
= test_migrate_tls_x509_start_hostile_client
,
1723 .finish_hook
= test_migrate_tls_x509_finish
,
1724 .result
= MIG_TEST_FAIL
,
1727 test_precopy_common(&args
);
1730 static void test_precopy_tcp_tls_x509_allow_anon_client(void)
1732 MigrateCommon args
= {
1733 .listen_uri
= "tcp:127.0.0.1:0",
1734 .start_hook
= test_migrate_tls_x509_start_allow_anon_client
,
1735 .finish_hook
= test_migrate_tls_x509_finish
,
1738 test_precopy_common(&args
);
1741 static void test_precopy_tcp_tls_x509_reject_anon_client(void)
1743 MigrateCommon args
= {
1745 .hide_stderr
= true,
1747 .listen_uri
= "tcp:127.0.0.1:0",
1748 .start_hook
= test_migrate_tls_x509_start_reject_anon_client
,
1749 .finish_hook
= test_migrate_tls_x509_finish
,
1750 .result
= MIG_TEST_FAIL
,
1753 test_precopy_common(&args
);
1755 #endif /* CONFIG_TASN1 */
1756 #endif /* CONFIG_GNUTLS */
1759 static void *test_migrate_fd_start_hook(QTestState
*from
,
1766 /* Create two connected sockets for migration */
1767 ret
= qemu_socketpair(PF_LOCAL
, SOCK_STREAM
, 0, pair
);
1768 g_assert_cmpint(ret
, ==, 0);
1770 /* Send the 1st socket to the target */
1771 rsp
= wait_command_fd(to
, pair
[0],
1772 "{ 'execute': 'getfd',"
1773 " 'arguments': { 'fdname': 'fd-mig' }}");
1777 /* Start incoming migration from the 1st socket */
1778 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
1779 " 'arguments': { 'uri': 'fd:fd-mig' }}");
1782 /* Send the 2nd socket to the target */
1783 rsp
= wait_command_fd(from
, pair
[1],
1784 "{ 'execute': 'getfd',"
1785 " 'arguments': { 'fdname': 'fd-mig' }}");
1792 static void test_migrate_fd_finish_hook(QTestState
*from
,
1797 const char *error_desc
;
1799 /* Test closing fds */
1800 /* We assume, that QEMU removes named fd from its list,
1801 * so this should fail */
1802 rsp
= qtest_qmp(from
, "{ 'execute': 'closefd',"
1803 " 'arguments': { 'fdname': 'fd-mig' }}");
1804 g_assert_true(qdict_haskey(rsp
, "error"));
1805 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1806 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1809 rsp
= qtest_qmp(to
, "{ 'execute': 'closefd',"
1810 " 'arguments': { 'fdname': 'fd-mig' }}");
1811 g_assert_true(qdict_haskey(rsp
, "error"));
1812 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1813 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1817 static void test_migrate_fd_proto(void)
1819 MigrateCommon args
= {
1820 .listen_uri
= "defer",
1821 .connect_uri
= "fd:fd-mig",
1822 .start_hook
= test_migrate_fd_start_hook
,
1823 .finish_hook
= test_migrate_fd_finish_hook
1825 test_precopy_common(&args
);
1829 static void do_test_validate_uuid(MigrateStart
*args
, bool should_fail
)
1831 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1832 QTestState
*from
, *to
;
1834 if (test_migrate_start(&from
, &to
, uri
, args
)) {
1839 * UUID validation is at the begin of migration. So, the main process of
1840 * migration is not interesting for us here. Thus, set huge downtime for
1841 * very fast migration.
1843 migrate_set_parameter_int(from
, "downtime-limit", 1000000);
1844 migrate_set_capability(from
, "validate-uuid", true);
1846 /* Wait for the first serial output from the source */
1847 wait_for_serial("src_serial");
1849 migrate_qmp(from
, uri
, "{}");
1852 qtest_set_expected_status(to
, EXIT_FAILURE
);
1853 wait_for_migration_fail(from
, true);
1855 wait_for_migration_complete(from
);
1858 test_migrate_end(from
, to
, false);
1861 static void test_validate_uuid(void)
1863 MigrateStart args
= {
1864 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1865 .opts_target
= "-uuid 11111111-1111-1111-1111-111111111111",
1868 do_test_validate_uuid(&args
, false);
1871 static void test_validate_uuid_error(void)
1873 MigrateStart args
= {
1874 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1875 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1876 .hide_stderr
= true,
1879 do_test_validate_uuid(&args
, true);
1882 static void test_validate_uuid_src_not_set(void)
1884 MigrateStart args
= {
1885 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1886 .hide_stderr
= true,
1889 do_test_validate_uuid(&args
, false);
1892 static void test_validate_uuid_dst_not_set(void)
1894 MigrateStart args
= {
1895 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1896 .hide_stderr
= true,
1899 do_test_validate_uuid(&args
, false);
1903 * The way auto_converge works, we need to do too many passes to
1904 * run this test. Auto_converge logic is only run once every
1905 * three iterations, so:
1907 * - 3 iterations without auto_converge enabled
1908 * - 3 iterations with pct = 5
1909 * - 3 iterations with pct = 30
1910 * - 3 iterations with pct = 55
1911 * - 3 iterations with pct = 80
1912 * - 3 iterations with pct = 95 (max(95, 80 + 25))
1914 * To make things even worse, we need to run the initial stage at
1915 * 3MB/s so we enter autoconverge even when host is (over)loaded.
1917 static void test_migrate_auto_converge(void)
1919 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1920 MigrateStart args
= {};
1921 QTestState
*from
, *to
;
1925 * We want the test to be stable and as fast as possible.
1926 * E.g., with 1Gb/s bandwith migration may pass without throttling,
1927 * so we need to decrease a bandwidth.
1929 const int64_t init_pct
= 5, inc_pct
= 25, max_pct
= 95;
1931 if (test_migrate_start(&from
, &to
, uri
, &args
)) {
1935 migrate_set_capability(from
, "auto-converge", true);
1936 migrate_set_parameter_int(from
, "cpu-throttle-initial", init_pct
);
1937 migrate_set_parameter_int(from
, "cpu-throttle-increment", inc_pct
);
1938 migrate_set_parameter_int(from
, "max-cpu-throttle", max_pct
);
1941 * Set the initial parameters so that the migration could not converge
1942 * without throttling.
1944 migrate_ensure_non_converge(from
);
1946 /* To check remaining size after precopy */
1947 migrate_set_capability(from
, "pause-before-switchover", true);
1949 /* Wait for the first serial output from the source */
1950 wait_for_serial("src_serial");
1952 migrate_qmp(from
, uri
, "{}");
1954 /* Wait for throttling begins */
1957 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1958 if (percentage
!= 0) {
1962 g_assert_false(got_stop
);
1964 /* The first percentage of throttling should be at least init_pct */
1965 g_assert_cmpint(percentage
, >=, init_pct
);
1966 /* Now, when we tested that throttling works, let it converge */
1967 migrate_ensure_converge(from
);
1970 * Wait for pre-switchover status to check last throttle percentage
1971 * and remaining. These values will be zeroed later
1973 wait_for_migration_status(from
, "pre-switchover", NULL
);
1975 /* The final percentage of throttling shouldn't be greater than max_pct */
1976 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1977 g_assert_cmpint(percentage
, <=, max_pct
);
1978 migrate_continue(from
, "pre-switchover");
1980 qtest_qmp_eventwait(to
, "RESUME");
1982 wait_for_serial("dest_serial");
1983 wait_for_migration_complete(from
);
1985 test_migrate_end(from
, to
, true);
1989 test_migrate_precopy_tcp_multifd_start_common(QTestState
*from
,
1995 migrate_set_parameter_int(from
, "multifd-channels", 16);
1996 migrate_set_parameter_int(to
, "multifd-channels", 16);
1998 migrate_set_parameter_str(from
, "multifd-compression", method
);
1999 migrate_set_parameter_str(to
, "multifd-compression", method
);
2001 migrate_set_capability(from
, "multifd", true);
2002 migrate_set_capability(to
, "multifd", true);
2004 /* Start incoming migration from the 1st socket */
2005 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
2006 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2013 test_migrate_precopy_tcp_multifd_start(QTestState
*from
,
2016 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2020 test_migrate_precopy_tcp_multifd_zlib_start(QTestState
*from
,
2023 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zlib");
2028 test_migrate_precopy_tcp_multifd_zstd_start(QTestState
*from
,
2031 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zstd");
2033 #endif /* CONFIG_ZSTD */
2035 static void test_multifd_tcp_none(void)
2037 MigrateCommon args
= {
2038 .listen_uri
= "defer",
2039 .start_hook
= test_migrate_precopy_tcp_multifd_start
,
2041 test_precopy_common(&args
);
2044 static void test_multifd_tcp_zlib(void)
2046 MigrateCommon args
= {
2047 .listen_uri
= "defer",
2048 .start_hook
= test_migrate_precopy_tcp_multifd_zlib_start
,
2050 test_precopy_common(&args
);
2054 static void test_multifd_tcp_zstd(void)
2056 MigrateCommon args
= {
2057 .listen_uri
= "defer",
2058 .start_hook
= test_migrate_precopy_tcp_multifd_zstd_start
,
2060 test_precopy_common(&args
);
2064 #ifdef CONFIG_GNUTLS
2066 test_migrate_multifd_tcp_tls_psk_start_match(QTestState
*from
,
2069 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2070 return test_migrate_tls_psk_start_match(from
, to
);
2074 test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState
*from
,
2077 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2078 return test_migrate_tls_psk_start_mismatch(from
, to
);
2083 test_migrate_multifd_tls_x509_start_default_host(QTestState
*from
,
2086 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2087 return test_migrate_tls_x509_start_default_host(from
, to
);
2091 test_migrate_multifd_tls_x509_start_override_host(QTestState
*from
,
2094 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2095 return test_migrate_tls_x509_start_override_host(from
, to
);
2099 test_migrate_multifd_tls_x509_start_mismatch_host(QTestState
*from
,
2102 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2103 return test_migrate_tls_x509_start_mismatch_host(from
, to
);
2107 test_migrate_multifd_tls_x509_start_allow_anon_client(QTestState
*from
,
2110 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2111 return test_migrate_tls_x509_start_allow_anon_client(from
, to
);
2115 test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState
*from
,
2118 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2119 return test_migrate_tls_x509_start_reject_anon_client(from
, to
);
2121 #endif /* CONFIG_TASN1 */
2123 static void test_multifd_tcp_tls_psk_match(void)
2125 MigrateCommon args
= {
2126 .listen_uri
= "defer",
2127 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_match
,
2128 .finish_hook
= test_migrate_tls_psk_finish
,
2130 test_precopy_common(&args
);
2133 static void test_multifd_tcp_tls_psk_mismatch(void)
2135 MigrateCommon args
= {
2137 .hide_stderr
= true,
2139 .listen_uri
= "defer",
2140 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_mismatch
,
2141 .finish_hook
= test_migrate_tls_psk_finish
,
2142 .result
= MIG_TEST_FAIL
,
2144 test_precopy_common(&args
);
2148 static void test_multifd_tcp_tls_x509_default_host(void)
2150 MigrateCommon args
= {
2151 .listen_uri
= "defer",
2152 .start_hook
= test_migrate_multifd_tls_x509_start_default_host
,
2153 .finish_hook
= test_migrate_tls_x509_finish
,
2155 test_precopy_common(&args
);
2158 static void test_multifd_tcp_tls_x509_override_host(void)
2160 MigrateCommon args
= {
2161 .listen_uri
= "defer",
2162 .start_hook
= test_migrate_multifd_tls_x509_start_override_host
,
2163 .finish_hook
= test_migrate_tls_x509_finish
,
2165 test_precopy_common(&args
);
2168 static void test_multifd_tcp_tls_x509_mismatch_host(void)
2171 * This has different behaviour to the non-multifd case.
2173 * In non-multifd case when client aborts due to mismatched
2174 * cert host, the server has already started trying to load
2175 * migration state, and so it exits with I/O failure.
2177 * In multifd case when client aborts due to mismatched
2178 * cert host, the server is still waiting for the other
2179 * multifd connections to arrive so hasn't started trying
2180 * to load migration state, and thus just aborts the migration
2183 MigrateCommon args
= {
2185 .hide_stderr
= true,
2187 .listen_uri
= "defer",
2188 .start_hook
= test_migrate_multifd_tls_x509_start_mismatch_host
,
2189 .finish_hook
= test_migrate_tls_x509_finish
,
2190 .result
= MIG_TEST_FAIL
,
2192 test_precopy_common(&args
);
2195 static void test_multifd_tcp_tls_x509_allow_anon_client(void)
2197 MigrateCommon args
= {
2198 .listen_uri
= "defer",
2199 .start_hook
= test_migrate_multifd_tls_x509_start_allow_anon_client
,
2200 .finish_hook
= test_migrate_tls_x509_finish
,
2202 test_precopy_common(&args
);
2205 static void test_multifd_tcp_tls_x509_reject_anon_client(void)
2207 MigrateCommon args
= {
2209 .hide_stderr
= true,
2211 .listen_uri
= "defer",
2212 .start_hook
= test_migrate_multifd_tls_x509_start_reject_anon_client
,
2213 .finish_hook
= test_migrate_tls_x509_finish
,
2214 .result
= MIG_TEST_FAIL
,
2216 test_precopy_common(&args
);
2218 #endif /* CONFIG_TASN1 */
2219 #endif /* CONFIG_GNUTLS */
2227 * launch another target
2230 * And see that it works
2232 static void test_multifd_tcp_cancel(void)
2234 MigrateStart args
= {
2235 .hide_stderr
= true,
2237 QTestState
*from
, *to
, *to2
;
2239 g_autofree
char *uri
= NULL
;
2241 if (test_migrate_start(&from
, &to
, "defer", &args
)) {
2245 migrate_ensure_non_converge(from
);
2247 migrate_set_parameter_int(from
, "multifd-channels", 16);
2248 migrate_set_parameter_int(to
, "multifd-channels", 16);
2250 migrate_set_capability(from
, "multifd", true);
2251 migrate_set_capability(to
, "multifd", true);
2253 /* Start incoming migration from the 1st socket */
2254 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
2255 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2258 /* Wait for the first serial output from the source */
2259 wait_for_serial("src_serial");
2261 uri
= migrate_get_socket_address(to
, "socket-address");
2263 migrate_qmp(from
, uri
, "{}");
2265 wait_for_migration_pass(from
);
2267 migrate_cancel(from
);
2269 /* Make sure QEMU process "to" exited */
2270 qtest_set_expected_status(to
, EXIT_FAILURE
);
2271 qtest_wait_qemu(to
);
2273 args
= (MigrateStart
){
2274 .only_target
= true,
2277 if (test_migrate_start(&from
, &to2
, "defer", &args
)) {
2281 migrate_set_parameter_int(to2
, "multifd-channels", 16);
2283 migrate_set_capability(to2
, "multifd", true);
2285 /* Start incoming migration from the 1st socket */
2286 rsp
= wait_command(to2
, "{ 'execute': 'migrate-incoming',"
2287 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2291 uri
= migrate_get_socket_address(to2
, "socket-address");
2293 wait_for_migration_status(from
, "cancelled", NULL
);
2295 migrate_ensure_converge(from
);
2297 migrate_qmp(from
, uri
, "{}");
2299 wait_for_migration_pass(from
);
2302 qtest_qmp_eventwait(from
, "STOP");
2304 qtest_qmp_eventwait(to2
, "RESUME");
2306 wait_for_serial("dest_serial");
2307 wait_for_migration_complete(from
);
2308 test_migrate_end(from
, to2
, true);
2311 static void calc_dirty_rate(QTestState
*who
, uint64_t calc_time
)
2313 qtest_qmp_assert_success(who
,
2314 "{ 'execute': 'calc-dirty-rate',"
2316 "'calc-time': %" PRIu64
","
2317 "'mode': 'dirty-ring' }}",
2321 static QDict
*query_dirty_rate(QTestState
*who
)
2323 return qtest_qmp_assert_success_ref(who
,
2324 "{ 'execute': 'query-dirty-rate' }");
2327 static void dirtylimit_set_all(QTestState
*who
, uint64_t dirtyrate
)
2329 qtest_qmp_assert_success(who
,
2330 "{ 'execute': 'set-vcpu-dirty-limit',"
2332 "'dirty-rate': %" PRIu64
" } }",
2336 static void cancel_vcpu_dirty_limit(QTestState
*who
)
2338 qtest_qmp_assert_success(who
,
2339 "{ 'execute': 'cancel-vcpu-dirty-limit' }");
2342 static QDict
*query_vcpu_dirty_limit(QTestState
*who
)
2346 rsp
= qtest_qmp(who
, "{ 'execute': 'query-vcpu-dirty-limit' }");
2347 g_assert(!qdict_haskey(rsp
, "error"));
2348 g_assert(qdict_haskey(rsp
, "return"));
2353 static bool calc_dirtyrate_ready(QTestState
*who
)
2358 rsp_return
= query_dirty_rate(who
);
2359 g_assert(rsp_return
);
2361 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2364 return g_strcmp0(status
, "measuring");
2367 static void wait_for_calc_dirtyrate_complete(QTestState
*who
,
2370 int max_try_count
= 10000;
2371 usleep(time_s
* 1000000);
2373 while (!calc_dirtyrate_ready(who
) && max_try_count
--) {
2378 * Set the timeout with 10 s(max_try_count * 1000us),
2379 * if dirtyrate measurement not complete, fail test.
2381 g_assert_cmpint(max_try_count
, !=, 0);
2384 static int64_t get_dirty_rate(QTestState
*who
)
2389 const QListEntry
*entry
;
2393 rsp_return
= query_dirty_rate(who
);
2394 g_assert(rsp_return
);
2396 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2398 g_assert_cmpstr(status
, ==, "measured");
2400 rates
= qdict_get_qlist(rsp_return
, "vcpu-dirty-rate");
2401 g_assert(rates
&& !qlist_empty(rates
));
2403 entry
= qlist_first(rates
);
2406 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2409 dirtyrate
= qdict_get_try_int(rate
, "dirty-rate", -1);
2411 qobject_unref(rsp_return
);
2415 static int64_t get_limit_rate(QTestState
*who
)
2419 const QListEntry
*entry
;
2423 rsp_return
= query_vcpu_dirty_limit(who
);
2424 g_assert(rsp_return
);
2426 rates
= qdict_get_qlist(rsp_return
, "return");
2427 g_assert(rates
&& !qlist_empty(rates
));
2429 entry
= qlist_first(rates
);
2432 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2435 dirtyrate
= qdict_get_try_int(rate
, "limit-rate", -1);
2437 qobject_unref(rsp_return
);
2441 static QTestState
*dirtylimit_start_vm(void)
2443 QTestState
*vm
= NULL
;
2444 g_autofree gchar
*cmd
= NULL
;
2445 const char *arch
= qtest_get_arch();
2446 g_autofree
char *bootpath
= NULL
;
2448 assert((strcmp(arch
, "x86_64") == 0));
2449 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
2450 assert(sizeof(x86_bootsect
) == 512);
2451 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
2453 cmd
= g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
2454 "-name dirtylimit-test,debug-threads=on "
2456 "-serial file:%s/vm_serial "
2457 "-drive file=%s,format=raw ",
2460 vm
= qtest_init(cmd
);
2464 static void dirtylimit_stop_vm(QTestState
*vm
)
2467 cleanup("bootsect");
2468 cleanup("vm_serial");
2471 static void test_vcpu_dirty_limit(void)
2474 int64_t origin_rate
;
2477 int max_try_count
= 20;
2480 /* Start vm for vcpu dirtylimit test */
2481 vm
= dirtylimit_start_vm();
2483 /* Wait for the first serial output from the vm*/
2484 wait_for_serial("vm_serial");
2486 /* Do dirtyrate measurement with calc time equals 1s */
2487 calc_dirty_rate(vm
, 1);
2489 /* Sleep calc time and wait for calc dirtyrate complete */
2490 wait_for_calc_dirtyrate_complete(vm
, 1);
2492 /* Query original dirty page rate */
2493 origin_rate
= get_dirty_rate(vm
);
2495 /* VM booted from bootsect should dirty memory steadily */
2496 assert(origin_rate
!= 0);
2498 /* Setup quota dirty page rate at half of origin */
2499 quota_rate
= origin_rate
/ 2;
2501 /* Set dirtylimit */
2502 dirtylimit_set_all(vm
, quota_rate
);
2505 * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
2508 g_assert_cmpint(quota_rate
, ==, get_limit_rate(vm
));
2510 /* Sleep a bit to check if it take effect */
2514 * Check if dirtylimit take effect realistically, set the
2515 * timeout with 20 s(max_try_count * 1s), if dirtylimit
2516 * doesn't take effect, fail test.
2518 while (--max_try_count
) {
2519 calc_dirty_rate(vm
, 1);
2520 wait_for_calc_dirtyrate_complete(vm
, 1);
2521 rate
= get_dirty_rate(vm
);
2524 * Assume hitting if current rate is less
2525 * than quota rate (within accepting error)
2527 if (rate
< (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2533 g_assert_cmpint(hit
, ==, 1);
2538 /* Check if dirtylimit cancellation take effect */
2539 cancel_vcpu_dirty_limit(vm
);
2540 while (--max_try_count
) {
2541 calc_dirty_rate(vm
, 1);
2542 wait_for_calc_dirtyrate_complete(vm
, 1);
2543 rate
= get_dirty_rate(vm
);
2546 * Assume dirtylimit be canceled if current rate is
2547 * greater than quota rate (within accepting error)
2549 if (rate
> (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2555 g_assert_cmpint(hit
, ==, 1);
2556 dirtylimit_stop_vm(vm
);
2559 static bool kvm_dirty_ring_supported(void)
2561 #if defined(__linux__) && defined(HOST_X86_64)
2562 int ret
, kvm_fd
= open("/dev/kvm", O_RDONLY
);
2568 ret
= ioctl(kvm_fd
, KVM_CHECK_EXTENSION
, KVM_CAP_DIRTY_LOG_RING
);
2571 /* We test with 4096 slots */
2582 int main(int argc
, char **argv
)
2584 bool has_kvm
, has_tcg
;
2587 g_autoptr(GError
) err
= NULL
;
2590 g_test_init(&argc
, &argv
, NULL
);
2592 has_kvm
= qtest_has_accel("kvm");
2593 has_tcg
= qtest_has_accel("tcg");
2595 if (!has_tcg
&& !has_kvm
) {
2596 g_test_skip("No KVM or TCG accelerator available");
2600 has_uffd
= ufd_version_check();
2601 arch
= qtest_get_arch();
2604 * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
2605 * is touchy due to race conditions on dirty bits (especially on PPC for
2608 if (g_str_equal(arch
, "ppc64") &&
2609 (!has_kvm
|| access("/sys/module/kvm_hv", F_OK
))) {
2610 g_test_message("Skipping test: kvm_hv not available");
2611 return g_test_run();
2615 * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
2616 * there until the problems are resolved
2618 if (g_str_equal(arch
, "s390x") && !has_kvm
) {
2619 g_test_message("Skipping test: s390x host with KVM is required");
2620 return g_test_run();
2623 tmpfs
= g_dir_make_tmp("migration-test-XXXXXX", &err
);
2625 g_test_message("Can't create temporary directory in %s: %s",
2626 g_get_tmp_dir(), err
->message
);
2630 module_call_init(MODULE_INIT_QOM
);
2633 qtest_add_func("/migration/postcopy/plain", test_postcopy
);
2634 qtest_add_func("/migration/postcopy/recovery/plain",
2635 test_postcopy_recovery
);
2636 qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_preempt
);
2637 qtest_add_func("/migration/postcopy/preempt/recovery/plain",
2638 test_postcopy_preempt_recovery
);
2639 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2640 qtest_add_func("/migration/postcopy/compress/plain",
2641 test_postcopy_compress
);
2642 qtest_add_func("/migration/postcopy/recovery/compress/plain",
2643 test_postcopy_recovery_compress
);
2647 qtest_add_func("/migration/bad_dest", test_baddest
);
2648 qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain
);
2649 qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle
);
2651 * Compression fails from time to time.
2652 * Put test here but don't enable it until everything is fixed.
2654 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2655 qtest_add_func("/migration/precopy/unix/compress/wait",
2656 test_precopy_unix_compress
);
2657 qtest_add_func("/migration/precopy/unix/compress/nowait",
2658 test_precopy_unix_compress_nowait
);
2660 #ifdef CONFIG_GNUTLS
2661 qtest_add_func("/migration/precopy/unix/tls/psk",
2662 test_precopy_unix_tls_psk
);
2666 * NOTE: psk test is enough for postcopy, as other types of TLS
2667 * channels are tested under precopy. Here what we want to test is the
2668 * general postcopy path that has TLS channel enabled.
2670 qtest_add_func("/migration/postcopy/tls/psk", test_postcopy_tls_psk
);
2671 qtest_add_func("/migration/postcopy/recovery/tls/psk",
2672 test_postcopy_recovery_tls_psk
);
2673 qtest_add_func("/migration/postcopy/preempt/tls/psk",
2674 test_postcopy_preempt_tls_psk
);
2675 qtest_add_func("/migration/postcopy/preempt/recovery/tls/psk",
2676 test_postcopy_preempt_all
);
2679 qtest_add_func("/migration/precopy/unix/tls/x509/default-host",
2680 test_precopy_unix_tls_x509_default_host
);
2681 qtest_add_func("/migration/precopy/unix/tls/x509/override-host",
2682 test_precopy_unix_tls_x509_override_host
);
2683 #endif /* CONFIG_TASN1 */
2684 #endif /* CONFIG_GNUTLS */
2686 qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain
);
2687 #ifdef CONFIG_GNUTLS
2688 qtest_add_func("/migration/precopy/tcp/tls/psk/match",
2689 test_precopy_tcp_tls_psk_match
);
2690 qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch",
2691 test_precopy_tcp_tls_psk_mismatch
);
2693 qtest_add_func("/migration/precopy/tcp/tls/x509/default-host",
2694 test_precopy_tcp_tls_x509_default_host
);
2695 qtest_add_func("/migration/precopy/tcp/tls/x509/override-host",
2696 test_precopy_tcp_tls_x509_override_host
);
2697 qtest_add_func("/migration/precopy/tcp/tls/x509/mismatch-host",
2698 test_precopy_tcp_tls_x509_mismatch_host
);
2699 qtest_add_func("/migration/precopy/tcp/tls/x509/friendly-client",
2700 test_precopy_tcp_tls_x509_friendly_client
);
2701 qtest_add_func("/migration/precopy/tcp/tls/x509/hostile-client",
2702 test_precopy_tcp_tls_x509_hostile_client
);
2703 qtest_add_func("/migration/precopy/tcp/tls/x509/allow-anon-client",
2704 test_precopy_tcp_tls_x509_allow_anon_client
);
2705 qtest_add_func("/migration/precopy/tcp/tls/x509/reject-anon-client",
2706 test_precopy_tcp_tls_x509_reject_anon_client
);
2707 #endif /* CONFIG_TASN1 */
2708 #endif /* CONFIG_GNUTLS */
2710 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
2712 qtest_add_func("/migration/fd_proto", test_migrate_fd_proto
);
2714 qtest_add_func("/migration/validate_uuid", test_validate_uuid
);
2715 qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error
);
2716 qtest_add_func("/migration/validate_uuid_src_not_set",
2717 test_validate_uuid_src_not_set
);
2718 qtest_add_func("/migration/validate_uuid_dst_not_set",
2719 test_validate_uuid_dst_not_set
);
2721 * See explanation why this test is slow on function definition
2723 if (g_test_slow()) {
2724 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge
);
2726 qtest_add_func("/migration/multifd/tcp/plain/none",
2727 test_multifd_tcp_none
);
2729 * This test is flaky and sometimes fails in CI and otherwise:
2730 * don't run unless user opts in via environment variable.
2732 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2733 qtest_add_func("/migration/multifd/tcp/plain/cancel",
2734 test_multifd_tcp_cancel
);
2736 qtest_add_func("/migration/multifd/tcp/plain/zlib",
2737 test_multifd_tcp_zlib
);
2739 qtest_add_func("/migration/multifd/tcp/plain/zstd",
2740 test_multifd_tcp_zstd
);
2742 #ifdef CONFIG_GNUTLS
2743 qtest_add_func("/migration/multifd/tcp/tls/psk/match",
2744 test_multifd_tcp_tls_psk_match
);
2745 qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
2746 test_multifd_tcp_tls_psk_mismatch
);
2748 qtest_add_func("/migration/multifd/tcp/tls/x509/default-host",
2749 test_multifd_tcp_tls_x509_default_host
);
2750 qtest_add_func("/migration/multifd/tcp/tls/x509/override-host",
2751 test_multifd_tcp_tls_x509_override_host
);
2752 qtest_add_func("/migration/multifd/tcp/tls/x509/mismatch-host",
2753 test_multifd_tcp_tls_x509_mismatch_host
);
2754 qtest_add_func("/migration/multifd/tcp/tls/x509/allow-anon-client",
2755 test_multifd_tcp_tls_x509_allow_anon_client
);
2756 qtest_add_func("/migration/multifd/tcp/tls/x509/reject-anon-client",
2757 test_multifd_tcp_tls_x509_reject_anon_client
);
2758 #endif /* CONFIG_TASN1 */
2759 #endif /* CONFIG_GNUTLS */
2761 if (g_str_equal(arch
, "x86_64") && has_kvm
&& kvm_dirty_ring_supported()) {
2762 qtest_add_func("/migration/dirty_ring",
2763 test_precopy_unix_dirty_ring
);
2764 qtest_add_func("/migration/vcpu_dirty_limit",
2765 test_vcpu_dirty_limit
);
2770 g_assert_cmpint(ret
, ==, 0);
2774 g_test_message("unable to rmdir: path (%s): %s",
2775 tmpfs
, strerror(errno
));