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 long long migrate_get_parameter_bool(QTestState
*who
,
410 const char *parameter
)
415 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
416 result
= qdict_get_bool(rsp
, parameter
);
421 static void migrate_check_parameter_bool(QTestState
*who
, const char *parameter
,
426 result
= migrate_get_parameter_bool(who
, parameter
);
427 g_assert_cmpint(result
, ==, value
);
430 static void migrate_set_parameter_bool(QTestState
*who
, const char *parameter
,
436 "{ 'execute': 'migrate-set-parameters',"
437 "'arguments': { %s: %i } }",
439 g_assert(qdict_haskey(rsp
, "return"));
441 migrate_check_parameter_bool(who
, parameter
, value
);
444 static void migrate_ensure_non_converge(QTestState
*who
)
446 /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
447 migrate_set_parameter_int(who
, "max-bandwidth", 3 * 1000 * 1000);
448 migrate_set_parameter_int(who
, "downtime-limit", 1);
451 static void migrate_ensure_converge(QTestState
*who
)
453 /* Should converge with 30s downtime + 1 gbs bandwidth limit */
454 migrate_set_parameter_int(who
, "max-bandwidth", 1 * 1000 * 1000 * 1000);
455 migrate_set_parameter_int(who
, "downtime-limit", 30 * 1000);
458 static void migrate_pause(QTestState
*who
)
462 rsp
= wait_command(who
, "{ 'execute': 'migrate-pause' }");
466 static void migrate_continue(QTestState
*who
, const char *state
)
470 rsp
= wait_command(who
,
471 "{ 'execute': 'migrate-continue',"
472 " 'arguments': { 'state': %s } }",
477 static void migrate_recover(QTestState
*who
, const char *uri
)
481 rsp
= wait_command(who
,
482 "{ 'execute': 'migrate-recover', "
483 " 'id': 'recover-cmd', "
484 " 'arguments': { 'uri': %s } }",
489 static void migrate_cancel(QTestState
*who
)
493 rsp
= wait_command(who
, "{ 'execute': 'migrate_cancel' }");
497 static void migrate_set_capability(QTestState
*who
, const char *capability
,
503 "{ 'execute': 'migrate-set-capabilities',"
505 "'capabilities': [ { "
506 "'capability': %s, 'state': %i } ] } }",
508 g_assert(qdict_haskey(rsp
, "return"));
512 static void migrate_postcopy_start(QTestState
*from
, QTestState
*to
)
516 rsp
= wait_command(from
, "{ 'execute': 'migrate-start-postcopy' }");
520 qtest_qmp_eventwait(from
, "STOP");
523 qtest_qmp_eventwait(to
, "RESUME");
528 * QTEST_LOG=1 may override this. When QTEST_LOG=1, we always dump errors
529 * unconditionally, because it means the user would like to be verbose.
533 /* only launch the target process */
535 /* Use dirty ring if true; dirty logging otherwise */
537 const char *opts_source
;
538 const char *opts_target
;
542 * A hook that runs after the src and dst QEMUs have been
543 * created, but before the migration is started. This can
544 * be used to set migration parameters and capabilities.
546 * Returns: NULL, or a pointer to opaque state to be
547 * later passed to the TestMigrateFinishHook
549 typedef void * (*TestMigrateStartHook
)(QTestState
*from
,
553 * A hook that runs after the migration has finished,
554 * regardless of whether it succeeded or failed, but
555 * before QEMU has terminated (unless it self-terminated
556 * due to migration error)
558 * @opaque is a pointer to state previously returned
559 * by the TestMigrateStartHook if any, or NULL.
561 typedef void (*TestMigrateFinishHook
)(QTestState
*from
,
566 /* Optional: fine tune start parameters */
569 /* Required: the URI for the dst QEMU to listen on */
570 const char *listen_uri
;
573 * Optional: the URI for the src QEMU to connect to
574 * If NULL, then it will query the dst QEMU for its actual
575 * listening address and use that as the connect address.
576 * This allows for dynamically picking a free TCP port.
578 const char *connect_uri
;
580 /* Optional: callback to run at start to set migration parameters */
581 TestMigrateStartHook start_hook
;
582 /* Optional: callback to run at finish to cleanup */
583 TestMigrateFinishHook finish_hook
;
586 * Optional: normally we expect the migration process to complete.
588 * There can be a variety of reasons and stages in which failure
589 * can happen during tests.
591 * If a failure is expected to happen at time of establishing
592 * the connection, then MIG_TEST_FAIL will indicate that the dst
593 * QEMU is expected to stay running and accept future migration
596 * If a failure is expected to happen while processing the
597 * migration stream, then MIG_TEST_FAIL_DEST_QUIT_ERR will indicate
598 * that the dst QEMU is expected to quit with non-zero exit status
601 /* This test should succeed, the default */
602 MIG_TEST_SUCCEED
= 0,
603 /* This test should fail, dest qemu should keep alive */
605 /* This test should fail, dest qemu should fail with abnormal status */
606 MIG_TEST_FAIL_DEST_QUIT_ERR
,
609 /* Optional: set number of migration passes to wait for */
610 unsigned int iterations
;
612 /* Postcopy specific fields */
614 bool postcopy_preempt
;
617 static int test_migrate_start(QTestState
**from
, QTestState
**to
,
618 const char *uri
, MigrateStart
*args
)
620 g_autofree gchar
*arch_source
= NULL
;
621 g_autofree gchar
*arch_target
= NULL
;
622 g_autofree gchar
*cmd_source
= NULL
;
623 g_autofree gchar
*cmd_target
= NULL
;
624 const gchar
*ignore_stderr
;
625 g_autofree
char *bootpath
= NULL
;
626 g_autofree
char *shmem_opts
= NULL
;
627 g_autofree
char *shmem_path
= NULL
;
628 const char *arch
= qtest_get_arch();
629 const char *machine_opts
= NULL
;
630 const char *memory_size
;
632 if (args
->use_shmem
) {
633 if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR
)) {
634 g_test_skip("/dev/shm is not supported");
640 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
641 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
642 /* the assembled x86 boot sector should be exactly one sector large */
643 assert(sizeof(x86_bootsect
) == 512);
644 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
645 memory_size
= "150M";
646 arch_source
= g_strdup_printf("-drive file=%s,format=raw", bootpath
);
647 arch_target
= g_strdup(arch_source
);
648 start_address
= X86_TEST_MEM_START
;
649 end_address
= X86_TEST_MEM_END
;
650 } else if (g_str_equal(arch
, "s390x")) {
651 init_bootfile(bootpath
, s390x_elf
, sizeof(s390x_elf
));
652 memory_size
= "128M";
653 arch_source
= g_strdup_printf("-bios %s", bootpath
);
654 arch_target
= g_strdup(arch_source
);
655 start_address
= S390_TEST_MEM_START
;
656 end_address
= S390_TEST_MEM_END
;
657 } else if (strcmp(arch
, "ppc64") == 0) {
658 machine_opts
= "vsmt=8";
659 memory_size
= "256M";
660 start_address
= PPC_TEST_MEM_START
;
661 end_address
= PPC_TEST_MEM_END
;
662 arch_source
= g_strdup_printf("-nodefaults "
663 "-prom-env 'use-nvramrc?=true' -prom-env "
664 "'nvramrc=hex .\" _\" begin %x %x "
665 "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
666 "until'", end_address
, start_address
);
667 arch_target
= g_strdup("");
668 } else if (strcmp(arch
, "aarch64") == 0) {
669 init_bootfile(bootpath
, aarch64_kernel
, sizeof(aarch64_kernel
));
670 machine_opts
= "virt,gic-version=max";
671 memory_size
= "150M";
672 arch_source
= g_strdup_printf("-cpu max "
675 arch_target
= g_strdup(arch_source
);
676 start_address
= ARM_TEST_MEM_START
;
677 end_address
= ARM_TEST_MEM_END
;
679 g_assert(sizeof(aarch64_kernel
) <= ARM_TEST_MAX_KERNEL_SIZE
);
681 g_assert_not_reached();
684 if (!getenv("QTEST_LOG") && args
->hide_stderr
) {
686 ignore_stderr
= "2>/dev/null";
689 * On Windows the QEMU executable is created via CreateProcess() and
690 * IO redirection does not work, so don't bother adding IO redirection
691 * to the command line.
699 if (args
->use_shmem
) {
700 shmem_path
= g_strdup_printf("/dev/shm/qemu-%d", getpid());
701 shmem_opts
= g_strdup_printf(
702 "-object memory-backend-file,id=mem0,size=%s"
703 ",mem-path=%s,share=on -numa node,memdev=mem0",
704 memory_size
, shmem_path
);
707 shmem_opts
= g_strdup("");
710 cmd_source
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
711 "-name source,debug-threads=on "
713 "-serial file:%s/src_serial "
715 args
->use_dirty_ring
?
716 ",dirty-ring-size=4096" : "",
717 machine_opts
? " -machine " : "",
718 machine_opts
? machine_opts
: "",
720 arch_source
, shmem_opts
,
721 args
->opts_source
? args
->opts_source
: "",
723 if (!args
->only_target
) {
724 *from
= qtest_init(cmd_source
);
727 cmd_target
= g_strdup_printf("-accel kvm%s -accel tcg%s%s "
728 "-name target,debug-threads=on "
730 "-serial file:%s/dest_serial "
733 args
->use_dirty_ring
?
734 ",dirty-ring-size=4096" : "",
735 machine_opts
? " -machine " : "",
736 machine_opts
? machine_opts
: "",
737 memory_size
, tmpfs
, uri
,
738 arch_target
, shmem_opts
,
739 args
->opts_target
? args
->opts_target
: "",
741 *to
= qtest_init(cmd_target
);
744 * Remove shmem file immediately to avoid memory leak in test failed case.
745 * It's valid becase QEMU has already opened this file
747 if (args
->use_shmem
) {
754 static void test_migrate_end(QTestState
*from
, QTestState
*to
, bool test_dest
)
756 unsigned char dest_byte_a
, dest_byte_b
, dest_byte_c
, dest_byte_d
;
761 qtest_memread(to
, start_address
, &dest_byte_a
, 1);
763 /* Destination still running, wait for a byte to change */
765 qtest_memread(to
, start_address
, &dest_byte_b
, 1);
767 } while (dest_byte_a
== dest_byte_b
);
769 qtest_qmp_discard_response(to
, "{ 'execute' : 'stop'}");
771 /* With it stopped, check nothing changes */
772 qtest_memread(to
, start_address
, &dest_byte_c
, 1);
774 qtest_memread(to
, start_address
, &dest_byte_d
, 1);
775 g_assert_cmpint(dest_byte_c
, ==, dest_byte_d
);
777 check_guests_ram(to
);
783 cleanup("migsocket");
784 cleanup("src_serial");
785 cleanup("dest_serial");
789 struct TestMigrateTLSPSKData
{
797 test_migrate_tls_psk_start_common(QTestState
*from
,
801 struct TestMigrateTLSPSKData
*data
=
802 g_new0(struct TestMigrateTLSPSKData
, 1);
805 data
->workdir
= g_strdup_printf("%s/tlscredspsk0", tmpfs
);
806 data
->pskfile
= g_strdup_printf("%s/%s", data
->workdir
,
807 QCRYPTO_TLS_CREDS_PSKFILE
);
808 g_mkdir_with_parents(data
->workdir
, 0700);
809 test_tls_psk_init(data
->pskfile
);
812 data
->workdiralt
= g_strdup_printf("%s/tlscredspskalt0", tmpfs
);
813 data
->pskfilealt
= g_strdup_printf("%s/%s", data
->workdiralt
,
814 QCRYPTO_TLS_CREDS_PSKFILE
);
815 g_mkdir_with_parents(data
->workdiralt
, 0700);
816 test_tls_psk_init_alt(data
->pskfilealt
);
819 rsp
= wait_command(from
,
820 "{ 'execute': 'object-add',"
821 " 'arguments': { 'qom-type': 'tls-creds-psk',"
822 " 'id': 'tlscredspsk0',"
823 " 'endpoint': 'client',"
825 " 'username': 'qemu'} }",
829 rsp
= wait_command(to
,
830 "{ 'execute': 'object-add',"
831 " 'arguments': { 'qom-type': 'tls-creds-psk',"
832 " 'id': 'tlscredspsk0',"
833 " 'endpoint': 'server',"
835 mismatch
? data
->workdiralt
: data
->workdir
);
838 migrate_set_parameter_str(from
, "tls-creds", "tlscredspsk0");
839 migrate_set_parameter_str(to
, "tls-creds", "tlscredspsk0");
845 test_migrate_tls_psk_start_match(QTestState
*from
,
848 return test_migrate_tls_psk_start_common(from
, to
, false);
852 test_migrate_tls_psk_start_mismatch(QTestState
*from
,
855 return test_migrate_tls_psk_start_common(from
, to
, true);
859 test_migrate_tls_psk_finish(QTestState
*from
,
863 struct TestMigrateTLSPSKData
*data
= opaque
;
865 test_tls_psk_cleanup(data
->pskfile
);
866 if (data
->pskfilealt
) {
867 test_tls_psk_cleanup(data
->pskfilealt
);
869 rmdir(data
->workdir
);
870 if (data
->workdiralt
) {
871 rmdir(data
->workdiralt
);
874 g_free(data
->workdiralt
);
875 g_free(data
->pskfilealt
);
876 g_free(data
->workdir
);
877 g_free(data
->pskfile
);
890 } TestMigrateTLSX509Data
;
897 const char *certhostname
;
898 const char *certipaddr
;
899 } TestMigrateTLSX509
;
902 test_migrate_tls_x509_start_common(QTestState
*from
,
904 TestMigrateTLSX509
*args
)
906 TestMigrateTLSX509Data
*data
= g_new0(TestMigrateTLSX509Data
, 1);
909 data
->workdir
= g_strdup_printf("%s/tlscredsx5090", tmpfs
);
910 data
->keyfile
= g_strdup_printf("%s/key.pem", data
->workdir
);
912 data
->cacert
= g_strdup_printf("%s/ca-cert.pem", data
->workdir
);
913 data
->serverkey
= g_strdup_printf("%s/server-key.pem", data
->workdir
);
914 data
->servercert
= g_strdup_printf("%s/server-cert.pem", data
->workdir
);
915 if (args
->clientcert
) {
916 data
->clientkey
= g_strdup_printf("%s/client-key.pem", data
->workdir
);
917 data
->clientcert
= g_strdup_printf("%s/client-cert.pem", data
->workdir
);
920 g_mkdir_with_parents(data
->workdir
, 0700);
922 test_tls_init(data
->keyfile
);
924 g_assert(link(data
->keyfile
, data
->serverkey
) == 0);
926 g_assert(CreateHardLink(data
->serverkey
, data
->keyfile
, NULL
) != 0);
928 if (args
->clientcert
) {
930 g_assert(link(data
->keyfile
, data
->clientkey
) == 0);
932 g_assert(CreateHardLink(data
->clientkey
, data
->keyfile
, NULL
) != 0);
936 TLS_ROOT_REQ_SIMPLE(cacertreq
, data
->cacert
);
937 if (args
->clientcert
) {
938 TLS_CERT_REQ_SIMPLE_CLIENT(servercertreq
, cacertreq
,
939 args
->hostileclient
?
940 QCRYPTO_TLS_TEST_CLIENT_HOSTILE_NAME
:
941 QCRYPTO_TLS_TEST_CLIENT_NAME
,
945 TLS_CERT_REQ_SIMPLE_SERVER(clientcertreq
, cacertreq
,
950 rsp
= wait_command(from
,
951 "{ 'execute': 'object-add',"
952 " 'arguments': { 'qom-type': 'tls-creds-x509',"
953 " 'id': 'tlscredsx509client0',"
954 " 'endpoint': 'client',"
956 " 'sanity-check': true,"
957 " 'verify-peer': true} }",
960 migrate_set_parameter_str(from
, "tls-creds", "tlscredsx509client0");
961 if (args
->certhostname
) {
962 migrate_set_parameter_str(from
, "tls-hostname", args
->certhostname
);
965 rsp
= wait_command(to
,
966 "{ 'execute': 'object-add',"
967 " 'arguments': { 'qom-type': 'tls-creds-x509',"
968 " 'id': 'tlscredsx509server0',"
969 " 'endpoint': 'server',"
971 " 'sanity-check': true,"
972 " 'verify-peer': %i} }",
973 data
->workdir
, args
->verifyclient
);
975 migrate_set_parameter_str(to
, "tls-creds", "tlscredsx509server0");
977 if (args
->authzclient
) {
978 rsp
= wait_command(to
,
979 "{ 'execute': 'object-add',"
980 " 'arguments': { 'qom-type': 'authz-simple',"
981 " 'id': 'tlsauthz0',"
982 " 'identity': %s} }",
983 "CN=" QCRYPTO_TLS_TEST_CLIENT_NAME
);
984 migrate_set_parameter_str(to
, "tls-authz", "tlsauthz0");
991 * The normal case: match server's cert hostname against
992 * whatever host we were telling QEMU to connect to (if any)
995 test_migrate_tls_x509_start_default_host(QTestState
*from
,
998 TestMigrateTLSX509 args
= {
999 .verifyclient
= true,
1001 .certipaddr
= "127.0.0.1"
1003 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1007 * The unusual case: the server's cert is different from
1008 * the address we're telling QEMU to connect to (if any),
1009 * so we must give QEMU an explicit hostname to validate
1012 test_migrate_tls_x509_start_override_host(QTestState
*from
,
1015 TestMigrateTLSX509 args
= {
1016 .verifyclient
= true,
1018 .certhostname
= "qemu.org",
1020 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1024 * The unusual case: the server's cert is different from
1025 * the address we're telling QEMU to connect to, and so we
1026 * expect the client to reject the server
1029 test_migrate_tls_x509_start_mismatch_host(QTestState
*from
,
1032 TestMigrateTLSX509 args
= {
1033 .verifyclient
= true,
1035 .certipaddr
= "10.0.0.1",
1037 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1041 test_migrate_tls_x509_start_friendly_client(QTestState
*from
,
1044 TestMigrateTLSX509 args
= {
1045 .verifyclient
= true,
1047 .authzclient
= true,
1048 .certipaddr
= "127.0.0.1",
1050 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1054 test_migrate_tls_x509_start_hostile_client(QTestState
*from
,
1057 TestMigrateTLSX509 args
= {
1058 .verifyclient
= true,
1060 .hostileclient
= true,
1061 .authzclient
= true,
1062 .certipaddr
= "127.0.0.1",
1064 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1068 * The case with no client certificate presented,
1069 * and no server verification
1072 test_migrate_tls_x509_start_allow_anon_client(QTestState
*from
,
1075 TestMigrateTLSX509 args
= {
1076 .certipaddr
= "127.0.0.1",
1078 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1082 * The case with no client certificate presented,
1083 * and server verification rejecting
1086 test_migrate_tls_x509_start_reject_anon_client(QTestState
*from
,
1089 TestMigrateTLSX509 args
= {
1090 .verifyclient
= true,
1091 .certipaddr
= "127.0.0.1",
1093 return test_migrate_tls_x509_start_common(from
, to
, &args
);
1097 test_migrate_tls_x509_finish(QTestState
*from
,
1101 TestMigrateTLSX509Data
*data
= opaque
;
1103 test_tls_cleanup(data
->keyfile
);
1104 g_free(data
->keyfile
);
1106 unlink(data
->cacert
);
1107 g_free(data
->cacert
);
1108 unlink(data
->servercert
);
1109 g_free(data
->servercert
);
1110 unlink(data
->serverkey
);
1111 g_free(data
->serverkey
);
1113 if (data
->clientcert
) {
1114 unlink(data
->clientcert
);
1115 g_free(data
->clientcert
);
1117 if (data
->clientkey
) {
1118 unlink(data
->clientkey
);
1119 g_free(data
->clientkey
);
1122 rmdir(data
->workdir
);
1123 g_free(data
->workdir
);
1127 #endif /* CONFIG_TASN1 */
1128 #endif /* CONFIG_GNUTLS */
1131 test_migrate_compress_start(QTestState
*from
,
1134 migrate_set_parameter_int(from
, "compress-level", 1);
1135 migrate_set_parameter_int(from
, "compress-threads", 4);
1136 migrate_set_parameter_bool(from
, "compress-wait-thread", true);
1137 migrate_set_parameter_int(to
, "decompress-threads", 4);
1139 migrate_set_capability(from
, "compress", true);
1140 migrate_set_capability(to
, "compress", true);
1146 test_migrate_compress_nowait_start(QTestState
*from
,
1149 migrate_set_parameter_int(from
, "compress-level", 9);
1150 migrate_set_parameter_int(from
, "compress-threads", 1);
1151 migrate_set_parameter_bool(from
, "compress-wait-thread", false);
1152 migrate_set_parameter_int(to
, "decompress-threads", 1);
1154 migrate_set_capability(from
, "compress", true);
1155 migrate_set_capability(to
, "compress", true);
1160 static int migrate_postcopy_prepare(QTestState
**from_ptr
,
1161 QTestState
**to_ptr
,
1162 MigrateCommon
*args
)
1164 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1165 QTestState
*from
, *to
;
1167 if (test_migrate_start(&from
, &to
, uri
, &args
->start
)) {
1171 if (args
->start_hook
) {
1172 args
->postcopy_data
= args
->start_hook(from
, to
);
1175 migrate_set_capability(from
, "postcopy-ram", true);
1176 migrate_set_capability(to
, "postcopy-ram", true);
1177 migrate_set_capability(to
, "postcopy-blocktime", true);
1179 if (args
->postcopy_preempt
) {
1180 migrate_set_capability(from
, "postcopy-preempt", true);
1181 migrate_set_capability(to
, "postcopy-preempt", true);
1184 migrate_ensure_non_converge(from
);
1186 /* Wait for the first serial output from the source */
1187 wait_for_serial("src_serial");
1189 migrate_qmp(from
, uri
, "{}");
1191 wait_for_migration_pass(from
);
1199 static void migrate_postcopy_complete(QTestState
*from
, QTestState
*to
,
1200 MigrateCommon
*args
)
1202 wait_for_migration_complete(from
);
1204 /* Make sure we get at least one "B" on destination */
1205 wait_for_serial("dest_serial");
1207 if (uffd_feature_thread_id
) {
1211 if (args
->finish_hook
) {
1212 args
->finish_hook(from
, to
, args
->postcopy_data
);
1213 args
->postcopy_data
= NULL
;
1216 test_migrate_end(from
, to
, true);
1219 static void test_postcopy_common(MigrateCommon
*args
)
1221 QTestState
*from
, *to
;
1223 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1226 migrate_postcopy_start(from
, to
);
1227 migrate_postcopy_complete(from
, to
, args
);
1230 static void test_postcopy(void)
1232 MigrateCommon args
= { };
1234 test_postcopy_common(&args
);
1237 static void test_postcopy_compress(void)
1239 MigrateCommon args
= {
1240 .start_hook
= test_migrate_compress_start
1243 test_postcopy_common(&args
);
1246 static void test_postcopy_preempt(void)
1248 MigrateCommon args
= {
1249 .postcopy_preempt
= true,
1252 test_postcopy_common(&args
);
1255 #ifdef CONFIG_GNUTLS
1256 static void test_postcopy_tls_psk(void)
1258 MigrateCommon args
= {
1259 .start_hook
= test_migrate_tls_psk_start_match
,
1260 .finish_hook
= test_migrate_tls_psk_finish
,
1263 test_postcopy_common(&args
);
1266 static void test_postcopy_preempt_tls_psk(void)
1268 MigrateCommon args
= {
1269 .postcopy_preempt
= true,
1270 .start_hook
= test_migrate_tls_psk_start_match
,
1271 .finish_hook
= test_migrate_tls_psk_finish
,
1274 test_postcopy_common(&args
);
1278 static void test_postcopy_recovery_common(MigrateCommon
*args
)
1280 QTestState
*from
, *to
;
1281 g_autofree
char *uri
= NULL
;
1283 /* Always hide errors for postcopy recover tests since they're expected */
1284 args
->start
.hide_stderr
= true;
1286 if (migrate_postcopy_prepare(&from
, &to
, args
)) {
1290 /* Turn postcopy speed down, 4K/s is slow enough on any machines */
1291 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 4096);
1293 /* Now we start the postcopy */
1294 migrate_postcopy_start(from
, to
);
1297 * Wait until postcopy is really started; we can only run the
1298 * migrate-pause command during a postcopy
1300 wait_for_migration_status(from
, "postcopy-active", NULL
);
1303 * Manually stop the postcopy migration. This emulates a network
1304 * failure with the migration socket
1306 migrate_pause(from
);
1309 * Wait for destination side to reach postcopy-paused state. The
1310 * migrate-recover command can only succeed if destination machine
1311 * is in the paused state
1313 wait_for_migration_status(to
, "postcopy-paused",
1314 (const char * []) { "failed", "active",
1315 "completed", NULL
});
1318 * Create a new socket to emulate a new channel that is different
1319 * from the broken migration channel; tell the destination to
1320 * listen to the new port
1322 uri
= g_strdup_printf("unix:%s/migsocket-recover", tmpfs
);
1323 migrate_recover(to
, uri
);
1326 * Try to rebuild the migration channel using the resume flag and
1327 * the newly created channel
1329 wait_for_migration_status(from
, "postcopy-paused",
1330 (const char * []) { "failed", "active",
1331 "completed", NULL
});
1332 migrate_qmp(from
, uri
, "{'resume': true}");
1334 /* Restore the postcopy bandwidth to unlimited */
1335 migrate_set_parameter_int(from
, "max-postcopy-bandwidth", 0);
1337 migrate_postcopy_complete(from
, to
, args
);
1340 static void test_postcopy_recovery(void)
1342 MigrateCommon args
= { };
1344 test_postcopy_recovery_common(&args
);
1347 static void test_postcopy_recovery_compress(void)
1349 MigrateCommon args
= {
1350 .start_hook
= test_migrate_compress_start
1353 test_postcopy_recovery_common(&args
);
1356 #ifdef CONFIG_GNUTLS
1357 static void test_postcopy_recovery_tls_psk(void)
1359 MigrateCommon args
= {
1360 .start_hook
= test_migrate_tls_psk_start_match
,
1361 .finish_hook
= test_migrate_tls_psk_finish
,
1364 test_postcopy_recovery_common(&args
);
1368 static void test_postcopy_preempt_recovery(void)
1370 MigrateCommon args
= {
1371 .postcopy_preempt
= true,
1374 test_postcopy_recovery_common(&args
);
1377 #ifdef CONFIG_GNUTLS
1378 /* This contains preempt+recovery+tls test altogether */
1379 static void test_postcopy_preempt_all(void)
1381 MigrateCommon args
= {
1382 .postcopy_preempt
= true,
1383 .start_hook
= test_migrate_tls_psk_start_match
,
1384 .finish_hook
= test_migrate_tls_psk_finish
,
1387 test_postcopy_recovery_common(&args
);
1392 static void test_baddest(void)
1394 MigrateStart args
= {
1397 QTestState
*from
, *to
;
1399 if (test_migrate_start(&from
, &to
, "tcp:127.0.0.1:0", &args
)) {
1402 migrate_qmp(from
, "tcp:127.0.0.1:0", "{}");
1403 wait_for_migration_fail(from
, false);
1404 test_migrate_end(from
, to
, false);
1407 static void test_precopy_common(MigrateCommon
*args
)
1409 QTestState
*from
, *to
;
1410 void *data_hook
= NULL
;
1412 if (test_migrate_start(&from
, &to
, args
->listen_uri
, &args
->start
)) {
1416 migrate_ensure_non_converge(from
);
1418 if (args
->start_hook
) {
1419 data_hook
= args
->start_hook(from
, to
);
1422 /* Wait for the first serial output from the source */
1423 if (args
->result
== MIG_TEST_SUCCEED
) {
1424 wait_for_serial("src_serial");
1427 if (!args
->connect_uri
) {
1428 g_autofree
char *local_connect_uri
=
1429 migrate_get_socket_address(to
, "socket-address");
1430 migrate_qmp(from
, local_connect_uri
, "{}");
1432 migrate_qmp(from
, args
->connect_uri
, "{}");
1436 if (args
->result
!= MIG_TEST_SUCCEED
) {
1437 bool allow_active
= args
->result
== MIG_TEST_FAIL
;
1438 wait_for_migration_fail(from
, allow_active
);
1440 if (args
->result
== MIG_TEST_FAIL_DEST_QUIT_ERR
) {
1441 qtest_set_expected_status(to
, EXIT_FAILURE
);
1444 if (args
->iterations
) {
1445 while (args
->iterations
--) {
1446 wait_for_migration_pass(from
);
1449 wait_for_migration_pass(from
);
1452 migrate_ensure_converge(from
);
1454 /* We do this first, as it has a timeout to stop us
1455 * hanging forever if migration didn't converge */
1456 wait_for_migration_complete(from
);
1459 qtest_qmp_eventwait(from
, "STOP");
1462 qtest_qmp_eventwait(to
, "RESUME");
1464 wait_for_serial("dest_serial");
1467 if (args
->finish_hook
) {
1468 args
->finish_hook(from
, to
, data_hook
);
1471 test_migrate_end(from
, to
, args
->result
== MIG_TEST_SUCCEED
);
1474 static void test_precopy_unix_plain(void)
1476 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1477 MigrateCommon args
= {
1482 test_precopy_common(&args
);
1486 static void test_precopy_unix_dirty_ring(void)
1488 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1489 MigrateCommon args
= {
1491 .use_dirty_ring
= true,
1497 test_precopy_common(&args
);
1500 #ifdef CONFIG_GNUTLS
1501 static void test_precopy_unix_tls_psk(void)
1503 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1504 MigrateCommon args
= {
1507 .start_hook
= test_migrate_tls_psk_start_match
,
1508 .finish_hook
= test_migrate_tls_psk_finish
,
1511 test_precopy_common(&args
);
1515 static void test_precopy_unix_tls_x509_default_host(void)
1517 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1518 MigrateCommon args
= {
1520 .hide_stderr
= true,
1524 .start_hook
= test_migrate_tls_x509_start_default_host
,
1525 .finish_hook
= test_migrate_tls_x509_finish
,
1526 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1529 test_precopy_common(&args
);
1532 static void test_precopy_unix_tls_x509_override_host(void)
1534 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1535 MigrateCommon args
= {
1538 .start_hook
= test_migrate_tls_x509_start_override_host
,
1539 .finish_hook
= test_migrate_tls_x509_finish
,
1542 test_precopy_common(&args
);
1544 #endif /* CONFIG_TASN1 */
1545 #endif /* CONFIG_GNUTLS */
1548 /* Currently upset on aarch64 TCG */
1549 static void test_ignore_shared(void)
1551 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1552 QTestState
*from
, *to
;
1554 if (test_migrate_start(&from
, &to
, uri
, false, true, NULL
, NULL
)) {
1558 migrate_set_capability(from
, "x-ignore-shared", true);
1559 migrate_set_capability(to
, "x-ignore-shared", true);
1561 /* Wait for the first serial output from the source */
1562 wait_for_serial("src_serial");
1564 migrate_qmp(from
, uri
, "{}");
1566 wait_for_migration_pass(from
);
1569 qtest_qmp_eventwait(from
, "STOP");
1572 qtest_qmp_eventwait(to
, "RESUME");
1574 wait_for_serial("dest_serial");
1575 wait_for_migration_complete(from
);
1577 /* Check whether shared RAM has been really skipped */
1578 g_assert_cmpint(read_ram_property_int(from
, "transferred"), <, 1024 * 1024);
1580 test_migrate_end(from
, to
, true);
1585 test_migrate_xbzrle_start(QTestState
*from
,
1588 migrate_set_parameter_int(from
, "xbzrle-cache-size", 33554432);
1590 migrate_set_capability(from
, "xbzrle", true);
1591 migrate_set_capability(to
, "xbzrle", true);
1596 static void test_precopy_unix_xbzrle(void)
1598 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1599 MigrateCommon args
= {
1603 .start_hook
= test_migrate_xbzrle_start
,
1608 test_precopy_common(&args
);
1611 static void test_precopy_unix_compress(void)
1613 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1614 MigrateCommon args
= {
1617 .start_hook
= test_migrate_compress_start
,
1619 * Test that no invalid thread state is left over from
1620 * the previous iteration.
1625 test_precopy_common(&args
);
1628 static void test_precopy_unix_compress_nowait(void)
1630 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1631 MigrateCommon args
= {
1634 .start_hook
= test_migrate_compress_nowait_start
,
1636 * Test that no invalid thread state is left over from
1637 * the previous iteration.
1642 test_precopy_common(&args
);
1645 static void test_precopy_tcp_plain(void)
1647 MigrateCommon args
= {
1648 .listen_uri
= "tcp:127.0.0.1:0",
1651 test_precopy_common(&args
);
1654 #ifdef CONFIG_GNUTLS
1655 static void test_precopy_tcp_tls_psk_match(void)
1657 MigrateCommon args
= {
1658 .listen_uri
= "tcp:127.0.0.1:0",
1659 .start_hook
= test_migrate_tls_psk_start_match
,
1660 .finish_hook
= test_migrate_tls_psk_finish
,
1663 test_precopy_common(&args
);
1666 static void test_precopy_tcp_tls_psk_mismatch(void)
1668 MigrateCommon args
= {
1670 .hide_stderr
= true,
1672 .listen_uri
= "tcp:127.0.0.1:0",
1673 .start_hook
= test_migrate_tls_psk_start_mismatch
,
1674 .finish_hook
= test_migrate_tls_psk_finish
,
1675 .result
= MIG_TEST_FAIL
,
1678 test_precopy_common(&args
);
1682 static void test_precopy_tcp_tls_x509_default_host(void)
1684 MigrateCommon args
= {
1685 .listen_uri
= "tcp:127.0.0.1:0",
1686 .start_hook
= test_migrate_tls_x509_start_default_host
,
1687 .finish_hook
= test_migrate_tls_x509_finish
,
1690 test_precopy_common(&args
);
1693 static void test_precopy_tcp_tls_x509_override_host(void)
1695 MigrateCommon args
= {
1696 .listen_uri
= "tcp:127.0.0.1:0",
1697 .start_hook
= test_migrate_tls_x509_start_override_host
,
1698 .finish_hook
= test_migrate_tls_x509_finish
,
1701 test_precopy_common(&args
);
1704 static void test_precopy_tcp_tls_x509_mismatch_host(void)
1706 MigrateCommon args
= {
1708 .hide_stderr
= true,
1710 .listen_uri
= "tcp:127.0.0.1:0",
1711 .start_hook
= test_migrate_tls_x509_start_mismatch_host
,
1712 .finish_hook
= test_migrate_tls_x509_finish
,
1713 .result
= MIG_TEST_FAIL_DEST_QUIT_ERR
,
1716 test_precopy_common(&args
);
1719 static void test_precopy_tcp_tls_x509_friendly_client(void)
1721 MigrateCommon args
= {
1722 .listen_uri
= "tcp:127.0.0.1:0",
1723 .start_hook
= test_migrate_tls_x509_start_friendly_client
,
1724 .finish_hook
= test_migrate_tls_x509_finish
,
1727 test_precopy_common(&args
);
1730 static void test_precopy_tcp_tls_x509_hostile_client(void)
1732 MigrateCommon args
= {
1734 .hide_stderr
= true,
1736 .listen_uri
= "tcp:127.0.0.1:0",
1737 .start_hook
= test_migrate_tls_x509_start_hostile_client
,
1738 .finish_hook
= test_migrate_tls_x509_finish
,
1739 .result
= MIG_TEST_FAIL
,
1742 test_precopy_common(&args
);
1745 static void test_precopy_tcp_tls_x509_allow_anon_client(void)
1747 MigrateCommon args
= {
1748 .listen_uri
= "tcp:127.0.0.1:0",
1749 .start_hook
= test_migrate_tls_x509_start_allow_anon_client
,
1750 .finish_hook
= test_migrate_tls_x509_finish
,
1753 test_precopy_common(&args
);
1756 static void test_precopy_tcp_tls_x509_reject_anon_client(void)
1758 MigrateCommon args
= {
1760 .hide_stderr
= true,
1762 .listen_uri
= "tcp:127.0.0.1:0",
1763 .start_hook
= test_migrate_tls_x509_start_reject_anon_client
,
1764 .finish_hook
= test_migrate_tls_x509_finish
,
1765 .result
= MIG_TEST_FAIL
,
1768 test_precopy_common(&args
);
1770 #endif /* CONFIG_TASN1 */
1771 #endif /* CONFIG_GNUTLS */
1774 static void *test_migrate_fd_start_hook(QTestState
*from
,
1781 /* Create two connected sockets for migration */
1782 ret
= qemu_socketpair(PF_LOCAL
, SOCK_STREAM
, 0, pair
);
1783 g_assert_cmpint(ret
, ==, 0);
1785 /* Send the 1st socket to the target */
1786 rsp
= wait_command_fd(to
, pair
[0],
1787 "{ 'execute': 'getfd',"
1788 " 'arguments': { 'fdname': 'fd-mig' }}");
1792 /* Start incoming migration from the 1st socket */
1793 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
1794 " 'arguments': { 'uri': 'fd:fd-mig' }}");
1797 /* Send the 2nd socket to the target */
1798 rsp
= wait_command_fd(from
, pair
[1],
1799 "{ 'execute': 'getfd',"
1800 " 'arguments': { 'fdname': 'fd-mig' }}");
1807 static void test_migrate_fd_finish_hook(QTestState
*from
,
1812 const char *error_desc
;
1814 /* Test closing fds */
1815 /* We assume, that QEMU removes named fd from its list,
1816 * so this should fail */
1817 rsp
= qtest_qmp(from
, "{ 'execute': 'closefd',"
1818 " 'arguments': { 'fdname': 'fd-mig' }}");
1819 g_assert_true(qdict_haskey(rsp
, "error"));
1820 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1821 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1824 rsp
= qtest_qmp(to
, "{ 'execute': 'closefd',"
1825 " 'arguments': { 'fdname': 'fd-mig' }}");
1826 g_assert_true(qdict_haskey(rsp
, "error"));
1827 error_desc
= qdict_get_str(qdict_get_qdict(rsp
, "error"), "desc");
1828 g_assert_cmpstr(error_desc
, ==, "File descriptor named 'fd-mig' not found");
1832 static void test_migrate_fd_proto(void)
1834 MigrateCommon args
= {
1835 .listen_uri
= "defer",
1836 .connect_uri
= "fd:fd-mig",
1837 .start_hook
= test_migrate_fd_start_hook
,
1838 .finish_hook
= test_migrate_fd_finish_hook
1840 test_precopy_common(&args
);
1844 static void do_test_validate_uuid(MigrateStart
*args
, bool should_fail
)
1846 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1847 QTestState
*from
, *to
;
1849 if (test_migrate_start(&from
, &to
, uri
, args
)) {
1854 * UUID validation is at the begin of migration. So, the main process of
1855 * migration is not interesting for us here. Thus, set huge downtime for
1856 * very fast migration.
1858 migrate_set_parameter_int(from
, "downtime-limit", 1000000);
1859 migrate_set_capability(from
, "validate-uuid", true);
1861 /* Wait for the first serial output from the source */
1862 wait_for_serial("src_serial");
1864 migrate_qmp(from
, uri
, "{}");
1867 qtest_set_expected_status(to
, EXIT_FAILURE
);
1868 wait_for_migration_fail(from
, true);
1870 wait_for_migration_complete(from
);
1873 test_migrate_end(from
, to
, false);
1876 static void test_validate_uuid(void)
1878 MigrateStart args
= {
1879 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1880 .opts_target
= "-uuid 11111111-1111-1111-1111-111111111111",
1883 do_test_validate_uuid(&args
, false);
1886 static void test_validate_uuid_error(void)
1888 MigrateStart args
= {
1889 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1890 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1891 .hide_stderr
= true,
1894 do_test_validate_uuid(&args
, true);
1897 static void test_validate_uuid_src_not_set(void)
1899 MigrateStart args
= {
1900 .opts_target
= "-uuid 22222222-2222-2222-2222-222222222222",
1901 .hide_stderr
= true,
1904 do_test_validate_uuid(&args
, false);
1907 static void test_validate_uuid_dst_not_set(void)
1909 MigrateStart args
= {
1910 .opts_source
= "-uuid 11111111-1111-1111-1111-111111111111",
1911 .hide_stderr
= true,
1914 do_test_validate_uuid(&args
, false);
1918 * The way auto_converge works, we need to do too many passes to
1919 * run this test. Auto_converge logic is only run once every
1920 * three iterations, so:
1922 * - 3 iterations without auto_converge enabled
1923 * - 3 iterations with pct = 5
1924 * - 3 iterations with pct = 30
1925 * - 3 iterations with pct = 55
1926 * - 3 iterations with pct = 80
1927 * - 3 iterations with pct = 95 (max(95, 80 + 25))
1929 * To make things even worse, we need to run the initial stage at
1930 * 3MB/s so we enter autoconverge even when host is (over)loaded.
1932 static void test_migrate_auto_converge(void)
1934 g_autofree
char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
1935 MigrateStart args
= {};
1936 QTestState
*from
, *to
;
1940 * We want the test to be stable and as fast as possible.
1941 * E.g., with 1Gb/s bandwith migration may pass without throttling,
1942 * so we need to decrease a bandwidth.
1944 const int64_t init_pct
= 5, inc_pct
= 25, max_pct
= 95;
1946 if (test_migrate_start(&from
, &to
, uri
, &args
)) {
1950 migrate_set_capability(from
, "auto-converge", true);
1951 migrate_set_parameter_int(from
, "cpu-throttle-initial", init_pct
);
1952 migrate_set_parameter_int(from
, "cpu-throttle-increment", inc_pct
);
1953 migrate_set_parameter_int(from
, "max-cpu-throttle", max_pct
);
1956 * Set the initial parameters so that the migration could not converge
1957 * without throttling.
1959 migrate_ensure_non_converge(from
);
1961 /* To check remaining size after precopy */
1962 migrate_set_capability(from
, "pause-before-switchover", true);
1964 /* Wait for the first serial output from the source */
1965 wait_for_serial("src_serial");
1967 migrate_qmp(from
, uri
, "{}");
1969 /* Wait for throttling begins */
1972 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1973 if (percentage
!= 0) {
1977 g_assert_false(got_stop
);
1979 /* The first percentage of throttling should be at least init_pct */
1980 g_assert_cmpint(percentage
, >=, init_pct
);
1981 /* Now, when we tested that throttling works, let it converge */
1982 migrate_ensure_converge(from
);
1985 * Wait for pre-switchover status to check last throttle percentage
1986 * and remaining. These values will be zeroed later
1988 wait_for_migration_status(from
, "pre-switchover", NULL
);
1990 /* The final percentage of throttling shouldn't be greater than max_pct */
1991 percentage
= read_migrate_property_int(from
, "cpu-throttle-percentage");
1992 g_assert_cmpint(percentage
, <=, max_pct
);
1993 migrate_continue(from
, "pre-switchover");
1995 qtest_qmp_eventwait(to
, "RESUME");
1997 wait_for_serial("dest_serial");
1998 wait_for_migration_complete(from
);
2000 test_migrate_end(from
, to
, true);
2004 test_migrate_precopy_tcp_multifd_start_common(QTestState
*from
,
2010 migrate_set_parameter_int(from
, "multifd-channels", 16);
2011 migrate_set_parameter_int(to
, "multifd-channels", 16);
2013 migrate_set_parameter_str(from
, "multifd-compression", method
);
2014 migrate_set_parameter_str(to
, "multifd-compression", method
);
2016 migrate_set_capability(from
, "multifd", true);
2017 migrate_set_capability(to
, "multifd", true);
2019 /* Start incoming migration from the 1st socket */
2020 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
2021 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2028 test_migrate_precopy_tcp_multifd_start(QTestState
*from
,
2031 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2035 test_migrate_precopy_tcp_multifd_zlib_start(QTestState
*from
,
2038 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zlib");
2043 test_migrate_precopy_tcp_multifd_zstd_start(QTestState
*from
,
2046 return test_migrate_precopy_tcp_multifd_start_common(from
, to
, "zstd");
2048 #endif /* CONFIG_ZSTD */
2050 static void test_multifd_tcp_none(void)
2052 MigrateCommon args
= {
2053 .listen_uri
= "defer",
2054 .start_hook
= test_migrate_precopy_tcp_multifd_start
,
2056 test_precopy_common(&args
);
2059 static void test_multifd_tcp_zlib(void)
2061 MigrateCommon args
= {
2062 .listen_uri
= "defer",
2063 .start_hook
= test_migrate_precopy_tcp_multifd_zlib_start
,
2065 test_precopy_common(&args
);
2069 static void test_multifd_tcp_zstd(void)
2071 MigrateCommon args
= {
2072 .listen_uri
= "defer",
2073 .start_hook
= test_migrate_precopy_tcp_multifd_zstd_start
,
2075 test_precopy_common(&args
);
2079 #ifdef CONFIG_GNUTLS
2081 test_migrate_multifd_tcp_tls_psk_start_match(QTestState
*from
,
2084 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2085 return test_migrate_tls_psk_start_match(from
, to
);
2089 test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState
*from
,
2092 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2093 return test_migrate_tls_psk_start_mismatch(from
, to
);
2098 test_migrate_multifd_tls_x509_start_default_host(QTestState
*from
,
2101 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2102 return test_migrate_tls_x509_start_default_host(from
, to
);
2106 test_migrate_multifd_tls_x509_start_override_host(QTestState
*from
,
2109 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2110 return test_migrate_tls_x509_start_override_host(from
, to
);
2114 test_migrate_multifd_tls_x509_start_mismatch_host(QTestState
*from
,
2117 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2118 return test_migrate_tls_x509_start_mismatch_host(from
, to
);
2122 test_migrate_multifd_tls_x509_start_allow_anon_client(QTestState
*from
,
2125 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2126 return test_migrate_tls_x509_start_allow_anon_client(from
, to
);
2130 test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState
*from
,
2133 test_migrate_precopy_tcp_multifd_start_common(from
, to
, "none");
2134 return test_migrate_tls_x509_start_reject_anon_client(from
, to
);
2136 #endif /* CONFIG_TASN1 */
2138 static void test_multifd_tcp_tls_psk_match(void)
2140 MigrateCommon args
= {
2141 .listen_uri
= "defer",
2142 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_match
,
2143 .finish_hook
= test_migrate_tls_psk_finish
,
2145 test_precopy_common(&args
);
2148 static void test_multifd_tcp_tls_psk_mismatch(void)
2150 MigrateCommon args
= {
2152 .hide_stderr
= true,
2154 .listen_uri
= "defer",
2155 .start_hook
= test_migrate_multifd_tcp_tls_psk_start_mismatch
,
2156 .finish_hook
= test_migrate_tls_psk_finish
,
2157 .result
= MIG_TEST_FAIL
,
2159 test_precopy_common(&args
);
2163 static void test_multifd_tcp_tls_x509_default_host(void)
2165 MigrateCommon args
= {
2166 .listen_uri
= "defer",
2167 .start_hook
= test_migrate_multifd_tls_x509_start_default_host
,
2168 .finish_hook
= test_migrate_tls_x509_finish
,
2170 test_precopy_common(&args
);
2173 static void test_multifd_tcp_tls_x509_override_host(void)
2175 MigrateCommon args
= {
2176 .listen_uri
= "defer",
2177 .start_hook
= test_migrate_multifd_tls_x509_start_override_host
,
2178 .finish_hook
= test_migrate_tls_x509_finish
,
2180 test_precopy_common(&args
);
2183 static void test_multifd_tcp_tls_x509_mismatch_host(void)
2186 * This has different behaviour to the non-multifd case.
2188 * In non-multifd case when client aborts due to mismatched
2189 * cert host, the server has already started trying to load
2190 * migration state, and so it exits with I/O failure.
2192 * In multifd case when client aborts due to mismatched
2193 * cert host, the server is still waiting for the other
2194 * multifd connections to arrive so hasn't started trying
2195 * to load migration state, and thus just aborts the migration
2198 MigrateCommon args
= {
2200 .hide_stderr
= true,
2202 .listen_uri
= "defer",
2203 .start_hook
= test_migrate_multifd_tls_x509_start_mismatch_host
,
2204 .finish_hook
= test_migrate_tls_x509_finish
,
2205 .result
= MIG_TEST_FAIL
,
2207 test_precopy_common(&args
);
2210 static void test_multifd_tcp_tls_x509_allow_anon_client(void)
2212 MigrateCommon args
= {
2213 .listen_uri
= "defer",
2214 .start_hook
= test_migrate_multifd_tls_x509_start_allow_anon_client
,
2215 .finish_hook
= test_migrate_tls_x509_finish
,
2217 test_precopy_common(&args
);
2220 static void test_multifd_tcp_tls_x509_reject_anon_client(void)
2222 MigrateCommon args
= {
2224 .hide_stderr
= true,
2226 .listen_uri
= "defer",
2227 .start_hook
= test_migrate_multifd_tls_x509_start_reject_anon_client
,
2228 .finish_hook
= test_migrate_tls_x509_finish
,
2229 .result
= MIG_TEST_FAIL
,
2231 test_precopy_common(&args
);
2233 #endif /* CONFIG_TASN1 */
2234 #endif /* CONFIG_GNUTLS */
2242 * launch another target
2245 * And see that it works
2247 static void test_multifd_tcp_cancel(void)
2249 MigrateStart args
= {
2250 .hide_stderr
= true,
2252 QTestState
*from
, *to
, *to2
;
2254 g_autofree
char *uri
= NULL
;
2256 if (test_migrate_start(&from
, &to
, "defer", &args
)) {
2260 migrate_ensure_non_converge(from
);
2262 migrate_set_parameter_int(from
, "multifd-channels", 16);
2263 migrate_set_parameter_int(to
, "multifd-channels", 16);
2265 migrate_set_capability(from
, "multifd", true);
2266 migrate_set_capability(to
, "multifd", true);
2268 /* Start incoming migration from the 1st socket */
2269 rsp
= wait_command(to
, "{ 'execute': 'migrate-incoming',"
2270 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2273 /* Wait for the first serial output from the source */
2274 wait_for_serial("src_serial");
2276 uri
= migrate_get_socket_address(to
, "socket-address");
2278 migrate_qmp(from
, uri
, "{}");
2280 wait_for_migration_pass(from
);
2282 migrate_cancel(from
);
2284 /* Make sure QEMU process "to" exited */
2285 qtest_set_expected_status(to
, EXIT_FAILURE
);
2286 qtest_wait_qemu(to
);
2288 args
= (MigrateStart
){
2289 .only_target
= true,
2292 if (test_migrate_start(&from
, &to2
, "defer", &args
)) {
2296 migrate_set_parameter_int(to2
, "multifd-channels", 16);
2298 migrate_set_capability(to2
, "multifd", true);
2300 /* Start incoming migration from the 1st socket */
2301 rsp
= wait_command(to2
, "{ 'execute': 'migrate-incoming',"
2302 " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
2306 uri
= migrate_get_socket_address(to2
, "socket-address");
2308 wait_for_migration_status(from
, "cancelled", NULL
);
2310 migrate_ensure_converge(from
);
2312 migrate_qmp(from
, uri
, "{}");
2314 wait_for_migration_pass(from
);
2317 qtest_qmp_eventwait(from
, "STOP");
2319 qtest_qmp_eventwait(to2
, "RESUME");
2321 wait_for_serial("dest_serial");
2322 wait_for_migration_complete(from
);
2323 test_migrate_end(from
, to2
, true);
2326 static void calc_dirty_rate(QTestState
*who
, uint64_t calc_time
)
2328 qobject_unref(qmp_command(who
,
2329 "{ 'execute': 'calc-dirty-rate',"
2331 "'calc-time': %" PRIu64
","
2332 "'mode': 'dirty-ring' }}",
2336 static QDict
*query_dirty_rate(QTestState
*who
)
2338 return qmp_command(who
, "{ 'execute': 'query-dirty-rate' }");
2341 static void dirtylimit_set_all(QTestState
*who
, uint64_t dirtyrate
)
2343 qobject_unref(qmp_command(who
,
2344 "{ 'execute': 'set-vcpu-dirty-limit',"
2346 "'dirty-rate': %" PRIu64
" } }",
2350 static void cancel_vcpu_dirty_limit(QTestState
*who
)
2352 qobject_unref(qmp_command(who
,
2353 "{ 'execute': 'cancel-vcpu-dirty-limit' }"));
2356 static QDict
*query_vcpu_dirty_limit(QTestState
*who
)
2360 rsp
= qtest_qmp(who
, "{ 'execute': 'query-vcpu-dirty-limit' }");
2361 g_assert(!qdict_haskey(rsp
, "error"));
2362 g_assert(qdict_haskey(rsp
, "return"));
2367 static bool calc_dirtyrate_ready(QTestState
*who
)
2372 rsp_return
= query_dirty_rate(who
);
2373 g_assert(rsp_return
);
2375 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2378 return g_strcmp0(status
, "measuring");
2381 static void wait_for_calc_dirtyrate_complete(QTestState
*who
,
2384 int max_try_count
= 10000;
2385 usleep(time_s
* 1000000);
2387 while (!calc_dirtyrate_ready(who
) && max_try_count
--) {
2392 * Set the timeout with 10 s(max_try_count * 1000us),
2393 * if dirtyrate measurement not complete, fail test.
2395 g_assert_cmpint(max_try_count
, !=, 0);
2398 static int64_t get_dirty_rate(QTestState
*who
)
2403 const QListEntry
*entry
;
2407 rsp_return
= query_dirty_rate(who
);
2408 g_assert(rsp_return
);
2410 status
= g_strdup(qdict_get_str(rsp_return
, "status"));
2412 g_assert_cmpstr(status
, ==, "measured");
2414 rates
= qdict_get_qlist(rsp_return
, "vcpu-dirty-rate");
2415 g_assert(rates
&& !qlist_empty(rates
));
2417 entry
= qlist_first(rates
);
2420 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2423 dirtyrate
= qdict_get_try_int(rate
, "dirty-rate", -1);
2425 qobject_unref(rsp_return
);
2429 static int64_t get_limit_rate(QTestState
*who
)
2433 const QListEntry
*entry
;
2437 rsp_return
= query_vcpu_dirty_limit(who
);
2438 g_assert(rsp_return
);
2440 rates
= qdict_get_qlist(rsp_return
, "return");
2441 g_assert(rates
&& !qlist_empty(rates
));
2443 entry
= qlist_first(rates
);
2446 rate
= qobject_to(QDict
, qlist_entry_obj(entry
));
2449 dirtyrate
= qdict_get_try_int(rate
, "limit-rate", -1);
2451 qobject_unref(rsp_return
);
2455 static QTestState
*dirtylimit_start_vm(void)
2457 QTestState
*vm
= NULL
;
2458 g_autofree gchar
*cmd
= NULL
;
2459 const char *arch
= qtest_get_arch();
2460 g_autofree
char *bootpath
= NULL
;
2462 assert((strcmp(arch
, "x86_64") == 0));
2463 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
2464 assert(sizeof(x86_bootsect
) == 512);
2465 init_bootfile(bootpath
, x86_bootsect
, sizeof(x86_bootsect
));
2467 cmd
= g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
2468 "-name dirtylimit-test,debug-threads=on "
2470 "-serial file:%s/vm_serial "
2471 "-drive file=%s,format=raw ",
2474 vm
= qtest_init(cmd
);
2478 static void dirtylimit_stop_vm(QTestState
*vm
)
2481 cleanup("bootsect");
2482 cleanup("vm_serial");
2485 static void test_vcpu_dirty_limit(void)
2488 int64_t origin_rate
;
2491 int max_try_count
= 20;
2494 /* Start vm for vcpu dirtylimit test */
2495 vm
= dirtylimit_start_vm();
2497 /* Wait for the first serial output from the vm*/
2498 wait_for_serial("vm_serial");
2500 /* Do dirtyrate measurement with calc time equals 1s */
2501 calc_dirty_rate(vm
, 1);
2503 /* Sleep calc time and wait for calc dirtyrate complete */
2504 wait_for_calc_dirtyrate_complete(vm
, 1);
2506 /* Query original dirty page rate */
2507 origin_rate
= get_dirty_rate(vm
);
2509 /* VM booted from bootsect should dirty memory steadily */
2510 assert(origin_rate
!= 0);
2512 /* Setup quota dirty page rate at half of origin */
2513 quota_rate
= origin_rate
/ 2;
2515 /* Set dirtylimit */
2516 dirtylimit_set_all(vm
, quota_rate
);
2519 * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit
2522 g_assert_cmpint(quota_rate
, ==, get_limit_rate(vm
));
2524 /* Sleep a bit to check if it take effect */
2528 * Check if dirtylimit take effect realistically, set the
2529 * timeout with 20 s(max_try_count * 1s), if dirtylimit
2530 * doesn't take effect, fail test.
2532 while (--max_try_count
) {
2533 calc_dirty_rate(vm
, 1);
2534 wait_for_calc_dirtyrate_complete(vm
, 1);
2535 rate
= get_dirty_rate(vm
);
2538 * Assume hitting if current rate is less
2539 * than quota rate (within accepting error)
2541 if (rate
< (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2547 g_assert_cmpint(hit
, ==, 1);
2552 /* Check if dirtylimit cancellation take effect */
2553 cancel_vcpu_dirty_limit(vm
);
2554 while (--max_try_count
) {
2555 calc_dirty_rate(vm
, 1);
2556 wait_for_calc_dirtyrate_complete(vm
, 1);
2557 rate
= get_dirty_rate(vm
);
2560 * Assume dirtylimit be canceled if current rate is
2561 * greater than quota rate (within accepting error)
2563 if (rate
> (quota_rate
+ DIRTYLIMIT_TOLERANCE_RANGE
)) {
2569 g_assert_cmpint(hit
, ==, 1);
2570 dirtylimit_stop_vm(vm
);
2573 static bool kvm_dirty_ring_supported(void)
2575 #if defined(__linux__) && defined(HOST_X86_64)
2576 int ret
, kvm_fd
= open("/dev/kvm", O_RDONLY
);
2582 ret
= ioctl(kvm_fd
, KVM_CHECK_EXTENSION
, KVM_CAP_DIRTY_LOG_RING
);
2585 /* We test with 4096 slots */
2596 int main(int argc
, char **argv
)
2598 bool has_kvm
, has_tcg
;
2601 g_autoptr(GError
) err
= NULL
;
2604 g_test_init(&argc
, &argv
, NULL
);
2606 has_kvm
= qtest_has_accel("kvm");
2607 has_tcg
= qtest_has_accel("tcg");
2609 if (!has_tcg
&& !has_kvm
) {
2610 g_test_skip("No KVM or TCG accelerator available");
2614 has_uffd
= ufd_version_check();
2615 arch
= qtest_get_arch();
2618 * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
2619 * is touchy due to race conditions on dirty bits (especially on PPC for
2622 if (g_str_equal(arch
, "ppc64") &&
2623 (!has_kvm
|| access("/sys/module/kvm_hv", F_OK
))) {
2624 g_test_message("Skipping test: kvm_hv not available");
2625 return g_test_run();
2629 * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
2630 * there until the problems are resolved
2632 if (g_str_equal(arch
, "s390x") && !has_kvm
) {
2633 g_test_message("Skipping test: s390x host with KVM is required");
2634 return g_test_run();
2637 tmpfs
= g_dir_make_tmp("migration-test-XXXXXX", &err
);
2639 g_test_message("Can't create temporary directory in %s: %s",
2640 g_get_tmp_dir(), err
->message
);
2644 module_call_init(MODULE_INIT_QOM
);
2647 qtest_add_func("/migration/postcopy/plain", test_postcopy
);
2648 qtest_add_func("/migration/postcopy/recovery/plain",
2649 test_postcopy_recovery
);
2650 qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_preempt
);
2651 qtest_add_func("/migration/postcopy/preempt/recovery/plain",
2652 test_postcopy_preempt_recovery
);
2653 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2654 qtest_add_func("/migration/postcopy/compress/plain",
2655 test_postcopy_compress
);
2656 qtest_add_func("/migration/postcopy/recovery/compress/plain",
2657 test_postcopy_recovery_compress
);
2661 qtest_add_func("/migration/bad_dest", test_baddest
);
2662 qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain
);
2663 qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle
);
2665 * Compression fails from time to time.
2666 * Put test here but don't enable it until everything is fixed.
2668 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2669 qtest_add_func("/migration/precopy/unix/compress/wait",
2670 test_precopy_unix_compress
);
2671 qtest_add_func("/migration/precopy/unix/compress/nowait",
2672 test_precopy_unix_compress_nowait
);
2674 #ifdef CONFIG_GNUTLS
2675 qtest_add_func("/migration/precopy/unix/tls/psk",
2676 test_precopy_unix_tls_psk
);
2680 * NOTE: psk test is enough for postcopy, as other types of TLS
2681 * channels are tested under precopy. Here what we want to test is the
2682 * general postcopy path that has TLS channel enabled.
2684 qtest_add_func("/migration/postcopy/tls/psk", test_postcopy_tls_psk
);
2685 qtest_add_func("/migration/postcopy/recovery/tls/psk",
2686 test_postcopy_recovery_tls_psk
);
2687 qtest_add_func("/migration/postcopy/preempt/tls/psk",
2688 test_postcopy_preempt_tls_psk
);
2689 qtest_add_func("/migration/postcopy/preempt/recovery/tls/psk",
2690 test_postcopy_preempt_all
);
2693 qtest_add_func("/migration/precopy/unix/tls/x509/default-host",
2694 test_precopy_unix_tls_x509_default_host
);
2695 qtest_add_func("/migration/precopy/unix/tls/x509/override-host",
2696 test_precopy_unix_tls_x509_override_host
);
2697 #endif /* CONFIG_TASN1 */
2698 #endif /* CONFIG_GNUTLS */
2700 qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain
);
2701 #ifdef CONFIG_GNUTLS
2702 qtest_add_func("/migration/precopy/tcp/tls/psk/match",
2703 test_precopy_tcp_tls_psk_match
);
2704 qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch",
2705 test_precopy_tcp_tls_psk_mismatch
);
2707 qtest_add_func("/migration/precopy/tcp/tls/x509/default-host",
2708 test_precopy_tcp_tls_x509_default_host
);
2709 qtest_add_func("/migration/precopy/tcp/tls/x509/override-host",
2710 test_precopy_tcp_tls_x509_override_host
);
2711 qtest_add_func("/migration/precopy/tcp/tls/x509/mismatch-host",
2712 test_precopy_tcp_tls_x509_mismatch_host
);
2713 qtest_add_func("/migration/precopy/tcp/tls/x509/friendly-client",
2714 test_precopy_tcp_tls_x509_friendly_client
);
2715 qtest_add_func("/migration/precopy/tcp/tls/x509/hostile-client",
2716 test_precopy_tcp_tls_x509_hostile_client
);
2717 qtest_add_func("/migration/precopy/tcp/tls/x509/allow-anon-client",
2718 test_precopy_tcp_tls_x509_allow_anon_client
);
2719 qtest_add_func("/migration/precopy/tcp/tls/x509/reject-anon-client",
2720 test_precopy_tcp_tls_x509_reject_anon_client
);
2721 #endif /* CONFIG_TASN1 */
2722 #endif /* CONFIG_GNUTLS */
2724 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
2726 qtest_add_func("/migration/fd_proto", test_migrate_fd_proto
);
2728 qtest_add_func("/migration/validate_uuid", test_validate_uuid
);
2729 qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error
);
2730 qtest_add_func("/migration/validate_uuid_src_not_set",
2731 test_validate_uuid_src_not_set
);
2732 qtest_add_func("/migration/validate_uuid_dst_not_set",
2733 test_validate_uuid_dst_not_set
);
2735 * See explanation why this test is slow on function definition
2737 if (g_test_slow()) {
2738 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge
);
2740 qtest_add_func("/migration/multifd/tcp/plain/none",
2741 test_multifd_tcp_none
);
2743 * This test is flaky and sometimes fails in CI and otherwise:
2744 * don't run unless user opts in via environment variable.
2746 if (getenv("QEMU_TEST_FLAKY_TESTS")) {
2747 qtest_add_func("/migration/multifd/tcp/plain/cancel",
2748 test_multifd_tcp_cancel
);
2750 qtest_add_func("/migration/multifd/tcp/plain/zlib",
2751 test_multifd_tcp_zlib
);
2753 qtest_add_func("/migration/multifd/tcp/plain/zstd",
2754 test_multifd_tcp_zstd
);
2756 #ifdef CONFIG_GNUTLS
2757 qtest_add_func("/migration/multifd/tcp/tls/psk/match",
2758 test_multifd_tcp_tls_psk_match
);
2759 qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
2760 test_multifd_tcp_tls_psk_mismatch
);
2762 qtest_add_func("/migration/multifd/tcp/tls/x509/default-host",
2763 test_multifd_tcp_tls_x509_default_host
);
2764 qtest_add_func("/migration/multifd/tcp/tls/x509/override-host",
2765 test_multifd_tcp_tls_x509_override_host
);
2766 qtest_add_func("/migration/multifd/tcp/tls/x509/mismatch-host",
2767 test_multifd_tcp_tls_x509_mismatch_host
);
2768 qtest_add_func("/migration/multifd/tcp/tls/x509/allow-anon-client",
2769 test_multifd_tcp_tls_x509_allow_anon_client
);
2770 qtest_add_func("/migration/multifd/tcp/tls/x509/reject-anon-client",
2771 test_multifd_tcp_tls_x509_reject_anon_client
);
2772 #endif /* CONFIG_TASN1 */
2773 #endif /* CONFIG_GNUTLS */
2775 if (g_str_equal(arch
, "x86_64") && has_kvm
&& kvm_dirty_ring_supported()) {
2776 qtest_add_func("/migration/dirty_ring",
2777 test_precopy_unix_dirty_ring
);
2778 qtest_add_func("/migration/vcpu_dirty_limit",
2779 test_vcpu_dirty_limit
);
2784 g_assert_cmpint(ret
, ==, 0);
2788 g_test_message("unable to rmdir: path (%s): %s",
2789 tmpfs
, strerror(errno
));