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
= qtest_qmp_assert_success_ref(
346 who
, "{ 'execute': 'query-migrate-parameters' }");
347 result
= qdict_get_int(rsp
, parameter
);
352 static void migrate_check_parameter_int(QTestState
*who
, const char *parameter
,
357 result
= migrate_get_parameter_int(who
, parameter
);
358 g_assert_cmpint(result
, ==, value
);
361 static void migrate_set_parameter_int(QTestState
*who
, const char *parameter
,
364 qtest_qmp_assert_success(who
,
365 "{ 'execute': 'migrate-set-parameters',"
366 "'arguments': { %s: %lld } }",
368 migrate_check_parameter_int(who
, parameter
, value
);
371 static char *migrate_get_parameter_str(QTestState
*who
,
372 const char *parameter
)
377 rsp
= qtest_qmp_assert_success_ref(
378 who
, "{ 'execute': 'query-migrate-parameters' }");
379 result
= g_strdup(qdict_get_str(rsp
, parameter
));
384 static void migrate_check_parameter_str(QTestState
*who
, const char *parameter
,
387 g_autofree
char *result
= migrate_get_parameter_str(who
, parameter
);
388 g_assert_cmpstr(result
, ==, value
);
391 static void migrate_set_parameter_str(QTestState
*who
, const char *parameter
,
394 qtest_qmp_assert_success(who
,
395 "{ 'execute': 'migrate-set-parameters',"
396 "'arguments': { %s: %s } }",
398 migrate_check_parameter_str(who
, parameter
, value
);
401 static long long migrate_get_parameter_bool(QTestState
*who
,
402 const char *parameter
)
407 rsp
= qtest_qmp_assert_success_ref(
408 who
, "{ 'execute': 'query-migrate-parameters' }");
409 result
= qdict_get_bool(rsp
, parameter
);
414 static void migrate_check_parameter_bool(QTestState
*who
, const char *parameter
,
419 result
= migrate_get_parameter_bool(who
, parameter
);
420 g_assert_cmpint(result
, ==, value
);
423 static void migrate_set_parameter_bool(QTestState
*who
, const char *parameter
,
426 qtest_qmp_assert_success(who
,
427 "{ 'execute': 'migrate-set-parameters',"
428 "'arguments': { %s: %i } }",
430 migrate_check_parameter_bool(who
, parameter
, value
);
433 static void migrate_ensure_non_converge(QTestState
*who
)
435 /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
436 migrate_set_parameter_int(who
, "max-bandwidth", 3 * 1000 * 1000);
437 migrate_set_parameter_int(who
, "downtime-limit", 1);
440 static void migrate_ensure_converge(QTestState
*who
)
442 /* Should converge with 30s downtime + 1 gbs bandwidth limit */
443 migrate_set_parameter_int(who
, "max-bandwidth", 1 * 1000 * 1000 * 1000);
444 migrate_set_parameter_int(who
, "downtime-limit", 30 * 1000);
447 static void migrate_pause(QTestState
*who
)
449 qtest_qmp_assert_success(who
, "{ 'execute': 'migrate-pause' }");
452 static void migrate_continue(QTestState
*who
, const char *state
)
454 qtest_qmp_assert_success(who
,
455 "{ 'execute': 'migrate-continue',"
456 " 'arguments': { 'state': %s } }",
460 static void migrate_recover(QTestState
*who
, const char *uri
)
462 qtest_qmp_assert_success(who
,
463 "{ 'execute': 'migrate-recover', "
464 " 'id': 'recover-cmd', "
465 " 'arguments': { 'uri': %s } }",
469 static void migrate_cancel(QTestState
*who
)
471 qtest_qmp_assert_success(who
, "{ 'execute': 'migrate_cancel' }");
474 static void migrate_set_capability(QTestState
*who
, const char *capability
,
477 qtest_qmp_assert_success(who
,
478 "{ 'execute': 'migrate-set-capabilities',"
480 "'capabilities': [ { "
481 "'capability': %s, 'state': %i } ] } }",
485 static void migrate_postcopy_start(QTestState
*from
, QTestState
*to
)
487 qtest_qmp_assert_success(from
, "{ 'execute': 'migrate-start-postcopy' }");
490 qtest_qmp_eventwait(from
, "STOP");
493 qtest_qmp_eventwait(to
, "RESUME");
498 * QTEST_LOG=1 may override this. When QTEST_LOG=1, we always dump errors
499 * unconditionally, because it means the user would like to be verbose.
503 /* only launch the target process */
505 /* Use dirty ring if true; dirty logging otherwise */
507 const char *opts_source
;
508 const char *opts_target
;
512 * A hook that runs after the src and dst QEMUs have been
513 * created, but before the migration is started. This can
514 * be used to set migration parameters and capabilities.
516 * Returns: NULL, or a pointer to opaque state to be
517 * later passed to the TestMigrateFinishHook
519 typedef void * (*TestMigrateStartHook
)(QTestState
*from
,
523 * A hook that runs after the migration has finished,
524 * regardless of whether it succeeded or failed, but
525 * before QEMU has terminated (unless it self-terminated
526 * due to migration error)
528 * @opaque is a pointer to state previously returned
529 * by the TestMigrateStartHook if any, or NULL.
531 typedef void (*TestMigrateFinishHook
)(QTestState
*from
,
536 /* Optional: fine tune start parameters */
539 /* Required: the URI for the dst QEMU to listen on */
540 const char *listen_uri
;
543 * Optional: the URI for the src QEMU to connect to
544 * If NULL, then it will query the dst QEMU for its actual
545 * listening address and use that as the connect address.
546 * This allows for dynamically picking a free TCP port.
548 const char *connect_uri
;
550 /* Optional: callback to run at start to set migration parameters */
551 TestMigrateStartHook start_hook
;
552 /* Optional: callback to run at finish to cleanup */
553 TestMigrateFinishHook finish_hook
;
556 * Optional: normally we expect the migration process to complete.
558 * There can be a variety of reasons and stages in which failure
559 * can happen during tests.
561 * If a failure is expected to happen at time of establishing
562 * the connection, then MIG_TEST_FAIL will indicate that the dst
563 * QEMU is expected to stay running and accept future migration
566 * If a failure is expected to happen while processing the
567 * migration stream, then MIG_TEST_FAIL_DEST_QUIT_ERR will indicate
568 * that the dst QEMU is expected to quit with non-zero exit status
571 /* This test should succeed, the default */
572 MIG_TEST_SUCCEED
= 0,
573 /* This test should fail, dest qemu should keep alive */
575 /* This test should fail, dest qemu should fail with abnormal status */
576 MIG_TEST_FAIL_DEST_QUIT_ERR
,
579 /* Optional: set number of migration passes to wait for */
580 unsigned int iterations
;
582 /* Postcopy specific fields */
584 bool postcopy_preempt
;
587 static int test_migrate_start(QTestState
**from
, QTestState
**to
,
588 const char *uri
, MigrateStart
*args
)
590 g_autofree gchar
*arch_source
= NULL
;
591 g_autofree gchar
*arch_target
= NULL
;
592 g_autofree gchar
*cmd_source
= NULL
;
593 g_autofree gchar
*cmd_target
= NULL
;
594 const gchar
*ignore_stderr
;
595 g_autofree
char *bootpath
= NULL
;
596 g_autofree
char *shmem_opts
= NULL
;
597 g_autofree
char *shmem_path
= NULL
;
598 const char *arch
= qtest_get_arch();
599 const char *machine_opts
= NULL
;
600 const char *memory_size
;
602 if (args
->use_shmem
) {
603 if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR
)) {
604 g_test_skip("/dev/shm is not supported");
610 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
611 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
612 /* the assembled x86 boot sector should be exactly one sector large */
613 assert(sizeof(x86_bootsect
) == 512);
614 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
615 memory_size
= "150M";
616 arch_source
= g_strdup_printf("-drive file=%s,format=raw", bootpath
);
617 arch_target
= g_strdup(arch_source
);
618 start_address
= X86_TEST_MEM_START
;
619 end_address
= X86_TEST_MEM_END
;
620 } else if (g_str_equal(arch
, "s390x")) {
621 init_bootfile(bootpath
, s390x_elf
, sizeof(s390x_elf
));
622 memory_size
= "128M";
623 arch_source
= g_strdup_printf("-bios %s", bootpath
);
624 arch_target
= g_strdup(arch_source
);
625 start_address
= S390_TEST_MEM_START
;
626 end_address
= S390_TEST_MEM_END
;
627 } else if (strcmp(arch
, "ppc64") == 0) {
628 machine_opts
= "vsmt=8";
629 memory_size
= "256M";
630 start_address
= PPC_TEST_MEM_START
;
631 end_address
= PPC_TEST_MEM_END
;
632 arch_source
= g_strdup_printf("-nodefaults "
633 "-prom-env 'use-nvramrc?=true' -prom-env "
634 "'nvramrc=hex .\" _\" begin %x %x "
635 "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
636 "until'", end_address
, start_address
);
637 arch_target
= g_strdup("");
638 } else if (strcmp(arch
, "aarch64") == 0) {
639 init_bootfile(bootpath
, aarch64_kernel
, sizeof(aarch64_kernel
));
640 machine_opts
= "virt,gic-version=max";
641 memory_size
= "150M";
642 arch_source
= g_strdup_printf("-cpu max "
645 arch_target
= g_strdup(arch_source
);
646 start_address
= ARM_TEST_MEM_START
;
647 end_address
= ARM_TEST_MEM_END
;
649 g_assert(sizeof(aarch64_kernel
) <= ARM_TEST_MAX_KERNEL_SIZE
);
651 g_assert_not_reached();
654 if (!getenv("QTEST_LOG") && args
->hide_stderr
) {
656 ignore_stderr
= "2>/dev/null";
659 * On Windows the QEMU executable is created via CreateProcess() and
660 * IO redirection does not work, so don't bother adding IO redirection
661 * to the command line.
669 if (args
->use_shmem
) {
670 shmem_path
= g_strdup_printf("/dev/shm/qemu-%d", getpid());
671 shmem_opts
= g_strdup_printf(
672 "-object memory-backend-file,id=mem0,size=%s"
673 ",mem-path=%s,share=on -numa node,memdev=mem0",
674 memory_size
, shmem_path
);
677 shmem_opts
= g_strdup("");
680 cmd_source
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
681 "-name source,debug-threads=on "
683 "-serial file:%s/src_serial "
685 args
->use_dirty_ring
?
686 ",dirty-ring-size=4096" : "",
687 machine_opts
? " -machine " : "",
688 machine_opts
? machine_opts
: "",
690 arch_source
, shmem_opts
,
691 args
->opts_source
? args
->opts_source
: "",
693 if (!args
->only_target
) {
694 *from
= qtest_init(cmd_source
);
695 qtest_qmp_set_event_callback(*from
,
696 migrate_watch_for_stop
,
700 cmd_target
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
701 "-name target,debug-threads=on "
703 "-serial file:%s/dest_serial "
706 args
->use_dirty_ring
?
707 ",dirty-ring-size=4096" : "",
708 machine_opts
? " -machine " : "",
709 machine_opts
? machine_opts
: "",
710 memory_size
, tmpfs
, uri
,
711 arch_target
, shmem_opts
,
712 args
->opts_target
? args
->opts_target
: "",
714 *to
= qtest_init(cmd_target
);
717 * Remove shmem file immediately to avoid memory leak in test failed case.
718 * It's valid becase QEMU has already opened this file
720 if (args
->use_shmem
) {
727 static void test_migrate_end(QTestState
*from
, QTestState
*to
, bool test_dest
)
729 unsigned char dest_byte_a
, dest_byte_b
, dest_byte_c
, dest_byte_d
;
734 qtest_memread(to
, start_address
, &dest_byte_a
, 1);
736 /* Destination still running, wait for a byte to change */
738 qtest_memread(to
, start_address
, &dest_byte_b
, 1);
740 } while (dest_byte_a
== dest_byte_b
);
742 qtest_qmp_assert_success(to
, "{ 'execute' : 'stop'}");
744 /* With it stopped, check nothing changes */
745 qtest_memread(to
, start_address
, &dest_byte_c
, 1);
747 qtest_memread(to
, start_address
, &dest_byte_d
, 1);
748 g_assert_cmpint(dest_byte_c
, ==, dest_byte_d
);
750 check_guests_ram(to
);
756 cleanup("migsocket");
757 cleanup("src_serial");
758 cleanup("dest_serial");
762 struct TestMigrateTLSPSKData
{
770 test_migrate_tls_psk_start_common(QTestState
*from
,
774 struct TestMigrateTLSPSKData
*data
=
775 g_new0(struct TestMigrateTLSPSKData
, 1);
777 data
->workdir
= g_strdup_printf("%s/tlscredspsk0", tmpfs
);
778 data
->pskfile
= g_strdup_printf("%s/%s", data
->workdir
,
779 QCRYPTO_TLS_CREDS_PSKFILE
);
780 g_mkdir_with_parents(data
->workdir
, 0700);
781 test_tls_psk_init(data
->pskfile
);
784 data
->workdiralt
= g_strdup_printf("%s/tlscredspskalt0", tmpfs
);
785 data
->pskfilealt
= g_strdup_printf("%s/%s", data
->workdiralt
,
786 QCRYPTO_TLS_CREDS_PSKFILE
);
787 g_mkdir_with_parents(data
->workdiralt
, 0700);
788 test_tls_psk_init_alt(data
->pskfilealt
);
791 qtest_qmp_assert_success(from
,
792 "{ 'execute': 'object-add',"
793 " 'arguments': { 'qom-type': 'tls-creds-psk',"
794 " 'id': 'tlscredspsk0',"
795 " 'endpoint': 'client',"
797 " 'username': 'qemu'} }",
800 qtest_qmp_assert_success(to
,
801 "{ 'execute': 'object-add',"
802 " 'arguments': { 'qom-type': 'tls-creds-psk',"
803 " 'id': 'tlscredspsk0',"
804 " 'endpoint': 'server',"
806 mismatch
? data
->workdiralt
: data
->workdir
);
808 migrate_set_parameter_str(from
, "tls-creds", "tlscredspsk0");
809 migrate_set_parameter_str(to
, "tls-creds", "tlscredspsk0");
815 test_migrate_tls_psk_start_match(QTestState
*from
,
818 return test_migrate_tls_psk_start_common(from
, to
, false);
822 test_migrate_tls_psk_start_mismatch(QTestState
*from
,
825 return test_migrate_tls_psk_start_common(from
, to
, true);
829 test_migrate_tls_psk_finish(QTestState
*from
,
833 struct TestMigrateTLSPSKData
*data
= opaque
;
835 test_tls_psk_cleanup(data
->pskfile
);
836 if (data
->pskfilealt
) {
837 test_tls_psk_cleanup(data
->pskfilealt
);
839 rmdir(data
->workdir
);
840 if (data
->workdiralt
) {
841 rmdir(data
->workdiralt
);
844 g_free(data
->workdiralt
);
845 g_free(data
->pskfilealt
);
846 g_free(data
->workdir
);
847 g_free(data
->pskfile
);
860 } TestMigrateTLSX509Data
;
867 const char *certhostname
;
868 const char *certipaddr
;
869 } TestMigrateTLSX509
;
872 test_migrate_tls_x509_start_common(QTestState
*from
,
874 TestMigrateTLSX509
*args
)
876 TestMigrateTLSX509Data
*data
= g_new0(TestMigrateTLSX509Data
, 1);
878 data
->workdir
= g_strdup_printf("%s/tlscredsx5090", tmpfs
);
879 data
->keyfile
= g_strdup_printf("%s/key.pem", data
->workdir
);
881 data
->cacert
= g_strdup_printf("%s/ca-cert.pem", data
->workdir
);
882 data
->serverkey
= g_strdup_printf("%s/server-key.pem", data
->workdir
);
883 data
->servercert
= g_strdup_printf("%s/server-cert.pem", data
->workdir
);
884 if (args
->clientcert
) {
885 data
->clientkey
= g_strdup_printf("%s/client-key.pem", data
->workdir
);
886 data
->clientcert
= g_strdup_printf("%s/client-cert.pem", data
->workdir
);
889 g_mkdir_with_parents(data
->workdir
, 0700);
891 test_tls_init(data
->keyfile
);
893 g_assert(link(data
->keyfile
, data
->serverkey
) == 0);
895 g_assert(CreateHardLink(data
->serverkey
, data
->keyfile
, NULL
) != 0);
897 if (args
->clientcert
) {
899 g_assert(link(data
->keyfile
, data
->clientkey
) == 0);
901 g_assert(CreateHardLink(data
->clientkey
, data
->keyfile
, NULL
) != 0);
905 TLS_ROOT_REQ_SIMPLE(cacertreq
, data
->cacert
);
906 if (args
->clientcert
) {
907 TLS_CERT_REQ_SIMPLE_CLIENT(servercertreq
, cacertreq
,
908 args
->hostileclient
?
909 QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME
:
910 QCRYPTO_TLS_TEST_CLIENT_NAME
,
914 TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq
, cacertreq
,
919 qtest_qmp_assert_success(from
,
920 "{ 'execute': 'object-add',"
921 " 'arguments': { 'qom-type': 'tls-creds-x509',"
922 " 'id': 'tlscredsx509client0',"
923 " 'endpoint': 'client',"
925 " 'sanity-check': true,"
926 " 'verify-peer': true} }",
928 migrate_set_parameter_str(from
, "tls-creds", "tlscredsx509client0");
929 if (args
->certhostname
) {
930 migrate_set_parameter_str(from
, "tls-hostname", args
->certhostname
);
933 qtest_qmp_assert_success(to
,
934 "{ 'execute': 'object-add',"
935 " 'arguments': { 'qom-type': 'tls-creds-x509',"
936 " 'id': 'tlscredsx509server0',"
937 " 'endpoint': 'server',"
939 " 'sanity-check': true,"
940 " 'verify-peer': %i} }",
941 data
->workdir
, args
->verifyclient
);
942 migrate_set_parameter_str(to
, "tls-creds", "tlscredsx509server0");
944 if (args
->authzclient
) {
945 qtest_qmp_assert_success(to
,
946 "{ 'execute': 'object-add',"
947 " 'arguments': { 'qom-type': 'authz-simple',"
948 " 'id': 'tlsauthz0',"
949 " 'identity': %s} }",
950 "CN=" QCRYPTO_TLS_TEST_CLIENT_NAME
);
951 migrate_set_parameter_str(to
, "tls-authz", "tlsauthz0");
958 * The normal case: match server's cert hostname against
959 * whatever host we were telling QEMU to connect to (if any)
962 test_migrate_tls_x509_start_default_host(QTestState
*from
,
965 TestMigrateTLSX509 args
= {
966 .verifyclient
= true,
968 .certipaddr
= "127.0.0.1"
970 return test_migrate_tls_x509_start_common(from
, to
, &args
);
974 * The unusual case: the server's cert is different from
975 * the address we're telling QEMU to connect to (if any),
976 * so we must give QEMU an explicit hostname to validate
979 test_migrate_tls_x509_start_override_host(QTestState
*from
,
982 TestMigrateTLSX509 args
= {
983 .verifyclient
= true,
985 .certhostname
= "qemu.org",
987 return test_migrate_tls_x509_start_common(from
, to
, &args
);
991 * The unusual case: the server's cert is different from
992 * the address we're telling QEMU to connect to, and so we
993 * expect the client to reject the server
996 test_migrate_tls_x509_start_mismatch_host(QTestState
*from
,
999 TestMigrateTLSX509 args
= {
1000 .verifyclient
= true,
1002 .certipaddr
= "10.0.0.1",
1004 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1008 test_migrate_tls_x509_start_friendly_client(QTestState
*from
,
1011 TestMigrateTLSX509 args
= {
1012 .verifyclient
= true,
1014 .authzclient
= true,
1015 .certipaddr
= "127.0.0.1",
1017 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1021 test_migrate_tls_x509_start_hostile_client(QTestState
*from
,
1024 TestMigrateTLSX509 args
= {
1025 .verifyclient
= true,
1027 .hostileclient
= true,
1028 .authzclient
= true,
1029 .certipaddr
= "127.0.0.1",
1031 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1035 * The case with no client certificate presented,
1036 * and no server verification
1039 test_migrate_tls_x509_start_allow_anon_client(QTestState
*from
,
1042 TestMigrateTLSX509 args
= {
1043 .certipaddr
= "127.0.0.1",
1045 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1049 * The case with no client certificate presented,
1050 * and server verification rejecting
1053 test_migrate_tls_x509_start_reject_anon_client(QTestState
*from
,
1056 TestMigrateTLSX509 args
= {
1057 .verifyclient
= true,
1058 .certipaddr
= "127.0.0.1",
1060 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1064 test_migrate_tls_x509_finish(QTestState
*from
,
1068 TestMigrateTLSX509Data
*data
= opaque
;
1070 test_tls_cleanup(data
->keyfile
);
1071 g_free(data
->keyfile
);
1073 unlink(data
->cacert
);
1074 g_free(data
->cacert
);
1075 unlink(data
->servercert
);
1076 g_free(data
->servercert
);
1077 unlink(data
->serverkey
);
1078 g_free(data
->serverkey
);
1080 if (data
->clientcert
) {
1081 unlink(data
->clientcert
);
1082 g_free(data
->clientcert
);
1084 if (data
->clientkey
) {
1085 unlink(data
->clientkey
);
1086 g_free(data
->clientkey
);
1089 rmdir(data
->workdir
);
1090 g_free(data
->workdir
);
1094 #endif /* CONFIG_TASN1 */
1095 #endif /* CONFIG_GNUTLS */
1098 test_migrate_compress_start(QTestState
*from
,
1101 migrate_set_parameter_int(from
, "compress-level", 1);
1102 migrate_set_parameter_int(from
, "compress-threads", 4);
1103 migrate_set_parameter_bool(from
, "compress-wait-thread", true);
1104 migrate_set_parameter_int(to
, "decompress-threads", 4);
1106 migrate_set_capability(from
, "compress", true);
1107 migrate_set_capability(to
, "compress", true);
1113 test_migrate_compress_nowait_start(QTestState
*from
,
1116 migrate_set_parameter_int(from
, "compress-level", 9);
1117 migrate_set_parameter_int(from
, "compress-threads", 1);
1118 migrate_set_parameter_bool(from
, "compress-wait-thread", false);
1119 migrate_set_parameter_int(to
, "decompress-threads", 1);
1121 migrate_set_capability(from
, "compress", true);
1122 migrate_set_capability(to
, "compress", true);
1127 static int migrate_postcopy_prepare(QTestState
**from_ptr
,
1128 QTestState
**to_ptr
,
1129 MigrateCommon
*args
)
1131 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1132 QTestState
*from
, *to
;
1134 if (test_migrate_start(&from
, &to
, uri
, &args
->start
)) {
1138 if (args
->start_hook
) {
1139 args
->postcopy_data
= args
->start_hook(from
, to
);
1142 migrate_set_capability(from
, "postcopy-ram", true);
1143 migrate_set_capability(to
, "postcopy-ram", true);
1144 migrate_set_capability(to
, "postcopy-blocktime", true);
1146 if (args
->postcopy_preempt
) {
1147 migrate_set_capability(from
, "postcopy-preempt", true);
1148 migrate_set_capability(to
, "postcopy-preempt", true);
1151 migrate_ensure_non_converge(from
);
1153 /* Wait for the first serial output from the source */
1154 wait_for_serial("src_serial");
1156 migrate_qmp(from
, uri
, "{}");
1158 wait_for_migration_pass(from
);
1166 static void migrate_postcopy_complete(QTestState
*from
, QTestState
*to
,
1167 MigrateCommon
*args
)
1169 wait_for_migration_complete(from
);
1171 /* Make sure we get at least one "B" on destination */
1172 wait_for_serial("dest_serial");
1174 if (uffd_feature_thread_id
) {
1178 if (args
->finish_hook
) {
1179 args
->finish_hook(from
, to
, args
->postcopy_data
);
1180 args
->postcopy_data
= NULL
;
1183 test_migrate_end(from
, to
, true);
1186 static void test_postcopy_common(MigrateCommon
*args
)
1188 QTestState
*from
, *to
;
1190 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1193 migrate_postcopy_start(from
, to
);
1194 migrate_postcopy_complete(from
, to
, args
);
1197 static void test_postcopy(void)
1199 MigrateCommon args
= { };
1201 test_postcopy_common(&args
);
1204 static void test_postcopy_compress(void)
1206 MigrateCommon args
= {
1207 .start_hook
= test_migrate_compress_start
1210 test_postcopy_common(&args
);
1213 static void test_postcopy_preempt(void)
1215 MigrateCommon args
= {
1216 .postcopy_preempt
= true,
1219 test_postcopy_common(&args
);
1222 #ifdef CONFIG_GNUTLS
1223 static void test_postcopy_tls_psk(void)
1225 MigrateCommon args
= {
1226 .start_hook
= test_migrate_tls_psk_start_match
,
1227 .finish_hook
= test_migrate_tls_psk_finish
,
1230 test_postcopy_common(&args
);
1233 static void test_postcopy_preempt_tls_psk(void)
1235 MigrateCommon args
= {
1236 .postcopy_preempt
= true,
1237 .start_hook
= test_migrate_tls_psk_start_match
,
1238 .finish_hook
= test_migrate_tls_psk_finish
,
1241 test_postcopy_common(&args
);
1245 static void test_postcopy_recovery_common(MigrateCommon
*args
)
1247 QTestState
*from
, *to
;
1248 g_autofree
char *uri
= NULL
;
1250 /* Always hide errors for postcopy recover tests since they're expected */
1251 args
->start
.hide_stderr
= true;
1253 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1257 /* Turn postcopy speed down, 4K/s is slow enough on any machines */
1258 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 4096);
1260 /* Now we start the postcopy */
1261 migrate_postcopy_start(from
, to
);
1264 * Wait until postcopy is really started; we can only run the
1265 * migrate-pause command during a postcopy
1267 wait_for_migration_status(from
, "postcopy-active", NULL
);
1270 * Manually stop the postcopy migration. This emulates a network
1271 * failure with the migration socket
1273 migrate_pause(from
);
1276 * Wait for destination side to reach postcopy-paused state. The
1277 * migrate-recover command can only succeed if destination machine
1278 * is in the paused state
1280 wait_for_migration_status(to
, "postcopy-paused",
1281 (const char * []) { "failed", "active",
1282 "completed", NULL
});
1285 * Create a new socket to emulate a new channel that is different
1286 * from the broken migration channel; tell the destination to
1287 * listen to the new port
1289 uri
= g_strdup_printf("unix:%s/migsocket-recover", tmpfs
);
1290 migrate_recover(to
, uri
);
1293 * Try to rebuild the migration channel using the resume flag and
1294 * the newly created channel
1296 wait_for_migration_status(from
, "postcopy-paused",
1297 (const char * []) { "failed", "active",
1298 "completed", NULL
});
1299 migrate_qmp(from
, uri
, "{'resume': true}");
1301 /* Restore the postcopy bandwidth to unlimited */
1302 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 0);
1304 migrate_postcopy_complete(from
, to
, args
);
1307 static void test_postcopy_recovery(void)
1309 MigrateCommon args
= { };
1311 test_postcopy_recovery_common(&args
);
1314 static void test_postcopy_recovery_compress(void)
1316 MigrateCommon args
= {
1317 .start_hook
= test_migrate_compress_start
1320 test_postcopy_recovery_common(&args
);
1323 #ifdef CONFIG_GNUTLS
1324 static void test_postcopy_recovery_tls_psk(void)
1326 MigrateCommon args
= {
1327 .start_hook
= test_migrate_tls_psk_start_match
,
1328 .finish_hook
= test_migrate_tls_psk_finish
,
1331 test_postcopy_recovery_common(&args
);
1335 static void test_postcopy_preempt_recovery(void)
1337 MigrateCommon args
= {
1338 .postcopy_preempt
= true,
1341 test_postcopy_recovery_common(&args
);
1344 #ifdef CONFIG_GNUTLS
1345 /* This contains preempt+recovery+tls test altogether */
1346 static void test_postcopy_preempt_all(void)
1348 MigrateCommon args
= {
1349 .postcopy_preempt
= true,
1350 .start_hook
= test_migrate_tls_psk_start_match
,
1351 .finish_hook
= test_migrate_tls_psk_finish
,
1354 test_postcopy_recovery_common(&args
);
1359 static void test_baddest(void)
1361 MigrateStart args
= {
1364 QTestState
*from
, *to
;
1366 if (test_migrate_start(&from
, &to
, "tcp:127.0.0.1:0", &args
)) {
1369 migrate_qmp(from
, "tcp:127.0.0.1:0", "{}");
1370 wait_for_migration_fail(from
, false);
1371 test_migrate_end(from
, to
, false);
1374 static void test_precopy_common(MigrateCommon
*args
)
1376 QTestState
*from
, *to
;
1377 void *data_hook
= NULL
;
1379 if (test_migrate_start(&from
, &to
, args
->listen_uri
, &args
->start
)) {
1383 migrate_ensure_non_converge(from
);
1385 if (args
->start_hook
) {
1386 data_hook
= args
->start_hook(from
, to
);
1389 /* Wait for the first serial output from the source */
1390 if (args
->result
== MIG_TEST_SUCCEED
) {
1391 wait_for_serial("src_serial");
1394 if (!args
->connect_uri
) {
1395 g_autofree
char *local_connect_uri
=
1396 migrate_get_socket_address(to
, "socket-address");
1397 migrate_qmp(from
, local_connect_uri
, "{}");
1399 migrate_qmp(from
, args
->connect_uri
, "{}");
1403 if (args
->result
!= MIG_TEST_SUCCEED
) {
1404 bool allow_active
= args
->result
== MIG_TEST_FAIL
;
1405 wait_for_migration_fail(from
, allow_active
);
1407 if (args
->result
== MIG_TEST_FAIL_DEST_QUIT_ERR
) {
1408 qtest_set_expected_status(to
, EXIT_FAILURE
);
1411 if (args
->iterations
) {
1412 while (args
->iterations
--) {
1413 wait_for_migration_pass(from
);
1416 wait_for_migration_pass(from
);
1419 migrate_ensure_converge(from
);
1421 /* We do this first, as it has a timeout to stop us
1422 * hanging forever if migration didn't converge */
1423 wait_for_migration_complete(from
);
1426 qtest_qmp_eventwait(from
, "STOP");
1429 qtest_qmp_eventwait(to
, "RESUME");
1431 wait_for_serial("dest_serial");
1434 if (args
->finish_hook
) {
1435 args
->finish_hook(from
, to
, data_hook
);
1438 test_migrate_end(from
, to
, args
->result
== MIG_TEST_SUCCEED
);
1441 static void test_precopy_unix_plain(void)
1443 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1444 MigrateCommon args
= {
1449 test_precopy_common(&args
);
1453 static void test_precopy_unix_dirty_ring(void)
1455 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1456 MigrateCommon args
= {
1458 .use_dirty_ring
= true,
1464 test_precopy_common(&args
);
1467 #ifdef CONFIG_GNUTLS
1468 static void test_precopy_unix_tls_psk(void)
1470 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1471 MigrateCommon args
= {
1474 .start_hook
= test_migrate_tls_psk_start_match
,
1475 .finish_hook
= test_migrate_tls_psk_finish
,
1478 test_precopy_common(&args
);
1482 static void test_precopy_unix_tls_x509_default_host(void)
1484 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1485 MigrateCommon args
= {
1487 .hide_stderr
= true,
1491 .start_hook
= test_migrate_tls_x509_start_default_host
,
1492 .finish_hook
= test_migrate_tls_x509_finish
,
1493 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1496 test_precopy_common(&args
);
1499 static void test_precopy_unix_tls_x509_override_host(void)
1501 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1502 MigrateCommon args
= {
1505 .start_hook
= test_migrate_tls_x509_start_override_host
,
1506 .finish_hook
= test_migrate_tls_x509_finish
,
1509 test_precopy_common(&args
);
1511 #endif /* CONFIG_TASN1 */
1512 #endif /* CONFIG_GNUTLS */
1515 /* Currently upset on aarch64 TCG */
1516 static void test_ignore_shared(void)
1518 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1519 QTestState
*from
, *to
;
1521 if (test_migrate_start(&from
, &to
, uri
, false, true, NULL
, NULL
)) {
1525 migrate_set_capability(from
, "x-ignore-shared", true);
1526 migrate_set_capability(to
, "x-ignore-shared", true);
1528 /* Wait for the first serial output from the source */
1529 wait_for_serial("src_serial");
1531 migrate_qmp(from
, uri
, "{}");
1533 wait_for_migration_pass(from
);
1536 qtest_qmp_eventwait(from
, "STOP");
1539 qtest_qmp_eventwait(to
, "RESUME");
1541 wait_for_serial("dest_serial");
1542 wait_for_migration_complete(from
);
1544 /* Check whether shared RAM has been really skipped */
1545 g_assert_cmpint(read_ram_property_int(from
, "transferred"), <, 1024 * 1024);
1547 test_migrate_end(from
, to
, true);
1552 test_migrate_xbzrle_start(QTestState
*from
,
1555 migrate_set_parameter_int(from
, "xbzrle-cache-size", 33554432);
1557 migrate_set_capability(from
, "xbzrle", true);
1558 migrate_set_capability(to
, "xbzrle", true);
1563 static void test_precopy_unix_xbzrle(void)
1565 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1566 MigrateCommon args
= {
1570 .start_hook
= test_migrate_xbzrle_start
,
1575 test_precopy_common(&args
);
1578 static void test_precopy_unix_compress(void)
1580 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1581 MigrateCommon args
= {
1584 .start_hook
= test_migrate_compress_start
,
1586 * Test that no invalid thread state is left over from
1587 * the previous iteration.
1592 test_precopy_common(&args
);
1595 static void test_precopy_unix_compress_nowait(void)
1597 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1598 MigrateCommon args
= {
1601 .start_hook
= test_migrate_compress_nowait_start
,
1603 * Test that no invalid thread state is left over from
1604 * the previous iteration.
1609 test_precopy_common(&args
);
1612 static void test_precopy_tcp_plain(void)
1614 MigrateCommon args
= {
1615 .listen_uri
= "tcp:127.0.0.1:0",
1618 test_precopy_common(&args
);
1621 #ifdef CONFIG_GNUTLS
1622 static void test_precopy_tcp_tls_psk_match(void)
1624 MigrateCommon args
= {
1625 .listen_uri
= "tcp:127.0.0.1:0",
1626 .start_hook
= test_migrate_tls_psk_start_match
,
1627 .finish_hook
= test_migrate_tls_psk_finish
,
1630 test_precopy_common(&args
);
1633 static void test_precopy_tcp_tls_psk_mismatch(void)
1635 MigrateCommon args
= {
1637 .hide_stderr
= true,
1639 .listen_uri
= "tcp:127.0.0.1:0",
1640 .start_hook
= test_migrate_tls_psk_start_mismatch
,
1641 .finish_hook
= test_migrate_tls_psk_finish
,
1642 .result
= MIG_TEST_FAIL
,
1645 test_precopy_common(&args
);
1649 static void test_precopy_tcp_tls_x509_default_host(void)
1651 MigrateCommon args
= {
1652 .listen_uri
= "tcp:127.0.0.1:0",
1653 .start_hook
= test_migrate_tls_x509_start_default_host
,
1654 .finish_hook
= test_migrate_tls_x509_finish
,
1657 test_precopy_common(&args
);
1660 static void test_precopy_tcp_tls_x509_override_host(void)
1662 MigrateCommon args
= {
1663 .listen_uri
= "tcp:127.0.0.1:0",
1664 .start_hook
= test_migrate_tls_x509_start_override_host
,
1665 .finish_hook
= test_migrate_tls_x509_finish
,
1668 test_precopy_common(&args
);
1671 static void test_precopy_tcp_tls_x509_mismatch_host(void)
1673 MigrateCommon args
= {
1675 .hide_stderr
= true,
1677 .listen_uri
= "tcp:127.0.0.1:0",
1678 .start_hook
= test_migrate_tls_x509_start_mismatch_host
,
1679 .finish_hook
= test_migrate_tls_x509_finish
,
1680 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1683 test_precopy_common(&args
);
1686 static void test_precopy_tcp_tls_x509_friendly_client(void)
1688 MigrateCommon args
= {
1689 .listen_uri
= "tcp:127.0.0.1:0",
1690 .start_hook
= test_migrate_tls_x509_start_friendly_client
,
1691 .finish_hook
= test_migrate_tls_x509_finish
,
1694 test_precopy_common(&args
);
1697 static void test_precopy_tcp_tls_x509_hostile_client(void)
1699 MigrateCommon args
= {
1701 .hide_stderr
= true,
1703 .listen_uri
= "tcp:127.0.0.1:0",
1704 .start_hook
= test_migrate_tls_x509_start_hostile_client
,
1705 .finish_hook
= test_migrate_tls_x509_finish
,
1706 .result
= MIG_TEST_FAIL
,
1709 test_precopy_common(&args
);
1712 static void test_precopy_tcp_tls_x509_allow_anon_client(void)
1714 MigrateCommon args
= {
1715 .listen_uri
= "tcp:127.0.0.1:0",
1716 .start_hook
= test_migrate_tls_x509_start_allow_anon_client
,
1717 .finish_hook
= test_migrate_tls_x509_finish
,
1720 test_precopy_common(&args
);
1723 static void test_precopy_tcp_tls_x509_reject_anon_client(void)
1725 MigrateCommon args
= {
1727 .hide_stderr
= true,
1729 .listen_uri
= "tcp:127.0.0.1:0",
1730 .start_hook
= test_migrate_tls_x509_start_reject_anon_client
,
1731 .finish_hook
= test_migrate_tls_x509_finish
,
1732 .result
= MIG_TEST_FAIL
,
1735 test_precopy_common(&args
);
1737 #endif /* CONFIG_TASN1 */
1738 #endif /* CONFIG_GNUTLS */
1741 static void *test_migrate_fd_start_hook(QTestState
*from
,
1747 /* Create two connected sockets for migration */
1748 ret
= qemu_socketpair(PF_LOCAL
, SOCK_STREAM
, 0, pair
);
1749 g_assert_cmpint(ret
, ==, 0);
1751 /* Send the 1st socket to the target */
1752 qtest_qmp_fds_assert_success(to
, &pair
[0], 1,
1753 "{ 'execute': 'getfd',"
1754 " 'arguments': { 'fdname': 'fd-mig' }}");
1757 /* Start incoming migration from the 1st socket */
1758 qtest_qmp_assert_success(to
, "{ 'execute': 'migrate-incoming',"
1759 " 'arguments': { 'uri': 'fd:fd-mig' }}");
1761 /* Send the 2nd socket to the target */
1762 qtest_qmp_fds_assert_success(from
, &pair
[1], 1,
1763 "{ 'execute': 'getfd',"
1764 " 'arguments': { 'fdname': 'fd-mig' }}");
1770 static void test_migrate_fd_finish_hook(QTestState
*from
,
1775 const char *error_desc
;
1777 /* Test closing fds */
1778 /* We assume, that QEMU removes named fd from its list,
1779 * so this should fail */
1780 rsp
= qtest_qmp(from
, "{ 'execute': 'closefd',"
1781 " 'arguments': { 'fdname': 'fd-mig' }}");
1782 g_assert_true(qdict_haskey(rsp
, "error"));
1783 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1784 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1787 rsp
= qtest_qmp(to
, "{ 'execute': 'closefd',"
1788 " 'arguments': { 'fdname': 'fd-mig' }}");
1789 g_assert_true(qdict_haskey(rsp
, "error"));
1790 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1791 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1795 static void test_migrate_fd_proto(void)
1797 MigrateCommon args
= {
1798 .listen_uri
= "defer",
1799 .connect_uri
= "fd:fd-mig",
1800 .start_hook
= test_migrate_fd_start_hook
,
1801 .finish_hook
= test_migrate_fd_finish_hook
1803 test_precopy_common(&args
);
1807 static void do_test_validate_uuid(MigrateStart
*args
, bool should_fail
)
1809 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1810 QTestState
*from
, *to
;
1812 if (test_migrate_start(&from
, &to
, uri
, args
)) {
1817 * UUID validation is at the begin of migration. So, the main process of
1818 * migration is not interesting for us here. Thus, set huge downtime for
1819 * very fast migration.
1821 migrate_set_parameter_int(from
, "downtime-limit", 1000000);
1822 migrate_set_capability(from
, "validate-uuid", true);
1824 /* Wait for the first serial output from the source */
1825 wait_for_serial("src_serial");
1827 migrate_qmp(from
, uri
, "{}");
1830 qtest_set_expected_status(to
, EXIT_FAILURE
);
1831 wait_for_migration_fail(from
, true);
1833 wait_for_migration_complete(from
);
1836 test_migrate_end(from
, to
, false);
1839 static void test_validate_uuid(void)
1841 MigrateStart args
= {
1842 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1843 .opts_target
= "-uuid 11111111-1111-1111-1111-111111111111",
1846 do_test_validate_uuid(&args
, false);
1849 static void test_validate_uuid_error(void)
1851 MigrateStart args
= {
1852 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1853 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1854 .hide_stderr
= true,
1857 do_test_validate_uuid(&args
, true);
1860 static void test_validate_uuid_src_not_set(void)
1862 MigrateStart args
= {
1863 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1864 .hide_stderr
= true,
1867 do_test_validate_uuid(&args
, false);
1870 static void test_validate_uuid_dst_not_set(void)
1872 MigrateStart args
= {
1873 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1874 .hide_stderr
= true,
1877 do_test_validate_uuid(&args
, false);
1881 * The way auto_converge works, we need to do too many passes to
1882 * run this test. Auto_converge logic is only run once every
1883 * three iterations, so:
1885 * - 3 iterations without auto_converge enabled
1886 * - 3 iterations with pct = 5
1887 * - 3 iterations with pct = 30
1888 * - 3 iterations with pct = 55
1889 * - 3 iterations with pct = 80
1890 * - 3 iterations with pct = 95 (max(95, 80 + 25))
1892 * To make things even worse, we need to run the initial stage at
1893 * 3MB/s so we enter autoconverge even when host is (over)loaded.
1895 static void test_migrate_auto_converge(void)
1897 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1898 MigrateStart args
= {};
1899 QTestState
*from
, *to
;
1903 * We want the test to be stable and as fast as possible.
1904 * E.g., with 1Gb/s bandwith migration may pass without throttling,
1905 * so we need to decrease a bandwidth.
1907 const int64_t init_pct
= 5, inc_pct
= 25, max_pct
= 95;
1909 if (test_migrate_start(&from
, &to
, uri
, &args
)) {
1913 migrate_set_capability(from
, "auto-converge", true);
1914 migrate_set_parameter_int(from
, "cpu-throttle-initial", init_pct
);
1915 migrate_set_parameter_int(from
, "cpu-throttle-increment", inc_pct
);
1916 migrate_set_parameter_int(from
, "max-cpu-throttle", max_pct
);
1919 * Set the initial parameters so that the migration could not converge
1920 * without throttling.
1922 migrate_ensure_non_converge(from
);
1924 /* To check remaining size after precopy */
1925 migrate_set_capability(from
, "pause-before-switchover", true);
1927 /* Wait for the first serial output from the source */
1928 wait_for_serial("src_serial");
1930 migrate_qmp(from
, uri
, "{}");
1932 /* Wait for throttling begins */
1935 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1936 if (percentage
!= 0) {
1940 g_assert_false(got_stop
);
1942 /* The first percentage of throttling should be at least init_pct */
1943 g_assert_cmpint(percentage
, >=, init_pct
);
1944 /* Now, when we tested that throttling works, let it converge */
1945 migrate_ensure_converge(from
);
1948 * Wait for pre-switchover status to check last throttle percentage
1949 * and remaining. These values will be zeroed later
1951 wait_for_migration_status(from
, "pre-switchover", NULL
);
1953 /* The final percentage of throttling shouldn't be greater than max_pct */
1954 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1955 g_assert_cmpint(percentage
, <=, max_pct
);
1956 migrate_continue(from
, "pre-switchover");
1958 qtest_qmp_eventwait(to
, "RESUME");
1960 wait_for_serial("dest_serial");
1961 wait_for_migration_complete(from
);
1963 test_migrate_end(from
, to
, true);
1967 test_migrate_precopy_tcp_multifd_start_common(QTestState
*from
,
1971 migrate_set_parameter_int(from
, "multifd-channels", 16);
1972 migrate_set_parameter_int(to
, "multifd-channels", 16);
1974 migrate_set_parameter_str(from
, "multifd-compression", method
);
1975 migrate_set_parameter_str(to
, "multifd-compression", method
);
1977 migrate_set_capability(from
, "multifd", true);
1978 migrate_set_capability(to
, "multifd", true);
1980 /* Start incoming migration from the 1st socket */
1981 qtest_qmp_assert_success(to
, "{ 'execute': 'migrate-incoming',"
1982 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
1988 test_migrate_precopy_tcp_multifd_start(QTestState
*from
,
1991 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
1995 test_migrate_precopy_tcp_multifd_zlib_start(QTestState
*from
,
1998 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zlib");
2003 test_migrate_precopy_tcp_multifd_zstd_start(QTestState
*from
,
2006 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zstd");
2008 #endif /* CONFIG_ZSTD */
2010 static void test_multifd_tcp_none(void)
2012 MigrateCommon args
= {
2013 .listen_uri
= "defer",
2014 .start_hook
= test_migrate_precopy_tcp_multifd_start
,
2016 test_precopy_common(&args
);
2019 static void test_multifd_tcp_zlib(void)
2021 MigrateCommon args
= {
2022 .listen_uri
= "defer",
2023 .start_hook
= test_migrate_precopy_tcp_multifd_zlib_start
,
2025 test_precopy_common(&args
);
2029 static void test_multifd_tcp_zstd(void)
2031 MigrateCommon args
= {
2032 .listen_uri
= "defer",
2033 .start_hook
= test_migrate_precopy_tcp_multifd_zstd_start
,
2035 test_precopy_common(&args
);
2039 #ifdef CONFIG_GNUTLS
2041 test_migrate_multifd_tcp_tls_psk_start_match(QTestState
*from
,
2044 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2045 return test_migrate_tls_psk_start_match(from
, to
);
2049 test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState
*from
,
2052 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2053 return test_migrate_tls_psk_start_mismatch(from
, to
);
2058 test_migrate_multifd_tls_x509_start_default_host(QTestState
*from
,
2061 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2062 return test_migrate_tls_x509_start_default_host(from
, to
);
2066 test_migrate_multifd_tls_x509_start_override_host(QTestState
*from
,
2069 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2070 return test_migrate_tls_x509_start_override_host(from
, to
);
2074 test_migrate_multifd_tls_x509_start_mismatch_host(QTestState
*from
,
2077 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2078 return test_migrate_tls_x509_start_mismatch_host(from
, to
);
2082 test_migrate_multifd_tls_x509_start_allow_anon_client(QTestState
*from
,
2085 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2086 return test_migrate_tls_x509_start_allow_anon_client(from
, to
);
2090 test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState
*from
,
2093 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2094 return test_migrate_tls_x509_start_reject_anon_client(from
, to
);
2096 #endif /* CONFIG_TASN1 */
2098 static void test_multifd_tcp_tls_psk_match(void)
2100 MigrateCommon args
= {
2101 .listen_uri
= "defer",
2102 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_match
,
2103 .finish_hook
= test_migrate_tls_psk_finish
,
2105 test_precopy_common(&args
);
2108 static void test_multifd_tcp_tls_psk_mismatch(void)
2110 MigrateCommon args
= {
2112 .hide_stderr
= true,
2114 .listen_uri
= "defer",
2115 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_mismatch
,
2116 .finish_hook
= test_migrate_tls_psk_finish
,
2117 .result
= MIG_TEST_FAIL
,
2119 test_precopy_common(&args
);
2123 static void test_multifd_tcp_tls_x509_default_host(void)
2125 MigrateCommon args
= {
2126 .listen_uri
= "defer",
2127 .start_hook
= test_migrate_multifd_tls_x509_start_default_host
,
2128 .finish_hook
= test_migrate_tls_x509_finish
,
2130 test_precopy_common(&args
);
2133 static void test_multifd_tcp_tls_x509_override_host(void)
2135 MigrateCommon args
= {
2136 .listen_uri
= "defer",
2137 .start_hook
= test_migrate_multifd_tls_x509_start_override_host
,
2138 .finish_hook
= test_migrate_tls_x509_finish
,
2140 test_precopy_common(&args
);
2143 static void test_multifd_tcp_tls_x509_mismatch_host(void)
2146 * This has different behaviour to the non-multifd case.
2148 * In non-multifd case when client aborts due to mismatched
2149 * cert host, the server has already started trying to load
2150 * migration state, and so it exits with I/O failure.
2152 * In multifd case when client aborts due to mismatched
2153 * cert host, the server is still waiting for the other
2154 * multifd connections to arrive so hasn't started trying
2155 * to load migration state, and thus just aborts the migration
2158 MigrateCommon args
= {
2160 .hide_stderr
= true,
2162 .listen_uri
= "defer",
2163 .start_hook
= test_migrate_multifd_tls_x509_start_mismatch_host
,
2164 .finish_hook
= test_migrate_tls_x509_finish
,
2165 .result
= MIG_TEST_FAIL
,
2167 test_precopy_common(&args
);
2170 static void test_multifd_tcp_tls_x509_allow_anon_client(void)
2172 MigrateCommon args
= {
2173 .listen_uri
= "defer",
2174 .start_hook
= test_migrate_multifd_tls_x509_start_allow_anon_client
,
2175 .finish_hook
= test_migrate_tls_x509_finish
,
2177 test_precopy_common(&args
);
2180 static void test_multifd_tcp_tls_x509_reject_anon_client(void)
2182 MigrateCommon args
= {
2184 .hide_stderr
= true,
2186 .listen_uri
= "defer",
2187 .start_hook
= test_migrate_multifd_tls_x509_start_reject_anon_client
,
2188 .finish_hook
= test_migrate_tls_x509_finish
,
2189 .result
= MIG_TEST_FAIL
,
2191 test_precopy_common(&args
);
2193 #endif /* CONFIG_TASN1 */
2194 #endif /* CONFIG_GNUTLS */
2202 * launch another target
2205 * And see that it works
2207 static void test_multifd_tcp_cancel(void)
2209 MigrateStart args
= {
2210 .hide_stderr
= true,
2212 QTestState
*from
, *to
, *to2
;
2213 g_autofree
char *uri
= NULL
;
2215 if (test_migrate_start(&from
, &to
, "defer", &args
)) {
2219 migrate_ensure_non_converge(from
);
2221 migrate_set_parameter_int(from
, "multifd-channels", 16);
2222 migrate_set_parameter_int(to
, "multifd-channels", 16);
2224 migrate_set_capability(from
, "multifd", true);
2225 migrate_set_capability(to
, "multifd", true);
2227 /* Start incoming migration from the 1st socket */
2228 qtest_qmp_assert_success(to
, "{ 'execute': 'migrate-incoming',"
2229 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2231 /* Wait for the first serial output from the source */
2232 wait_for_serial("src_serial");
2234 uri
= migrate_get_socket_address(to
, "socket-address");
2236 migrate_qmp(from
, uri
, "{}");
2238 wait_for_migration_pass(from
);
2240 migrate_cancel(from
);
2242 /* Make sure QEMU process "to" exited */
2243 qtest_set_expected_status(to
, EXIT_FAILURE
);
2244 qtest_wait_qemu(to
);
2246 args
= (MigrateStart
){
2247 .only_target
= true,
2250 if (test_migrate_start(&from
, &to2
, "defer", &args
)) {
2254 migrate_set_parameter_int(to2
, "multifd-channels", 16);
2256 migrate_set_capability(to2
, "multifd", true);
2258 /* Start incoming migration from the 1st socket */
2259 qtest_qmp_assert_success(to2
, "{ 'execute': 'migrate-incoming',"
2260 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2263 uri
= migrate_get_socket_address(to2
, "socket-address");
2265 wait_for_migration_status(from
, "cancelled", NULL
);
2267 migrate_ensure_converge(from
);
2269 migrate_qmp(from
, uri
, "{}");
2271 wait_for_migration_pass(from
);
2274 qtest_qmp_eventwait(from
, "STOP");
2276 qtest_qmp_eventwait(to2
, "RESUME");
2278 wait_for_serial("dest_serial");
2279 wait_for_migration_complete(from
);
2280 test_migrate_end(from
, to2
, true);
2283 static void calc_dirty_rate(QTestState
*who
, uint64_t calc_time
)
2285 qtest_qmp_assert_success(who
,
2286 "{ 'execute': 'calc-dirty-rate',"
2288 "'calc-time': %" PRIu64
","
2289 "'mode': 'dirty-ring' }}",
2293 static QDict
*query_dirty_rate(QTestState
*who
)
2295 return qtest_qmp_assert_success_ref(who
,
2296 "{ 'execute': 'query-dirty-rate' }");
2299 static void dirtylimit_set_all(QTestState
*who
, uint64_t dirtyrate
)
2301 qtest_qmp_assert_success(who
,
2302 "{ 'execute': 'set-vcpu-dirty-limit',"
2304 "'dirty-rate': %" PRIu64
" } }",
2308 static void cancel_vcpu_dirty_limit(QTestState
*who
)
2310 qtest_qmp_assert_success(who
,
2311 "{ 'execute': 'cancel-vcpu-dirty-limit' }");
2314 static QDict
*query_vcpu_dirty_limit(QTestState
*who
)
2318 rsp
= qtest_qmp(who
, "{ 'execute': 'query-vcpu-dirty-limit' }");
2319 g_assert(!qdict_haskey(rsp
, "error"));
2320 g_assert(qdict_haskey(rsp
, "return"));
2325 static bool calc_dirtyrate_ready(QTestState
*who
)
2330 rsp_return
= query_dirty_rate(who
);
2331 g_assert(rsp_return
);
2333 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2336 return g_strcmp0(status
, "measuring");
2339 static void wait_for_calc_dirtyrate_complete(QTestState
*who
,
2342 int max_try_count
= 10000;
2343 usleep(time_s
* 1000000);
2345 while (!calc_dirtyrate_ready(who
) && max_try_count
--) {
2350 * Set the timeout with 10 s(max_try_count * 1000us),
2351 * if dirtyrate measurement not complete, fail test.
2353 g_assert_cmpint(max_try_count
, !=, 0);
2356 static int64_t get_dirty_rate(QTestState
*who
)
2361 const QListEntry
*entry
;
2365 rsp_return
= query_dirty_rate(who
);
2366 g_assert(rsp_return
);
2368 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2370 g_assert_cmpstr(status
, ==, "measured");
2372 rates
= qdict_get_qlist(rsp_return
, "vcpu-dirty-rate");
2373 g_assert(rates
&& !qlist_empty(rates
));
2375 entry
= qlist_first(rates
);
2378 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2381 dirtyrate
= qdict_get_try_int(rate
, "dirty-rate", -1);
2383 qobject_unref(rsp_return
);
2387 static int64_t get_limit_rate(QTestState
*who
)
2391 const QListEntry
*entry
;
2395 rsp_return
= query_vcpu_dirty_limit(who
);
2396 g_assert(rsp_return
);
2398 rates
= qdict_get_qlist(rsp_return
, "return");
2399 g_assert(rates
&& !qlist_empty(rates
));
2401 entry
= qlist_first(rates
);
2404 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2407 dirtyrate
= qdict_get_try_int(rate
, "limit-rate", -1);
2409 qobject_unref(rsp_return
);
2413 static QTestState
*dirtylimit_start_vm(void)
2415 QTestState
*vm
= NULL
;
2416 g_autofree gchar
*cmd
= NULL
;
2417 const char *arch
= qtest_get_arch();
2418 g_autofree
char *bootpath
= NULL
;
2420 assert((strcmp(arch
, "x86_64") == 0));
2421 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
2422 assert(sizeof(x86_bootsect
) == 512);
2423 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
2425 cmd
= g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
2426 "-name dirtylimit-test,debug-threads=on "
2428 "-serial file:%s/vm_serial "
2429 "-drive file=%s,format=raw ",
2432 vm
= qtest_init(cmd
);
2436 static void dirtylimit_stop_vm(QTestState
*vm
)
2439 cleanup("bootsect");
2440 cleanup("vm_serial");
2443 static void test_vcpu_dirty_limit(void)
2446 int64_t origin_rate
;
2449 int max_try_count
= 20;
2452 /* Start vm for vcpu dirtylimit test */
2453 vm
= dirtylimit_start_vm();
2455 /* Wait for the first serial output from the vm*/
2456 wait_for_serial("vm_serial");
2458 /* Do dirtyrate measurement with calc time equals 1s */
2459 calc_dirty_rate(vm
, 1);
2461 /* Sleep calc time and wait for calc dirtyrate complete */
2462 wait_for_calc_dirtyrate_complete(vm
, 1);
2464 /* Query original dirty page rate */
2465 origin_rate
= get_dirty_rate(vm
);
2467 /* VM booted from bootsect should dirty memory steadily */
2468 assert(origin_rate
!= 0);
2470 /* Setup quota dirty page rate at half of origin */
2471 quota_rate
= origin_rate
/ 2;
2473 /* Set dirtylimit */
2474 dirtylimit_set_all(vm
, quota_rate
);
2477 * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
2480 g_assert_cmpint(quota_rate
, ==, get_limit_rate(vm
));
2482 /* Sleep a bit to check if it take effect */
2486 * Check if dirtylimit take effect realistically, set the
2487 * timeout with 20 s(max_try_count * 1s), if dirtylimit
2488 * doesn't take effect, fail test.
2490 while (--max_try_count
) {
2491 calc_dirty_rate(vm
, 1);
2492 wait_for_calc_dirtyrate_complete(vm
, 1);
2493 rate
= get_dirty_rate(vm
);
2496 * Assume hitting if current rate is less
2497 * than quota rate (within accepting error)
2499 if (rate
< (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2505 g_assert_cmpint(hit
, ==, 1);
2510 /* Check if dirtylimit cancellation take effect */
2511 cancel_vcpu_dirty_limit(vm
);
2512 while (--max_try_count
) {
2513 calc_dirty_rate(vm
, 1);
2514 wait_for_calc_dirtyrate_complete(vm
, 1);
2515 rate
= get_dirty_rate(vm
);
2518 * Assume dirtylimit be canceled if current rate is
2519 * greater than quota rate (within accepting error)
2521 if (rate
> (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2527 g_assert_cmpint(hit
, ==, 1);
2528 dirtylimit_stop_vm(vm
);
2531 static bool kvm_dirty_ring_supported(void)
2533 #if defined(__linux__) && defined(HOST_X86_64)
2534 int ret
, kvm_fd
= open("/dev/kvm", O_RDONLY
);
2540 ret
= ioctl(kvm_fd
, KVM_CHECK_EXTENSION
, KVM_CAP_DIRTY_LOG_RING
);
2543 /* We test with 4096 slots */
2554 int main(int argc
, char **argv
)
2556 bool has_kvm
, has_tcg
;
2559 g_autoptr(GError
) err
= NULL
;
2562 g_test_init(&argc
, &argv
, NULL
);
2564 has_kvm
= qtest_has_accel("kvm");
2565 has_tcg
= qtest_has_accel("tcg");
2567 if (!has_tcg
&& !has_kvm
) {
2568 g_test_skip("No KVM or TCG accelerator available");
2572 has_uffd
= ufd_version_check();
2573 arch
= qtest_get_arch();
2576 * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
2577 * is touchy due to race conditions on dirty bits (especially on PPC for
2580 if (g_str_equal(arch
, "ppc64") &&
2581 (!has_kvm
|| access("/sys/module/kvm_hv", F_OK
))) {
2582 g_test_message("Skipping test: kvm_hv not available");
2583 return g_test_run();
2587 * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
2588 * there until the problems are resolved
2590 if (g_str_equal(arch
, "s390x") && !has_kvm
) {
2591 g_test_message("Skipping test: s390x host with KVM is required");
2592 return g_test_run();
2595 tmpfs
= g_dir_make_tmp("migration-test-XXXXXX", &err
);
2597 g_test_message("Can't create temporary directory in %s: %s",
2598 g_get_tmp_dir(), err
->message
);
2602 module_call_init(MODULE_INIT_QOM
);
2605 qtest_add_func("/migration/postcopy/plain", test_postcopy
);
2606 qtest_add_func("/migration/postcopy/recovery/plain",
2607 test_postcopy_recovery
);
2608 qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_preempt
);
2609 qtest_add_func("/migration/postcopy/preempt/recovery/plain",
2610 test_postcopy_preempt_recovery
);
2611 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2612 qtest_add_func("/migration/postcopy/compress/plain",
2613 test_postcopy_compress
);
2614 qtest_add_func("/migration/postcopy/recovery/compress/plain",
2615 test_postcopy_recovery_compress
);
2619 qtest_add_func("/migration/bad_dest", test_baddest
);
2620 qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain
);
2621 qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle
);
2623 * Compression fails from time to time.
2624 * Put test here but don't enable it until everything is fixed.
2626 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2627 qtest_add_func("/migration/precopy/unix/compress/wait",
2628 test_precopy_unix_compress
);
2629 qtest_add_func("/migration/precopy/unix/compress/nowait",
2630 test_precopy_unix_compress_nowait
);
2632 #ifdef CONFIG_GNUTLS
2633 qtest_add_func("/migration/precopy/unix/tls/psk",
2634 test_precopy_unix_tls_psk
);
2638 * NOTE: psk test is enough for postcopy, as other types of TLS
2639 * channels are tested under precopy. Here what we want to test is the
2640 * general postcopy path that has TLS channel enabled.
2642 qtest_add_func("/migration/postcopy/tls/psk", test_postcopy_tls_psk
);
2643 qtest_add_func("/migration/postcopy/recovery/tls/psk",
2644 test_postcopy_recovery_tls_psk
);
2645 qtest_add_func("/migration/postcopy/preempt/tls/psk",
2646 test_postcopy_preempt_tls_psk
);
2647 qtest_add_func("/migration/postcopy/preempt/recovery/tls/psk",
2648 test_postcopy_preempt_all
);
2651 qtest_add_func("/migration/precopy/unix/tls/x509/default-host",
2652 test_precopy_unix_tls_x509_default_host
);
2653 qtest_add_func("/migration/precopy/unix/tls/x509/override-host",
2654 test_precopy_unix_tls_x509_override_host
);
2655 #endif /* CONFIG_TASN1 */
2656 #endif /* CONFIG_GNUTLS */
2658 qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain
);
2659 #ifdef CONFIG_GNUTLS
2660 qtest_add_func("/migration/precopy/tcp/tls/psk/match",
2661 test_precopy_tcp_tls_psk_match
);
2662 qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch",
2663 test_precopy_tcp_tls_psk_mismatch
);
2665 qtest_add_func("/migration/precopy/tcp/tls/x509/default-host",
2666 test_precopy_tcp_tls_x509_default_host
);
2667 qtest_add_func("/migration/precopy/tcp/tls/x509/override-host",
2668 test_precopy_tcp_tls_x509_override_host
);
2669 qtest_add_func("/migration/precopy/tcp/tls/x509/mismatch-host",
2670 test_precopy_tcp_tls_x509_mismatch_host
);
2671 qtest_add_func("/migration/precopy/tcp/tls/x509/friendly-client",
2672 test_precopy_tcp_tls_x509_friendly_client
);
2673 qtest_add_func("/migration/precopy/tcp/tls/x509/hostile-client",
2674 test_precopy_tcp_tls_x509_hostile_client
);
2675 qtest_add_func("/migration/precopy/tcp/tls/x509/allow-anon-client",
2676 test_precopy_tcp_tls_x509_allow_anon_client
);
2677 qtest_add_func("/migration/precopy/tcp/tls/x509/reject-anon-client",
2678 test_precopy_tcp_tls_x509_reject_anon_client
);
2679 #endif /* CONFIG_TASN1 */
2680 #endif /* CONFIG_GNUTLS */
2682 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
2684 qtest_add_func("/migration/fd_proto", test_migrate_fd_proto
);
2686 qtest_add_func("/migration/validate_uuid", test_validate_uuid
);
2687 qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error
);
2688 qtest_add_func("/migration/validate_uuid_src_not_set",
2689 test_validate_uuid_src_not_set
);
2690 qtest_add_func("/migration/validate_uuid_dst_not_set",
2691 test_validate_uuid_dst_not_set
);
2693 * See explanation why this test is slow on function definition
2695 if (g_test_slow()) {
2696 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge
);
2698 qtest_add_func("/migration/multifd/tcp/plain/none",
2699 test_multifd_tcp_none
);
2701 * This test is flaky and sometimes fails in CI and otherwise:
2702 * don't run unless user opts in via environment variable.
2704 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2705 qtest_add_func("/migration/multifd/tcp/plain/cancel",
2706 test_multifd_tcp_cancel
);
2708 qtest_add_func("/migration/multifd/tcp/plain/zlib",
2709 test_multifd_tcp_zlib
);
2711 qtest_add_func("/migration/multifd/tcp/plain/zstd",
2712 test_multifd_tcp_zstd
);
2714 #ifdef CONFIG_GNUTLS
2715 qtest_add_func("/migration/multifd/tcp/tls/psk/match",
2716 test_multifd_tcp_tls_psk_match
);
2717 qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
2718 test_multifd_tcp_tls_psk_mismatch
);
2720 qtest_add_func("/migration/multifd/tcp/tls/x509/default-host",
2721 test_multifd_tcp_tls_x509_default_host
);
2722 qtest_add_func("/migration/multifd/tcp/tls/x509/override-host",
2723 test_multifd_tcp_tls_x509_override_host
);
2724 qtest_add_func("/migration/multifd/tcp/tls/x509/mismatch-host",
2725 test_multifd_tcp_tls_x509_mismatch_host
);
2726 qtest_add_func("/migration/multifd/tcp/tls/x509/allow-anon-client",
2727 test_multifd_tcp_tls_x509_allow_anon_client
);
2728 qtest_add_func("/migration/multifd/tcp/tls/x509/reject-anon-client",
2729 test_multifd_tcp_tls_x509_reject_anon_client
);
2730 #endif /* CONFIG_TASN1 */
2731 #endif /* CONFIG_GNUTLS */
2733 if (g_str_equal(arch
, "x86_64") && has_kvm
&& kvm_dirty_ring_supported()) {
2734 qtest_add_func("/migration/dirty_ring",
2735 test_precopy_unix_dirty_ring
);
2736 qtest_add_func("/migration/vcpu_dirty_limit",
2737 test_vcpu_dirty_limit
);
2742 g_assert_cmpint(ret
, ==, 0);
2746 g_test_message("unable to rmdir: path (%s): %s",
2747 tmpfs
, strerror(errno
));