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 /* TODO actually test the results and get rid of this */
44 #define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
46 unsigned start_address
;
48 static bool uffd_feature_thread_id
;
51 * Dirtylimit stop working if dirty page rate error
52 * value less than DIRTYLIMIT_TOLERANCE_RANGE
54 #define DIRTYLIMIT_TOLERANCE_RANGE 25 /* MB/s */
56 #if defined(__linux__)
57 #include <sys/syscall.h>
61 #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
62 #include <sys/eventfd.h>
63 #include <sys/ioctl.h>
64 #include "qemu/userfaultfd.h"
66 static bool ufd_version_check(void)
68 struct uffdio_api api_struct
;
71 int ufd
= uffd_open(O_CLOEXEC
);
74 g_test_message("Skipping test: userfaultfd not available");
78 api_struct
.api
= UFFD_API
;
79 api_struct
.features
= 0;
80 if (ioctl(ufd
, UFFDIO_API
, &api_struct
)) {
81 g_test_message("Skipping test: UFFDIO_API failed");
84 uffd_feature_thread_id
= api_struct
.features
& UFFD_FEATURE_THREAD_ID
;
86 ioctl_mask
= (__u64
)1 << _UFFDIO_REGISTER
|
87 (__u64
)1 << _UFFDIO_UNREGISTER
;
88 if ((api_struct
.ioctls
& ioctl_mask
) != ioctl_mask
) {
89 g_test_message("Skipping test: Missing userfault feature");
97 static bool ufd_version_check(void)
99 g_test_message("Skipping test: Userfault not available (builtdtime)");
107 /* The boot file modifies memory area in [start_address, end_address)
108 * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
110 #include "tests/migration/i386/a-b-bootblock.h"
111 #include "tests/migration/aarch64/a-b-kernel.h"
112 #include "tests/migration/s390x/a-b-bios.h"
114 static void init_bootfile(const char *bootpath
, void *content
, size_t len
)
116 FILE *bootfile
= fopen(bootpath
, "wb");
118 g_assert_cmpint(fwrite(content
, len
, 1, bootfile
), ==, 1);
123 * Wait for some output in the serial output file,
124 * we get an 'A' followed by an endless string of 'B's
125 * but on the destination we won't have the A.
127 static void wait_for_serial(const char *side
)
129 g_autofree
char *serialpath
= g_strdup_printf("%s/%s", tmpfs
, side
);
130 FILE *serialfile
= fopen(serialpath
, "r");
131 const char *arch
= qtest_get_arch();
132 int started
= (strcmp(side
, "src_serial") == 0 &&
133 strcmp(arch
, "ppc64") == 0) ? 0 : 1;
136 int readvalue
= fgetc(serialfile
);
139 /* SLOF prints its banner before starting test,
140 * to ignore it, mark the start of the test with '_',
141 * ignore all characters until this marker
148 fseek(serialfile
, 0, SEEK_SET
);
165 started
= (strcmp(side
, "src_serial") == 0 &&
166 strcmp(arch
, "ppc64") == 0) ? 0 : 1;
167 fseek(serialfile
, 0, SEEK_SET
);
172 fprintf(stderr
, "Unexpected %d on %s serial\n", readvalue
, side
);
173 g_assert_not_reached();
179 * It's tricky to use qemu's migration event capability with qtest,
180 * events suddenly appearing confuse the qmp()/hmp() responses.
183 static int64_t read_ram_property_int(QTestState
*who
, const char *property
)
185 QDict
*rsp_return
, *rsp_ram
;
188 rsp_return
= migrate_query_not_failed(who
);
189 if (!qdict_haskey(rsp_return
, "ram")) {
193 rsp_ram
= qdict_get_qdict(rsp_return
, "ram");
194 result
= qdict_get_try_int(rsp_ram
, property
, 0);
196 qobject_unref(rsp_return
);
200 static int64_t read_migrate_property_int(QTestState
*who
, const char *property
)
205 rsp_return
= migrate_query_not_failed(who
);
206 result
= qdict_get_try_int(rsp_return
, property
, 0);
207 qobject_unref(rsp_return
);
211 static uint64_t get_migration_pass(QTestState
*who
)
213 return read_ram_property_int(who
, "dirty-sync-count");
216 static void read_blocktime(QTestState
*who
)
220 rsp_return
= migrate_query_not_failed(who
);
221 g_assert(qdict_haskey(rsp_return
, "postcopy-blocktime"));
222 qobject_unref(rsp_return
);
225 static void wait_for_migration_pass(QTestState
*who
)
227 uint64_t initial_pass
= get_migration_pass(who
);
230 /* Wait for the 1st sync */
231 while (!got_stop
&& !initial_pass
) {
233 initial_pass
= get_migration_pass(who
);
238 pass
= get_migration_pass(who
);
239 } while (pass
== initial_pass
&& !got_stop
);
242 static void check_guests_ram(QTestState
*who
)
244 /* Our ASM test will have been incrementing one byte from each page from
245 * start_address to < end_address in order. This gives us a constraint
246 * that any page's byte should be equal or less than the previous pages
247 * byte (mod 256); and they should all be equal except for one transition
248 * at the point where we meet the incrementer. (We're running this with
249 * the guest stopped).
254 bool hit_edge
= false;
257 qtest_memread(who
, start_address
, &first_byte
, 1);
258 last_byte
= first_byte
;
260 for (address
= start_address
+ TEST_MEM_PAGE_SIZE
; address
< end_address
;
261 address
+= TEST_MEM_PAGE_SIZE
)
264 qtest_memread(who
, address
, &b
, 1);
265 if (b
!= last_byte
) {
266 if (((b
+ 1) % 256) == last_byte
&& !hit_edge
) {
267 /* This is OK, the guest stopped at the point of
268 * incrementing the previous page but didn't get
276 fprintf(stderr
, "Memory content inconsistency at %x"
277 " first_byte = %x last_byte = %x current = %x"
279 address
, first_byte
, last_byte
, b
, hit_edge
);
285 fprintf(stderr
, "and in another %d pages", bad
- 10);
290 static void cleanup(const char *filename
)
292 g_autofree
char *path
= g_strdup_printf("%s/%s", tmpfs
, filename
);
297 static char *SocketAddress_to_str(SocketAddress
*addr
)
299 switch (addr
->type
) {
300 case SOCKET_ADDRESS_TYPE_INET
:
301 return g_strdup_printf("tcp:%s:%s",
304 case SOCKET_ADDRESS_TYPE_UNIX
:
305 return g_strdup_printf("unix:%s",
306 addr
->u
.q_unix
.path
);
307 case SOCKET_ADDRESS_TYPE_FD
:
308 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
309 case SOCKET_ADDRESS_TYPE_VSOCK
:
310 return g_strdup_printf("tcp:%s:%s",
314 return g_strdup("unknown address type");
318 static char *migrate_get_socket_address(QTestState
*who
, const char *parameter
)
322 SocketAddressList
*addrs
;
326 rsp
= migrate_query(who
);
327 object
= qdict_get(rsp
, parameter
);
329 iv
= qobject_input_visitor_new(object
);
330 visit_type_SocketAddressList(iv
, NULL
, &addrs
, &error_abort
);
333 /* we are only using a single address */
334 result
= SocketAddress_to_str(addrs
->value
);
336 qapi_free_SocketAddressList(addrs
);
341 static long long migrate_get_parameter_int(QTestState
*who
,
342 const char *parameter
)
347 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
348 result
= qdict_get_int(rsp
, parameter
);
353 static void migrate_check_parameter_int(QTestState
*who
, const char *parameter
,
358 result
= migrate_get_parameter_int(who
, parameter
);
359 g_assert_cmpint(result
, ==, value
);
362 static void migrate_set_parameter_int(QTestState
*who
, const char *parameter
,
368 "{ 'execute': 'migrate-set-parameters',"
369 "'arguments': { %s: %lld } }",
371 g_assert(qdict_haskey(rsp
, "return"));
373 migrate_check_parameter_int(who
, parameter
, value
);
376 static char *migrate_get_parameter_str(QTestState
*who
,
377 const char *parameter
)
382 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
383 result
= g_strdup(qdict_get_str(rsp
, parameter
));
388 static void migrate_check_parameter_str(QTestState
*who
, const char *parameter
,
391 g_autofree
char *result
= migrate_get_parameter_str(who
, parameter
);
392 g_assert_cmpstr(result
, ==, value
);
395 static void migrate_set_parameter_str(QTestState
*who
, const char *parameter
,
401 "{ 'execute': 'migrate-set-parameters',"
402 "'arguments': { %s: %s } }",
404 g_assert(qdict_haskey(rsp
, "return"));
406 migrate_check_parameter_str(who
, parameter
, value
);
409 static void migrate_ensure_non_converge(QTestState
*who
)
411 /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
412 migrate_set_parameter_int(who
, "max-bandwidth", 3 * 1000 * 1000);
413 migrate_set_parameter_int(who
, "downtime-limit", 1);
416 static void migrate_ensure_converge(QTestState
*who
)
418 /* Should converge with 30s downtime + 1 gbs bandwidth limit */
419 migrate_set_parameter_int(who
, "max-bandwidth", 1 * 1000 * 1000 * 1000);
420 migrate_set_parameter_int(who
, "downtime-limit", 30 * 1000);
423 static void migrate_pause(QTestState
*who
)
427 rsp
= wait_command(who
, "{ 'execute': 'migrate-pause' }");
431 static void migrate_continue(QTestState
*who
, const char *state
)
435 rsp
= wait_command(who
,
436 "{ 'execute': 'migrate-continue',"
437 " 'arguments': { 'state': %s } }",
442 static void migrate_recover(QTestState
*who
, const char *uri
)
446 rsp
= wait_command(who
,
447 "{ 'execute': 'migrate-recover', "
448 " 'id': 'recover-cmd', "
449 " 'arguments': { 'uri': %s } }",
454 static void migrate_cancel(QTestState
*who
)
458 rsp
= wait_command(who
, "{ 'execute': 'migrate_cancel' }");
462 static void migrate_set_capability(QTestState
*who
, const char *capability
,
468 "{ 'execute': 'migrate-set-capabilities',"
470 "'capabilities': [ { "
471 "'capability': %s, 'state': %i } ] } }",
473 g_assert(qdict_haskey(rsp
, "return"));
477 static void migrate_postcopy_start(QTestState
*from
, QTestState
*to
)
481 rsp
= wait_command(from
, "{ 'execute': 'migrate-start-postcopy' }");
485 qtest_qmp_eventwait(from
, "STOP");
488 qtest_qmp_eventwait(to
, "RESUME");
493 * QTEST_LOG=1 may override this. When QTEST_LOG=1, we always dump errors
494 * unconditionally, because it means the user would like to be verbose.
498 /* only launch the target process */
500 /* Use dirty ring if true; dirty logging otherwise */
502 const char *opts_source
;
503 const char *opts_target
;
507 * A hook that runs after the src and dst QEMUs have been
508 * created, but before the migration is started. This can
509 * be used to set migration parameters and capabilities.
511 * Returns: NULL, or a pointer to opaque state to be
512 * later passed to the TestMigrateFinishHook
514 typedef void * (*TestMigrateStartHook
)(QTestState
*from
,
518 * A hook that runs after the migration has finished,
519 * regardless of whether it succeeded or failed, but
520 * before QEMU has terminated (unless it self-terminated
521 * due to migration error)
523 * @opaque is a pointer to state previously returned
524 * by the TestMigrateStartHook if any, or NULL.
526 typedef void (*TestMigrateFinishHook
)(QTestState
*from
,
531 /* Optional: fine tune start parameters */
534 /* Required: the URI for the dst QEMU to listen on */
535 const char *listen_uri
;
538 * Optional: the URI for the src QEMU to connect to
539 * If NULL, then it will query the dst QEMU for its actual
540 * listening address and use that as the connect address.
541 * This allows for dynamically picking a free TCP port.
543 const char *connect_uri
;
545 /* Optional: callback to run at start to set migration parameters */
546 TestMigrateStartHook start_hook
;
547 /* Optional: callback to run at finish to cleanup */
548 TestMigrateFinishHook finish_hook
;
551 * Optional: normally we expect the migration process to complete.
553 * There can be a variety of reasons and stages in which failure
554 * can happen during tests.
556 * If a failure is expected to happen at time of establishing
557 * the connection, then MIG_TEST_FAIL will indicate that the dst
558 * QEMU is expected to stay running and accept future migration
561 * If a failure is expected to happen while processing the
562 * migration stream, then MIG_TEST_FAIL_DEST_QUIT_ERR will indicate
563 * that the dst QEMU is expected to quit with non-zero exit status
566 /* This test should succeed, the default */
567 MIG_TEST_SUCCEED
= 0,
568 /* This test should fail, dest qemu should keep alive */
570 /* This test should fail, dest qemu should fail with abnormal status */
571 MIG_TEST_FAIL_DEST_QUIT_ERR
,
574 /* Optional: set number of migration passes to wait for */
575 unsigned int iterations
;
577 /* Postcopy specific fields */
579 bool postcopy_preempt
;
582 static int test_migrate_start(QTestState
**from
, QTestState
**to
,
583 const char *uri
, MigrateStart
*args
)
585 g_autofree gchar
*arch_source
= NULL
;
586 g_autofree gchar
*arch_target
= NULL
;
587 g_autofree gchar
*cmd_source
= NULL
;
588 g_autofree gchar
*cmd_target
= NULL
;
589 const gchar
*ignore_stderr
;
590 g_autofree
char *bootpath
= NULL
;
591 g_autofree
char *shmem_opts
= NULL
;
592 g_autofree
char *shmem_path
= NULL
;
593 const char *arch
= qtest_get_arch();
594 const char *machine_opts
= NULL
;
595 const char *memory_size
;
597 if (args
->use_shmem
) {
598 if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR
)) {
599 g_test_skip("/dev/shm is not supported");
605 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
606 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
607 /* the assembled x86 boot sector should be exactly one sector large */
608 assert(sizeof(x86_bootsect
) == 512);
609 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
610 memory_size
= "150M";
611 arch_source
= g_strdup_printf("-drive file=%s,format=raw", bootpath
);
612 arch_target
= g_strdup(arch_source
);
613 start_address
= X86_TEST_MEM_START
;
614 end_address
= X86_TEST_MEM_END
;
615 } else if (g_str_equal(arch
, "s390x")) {
616 init_bootfile(bootpath
, s390x_elf
, sizeof(s390x_elf
));
617 memory_size
= "128M";
618 arch_source
= g_strdup_printf("-bios %s", bootpath
);
619 arch_target
= g_strdup(arch_source
);
620 start_address
= S390_TEST_MEM_START
;
621 end_address
= S390_TEST_MEM_END
;
622 } else if (strcmp(arch
, "ppc64") == 0) {
623 machine_opts
= "vsmt=8";
624 memory_size
= "256M";
625 start_address
= PPC_TEST_MEM_START
;
626 end_address
= PPC_TEST_MEM_END
;
627 arch_source
= g_strdup_printf("-nodefaults "
628 "-prom-env 'use-nvramrc?=true' -prom-env "
629 "'nvramrc=hex .\" _\" begin %x %x "
630 "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
631 "until'", end_address
, start_address
);
632 arch_target
= g_strdup("");
633 } else if (strcmp(arch
, "aarch64") == 0) {
634 init_bootfile(bootpath
, aarch64_kernel
, sizeof(aarch64_kernel
));
635 machine_opts
= "virt,gic-version=max";
636 memory_size
= "150M";
637 arch_source
= g_strdup_printf("-cpu max "
640 arch_target
= g_strdup(arch_source
);
641 start_address
= ARM_TEST_MEM_START
;
642 end_address
= ARM_TEST_MEM_END
;
644 g_assert(sizeof(aarch64_kernel
) <= ARM_TEST_MAX_KERNEL_SIZE
);
646 g_assert_not_reached();
649 if (!getenv("QTEST_LOG") && args
->hide_stderr
) {
651 ignore_stderr
= "2>/dev/null";
654 * On Windows the QEMU executable is created via CreateProcess() and
655 * IO redirection does not work, so don't bother adding IO redirection
656 * to the command line.
664 if (args
->use_shmem
) {
665 shmem_path
= g_strdup_printf("/dev/shm/qemu-%d", getpid());
666 shmem_opts
= g_strdup_printf(
667 "-object memory-backend-file,id=mem0,size=%s"
668 ",mem-path=%s,share=on -numa node,memdev=mem0",
669 memory_size
, shmem_path
);
672 shmem_opts
= g_strdup("");
675 cmd_source
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
676 "-name source,debug-threads=on "
678 "-serial file:%s/src_serial "
680 args
->use_dirty_ring
?
681 ",dirty-ring-size=4096" : "",
682 machine_opts
? " -machine " : "",
683 machine_opts
? machine_opts
: "",
685 arch_source
, shmem_opts
,
686 args
->opts_source
? args
->opts_source
: "",
688 if (!args
->only_target
) {
689 *from
= qtest_init(cmd_source
);
692 cmd_target
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
693 "-name target,debug-threads=on "
695 "-serial file:%s/dest_serial "
698 args
->use_dirty_ring
?
699 ",dirty-ring-size=4096" : "",
700 machine_opts
? " -machine " : "",
701 machine_opts
? machine_opts
: "",
702 memory_size
, tmpfs
, uri
,
703 arch_target
, shmem_opts
,
704 args
->opts_target
? args
->opts_target
: "",
706 *to
= qtest_init(cmd_target
);
709 * Remove shmem file immediately to avoid memory leak in test failed case.
710 * It's valid becase QEMU has already opened this file
712 if (args
->use_shmem
) {
719 static void test_migrate_end(QTestState
*from
, QTestState
*to
, bool test_dest
)
721 unsigned char dest_byte_a
, dest_byte_b
, dest_byte_c
, dest_byte_d
;
726 qtest_memread(to
, start_address
, &dest_byte_a
, 1);
728 /* Destination still running, wait for a byte to change */
730 qtest_memread(to
, start_address
, &dest_byte_b
, 1);
732 } while (dest_byte_a
== dest_byte_b
);
734 qtest_qmp_discard_response(to
, "{ 'execute' : 'stop'}");
736 /* With it stopped, check nothing changes */
737 qtest_memread(to
, start_address
, &dest_byte_c
, 1);
739 qtest_memread(to
, start_address
, &dest_byte_d
, 1);
740 g_assert_cmpint(dest_byte_c
, ==, dest_byte_d
);
742 check_guests_ram(to
);
748 cleanup("migsocket");
749 cleanup("src_serial");
750 cleanup("dest_serial");
754 struct TestMigrateTLSPSKData
{
762 test_migrate_tls_psk_start_common(QTestState
*from
,
766 struct TestMigrateTLSPSKData
*data
=
767 g_new0(struct TestMigrateTLSPSKData
, 1);
770 data
->workdir
= g_strdup_printf("%s/tlscredspsk0", tmpfs
);
771 data
->pskfile
= g_strdup_printf("%s/%s", data
->workdir
,
772 QCRYPTO_TLS_CREDS_PSKFILE
);
773 g_mkdir_with_parents(data
->workdir
, 0700);
774 test_tls_psk_init(data
->pskfile
);
777 data
->workdiralt
= g_strdup_printf("%s/tlscredspskalt0", tmpfs
);
778 data
->pskfilealt
= g_strdup_printf("%s/%s", data
->workdiralt
,
779 QCRYPTO_TLS_CREDS_PSKFILE
);
780 g_mkdir_with_parents(data
->workdiralt
, 0700);
781 test_tls_psk_init_alt(data
->pskfilealt
);
784 rsp
= wait_command(from
,
785 "{ 'execute': 'object-add',"
786 " 'arguments': { 'qom-type': 'tls-creds-psk',"
787 " 'id': 'tlscredspsk0',"
788 " 'endpoint': 'client',"
790 " 'username': 'qemu'} }",
794 rsp
= wait_command(to
,
795 "{ 'execute': 'object-add',"
796 " 'arguments': { 'qom-type': 'tls-creds-psk',"
797 " 'id': 'tlscredspsk0',"
798 " 'endpoint': 'server',"
800 mismatch
? data
->workdiralt
: data
->workdir
);
803 migrate_set_parameter_str(from
, "tls-creds", "tlscredspsk0");
804 migrate_set_parameter_str(to
, "tls-creds", "tlscredspsk0");
810 test_migrate_tls_psk_start_match(QTestState
*from
,
813 return test_migrate_tls_psk_start_common(from
, to
, false);
817 test_migrate_tls_psk_start_mismatch(QTestState
*from
,
820 return test_migrate_tls_psk_start_common(from
, to
, true);
824 test_migrate_tls_psk_finish(QTestState
*from
,
828 struct TestMigrateTLSPSKData
*data
= opaque
;
830 test_tls_psk_cleanup(data
->pskfile
);
831 if (data
->pskfilealt
) {
832 test_tls_psk_cleanup(data
->pskfilealt
);
834 rmdir(data
->workdir
);
835 if (data
->workdiralt
) {
836 rmdir(data
->workdiralt
);
839 g_free(data
->workdiralt
);
840 g_free(data
->pskfilealt
);
841 g_free(data
->workdir
);
842 g_free(data
->pskfile
);
855 } TestMigrateTLSX509Data
;
862 const char *certhostname
;
863 const char *certipaddr
;
864 } TestMigrateTLSX509
;
867 test_migrate_tls_x509_start_common(QTestState
*from
,
869 TestMigrateTLSX509
*args
)
871 TestMigrateTLSX509Data
*data
= g_new0(TestMigrateTLSX509Data
, 1);
874 data
->workdir
= g_strdup_printf("%s/tlscredsx5090", tmpfs
);
875 data
->keyfile
= g_strdup_printf("%s/key.pem", data
->workdir
);
877 data
->cacert
= g_strdup_printf("%s/ca-cert.pem", data
->workdir
);
878 data
->serverkey
= g_strdup_printf("%s/server-key.pem", data
->workdir
);
879 data
->servercert
= g_strdup_printf("%s/server-cert.pem", data
->workdir
);
880 if (args
->clientcert
) {
881 data
->clientkey
= g_strdup_printf("%s/client-key.pem", data
->workdir
);
882 data
->clientcert
= g_strdup_printf("%s/client-cert.pem", data
->workdir
);
885 g_mkdir_with_parents(data
->workdir
, 0700);
887 test_tls_init(data
->keyfile
);
889 g_assert(link(data
->keyfile
, data
->serverkey
) == 0);
891 g_assert(CreateHardLink(data
->serverkey
, data
->keyfile
, NULL
) != 0);
893 if (args
->clientcert
) {
895 g_assert(link(data
->keyfile
, data
->clientkey
) == 0);
897 g_assert(CreateHardLink(data
->clientkey
, data
->keyfile
, NULL
) != 0);
901 TLS_ROOT_REQ_SIMPLE(cacertreq
, data
->cacert
);
902 if (args
->clientcert
) {
903 TLS_CERT_REQ_SIMPLE_CLIENT(servercertreq
, cacertreq
,
904 args
->hostileclient
?
905 QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME
:
906 QCRYPTO_TLS_TEST_CLIENT_NAME
,
910 TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq
, cacertreq
,
915 rsp
= wait_command(from
,
916 "{ 'execute': 'object-add',"
917 " 'arguments': { 'qom-type': 'tls-creds-x509',"
918 " 'id': 'tlscredsx509client0',"
919 " 'endpoint': 'client',"
921 " 'sanity-check': true,"
922 " 'verify-peer': true} }",
925 migrate_set_parameter_str(from
, "tls-creds", "tlscredsx509client0");
926 if (args
->certhostname
) {
927 migrate_set_parameter_str(from
, "tls-hostname", args
->certhostname
);
930 rsp
= wait_command(to
,
931 "{ 'execute': 'object-add',"
932 " 'arguments': { 'qom-type': 'tls-creds-x509',"
933 " 'id': 'tlscredsx509server0',"
934 " 'endpoint': 'server',"
936 " 'sanity-check': true,"
937 " 'verify-peer': %i} }",
938 data
->workdir
, args
->verifyclient
);
940 migrate_set_parameter_str(to
, "tls-creds", "tlscredsx509server0");
942 if (args
->authzclient
) {
943 rsp
= wait_command(to
,
944 "{ 'execute': 'object-add',"
945 " 'arguments': { 'qom-type': 'authz-simple',"
946 " 'id': 'tlsauthz0',"
947 " 'identity': %s} }",
948 "CN=" QCRYPTO_TLS_TEST_CLIENT_NAME
);
949 migrate_set_parameter_str(to
, "tls-authz", "tlsauthz0");
956 * The normal case: match server's cert hostname against
957 * whatever host we were telling QEMU to connect to (if any)
960 test_migrate_tls_x509_start_default_host(QTestState
*from
,
963 TestMigrateTLSX509 args
= {
964 .verifyclient
= true,
966 .certipaddr
= "127.0.0.1"
968 return test_migrate_tls_x509_start_common(from
, to
, &args
);
972 * The unusual case: the server's cert is different from
973 * the address we're telling QEMU to connect to (if any),
974 * so we must give QEMU an explicit hostname to validate
977 test_migrate_tls_x509_start_override_host(QTestState
*from
,
980 TestMigrateTLSX509 args
= {
981 .verifyclient
= true,
983 .certhostname
= "qemu.org",
985 return test_migrate_tls_x509_start_common(from
, to
, &args
);
989 * The unusual case: the server's cert is different from
990 * the address we're telling QEMU to connect to, and so we
991 * expect the client to reject the server
994 test_migrate_tls_x509_start_mismatch_host(QTestState
*from
,
997 TestMigrateTLSX509 args
= {
998 .verifyclient
= true,
1000 .certipaddr
= "10.0.0.1",
1002 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1006 test_migrate_tls_x509_start_friendly_client(QTestState
*from
,
1009 TestMigrateTLSX509 args
= {
1010 .verifyclient
= true,
1012 .authzclient
= true,
1013 .certipaddr
= "127.0.0.1",
1015 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1019 test_migrate_tls_x509_start_hostile_client(QTestState
*from
,
1022 TestMigrateTLSX509 args
= {
1023 .verifyclient
= true,
1025 .hostileclient
= true,
1026 .authzclient
= true,
1027 .certipaddr
= "127.0.0.1",
1029 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1033 * The case with no client certificate presented,
1034 * and no server verification
1037 test_migrate_tls_x509_start_allow_anon_client(QTestState
*from
,
1040 TestMigrateTLSX509 args
= {
1041 .certipaddr
= "127.0.0.1",
1043 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1047 * The case with no client certificate presented,
1048 * and server verification rejecting
1051 test_migrate_tls_x509_start_reject_anon_client(QTestState
*from
,
1054 TestMigrateTLSX509 args
= {
1055 .verifyclient
= true,
1056 .certipaddr
= "127.0.0.1",
1058 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1062 test_migrate_tls_x509_finish(QTestState
*from
,
1066 TestMigrateTLSX509Data
*data
= opaque
;
1068 test_tls_cleanup(data
->keyfile
);
1069 g_free(data
->keyfile
);
1071 unlink(data
->cacert
);
1072 g_free(data
->cacert
);
1073 unlink(data
->servercert
);
1074 g_free(data
->servercert
);
1075 unlink(data
->serverkey
);
1076 g_free(data
->serverkey
);
1078 if (data
->clientcert
) {
1079 unlink(data
->clientcert
);
1080 g_free(data
->clientcert
);
1082 if (data
->clientkey
) {
1083 unlink(data
->clientkey
);
1084 g_free(data
->clientkey
);
1087 rmdir(data
->workdir
);
1088 g_free(data
->workdir
);
1092 #endif /* CONFIG_TASN1 */
1093 #endif /* CONFIG_GNUTLS */
1095 static int migrate_postcopy_prepare(QTestState
**from_ptr
,
1096 QTestState
**to_ptr
,
1097 MigrateCommon
*args
)
1099 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1100 QTestState
*from
, *to
;
1102 if (test_migrate_start(&from
, &to
, uri
, &args
->start
)) {
1106 if (args
->start_hook
) {
1107 args
->postcopy_data
= args
->start_hook(from
, to
);
1110 migrate_set_capability(from
, "postcopy-ram", true);
1111 migrate_set_capability(to
, "postcopy-ram", true);
1112 migrate_set_capability(to
, "postcopy-blocktime", true);
1114 if (args
->postcopy_preempt
) {
1115 migrate_set_capability(from
, "postcopy-preempt", true);
1116 migrate_set_capability(to
, "postcopy-preempt", true);
1119 migrate_ensure_non_converge(from
);
1121 /* Wait for the first serial output from the source */
1122 wait_for_serial("src_serial");
1124 migrate_qmp(from
, uri
, "{}");
1126 wait_for_migration_pass(from
);
1134 static void migrate_postcopy_complete(QTestState
*from
, QTestState
*to
,
1135 MigrateCommon
*args
)
1137 wait_for_migration_complete(from
);
1139 /* Make sure we get at least one "B" on destination */
1140 wait_for_serial("dest_serial");
1142 if (uffd_feature_thread_id
) {
1146 if (args
->finish_hook
) {
1147 args
->finish_hook(from
, to
, args
->postcopy_data
);
1148 args
->postcopy_data
= NULL
;
1151 test_migrate_end(from
, to
, true);
1154 static void test_postcopy_common(MigrateCommon
*args
)
1156 QTestState
*from
, *to
;
1158 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1161 migrate_postcopy_start(from
, to
);
1162 migrate_postcopy_complete(from
, to
, args
);
1165 static void test_postcopy(void)
1167 MigrateCommon args
= { };
1169 test_postcopy_common(&args
);
1172 static void test_postcopy_preempt(void)
1174 MigrateCommon args
= {
1175 .postcopy_preempt
= true,
1178 test_postcopy_common(&args
);
1181 #ifdef CONFIG_GNUTLS
1182 static void test_postcopy_tls_psk(void)
1184 MigrateCommon args
= {
1185 .start_hook
= test_migrate_tls_psk_start_match
,
1186 .finish_hook
= test_migrate_tls_psk_finish
,
1189 test_postcopy_common(&args
);
1192 static void test_postcopy_preempt_tls_psk(void)
1194 MigrateCommon args
= {
1195 .postcopy_preempt
= true,
1196 .start_hook
= test_migrate_tls_psk_start_match
,
1197 .finish_hook
= test_migrate_tls_psk_finish
,
1200 test_postcopy_common(&args
);
1204 static void test_postcopy_recovery_common(MigrateCommon
*args
)
1206 QTestState
*from
, *to
;
1207 g_autofree
char *uri
= NULL
;
1209 /* Always hide errors for postcopy recover tests since they're expected */
1210 args
->start
.hide_stderr
= true;
1212 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1216 /* Turn postcopy speed down, 4K/s is slow enough on any machines */
1217 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 4096);
1219 /* Now we start the postcopy */
1220 migrate_postcopy_start(from
, to
);
1223 * Wait until postcopy is really started; we can only run the
1224 * migrate-pause command during a postcopy
1226 wait_for_migration_status(from
, "postcopy-active", NULL
);
1229 * Manually stop the postcopy migration. This emulates a network
1230 * failure with the migration socket
1232 migrate_pause(from
);
1235 * Wait for destination side to reach postcopy-paused state. The
1236 * migrate-recover command can only succeed if destination machine
1237 * is in the paused state
1239 wait_for_migration_status(to
, "postcopy-paused",
1240 (const char * []) { "failed", "active",
1241 "completed", NULL
});
1244 * Create a new socket to emulate a new channel that is different
1245 * from the broken migration channel; tell the destination to
1246 * listen to the new port
1248 uri
= g_strdup_printf("unix:%s/migsocket-recover", tmpfs
);
1249 migrate_recover(to
, uri
);
1252 * Try to rebuild the migration channel using the resume flag and
1253 * the newly created channel
1255 wait_for_migration_status(from
, "postcopy-paused",
1256 (const char * []) { "failed", "active",
1257 "completed", NULL
});
1258 migrate_qmp(from
, uri
, "{'resume': true}");
1260 /* Restore the postcopy bandwidth to unlimited */
1261 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 0);
1263 migrate_postcopy_complete(from
, to
, args
);
1266 static void test_postcopy_recovery(void)
1268 MigrateCommon args
= { };
1270 test_postcopy_recovery_common(&args
);
1273 #ifdef CONFIG_GNUTLS
1274 static void test_postcopy_recovery_tls_psk(void)
1276 MigrateCommon args
= {
1277 .start_hook
= test_migrate_tls_psk_start_match
,
1278 .finish_hook
= test_migrate_tls_psk_finish
,
1281 test_postcopy_recovery_common(&args
);
1285 static void test_postcopy_preempt_recovery(void)
1287 MigrateCommon args
= {
1288 .postcopy_preempt
= true,
1291 test_postcopy_recovery_common(&args
);
1294 #ifdef CONFIG_GNUTLS
1295 /* This contains preempt+recovery+tls test altogether */
1296 static void test_postcopy_preempt_all(void)
1298 MigrateCommon args
= {
1299 .postcopy_preempt
= true,
1300 .start_hook
= test_migrate_tls_psk_start_match
,
1301 .finish_hook
= test_migrate_tls_psk_finish
,
1304 test_postcopy_recovery_common(&args
);
1308 static void test_baddest(void)
1310 MigrateStart args
= {
1313 QTestState
*from
, *to
;
1315 if (test_migrate_start(&from
, &to
, "tcp:127.0.0.1:0", &args
)) {
1318 migrate_qmp(from
, "tcp:127.0.0.1:0", "{}");
1319 wait_for_migration_fail(from
, false);
1320 test_migrate_end(from
, to
, false);
1323 static void test_precopy_common(MigrateCommon
*args
)
1325 QTestState
*from
, *to
;
1326 void *data_hook
= NULL
;
1328 if (test_migrate_start(&from
, &to
, args
->listen_uri
, &args
->start
)) {
1332 migrate_ensure_non_converge(from
);
1334 if (args
->start_hook
) {
1335 data_hook
= args
->start_hook(from
, to
);
1338 /* Wait for the first serial output from the source */
1339 if (args
->result
== MIG_TEST_SUCCEED
) {
1340 wait_for_serial("src_serial");
1343 if (!args
->connect_uri
) {
1344 g_autofree
char *local_connect_uri
=
1345 migrate_get_socket_address(to
, "socket-address");
1346 migrate_qmp(from
, local_connect_uri
, "{}");
1348 migrate_qmp(from
, args
->connect_uri
, "{}");
1352 if (args
->result
!= MIG_TEST_SUCCEED
) {
1353 bool allow_active
= args
->result
== MIG_TEST_FAIL
;
1354 wait_for_migration_fail(from
, allow_active
);
1356 if (args
->result
== MIG_TEST_FAIL_DEST_QUIT_ERR
) {
1357 qtest_set_expected_status(to
, EXIT_FAILURE
);
1360 if (args
->iterations
) {
1361 while (args
->iterations
--) {
1362 wait_for_migration_pass(from
);
1365 wait_for_migration_pass(from
);
1368 migrate_ensure_converge(from
);
1370 /* We do this first, as it has a timeout to stop us
1371 * hanging forever if migration didn't converge */
1372 wait_for_migration_complete(from
);
1375 qtest_qmp_eventwait(from
, "STOP");
1378 qtest_qmp_eventwait(to
, "RESUME");
1380 wait_for_serial("dest_serial");
1383 if (args
->finish_hook
) {
1384 args
->finish_hook(from
, to
, data_hook
);
1387 test_migrate_end(from
, to
, args
->result
== MIG_TEST_SUCCEED
);
1390 static void test_precopy_unix_plain(void)
1392 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1393 MigrateCommon args
= {
1398 test_precopy_common(&args
);
1402 static void test_precopy_unix_dirty_ring(void)
1404 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1405 MigrateCommon args
= {
1407 .use_dirty_ring
= true,
1413 test_precopy_common(&args
);
1416 #ifdef CONFIG_GNUTLS
1417 static void test_precopy_unix_tls_psk(void)
1419 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1420 MigrateCommon args
= {
1423 .start_hook
= test_migrate_tls_psk_start_match
,
1424 .finish_hook
= test_migrate_tls_psk_finish
,
1427 test_precopy_common(&args
);
1431 static void test_precopy_unix_tls_x509_default_host(void)
1433 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1434 MigrateCommon args
= {
1436 .hide_stderr
= true,
1440 .start_hook
= test_migrate_tls_x509_start_default_host
,
1441 .finish_hook
= test_migrate_tls_x509_finish
,
1442 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1445 test_precopy_common(&args
);
1448 static void test_precopy_unix_tls_x509_override_host(void)
1450 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1451 MigrateCommon args
= {
1454 .start_hook
= test_migrate_tls_x509_start_override_host
,
1455 .finish_hook
= test_migrate_tls_x509_finish
,
1458 test_precopy_common(&args
);
1460 #endif /* CONFIG_TASN1 */
1461 #endif /* CONFIG_GNUTLS */
1464 /* Currently upset on aarch64 TCG */
1465 static void test_ignore_shared(void)
1467 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1468 QTestState
*from
, *to
;
1470 if (test_migrate_start(&from
, &to
, uri
, false, true, NULL
, NULL
)) {
1474 migrate_set_capability(from
, "x-ignore-shared", true);
1475 migrate_set_capability(to
, "x-ignore-shared", true);
1477 /* Wait for the first serial output from the source */
1478 wait_for_serial("src_serial");
1480 migrate_qmp(from
, uri
, "{}");
1482 wait_for_migration_pass(from
);
1485 qtest_qmp_eventwait(from
, "STOP");
1488 qtest_qmp_eventwait(to
, "RESUME");
1490 wait_for_serial("dest_serial");
1491 wait_for_migration_complete(from
);
1493 /* Check whether shared RAM has been really skipped */
1494 g_assert_cmpint(read_ram_property_int(from
, "transferred"), <, 1024 * 1024);
1496 test_migrate_end(from
, to
, true);
1501 test_migrate_xbzrle_start(QTestState
*from
,
1504 migrate_set_parameter_int(from
, "xbzrle-cache-size", 33554432);
1506 migrate_set_capability(from
, "xbzrle", true);
1507 migrate_set_capability(to
, "xbzrle", true);
1512 static void test_precopy_unix_xbzrle(void)
1514 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1515 MigrateCommon args
= {
1519 .start_hook
= test_migrate_xbzrle_start
,
1524 test_precopy_common(&args
);
1527 static void test_precopy_tcp_plain(void)
1529 MigrateCommon args
= {
1530 .listen_uri
= "tcp:127.0.0.1:0",
1533 test_precopy_common(&args
);
1536 #ifdef CONFIG_GNUTLS
1537 static void test_precopy_tcp_tls_psk_match(void)
1539 MigrateCommon args
= {
1540 .listen_uri
= "tcp:127.0.0.1:0",
1541 .start_hook
= test_migrate_tls_psk_start_match
,
1542 .finish_hook
= test_migrate_tls_psk_finish
,
1545 test_precopy_common(&args
);
1548 static void test_precopy_tcp_tls_psk_mismatch(void)
1550 MigrateCommon args
= {
1552 .hide_stderr
= true,
1554 .listen_uri
= "tcp:127.0.0.1:0",
1555 .start_hook
= test_migrate_tls_psk_start_mismatch
,
1556 .finish_hook
= test_migrate_tls_psk_finish
,
1557 .result
= MIG_TEST_FAIL
,
1560 test_precopy_common(&args
);
1564 static void test_precopy_tcp_tls_x509_default_host(void)
1566 MigrateCommon args
= {
1567 .listen_uri
= "tcp:127.0.0.1:0",
1568 .start_hook
= test_migrate_tls_x509_start_default_host
,
1569 .finish_hook
= test_migrate_tls_x509_finish
,
1572 test_precopy_common(&args
);
1575 static void test_precopy_tcp_tls_x509_override_host(void)
1577 MigrateCommon args
= {
1578 .listen_uri
= "tcp:127.0.0.1:0",
1579 .start_hook
= test_migrate_tls_x509_start_override_host
,
1580 .finish_hook
= test_migrate_tls_x509_finish
,
1583 test_precopy_common(&args
);
1586 static void test_precopy_tcp_tls_x509_mismatch_host(void)
1588 MigrateCommon args
= {
1590 .hide_stderr
= true,
1592 .listen_uri
= "tcp:127.0.0.1:0",
1593 .start_hook
= test_migrate_tls_x509_start_mismatch_host
,
1594 .finish_hook
= test_migrate_tls_x509_finish
,
1595 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1598 test_precopy_common(&args
);
1601 static void test_precopy_tcp_tls_x509_friendly_client(void)
1603 MigrateCommon args
= {
1604 .listen_uri
= "tcp:127.0.0.1:0",
1605 .start_hook
= test_migrate_tls_x509_start_friendly_client
,
1606 .finish_hook
= test_migrate_tls_x509_finish
,
1609 test_precopy_common(&args
);
1612 static void test_precopy_tcp_tls_x509_hostile_client(void)
1614 MigrateCommon args
= {
1616 .hide_stderr
= true,
1618 .listen_uri
= "tcp:127.0.0.1:0",
1619 .start_hook
= test_migrate_tls_x509_start_hostile_client
,
1620 .finish_hook
= test_migrate_tls_x509_finish
,
1621 .result
= MIG_TEST_FAIL
,
1624 test_precopy_common(&args
);
1627 static void test_precopy_tcp_tls_x509_allow_anon_client(void)
1629 MigrateCommon args
= {
1630 .listen_uri
= "tcp:127.0.0.1:0",
1631 .start_hook
= test_migrate_tls_x509_start_allow_anon_client
,
1632 .finish_hook
= test_migrate_tls_x509_finish
,
1635 test_precopy_common(&args
);
1638 static void test_precopy_tcp_tls_x509_reject_anon_client(void)
1640 MigrateCommon args
= {
1642 .hide_stderr
= true,
1644 .listen_uri
= "tcp:127.0.0.1:0",
1645 .start_hook
= test_migrate_tls_x509_start_reject_anon_client
,
1646 .finish_hook
= test_migrate_tls_x509_finish
,
1647 .result
= MIG_TEST_FAIL
,
1650 test_precopy_common(&args
);
1652 #endif /* CONFIG_TASN1 */
1653 #endif /* CONFIG_GNUTLS */
1656 static void *test_migrate_fd_start_hook(QTestState
*from
,
1663 /* Create two connected sockets for migration */
1664 ret
= qemu_socketpair(PF_LOCAL
, SOCK_STREAM
, 0, pair
);
1665 g_assert_cmpint(ret
, ==, 0);
1667 /* Send the 1st socket to the target */
1668 rsp
= wait_command_fd(to
, pair
[0],
1669 "{ 'execute': 'getfd',"
1670 " 'arguments': { 'fdname': 'fd-mig' }}");
1674 /* Start incoming migration from the 1st socket */
1675 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
1676 " 'arguments': { 'uri': 'fd:fd-mig' }}");
1679 /* Send the 2nd socket to the target */
1680 rsp
= wait_command_fd(from
, pair
[1],
1681 "{ 'execute': 'getfd',"
1682 " 'arguments': { 'fdname': 'fd-mig' }}");
1689 static void test_migrate_fd_finish_hook(QTestState
*from
,
1694 const char *error_desc
;
1696 /* Test closing fds */
1697 /* We assume, that QEMU removes named fd from its list,
1698 * so this should fail */
1699 rsp
= qtest_qmp(from
, "{ 'execute': 'closefd',"
1700 " 'arguments': { 'fdname': 'fd-mig' }}");
1701 g_assert_true(qdict_haskey(rsp
, "error"));
1702 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1703 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1706 rsp
= qtest_qmp(to
, "{ 'execute': 'closefd',"
1707 " 'arguments': { 'fdname': 'fd-mig' }}");
1708 g_assert_true(qdict_haskey(rsp
, "error"));
1709 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1710 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1714 static void test_migrate_fd_proto(void)
1716 MigrateCommon args
= {
1717 .listen_uri
= "defer",
1718 .connect_uri
= "fd:fd-mig",
1719 .start_hook
= test_migrate_fd_start_hook
,
1720 .finish_hook
= test_migrate_fd_finish_hook
1722 test_precopy_common(&args
);
1726 static void do_test_validate_uuid(MigrateStart
*args
, bool should_fail
)
1728 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1729 QTestState
*from
, *to
;
1731 if (test_migrate_start(&from
, &to
, uri
, args
)) {
1736 * UUID validation is at the begin of migration. So, the main process of
1737 * migration is not interesting for us here. Thus, set huge downtime for
1738 * very fast migration.
1740 migrate_set_parameter_int(from
, "downtime-limit", 1000000);
1741 migrate_set_capability(from
, "validate-uuid", true);
1743 /* Wait for the first serial output from the source */
1744 wait_for_serial("src_serial");
1746 migrate_qmp(from
, uri
, "{}");
1749 qtest_set_expected_status(to
, EXIT_FAILURE
);
1750 wait_for_migration_fail(from
, true);
1752 wait_for_migration_complete(from
);
1755 test_migrate_end(from
, to
, false);
1758 static void test_validate_uuid(void)
1760 MigrateStart args
= {
1761 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1762 .opts_target
= "-uuid 11111111-1111-1111-1111-111111111111",
1765 do_test_validate_uuid(&args
, false);
1768 static void test_validate_uuid_error(void)
1770 MigrateStart args
= {
1771 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1772 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1773 .hide_stderr
= true,
1776 do_test_validate_uuid(&args
, true);
1779 static void test_validate_uuid_src_not_set(void)
1781 MigrateStart args
= {
1782 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1783 .hide_stderr
= true,
1786 do_test_validate_uuid(&args
, false);
1789 static void test_validate_uuid_dst_not_set(void)
1791 MigrateStart args
= {
1792 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1793 .hide_stderr
= true,
1796 do_test_validate_uuid(&args
, false);
1800 * The way auto_converge works, we need to do too many passes to
1801 * run this test. Auto_converge logic is only run once every
1802 * three iterations, so:
1804 * - 3 iterations without auto_converge enabled
1805 * - 3 iterations with pct = 5
1806 * - 3 iterations with pct = 30
1807 * - 3 iterations with pct = 55
1808 * - 3 iterations with pct = 80
1809 * - 3 iterations with pct = 95 (max(95, 80 + 25))
1811 * To make things even worse, we need to run the initial stage at
1812 * 3MB/s so we enter autoconverge even when host is (over)loaded.
1814 static void test_migrate_auto_converge(void)
1816 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1817 MigrateStart args
= {};
1818 QTestState
*from
, *to
;
1822 * We want the test to be stable and as fast as possible.
1823 * E.g., with 1Gb/s bandwith migration may pass without throttling,
1824 * so we need to decrease a bandwidth.
1826 const int64_t init_pct
= 5, inc_pct
= 25, max_pct
= 95;
1828 if (test_migrate_start(&from
, &to
, uri
, &args
)) {
1832 migrate_set_capability(from
, "auto-converge", true);
1833 migrate_set_parameter_int(from
, "cpu-throttle-initial", init_pct
);
1834 migrate_set_parameter_int(from
, "cpu-throttle-increment", inc_pct
);
1835 migrate_set_parameter_int(from
, "max-cpu-throttle", max_pct
);
1838 * Set the initial parameters so that the migration could not converge
1839 * without throttling.
1841 migrate_ensure_non_converge(from
);
1843 /* To check remaining size after precopy */
1844 migrate_set_capability(from
, "pause-before-switchover", true);
1846 /* Wait for the first serial output from the source */
1847 wait_for_serial("src_serial");
1849 migrate_qmp(from
, uri
, "{}");
1851 /* Wait for throttling begins */
1854 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1855 if (percentage
!= 0) {
1859 g_assert_false(got_stop
);
1861 /* The first percentage of throttling should be at least init_pct */
1862 g_assert_cmpint(percentage
, >=, init_pct
);
1863 /* Now, when we tested that throttling works, let it converge */
1864 migrate_ensure_converge(from
);
1867 * Wait for pre-switchover status to check last throttle percentage
1868 * and remaining. These values will be zeroed later
1870 wait_for_migration_status(from
, "pre-switchover", NULL
);
1872 /* The final percentage of throttling shouldn't be greater than max_pct */
1873 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1874 g_assert_cmpint(percentage
, <=, max_pct
);
1875 migrate_continue(from
, "pre-switchover");
1877 qtest_qmp_eventwait(to
, "RESUME");
1879 wait_for_serial("dest_serial");
1880 wait_for_migration_complete(from
);
1882 test_migrate_end(from
, to
, true);
1886 test_migrate_precopy_tcp_multifd_start_common(QTestState
*from
,
1892 migrate_set_parameter_int(from
, "multifd-channels", 16);
1893 migrate_set_parameter_int(to
, "multifd-channels", 16);
1895 migrate_set_parameter_str(from
, "multifd-compression", method
);
1896 migrate_set_parameter_str(to
, "multifd-compression", method
);
1898 migrate_set_capability(from
, "multifd", true);
1899 migrate_set_capability(to
, "multifd", true);
1901 /* Start incoming migration from the 1st socket */
1902 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
1903 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
1910 test_migrate_precopy_tcp_multifd_start(QTestState
*from
,
1913 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
1917 test_migrate_precopy_tcp_multifd_zlib_start(QTestState
*from
,
1920 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zlib");
1925 test_migrate_precopy_tcp_multifd_zstd_start(QTestState
*from
,
1928 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zstd");
1930 #endif /* CONFIG_ZSTD */
1932 static void test_multifd_tcp_none(void)
1934 MigrateCommon args
= {
1935 .listen_uri
= "defer",
1936 .start_hook
= test_migrate_precopy_tcp_multifd_start
,
1938 test_precopy_common(&args
);
1941 static void test_multifd_tcp_zlib(void)
1943 MigrateCommon args
= {
1944 .listen_uri
= "defer",
1945 .start_hook
= test_migrate_precopy_tcp_multifd_zlib_start
,
1947 test_precopy_common(&args
);
1951 static void test_multifd_tcp_zstd(void)
1953 MigrateCommon args
= {
1954 .listen_uri
= "defer",
1955 .start_hook
= test_migrate_precopy_tcp_multifd_zstd_start
,
1957 test_precopy_common(&args
);
1961 #ifdef CONFIG_GNUTLS
1963 test_migrate_multifd_tcp_tls_psk_start_match(QTestState
*from
,
1966 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
1967 return test_migrate_tls_psk_start_match(from
, to
);
1971 test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState
*from
,
1974 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
1975 return test_migrate_tls_psk_start_mismatch(from
, to
);
1980 test_migrate_multifd_tls_x509_start_default_host(QTestState
*from
,
1983 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
1984 return test_migrate_tls_x509_start_default_host(from
, to
);
1988 test_migrate_multifd_tls_x509_start_override_host(QTestState
*from
,
1991 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
1992 return test_migrate_tls_x509_start_override_host(from
, to
);
1996 test_migrate_multifd_tls_x509_start_mismatch_host(QTestState
*from
,
1999 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2000 return test_migrate_tls_x509_start_mismatch_host(from
, to
);
2004 test_migrate_multifd_tls_x509_start_allow_anon_client(QTestState
*from
,
2007 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2008 return test_migrate_tls_x509_start_allow_anon_client(from
, to
);
2012 test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState
*from
,
2015 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2016 return test_migrate_tls_x509_start_reject_anon_client(from
, to
);
2018 #endif /* CONFIG_TASN1 */
2020 static void test_multifd_tcp_tls_psk_match(void)
2022 MigrateCommon args
= {
2023 .listen_uri
= "defer",
2024 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_match
,
2025 .finish_hook
= test_migrate_tls_psk_finish
,
2027 test_precopy_common(&args
);
2030 static void test_multifd_tcp_tls_psk_mismatch(void)
2032 MigrateCommon args
= {
2034 .hide_stderr
= true,
2036 .listen_uri
= "defer",
2037 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_mismatch
,
2038 .finish_hook
= test_migrate_tls_psk_finish
,
2039 .result
= MIG_TEST_FAIL
,
2041 test_precopy_common(&args
);
2045 static void test_multifd_tcp_tls_x509_default_host(void)
2047 MigrateCommon args
= {
2048 .listen_uri
= "defer",
2049 .start_hook
= test_migrate_multifd_tls_x509_start_default_host
,
2050 .finish_hook
= test_migrate_tls_x509_finish
,
2052 test_precopy_common(&args
);
2055 static void test_multifd_tcp_tls_x509_override_host(void)
2057 MigrateCommon args
= {
2058 .listen_uri
= "defer",
2059 .start_hook
= test_migrate_multifd_tls_x509_start_override_host
,
2060 .finish_hook
= test_migrate_tls_x509_finish
,
2062 test_precopy_common(&args
);
2065 static void test_multifd_tcp_tls_x509_mismatch_host(void)
2068 * This has different behaviour to the non-multifd case.
2070 * In non-multifd case when client aborts due to mismatched
2071 * cert host, the server has already started trying to load
2072 * migration state, and so it exits with I/O failure.
2074 * In multifd case when client aborts due to mismatched
2075 * cert host, the server is still waiting for the other
2076 * multifd connections to arrive so hasn't started trying
2077 * to load migration state, and thus just aborts the migration
2080 MigrateCommon args
= {
2082 .hide_stderr
= true,
2084 .listen_uri
= "defer",
2085 .start_hook
= test_migrate_multifd_tls_x509_start_mismatch_host
,
2086 .finish_hook
= test_migrate_tls_x509_finish
,
2087 .result
= MIG_TEST_FAIL
,
2089 test_precopy_common(&args
);
2092 static void test_multifd_tcp_tls_x509_allow_anon_client(void)
2094 MigrateCommon args
= {
2095 .listen_uri
= "defer",
2096 .start_hook
= test_migrate_multifd_tls_x509_start_allow_anon_client
,
2097 .finish_hook
= test_migrate_tls_x509_finish
,
2099 test_precopy_common(&args
);
2102 static void test_multifd_tcp_tls_x509_reject_anon_client(void)
2104 MigrateCommon args
= {
2106 .hide_stderr
= true,
2108 .listen_uri
= "defer",
2109 .start_hook
= test_migrate_multifd_tls_x509_start_reject_anon_client
,
2110 .finish_hook
= test_migrate_tls_x509_finish
,
2111 .result
= MIG_TEST_FAIL
,
2113 test_precopy_common(&args
);
2115 #endif /* CONFIG_TASN1 */
2116 #endif /* CONFIG_GNUTLS */
2124 * launch another target
2127 * And see that it works
2129 static void test_multifd_tcp_cancel(void)
2131 MigrateStart args
= {
2132 .hide_stderr
= true,
2134 QTestState
*from
, *to
, *to2
;
2136 g_autofree
char *uri
= NULL
;
2138 if (test_migrate_start(&from
, &to
, "defer", &args
)) {
2142 migrate_ensure_non_converge(from
);
2144 migrate_set_parameter_int(from
, "multifd-channels", 16);
2145 migrate_set_parameter_int(to
, "multifd-channels", 16);
2147 migrate_set_capability(from
, "multifd", true);
2148 migrate_set_capability(to
, "multifd", true);
2150 /* Start incoming migration from the 1st socket */
2151 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
2152 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2155 /* Wait for the first serial output from the source */
2156 wait_for_serial("src_serial");
2158 uri
= migrate_get_socket_address(to
, "socket-address");
2160 migrate_qmp(from
, uri
, "{}");
2162 wait_for_migration_pass(from
);
2164 migrate_cancel(from
);
2166 /* Make sure QEMU process "to" exited */
2167 qtest_set_expected_status(to
, EXIT_FAILURE
);
2168 qtest_wait_qemu(to
);
2170 args
= (MigrateStart
){
2171 .only_target
= true,
2174 if (test_migrate_start(&from
, &to2
, "defer", &args
)) {
2178 migrate_set_parameter_int(to2
, "multifd-channels", 16);
2180 migrate_set_capability(to2
, "multifd", true);
2182 /* Start incoming migration from the 1st socket */
2183 rsp
= wait_command(to2
, "{ 'execute': 'migrate-incoming',"
2184 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2188 uri
= migrate_get_socket_address(to2
, "socket-address");
2190 wait_for_migration_status(from
, "cancelled", NULL
);
2192 migrate_ensure_converge(from
);
2194 migrate_qmp(from
, uri
, "{}");
2196 wait_for_migration_pass(from
);
2199 qtest_qmp_eventwait(from
, "STOP");
2201 qtest_qmp_eventwait(to2
, "RESUME");
2203 wait_for_serial("dest_serial");
2204 wait_for_migration_complete(from
);
2205 test_migrate_end(from
, to2
, true);
2208 static void calc_dirty_rate(QTestState
*who
, uint64_t calc_time
)
2210 qobject_unref(qmp_command(who
,
2211 "{ 'execute': 'calc-dirty-rate',"
2213 "'calc-time': %" PRIu64
","
2214 "'mode': 'dirty-ring' }}",
2218 static QDict
*query_dirty_rate(QTestState
*who
)
2220 return qmp_command(who
, "{ 'execute': 'query-dirty-rate' }");
2223 static void dirtylimit_set_all(QTestState
*who
, uint64_t dirtyrate
)
2225 qobject_unref(qmp_command(who
,
2226 "{ 'execute': 'set-vcpu-dirty-limit',"
2228 "'dirty-rate': %" PRIu64
" } }",
2232 static void cancel_vcpu_dirty_limit(QTestState
*who
)
2234 qobject_unref(qmp_command(who
,
2235 "{ 'execute': 'cancel-vcpu-dirty-limit' }"));
2238 static QDict
*query_vcpu_dirty_limit(QTestState
*who
)
2242 rsp
= qtest_qmp(who
, "{ 'execute': 'query-vcpu-dirty-limit' }");
2243 g_assert(!qdict_haskey(rsp
, "error"));
2244 g_assert(qdict_haskey(rsp
, "return"));
2249 static bool calc_dirtyrate_ready(QTestState
*who
)
2254 rsp_return
= query_dirty_rate(who
);
2255 g_assert(rsp_return
);
2257 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2260 return g_strcmp0(status
, "measuring");
2263 static void wait_for_calc_dirtyrate_complete(QTestState
*who
,
2266 int max_try_count
= 10000;
2267 usleep(time_s
* 1000000);
2269 while (!calc_dirtyrate_ready(who
) && max_try_count
--) {
2274 * Set the timeout with 10 s(max_try_count * 1000us),
2275 * if dirtyrate measurement not complete, fail test.
2277 g_assert_cmpint(max_try_count
, !=, 0);
2280 static int64_t get_dirty_rate(QTestState
*who
)
2285 const QListEntry
*entry
;
2289 rsp_return
= query_dirty_rate(who
);
2290 g_assert(rsp_return
);
2292 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2294 g_assert_cmpstr(status
, ==, "measured");
2296 rates
= qdict_get_qlist(rsp_return
, "vcpu-dirty-rate");
2297 g_assert(rates
&& !qlist_empty(rates
));
2299 entry
= qlist_first(rates
);
2302 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2305 dirtyrate
= qdict_get_try_int(rate
, "dirty-rate", -1);
2307 qobject_unref(rsp_return
);
2311 static int64_t get_limit_rate(QTestState
*who
)
2315 const QListEntry
*entry
;
2319 rsp_return
= query_vcpu_dirty_limit(who
);
2320 g_assert(rsp_return
);
2322 rates
= qdict_get_qlist(rsp_return
, "return");
2323 g_assert(rates
&& !qlist_empty(rates
));
2325 entry
= qlist_first(rates
);
2328 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2331 dirtyrate
= qdict_get_try_int(rate
, "limit-rate", -1);
2333 qobject_unref(rsp_return
);
2337 static QTestState
*dirtylimit_start_vm(void)
2339 QTestState
*vm
= NULL
;
2340 g_autofree gchar
*cmd
= NULL
;
2341 const char *arch
= qtest_get_arch();
2342 g_autofree
char *bootpath
= NULL
;
2344 assert((strcmp(arch
, "x86_64") == 0));
2345 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
2346 assert(sizeof(x86_bootsect
) == 512);
2347 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
2349 cmd
= g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
2350 "-name dirtylimit-test,debug-threads=on "
2352 "-serial file:%s/vm_serial "
2353 "-drive file=%s,format=raw ",
2356 vm
= qtest_init(cmd
);
2360 static void dirtylimit_stop_vm(QTestState
*vm
)
2363 cleanup("bootsect");
2364 cleanup("vm_serial");
2367 static void test_vcpu_dirty_limit(void)
2370 int64_t origin_rate
;
2373 int max_try_count
= 20;
2376 /* Start vm for vcpu dirtylimit test */
2377 vm
= dirtylimit_start_vm();
2379 /* Wait for the first serial output from the vm*/
2380 wait_for_serial("vm_serial");
2382 /* Do dirtyrate measurement with calc time equals 1s */
2383 calc_dirty_rate(vm
, 1);
2385 /* Sleep calc time and wait for calc dirtyrate complete */
2386 wait_for_calc_dirtyrate_complete(vm
, 1);
2388 /* Query original dirty page rate */
2389 origin_rate
= get_dirty_rate(vm
);
2391 /* VM booted from bootsect should dirty memory steadily */
2392 assert(origin_rate
!= 0);
2394 /* Setup quota dirty page rate at half of origin */
2395 quota_rate
= origin_rate
/ 2;
2397 /* Set dirtylimit */
2398 dirtylimit_set_all(vm
, quota_rate
);
2401 * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
2404 g_assert_cmpint(quota_rate
, ==, get_limit_rate(vm
));
2406 /* Sleep a bit to check if it take effect */
2410 * Check if dirtylimit take effect realistically, set the
2411 * timeout with 20 s(max_try_count * 1s), if dirtylimit
2412 * doesn't take effect, fail test.
2414 while (--max_try_count
) {
2415 calc_dirty_rate(vm
, 1);
2416 wait_for_calc_dirtyrate_complete(vm
, 1);
2417 rate
= get_dirty_rate(vm
);
2420 * Assume hitting if current rate is less
2421 * than quota rate (within accepting error)
2423 if (rate
< (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2429 g_assert_cmpint(hit
, ==, 1);
2434 /* Check if dirtylimit cancellation take effect */
2435 cancel_vcpu_dirty_limit(vm
);
2436 while (--max_try_count
) {
2437 calc_dirty_rate(vm
, 1);
2438 wait_for_calc_dirtyrate_complete(vm
, 1);
2439 rate
= get_dirty_rate(vm
);
2442 * Assume dirtylimit be canceled if current rate is
2443 * greater than quota rate (within accepting error)
2445 if (rate
> (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2451 g_assert_cmpint(hit
, ==, 1);
2452 dirtylimit_stop_vm(vm
);
2455 static bool kvm_dirty_ring_supported(void)
2457 #if defined(__linux__) && defined(HOST_X86_64)
2458 int ret
, kvm_fd
= open("/dev/kvm", O_RDONLY
);
2464 ret
= ioctl(kvm_fd
, KVM_CHECK_EXTENSION
, KVM_CAP_DIRTY_LOG_RING
);
2467 /* We test with 4096 slots */
2478 int main(int argc
, char **argv
)
2483 g_autoptr(GError
) err
= NULL
;
2486 g_test_init(&argc
, &argv
, NULL
);
2488 has_kvm
= qtest_has_accel("kvm");
2489 has_uffd
= ufd_version_check();
2490 arch
= qtest_get_arch();
2493 * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
2494 * is touchy due to race conditions on dirty bits (especially on PPC for
2497 if (g_str_equal(arch
, "ppc64") &&
2498 (!has_kvm
|| access("/sys/module/kvm_hv", F_OK
))) {
2499 g_test_message("Skipping test: kvm_hv not available");
2500 return g_test_run();
2504 * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
2505 * there until the problems are resolved
2507 if (g_str_equal(arch
, "s390x") && !has_kvm
) {
2508 g_test_message("Skipping test: s390x host with KVM is required");
2509 return g_test_run();
2512 tmpfs
= g_dir_make_tmp("migration-test-XXXXXX", &err
);
2514 g_test_message("Can't create temporary directory in %s: %s",
2515 g_get_tmp_dir(), err
->message
);
2519 module_call_init(MODULE_INIT_QOM
);
2522 qtest_add_func("/migration/postcopy/plain", test_postcopy
);
2523 qtest_add_func("/migration/postcopy/recovery/plain",
2524 test_postcopy_recovery
);
2525 qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_preempt
);
2526 qtest_add_func("/migration/postcopy/preempt/recovery/plain",
2527 test_postcopy_preempt_recovery
);
2530 qtest_add_func("/migration/bad_dest", test_baddest
);
2531 qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain
);
2532 qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle
);
2533 #ifdef CONFIG_GNUTLS
2534 qtest_add_func("/migration/precopy/unix/tls/psk",
2535 test_precopy_unix_tls_psk
);
2539 * NOTE: psk test is enough for postcopy, as other types of TLS
2540 * channels are tested under precopy. Here what we want to test is the
2541 * general postcopy path that has TLS channel enabled.
2543 qtest_add_func("/migration/postcopy/tls/psk", test_postcopy_tls_psk
);
2544 qtest_add_func("/migration/postcopy/recovery/tls/psk",
2545 test_postcopy_recovery_tls_psk
);
2546 qtest_add_func("/migration/postcopy/preempt/tls/psk",
2547 test_postcopy_preempt_tls_psk
);
2548 qtest_add_func("/migration/postcopy/preempt/recovery/tls/psk",
2549 test_postcopy_preempt_all
);
2552 qtest_add_func("/migration/precopy/unix/tls/x509/default-host",
2553 test_precopy_unix_tls_x509_default_host
);
2554 qtest_add_func("/migration/precopy/unix/tls/x509/override-host",
2555 test_precopy_unix_tls_x509_override_host
);
2556 #endif /* CONFIG_TASN1 */
2557 #endif /* CONFIG_GNUTLS */
2559 qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain
);
2560 #ifdef CONFIG_GNUTLS
2561 qtest_add_func("/migration/precopy/tcp/tls/psk/match",
2562 test_precopy_tcp_tls_psk_match
);
2563 qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch",
2564 test_precopy_tcp_tls_psk_mismatch
);
2566 qtest_add_func("/migration/precopy/tcp/tls/x509/default-host",
2567 test_precopy_tcp_tls_x509_default_host
);
2568 qtest_add_func("/migration/precopy/tcp/tls/x509/override-host",
2569 test_precopy_tcp_tls_x509_override_host
);
2570 qtest_add_func("/migration/precopy/tcp/tls/x509/mismatch-host",
2571 test_precopy_tcp_tls_x509_mismatch_host
);
2572 qtest_add_func("/migration/precopy/tcp/tls/x509/friendly-client",
2573 test_precopy_tcp_tls_x509_friendly_client
);
2574 qtest_add_func("/migration/precopy/tcp/tls/x509/hostile-client",
2575 test_precopy_tcp_tls_x509_hostile_client
);
2576 qtest_add_func("/migration/precopy/tcp/tls/x509/allow-anon-client",
2577 test_precopy_tcp_tls_x509_allow_anon_client
);
2578 qtest_add_func("/migration/precopy/tcp/tls/x509/reject-anon-client",
2579 test_precopy_tcp_tls_x509_reject_anon_client
);
2580 #endif /* CONFIG_TASN1 */
2581 #endif /* CONFIG_GNUTLS */
2583 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
2585 qtest_add_func("/migration/fd_proto", test_migrate_fd_proto
);
2587 qtest_add_func("/migration/validate_uuid", test_validate_uuid
);
2588 qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error
);
2589 qtest_add_func("/migration/validate_uuid_src_not_set",
2590 test_validate_uuid_src_not_set
);
2591 qtest_add_func("/migration/validate_uuid_dst_not_set",
2592 test_validate_uuid_dst_not_set
);
2594 * See explanation why this test is slow on function definition
2596 if (g_test_slow()) {
2597 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge
);
2599 qtest_add_func("/migration/multifd/tcp/plain/none",
2600 test_multifd_tcp_none
);
2602 * This test is flaky and sometimes fails in CI and otherwise:
2603 * don't run unless user opts in via environment variable.
2605 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2606 qtest_add_func("/migration/multifd/tcp/plain/cancel",
2607 test_multifd_tcp_cancel
);
2609 qtest_add_func("/migration/multifd/tcp/plain/zlib",
2610 test_multifd_tcp_zlib
);
2612 qtest_add_func("/migration/multifd/tcp/plain/zstd",
2613 test_multifd_tcp_zstd
);
2615 #ifdef CONFIG_GNUTLS
2616 qtest_add_func("/migration/multifd/tcp/tls/psk/match",
2617 test_multifd_tcp_tls_psk_match
);
2618 qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
2619 test_multifd_tcp_tls_psk_mismatch
);
2621 qtest_add_func("/migration/multifd/tcp/tls/x509/default-host",
2622 test_multifd_tcp_tls_x509_default_host
);
2623 qtest_add_func("/migration/multifd/tcp/tls/x509/override-host",
2624 test_multifd_tcp_tls_x509_override_host
);
2625 qtest_add_func("/migration/multifd/tcp/tls/x509/mismatch-host",
2626 test_multifd_tcp_tls_x509_mismatch_host
);
2627 qtest_add_func("/migration/multifd/tcp/tls/x509/allow-anon-client",
2628 test_multifd_tcp_tls_x509_allow_anon_client
);
2629 qtest_add_func("/migration/multifd/tcp/tls/x509/reject-anon-client",
2630 test_multifd_tcp_tls_x509_reject_anon_client
);
2631 #endif /* CONFIG_TASN1 */
2632 #endif /* CONFIG_GNUTLS */
2634 if (g_str_equal(arch
, "x86_64") && has_kvm
&& kvm_dirty_ring_supported()) {
2635 qtest_add_func("/migration/dirty_ring",
2636 test_precopy_unix_dirty_ring
);
2637 qtest_add_func("/migration/vcpu_dirty_limit",
2638 test_vcpu_dirty_limit
);
2643 g_assert_cmpint(ret
, ==, 0);
2647 g_test_message("unable to rmdir: path (%s): %s",
2648 tmpfs
, strerror(errno
));