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/qmp/qdict.h"
17 #include "qapi/qmp/qjson.h"
18 #include "qemu/option.h"
19 #include "qemu/range.h"
20 #include "qemu/sockets.h"
21 #include "chardev/char.h"
22 #include "sysemu/sysemu.h"
23 #include "qapi/qapi-visit-sockets.h"
24 #include "qapi/qobject-input-visitor.h"
25 #include "qapi/qobject-output-visitor.h"
27 #include "migration/migration-test.h"
29 /* TODO actually test the results and get rid of this */
30 #define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
32 unsigned start_address
;
35 static bool uffd_feature_thread_id
;
37 #if defined(__linux__)
38 #include <sys/syscall.h>
42 #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
43 #include <sys/eventfd.h>
44 #include <sys/ioctl.h>
45 #include <linux/userfaultfd.h>
47 static bool ufd_version_check(void)
49 struct uffdio_api api_struct
;
52 int ufd
= syscall(__NR_userfaultfd
, O_CLOEXEC
);
55 g_test_message("Skipping test: userfaultfd not available");
59 api_struct
.api
= UFFD_API
;
60 api_struct
.features
= 0;
61 if (ioctl(ufd
, UFFDIO_API
, &api_struct
)) {
62 g_test_message("Skipping test: UFFDIO_API failed");
65 uffd_feature_thread_id
= api_struct
.features
& UFFD_FEATURE_THREAD_ID
;
67 ioctl_mask
= (__u64
)1 << _UFFDIO_REGISTER
|
68 (__u64
)1 << _UFFDIO_UNREGISTER
;
69 if ((api_struct
.ioctls
& ioctl_mask
) != ioctl_mask
) {
70 g_test_message("Skipping test: Missing userfault feature");
78 static bool ufd_version_check(void)
80 g_test_message("Skipping test: Userfault not available (builtdtime)");
86 static const char *tmpfs
;
88 /* The boot file modifies memory area in [start_address, end_address)
89 * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
91 #include "tests/migration/i386/a-b-bootblock.h"
92 #include "tests/migration/aarch64/a-b-kernel.h"
94 static void init_bootfile(const char *bootpath
, void *content
)
96 FILE *bootfile
= fopen(bootpath
, "wb");
98 g_assert_cmpint(fwrite(content
, 512, 1, bootfile
), ==, 1);
102 #include "tests/migration/s390x/a-b-bios.h"
104 static void init_bootfile_s390x(const char *bootpath
)
106 FILE *bootfile
= fopen(bootpath
, "wb");
107 size_t len
= sizeof(s390x_elf
);
109 g_assert_cmpint(fwrite(s390x_elf
, len
, 1, bootfile
), ==, 1);
114 * Wait for some output in the serial output file,
115 * we get an 'A' followed by an endless string of 'B's
116 * but on the destination we won't have the A.
118 static void wait_for_serial(const char *side
)
120 char *serialpath
= g_strdup_printf("%s/%s", tmpfs
, side
);
121 FILE *serialfile
= fopen(serialpath
, "r");
122 const char *arch
= qtest_get_arch();
123 int started
= (strcmp(side
, "src_serial") == 0 &&
124 strcmp(arch
, "ppc64") == 0) ? 0 : 1;
128 int readvalue
= fgetc(serialfile
);
131 /* SLOF prints its banner before starting test,
132 * to ignore it, mark the start of the test with '_',
133 * ignore all characters until this marker
140 fseek(serialfile
, 0, SEEK_SET
);
157 started
= (strcmp(side
, "src_serial") == 0 &&
158 strcmp(arch
, "ppc64") == 0) ? 0 : 1;
159 fseek(serialfile
, 0, SEEK_SET
);
164 fprintf(stderr
, "Unexpected %d on %s serial\n", readvalue
, side
);
165 g_assert_not_reached();
170 static void stop_cb(void *opaque
, const char *name
, QDict
*data
)
172 if (!strcmp(name
, "STOP")) {
178 * Events can get in the way of responses we are actually waiting for.
181 static QDict
*wait_command(QTestState
*who
, const char *command
, ...)
185 va_start(ap
, command
);
186 qtest_qmp_vsend(who
, command
, ap
);
189 return qtest_qmp_receive_success(who
, stop_cb
, NULL
);
193 * Note: caller is responsible to free the returned object via
194 * qobject_unref() after use
196 static QDict
*migrate_query(QTestState
*who
)
198 return wait_command(who
, "{ 'execute': 'query-migrate' }");
202 * Note: caller is responsible to free the returned object via
205 static gchar
*migrate_query_status(QTestState
*who
)
207 QDict
*rsp_return
= migrate_query(who
);
208 gchar
*status
= g_strdup(qdict_get_str(rsp_return
, "status"));
211 qobject_unref(rsp_return
);
217 * It's tricky to use qemu's migration event capability with qtest,
218 * events suddenly appearing confuse the qmp()/hmp() responses.
221 static int64_t read_ram_property_int(QTestState
*who
, const char *property
)
223 QDict
*rsp_return
, *rsp_ram
;
226 rsp_return
= migrate_query(who
);
227 if (!qdict_haskey(rsp_return
, "ram")) {
231 rsp_ram
= qdict_get_qdict(rsp_return
, "ram");
232 result
= qdict_get_try_int(rsp_ram
, property
, 0);
234 qobject_unref(rsp_return
);
238 static uint64_t get_migration_pass(QTestState
*who
)
240 return read_ram_property_int(who
, "dirty-sync-count");
243 static void read_blocktime(QTestState
*who
)
247 rsp_return
= migrate_query(who
);
248 g_assert(qdict_haskey(rsp_return
, "postcopy-blocktime"));
249 qobject_unref(rsp_return
);
252 static void wait_for_migration_status(QTestState
*who
,
259 status
= migrate_query_status(who
);
260 completed
= strcmp(status
, goal
) == 0;
261 g_assert_cmpstr(status
, !=, "failed");
270 static void wait_for_migration_complete(QTestState
*who
)
272 wait_for_migration_status(who
, "completed");
275 static void wait_for_migration_pass(QTestState
*who
)
277 uint64_t initial_pass
= get_migration_pass(who
);
280 /* Wait for the 1st sync */
281 while (!got_stop
&& !initial_pass
) {
283 initial_pass
= get_migration_pass(who
);
288 pass
= get_migration_pass(who
);
289 } while (pass
== initial_pass
&& !got_stop
);
292 static void check_guests_ram(QTestState
*who
)
294 /* Our ASM test will have been incrementing one byte from each page from
295 * start_address to < end_address in order. This gives us a constraint
296 * that any page's byte should be equal or less than the previous pages
297 * byte (mod 256); and they should all be equal except for one transition
298 * at the point where we meet the incrementer. (We're running this with
299 * the guest stopped).
304 bool hit_edge
= false;
307 qtest_memread(who
, start_address
, &first_byte
, 1);
308 last_byte
= first_byte
;
310 for (address
= start_address
+ TEST_MEM_PAGE_SIZE
; address
< end_address
;
311 address
+= TEST_MEM_PAGE_SIZE
)
314 qtest_memread(who
, address
, &b
, 1);
315 if (b
!= last_byte
) {
316 if (((b
+ 1) % 256) == last_byte
&& !hit_edge
) {
317 /* This is OK, the guest stopped at the point of
318 * incrementing the previous page but didn't get
324 fprintf(stderr
, "Memory content inconsistency at %x"
325 " first_byte = %x last_byte = %x current = %x"
327 address
, first_byte
, last_byte
, b
, hit_edge
);
335 static void cleanup(const char *filename
)
337 char *path
= g_strdup_printf("%s/%s", tmpfs
, filename
);
343 static char *get_shmem_opts(const char *mem_size
, const char *shmem_path
)
345 return g_strdup_printf("-object memory-backend-file,id=mem0,size=%s"
346 ",mem-path=%s,share=on -numa node,memdev=mem0",
347 mem_size
, shmem_path
);
350 static char *SocketAddress_to_str(SocketAddress
*addr
)
352 switch (addr
->type
) {
353 case SOCKET_ADDRESS_TYPE_INET
:
354 return g_strdup_printf("tcp:%s:%s",
357 case SOCKET_ADDRESS_TYPE_UNIX
:
358 return g_strdup_printf("unix:%s",
359 addr
->u
.q_unix
.path
);
360 case SOCKET_ADDRESS_TYPE_FD
:
361 return g_strdup_printf("fd:%s", addr
->u
.fd
.str
);
362 case SOCKET_ADDRESS_TYPE_VSOCK
:
363 return g_strdup_printf("tcp:%s:%s",
367 return g_strdup("unknown address type");
371 static char *migrate_get_socket_address(QTestState
*who
, const char *parameter
)
375 Error
*local_err
= NULL
;
376 SocketAddressList
*addrs
;
380 rsp
= migrate_query(who
);
381 object
= qdict_get(rsp
, parameter
);
383 iv
= qobject_input_visitor_new(object
);
384 visit_type_SocketAddressList(iv
, NULL
, &addrs
, &local_err
);
387 /* we are only using a single address */
388 result
= SocketAddress_to_str(addrs
->value
);
390 qapi_free_SocketAddressList(addrs
);
395 static long long migrate_get_parameter(QTestState
*who
, const char *parameter
)
400 rsp
= wait_command(who
, "{ 'execute': 'query-migrate-parameters' }");
401 result
= qdict_get_int(rsp
, parameter
);
406 static void migrate_check_parameter(QTestState
*who
, const char *parameter
,
411 result
= migrate_get_parameter(who
, parameter
);
412 g_assert_cmpint(result
, ==, value
);
415 static void migrate_set_parameter(QTestState
*who
, const char *parameter
,
421 "{ 'execute': 'migrate-set-parameters',"
422 "'arguments': { %s: %lld } }",
424 g_assert(qdict_haskey(rsp
, "return"));
426 migrate_check_parameter(who
, parameter
, value
);
429 static void migrate_pause(QTestState
*who
)
433 rsp
= wait_command(who
, "{ 'execute': 'migrate-pause' }");
437 static void migrate_recover(QTestState
*who
, const char *uri
)
441 rsp
= wait_command(who
,
442 "{ 'execute': 'migrate-recover', "
443 " 'id': 'recover-cmd', "
444 " 'arguments': { 'uri': %s } }",
449 static void migrate_set_capability(QTestState
*who
, const char *capability
,
455 "{ 'execute': 'migrate-set-capabilities',"
457 "'capabilities': [ { "
458 "'capability': %s, 'state': %i } ] } }",
460 g_assert(qdict_haskey(rsp
, "return"));
465 * Send QMP command "migrate".
466 * Arguments are built from @fmt... (formatted like
467 * qobject_from_jsonf_nofail()) with "uri": @uri spliced in.
470 static void migrate(QTestState
*who
, const char *uri
, const char *fmt
, ...)
476 args
= qdict_from_vjsonf_nofail(fmt
, ap
);
479 g_assert(!qdict_haskey(args
, "uri"));
480 qdict_put_str(args
, "uri", uri
);
482 rsp
= qmp("{ 'execute': 'migrate', 'arguments': %p}", args
);
483 g_assert(qdict_haskey(rsp
, "return"));
487 static void migrate_postcopy_start(QTestState
*from
, QTestState
*to
)
491 rsp
= wait_command(from
, "{ 'execute': 'migrate-start-postcopy' }");
495 qtest_qmp_eventwait(from
, "STOP");
498 qtest_qmp_eventwait(to
, "RESUME");
501 static int test_migrate_start(QTestState
**from
, QTestState
**to
,
502 const char *uri
, bool hide_stderr
,
505 gchar
*cmd_src
, *cmd_dst
;
506 char *bootpath
= NULL
;
507 char *extra_opts
= NULL
;
508 char *shmem_path
= NULL
;
509 const char *arch
= qtest_get_arch();
510 const char *accel
= "kvm:tcg";
513 if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR
)) {
514 g_test_skip("/dev/shm is not supported");
517 shmem_path
= g_strdup_printf("/dev/shm/qemu-%d", getpid());
521 bootpath
= g_strdup_printf("%s/bootsect", tmpfs
);
522 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
523 init_bootfile(bootpath
, x86_bootsect
);
524 extra_opts
= use_shmem
? get_shmem_opts("150M", shmem_path
) : NULL
;
525 cmd_src
= g_strdup_printf("-machine accel=%s -m 150M"
526 " -name source,debug-threads=on"
527 " -serial file:%s/src_serial"
528 " -drive file=%s,format=raw %s",
529 accel
, tmpfs
, bootpath
,
530 extra_opts
? extra_opts
: "");
531 cmd_dst
= g_strdup_printf("-machine accel=%s -m 150M"
532 " -name target,debug-threads=on"
533 " -serial file:%s/dest_serial"
534 " -drive file=%s,format=raw"
536 accel
, tmpfs
, bootpath
, uri
,
537 extra_opts
? extra_opts
: "");
538 start_address
= X86_TEST_MEM_START
;
539 end_address
= X86_TEST_MEM_END
;
540 } else if (g_str_equal(arch
, "s390x")) {
541 init_bootfile_s390x(bootpath
);
542 extra_opts
= use_shmem
? get_shmem_opts("128M", shmem_path
) : NULL
;
543 cmd_src
= g_strdup_printf("-machine accel=%s -m 128M"
544 " -name source,debug-threads=on"
545 " -serial file:%s/src_serial -bios %s %s",
546 accel
, tmpfs
, bootpath
,
547 extra_opts
? extra_opts
: "");
548 cmd_dst
= g_strdup_printf("-machine accel=%s -m 128M"
549 " -name target,debug-threads=on"
550 " -serial file:%s/dest_serial -bios %s"
552 accel
, tmpfs
, bootpath
, uri
,
553 extra_opts
? extra_opts
: "");
554 start_address
= S390_TEST_MEM_START
;
555 end_address
= S390_TEST_MEM_END
;
556 } else if (strcmp(arch
, "ppc64") == 0) {
557 extra_opts
= use_shmem
? get_shmem_opts("256M", shmem_path
) : NULL
;
558 cmd_src
= g_strdup_printf("-machine accel=%s -m 256M -nodefaults"
559 " -name source,debug-threads=on"
560 " -serial file:%s/src_serial"
561 " -prom-env 'use-nvramrc?=true' -prom-env "
562 "'nvramrc=hex .\" _\" begin %x %x "
563 "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
564 "until' %s", accel
, tmpfs
, end_address
,
565 start_address
, extra_opts
? extra_opts
: "");
566 cmd_dst
= g_strdup_printf("-machine accel=%s -m 256M"
567 " -name target,debug-threads=on"
568 " -serial file:%s/dest_serial"
571 extra_opts
? extra_opts
: "");
573 start_address
= PPC_TEST_MEM_START
;
574 end_address
= PPC_TEST_MEM_END
;
575 } else if (strcmp(arch
, "aarch64") == 0) {
576 init_bootfile(bootpath
, aarch64_kernel
);
577 extra_opts
= use_shmem
? get_shmem_opts("150M", shmem_path
) : NULL
;
578 cmd_src
= g_strdup_printf("-machine virt,accel=%s,gic-version=max "
579 "-name vmsource,debug-threads=on -cpu max "
580 "-m 150M -serial file:%s/src_serial "
582 accel
, tmpfs
, bootpath
,
583 extra_opts
? extra_opts
: "");
584 cmd_dst
= g_strdup_printf("-machine virt,accel=%s,gic-version=max "
585 "-name vmdest,debug-threads=on -cpu max "
586 "-m 150M -serial file:%s/dest_serial "
589 accel
, tmpfs
, bootpath
, uri
,
590 extra_opts
? extra_opts
: "");
592 start_address
= ARM_TEST_MEM_START
;
593 end_address
= ARM_TEST_MEM_END
;
595 g_assert(sizeof(aarch64_kernel
) <= ARM_TEST_MAX_KERNEL_SIZE
);
597 g_assert_not_reached();
605 tmp
= g_strdup_printf("%s 2>/dev/null", cmd_src
);
609 tmp
= g_strdup_printf("%s 2>/dev/null", cmd_dst
);
614 *from
= qtest_start(cmd_src
);
617 *to
= qtest_init(cmd_dst
);
621 * Remove shmem file immediately to avoid memory leak in test failed case.
622 * It's valid becase QEMU has already opened this file
632 static void test_migrate_end(QTestState
*from
, QTestState
*to
, bool test_dest
)
634 unsigned char dest_byte_a
, dest_byte_b
, dest_byte_c
, dest_byte_d
;
639 qtest_memread(to
, start_address
, &dest_byte_a
, 1);
641 /* Destination still running, wait for a byte to change */
643 qtest_memread(to
, start_address
, &dest_byte_b
, 1);
645 } while (dest_byte_a
== dest_byte_b
);
647 qtest_qmp_discard_response(to
, "{ 'execute' : 'stop'}");
649 /* With it stopped, check nothing changes */
650 qtest_memread(to
, start_address
, &dest_byte_c
, 1);
652 qtest_memread(to
, start_address
, &dest_byte_d
, 1);
653 g_assert_cmpint(dest_byte_c
, ==, dest_byte_d
);
655 check_guests_ram(to
);
661 cleanup("migsocket");
662 cleanup("src_serial");
663 cleanup("dest_serial");
666 static void deprecated_set_downtime(QTestState
*who
, const double value
)
671 "{ 'execute': 'migrate_set_downtime',"
672 " 'arguments': { 'value': %f } }", value
);
673 g_assert(qdict_haskey(rsp
, "return"));
675 migrate_check_parameter(who
, "downtime-limit", value
* 1000);
678 static void deprecated_set_speed(QTestState
*who
, long long value
)
682 rsp
= qtest_qmp(who
, "{ 'execute': 'migrate_set_speed',"
683 "'arguments': { 'value': %lld } }", value
);
684 g_assert(qdict_haskey(rsp
, "return"));
686 migrate_check_parameter(who
, "max-bandwidth", value
);
689 static void deprecated_set_cache_size(QTestState
*who
, long long value
)
693 rsp
= qtest_qmp(who
, "{ 'execute': 'migrate-set-cache-size',"
694 "'arguments': { 'value': %lld } }", value
);
695 g_assert(qdict_haskey(rsp
, "return"));
697 migrate_check_parameter(who
, "xbzrle-cache-size", value
);
700 static void test_deprecated(void)
704 from
= qtest_start("-machine none");
706 deprecated_set_downtime(from
, 0.12345);
707 deprecated_set_speed(from
, 12345);
708 deprecated_set_cache_size(from
, 4096);
713 static int migrate_postcopy_prepare(QTestState
**from_ptr
,
717 char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
718 QTestState
*from
, *to
;
720 if (test_migrate_start(&from
, &to
, uri
, hide_error
, false)) {
724 migrate_set_capability(from
, "postcopy-ram", true);
725 migrate_set_capability(to
, "postcopy-ram", true);
726 migrate_set_capability(to
, "postcopy-blocktime", true);
728 /* We want to pick a speed slow enough that the test completes
729 * quickly, but that it doesn't complete precopy even on a slow
730 * machine, so also set the downtime.
732 migrate_set_parameter(from
, "max-bandwidth", 100000000);
733 migrate_set_parameter(from
, "downtime-limit", 1);
735 /* Wait for the first serial output from the source */
736 wait_for_serial("src_serial");
738 migrate(from
, uri
, "{}");
741 wait_for_migration_pass(from
);
749 static void migrate_postcopy_complete(QTestState
*from
, QTestState
*to
)
751 wait_for_migration_complete(from
);
753 /* Make sure we get at least one "B" on destination */
754 wait_for_serial("dest_serial");
756 if (uffd_feature_thread_id
) {
760 test_migrate_end(from
, to
, true);
763 static void test_postcopy(void)
765 QTestState
*from
, *to
;
767 if (migrate_postcopy_prepare(&from
, &to
, false)) {
770 migrate_postcopy_start(from
, to
);
771 migrate_postcopy_complete(from
, to
);
774 static void test_postcopy_recovery(void)
776 QTestState
*from
, *to
;
779 if (migrate_postcopy_prepare(&from
, &to
, true)) {
783 /* Turn postcopy speed down, 4K/s is slow enough on any machines */
784 migrate_set_parameter(from
, "max-postcopy-bandwidth", 4096);
786 /* Now we start the postcopy */
787 migrate_postcopy_start(from
, to
);
790 * Wait until postcopy is really started; we can only run the
791 * migrate-pause command during a postcopy
793 wait_for_migration_status(from
, "postcopy-active");
796 * Manually stop the postcopy migration. This emulates a network
797 * failure with the migration socket
802 * Wait for destination side to reach postcopy-paused state. The
803 * migrate-recover command can only succeed if destination machine
804 * is in the paused state
806 wait_for_migration_status(to
, "postcopy-paused");
809 * Create a new socket to emulate a new channel that is different
810 * from the broken migration channel; tell the destination to
811 * listen to the new port
813 uri
= g_strdup_printf("unix:%s/migsocket-recover", tmpfs
);
814 migrate_recover(to
, uri
);
817 * Try to rebuild the migration channel using the resume flag and
818 * the newly created channel
820 wait_for_migration_status(from
, "postcopy-paused");
821 migrate(from
, uri
, "{'resume': true}");
824 /* Restore the postcopy bandwidth to unlimited */
825 migrate_set_parameter(from
, "max-postcopy-bandwidth", 0);
827 migrate_postcopy_complete(from
, to
);
830 static void test_baddest(void)
832 QTestState
*from
, *to
;
837 if (test_migrate_start(&from
, &to
, "tcp:0:0", true, false)) {
840 migrate(from
, "tcp:0:0", "{}");
842 status
= migrate_query_status(from
);
843 g_assert(!strcmp(status
, "setup") || !(strcmp(status
, "failed")));
844 failed
= !strcmp(status
, "failed");
848 /* Is the machine currently running? */
849 rsp_return
= wait_command(from
, "{ 'execute': 'query-status' }");
850 g_assert(qdict_haskey(rsp_return
, "running"));
851 g_assert(qdict_get_bool(rsp_return
, "running"));
852 qobject_unref(rsp_return
);
854 test_migrate_end(from
, to
, false);
857 static void test_precopy_unix(void)
859 char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
860 QTestState
*from
, *to
;
862 if (test_migrate_start(&from
, &to
, uri
, false, false)) {
866 /* We want to pick a speed slow enough that the test completes
867 * quickly, but that it doesn't complete precopy even on a slow
868 * machine, so also set the downtime.
870 /* 1 ms should make it not converge*/
871 migrate_set_parameter(from
, "downtime-limit", 1);
873 migrate_set_parameter(from
, "max-bandwidth", 1000000000);
875 /* Wait for the first serial output from the source */
876 wait_for_serial("src_serial");
878 migrate(from
, uri
, "{}");
880 wait_for_migration_pass(from
);
882 /* 300 ms should converge */
883 migrate_set_parameter(from
, "downtime-limit", 300);
886 qtest_qmp_eventwait(from
, "STOP");
889 qtest_qmp_eventwait(to
, "RESUME");
891 wait_for_serial("dest_serial");
892 wait_for_migration_complete(from
);
894 test_migrate_end(from
, to
, true);
899 /* Currently upset on aarch64 TCG */
900 static void test_ignore_shared(void)
902 char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
903 QTestState
*from
, *to
;
905 if (test_migrate_start(&from
, &to
, uri
, false, true)) {
909 migrate_set_capability(from
, "x-ignore-shared", true);
910 migrate_set_capability(to
, "x-ignore-shared", true);
912 /* Wait for the first serial output from the source */
913 wait_for_serial("src_serial");
915 migrate(from
, uri
, "{}");
917 wait_for_migration_pass(from
);
920 qtest_qmp_eventwait(from
, "STOP");
923 qtest_qmp_eventwait(to
, "RESUME");
925 wait_for_serial("dest_serial");
926 wait_for_migration_complete(from
);
928 /* Check whether shared RAM has been really skipped */
929 g_assert_cmpint(read_ram_property_int(from
, "transferred"), <, 1024 * 1024);
931 test_migrate_end(from
, to
, true);
936 static void test_xbzrle(const char *uri
)
938 QTestState
*from
, *to
;
940 if (test_migrate_start(&from
, &to
, uri
, false, false)) {
945 * We want to pick a speed slow enough that the test completes
946 * quickly, but that it doesn't complete precopy even on a slow
947 * machine, so also set the downtime.
949 /* 1 ms should make it not converge*/
950 migrate_set_parameter(from
, "downtime-limit", 1);
952 migrate_set_parameter(from
, "max-bandwidth", 1000000000);
954 migrate_set_parameter(from
, "xbzrle-cache-size", 33554432);
956 migrate_set_capability(from
, "xbzrle", "true");
957 migrate_set_capability(to
, "xbzrle", "true");
958 /* Wait for the first serial output from the source */
959 wait_for_serial("src_serial");
961 migrate(from
, uri
, "{}");
963 wait_for_migration_pass(from
);
965 /* 300ms should converge */
966 migrate_set_parameter(from
, "downtime-limit", 300);
969 qtest_qmp_eventwait(from
, "STOP");
971 qtest_qmp_eventwait(to
, "RESUME");
973 wait_for_serial("dest_serial");
974 wait_for_migration_complete(from
);
976 test_migrate_end(from
, to
, true);
979 static void test_xbzrle_unix(void)
981 char *uri
= g_strdup_printf("unix:%s/migsocket", tmpfs
);
987 static void test_precopy_tcp(void)
990 QTestState
*from
, *to
;
992 if (test_migrate_start(&from
, &to
, "tcp:127.0.0.1:0", false, false)) {
997 * We want to pick a speed slow enough that the test completes
998 * quickly, but that it doesn't complete precopy even on a slow
999 * machine, so also set the downtime.
1001 /* 1 ms should make it not converge*/
1002 migrate_set_parameter(from
, "downtime-limit", 1);
1004 migrate_set_parameter(from
, "max-bandwidth", 1000000000);
1006 /* Wait for the first serial output from the source */
1007 wait_for_serial("src_serial");
1009 uri
= migrate_get_socket_address(to
, "socket-address");
1011 migrate(from
, uri
, "{}");
1013 wait_for_migration_pass(from
);
1015 /* 300ms should converge */
1016 migrate_set_parameter(from
, "downtime-limit", 300);
1019 qtest_qmp_eventwait(from
, "STOP");
1021 qtest_qmp_eventwait(to
, "RESUME");
1023 wait_for_serial("dest_serial");
1024 wait_for_migration_complete(from
);
1026 test_migrate_end(from
, to
, true);
1030 int main(int argc
, char **argv
)
1032 char template[] = "/tmp/migration-test-XXXXXX";
1035 g_test_init(&argc
, &argv
, NULL
);
1037 if (!ufd_version_check()) {
1038 return g_test_run();
1042 * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
1043 * is touchy due to race conditions on dirty bits (especially on PPC for
1046 if (g_str_equal(qtest_get_arch(), "ppc64") &&
1047 access("/sys/module/kvm_hv", F_OK
)) {
1048 g_test_message("Skipping test: kvm_hv not available");
1049 return g_test_run();
1053 * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
1054 * there until the problems are resolved
1056 if (g_str_equal(qtest_get_arch(), "s390x")) {
1057 #if defined(HOST_S390X)
1058 if (access("/dev/kvm", R_OK
| W_OK
)) {
1059 g_test_message("Skipping test: kvm not available");
1060 return g_test_run();
1063 g_test_message("Skipping test: Need s390x host to work properly");
1064 return g_test_run();
1068 tmpfs
= mkdtemp(template);
1070 g_test_message("mkdtemp on path (%s): %s", template, strerror(errno
));
1074 module_call_init(MODULE_INIT_QOM
);
1076 qtest_add_func("/migration/postcopy/unix", test_postcopy
);
1077 qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery
);
1078 qtest_add_func("/migration/deprecated", test_deprecated
);
1079 qtest_add_func("/migration/bad_dest", test_baddest
);
1080 qtest_add_func("/migration/precopy/unix", test_precopy_unix
);
1081 qtest_add_func("/migration/precopy/tcp", test_precopy_tcp
);
1082 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
1083 qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix
);
1087 g_assert_cmpint(ret
, ==, 0);
1091 g_test_message("unable to rmdir: path (%s): %s",
1092 tmpfs
, strerror(errno
));