]> git.proxmox.com Git - mirror_qemu.git/blame - tests/migration-test.c
tests/migration: Fail on unexpected migration states
[mirror_qemu.git] / tests / migration-test.c
CommitLineData
ea0c6d62 1/*
2656bfd9 2 * QTest testcase for migration
ea0c6d62 3 *
17ca7746 4 * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
ea0c6d62
DDAG
5 * based on the vhost-user-test.c that is:
6 * Copyright (c) 2014 Virtual Open Systems Sarl.
7 *
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.
10 *
11 */
12
13#include "qemu/osdep.h"
ea0c6d62
DDAG
14
15#include "libqtest.h"
452fcdbc 16#include "qapi/qmp/qdict.h"
b5bbd3f3 17#include "qapi/qmp/qjson.h"
0b8fa32f 18#include "qemu/module.h"
ea0c6d62
DDAG
19#include "qemu/option.h"
20#include "qemu/range.h"
a9c94277 21#include "qemu/sockets.h"
8228e353 22#include "chardev/char.h"
609d3844
JQ
23#include "qapi/qapi-visit-sockets.h"
24#include "qapi/qobject-input-visitor.h"
25#include "qapi/qobject-output-visitor.h"
ea0c6d62 26
e51e711b
WH
27#include "migration/migration-test.h"
28
055a1efc
MA
29/* TODO actually test the results and get rid of this */
30#define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
31
e51e711b
WH
32unsigned start_address;
33unsigned end_address;
ea0c6d62 34bool got_stop;
346f3dab 35static bool uffd_feature_thread_id;
ea0c6d62
DDAG
36
37#if defined(__linux__)
ea0c6d62
DDAG
38#include <sys/syscall.h>
39#include <sys/vfs.h>
40#endif
41
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>
46
47static bool ufd_version_check(void)
48{
49 struct uffdio_api api_struct;
50 uint64_t ioctl_mask;
51
e1ae9fb6 52 int ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
ea0c6d62
DDAG
53
54 if (ufd == -1) {
55 g_test_message("Skipping test: userfaultfd not available");
56 return false;
57 }
58
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");
63 return false;
64 }
346f3dab 65 uffd_feature_thread_id = api_struct.features & UFFD_FEATURE_THREAD_ID;
ea0c6d62
DDAG
66
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");
71 return false;
72 }
73
74 return true;
75}
76
77#else
78static bool ufd_version_check(void)
79{
80 g_test_message("Skipping test: Userfault not available (builtdtime)");
81 return false;
82}
83
84#endif
85
86static const char *tmpfs;
87
e51e711b
WH
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.
ea0c6d62 90 */
d54927ef 91#include "tests/migration/i386/a-b-bootblock.h"
c02b3781 92#include "tests/migration/aarch64/a-b-kernel.h"
5571dc82
TH
93#include "tests/migration/s390x/a-b-bios.h"
94
2785f196 95static void init_bootfile(const char *bootpath, void *content, size_t len)
5571dc82
TH
96{
97 FILE *bootfile = fopen(bootpath, "wb");
5571dc82 98
2785f196 99 g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
5571dc82
TH
100 fclose(bootfile);
101}
102
ea0c6d62
DDAG
103/*
104 * Wait for some output in the serial output file,
105 * we get an 'A' followed by an endless string of 'B's
106 * but on the destination we won't have the A.
107 */
108static void wait_for_serial(const char *side)
109{
110 char *serialpath = g_strdup_printf("%s/%s", tmpfs, side);
111 FILE *serialfile = fopen(serialpath, "r");
aaf89c8a 112 const char *arch = qtest_get_arch();
113 int started = (strcmp(side, "src_serial") == 0 &&
114 strcmp(arch, "ppc64") == 0) ? 0 : 1;
ea0c6d62 115
e2dd21e5 116 g_free(serialpath);
ea0c6d62
DDAG
117 do {
118 int readvalue = fgetc(serialfile);
119
aaf89c8a 120 if (!started) {
121 /* SLOF prints its banner before starting test,
122 * to ignore it, mark the start of the test with '_',
123 * ignore all characters until this marker
124 */
125 switch (readvalue) {
126 case '_':
127 started = 1;
128 break;
129 case EOF:
130 fseek(serialfile, 0, SEEK_SET);
131 usleep(1000);
132 break;
133 }
134 continue;
135 }
ea0c6d62
DDAG
136 switch (readvalue) {
137 case 'A':
138 /* Fine */
139 break;
140
141 case 'B':
142 /* It's alive! */
143 fclose(serialfile);
ea0c6d62
DDAG
144 return;
145
146 case EOF:
aaf89c8a 147 started = (strcmp(side, "src_serial") == 0 &&
148 strcmp(arch, "ppc64") == 0) ? 0 : 1;
ea0c6d62
DDAG
149 fseek(serialfile, 0, SEEK_SET);
150 usleep(1000);
151 break;
152
153 default:
154 fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, side);
155 g_assert_not_reached();
156 }
157 } while (true);
158}
159
3cd46d42
MA
160static void stop_cb(void *opaque, const char *name, QDict *data)
161{
162 if (!strcmp(name, "STOP")) {
163 got_stop = true;
164 }
165}
166
24d5588c
YK
167/*
168 * Events can get in the way of responses we are actually waiting for.
169 */
170GCC_FMT_ATTR(3, 4)
171static QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
172{
173 va_list ap;
174
175 va_start(ap, command);
176 qtest_qmp_vsend_fds(who, &fd, 1, command, ap);
177 va_end(ap);
178
179 return qtest_qmp_receive_success(who, stop_cb, NULL);
180}
181
ea0c6d62
DDAG
182/*
183 * Events can get in the way of responses we are actually waiting for.
184 */
b7281c69 185GCC_FMT_ATTR(2, 3)
4399596b 186static QDict *wait_command(QTestState *who, const char *command, ...)
ea0c6d62 187{
4399596b
MA
188 va_list ap;
189
190 va_start(ap, command);
191 qtest_qmp_vsend(who, command, ap);
192 va_end(ap);
193
3cd46d42 194 return qtest_qmp_receive_success(who, stop_cb, NULL);
ea0c6d62
DDAG
195}
196
2f7074c6
PX
197/*
198 * Note: caller is responsible to free the returned object via
199 * qobject_unref() after use
200 */
201static QDict *migrate_query(QTestState *who)
202{
e1454165 203 return wait_command(who, "{ 'execute': 'query-migrate' }");
2f7074c6
PX
204}
205
206/*
207 * Note: caller is responsible to free the returned object via
208 * g_free() after use
209 */
210static gchar *migrate_query_status(QTestState *who)
211{
212 QDict *rsp_return = migrate_query(who);
213 gchar *status = g_strdup(qdict_get_str(rsp_return, "status"));
214
215 g_assert(status);
216 qobject_unref(rsp_return);
217
218 return status;
219}
ea0c6d62
DDAG
220
221/*
222 * It's tricky to use qemu's migration event capability with qtest,
223 * events suddenly appearing confuse the qmp()/hmp() responses.
ea0c6d62
DDAG
224 */
225
660a9b68 226static int64_t read_ram_property_int(QTestState *who, const char *property)
ea0c6d62 227{
2f7074c6 228 QDict *rsp_return, *rsp_ram;
660a9b68 229 int64_t result;
ea0c6d62 230
2f7074c6 231 rsp_return = migrate_query(who);
ea0c6d62
DDAG
232 if (!qdict_haskey(rsp_return, "ram")) {
233 /* Still in setup */
234 result = 0;
235 } else {
236 rsp_ram = qdict_get_qdict(rsp_return, "ram");
660a9b68 237 result = qdict_get_try_int(rsp_ram, property, 0);
ea0c6d62 238 }
2f7074c6 239 qobject_unref(rsp_return);
ea0c6d62
DDAG
240 return result;
241}
242
660a9b68
YK
243static uint64_t get_migration_pass(QTestState *who)
244{
245 return read_ram_property_int(who, "dirty-sync-count");
246}
247
346f3dab
AP
248static void read_blocktime(QTestState *who)
249{
2f7074c6 250 QDict *rsp_return;
346f3dab 251
2f7074c6 252 rsp_return = migrate_query(who);
346f3dab 253 g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
2f7074c6 254 qobject_unref(rsp_return);
346f3dab
AP
255}
256
2f6d3138 257static void wait_for_migration_status(QTestState *who,
e15310ea
DDAG
258 const char *goal,
259 const char **ungoals)
ea0c6d62 260{
6a7724e9 261 while (true) {
6a7724e9 262 bool completed;
2f7074c6 263 char *status;
e15310ea 264 const char **ungoal;
ea0c6d62 265
2f7074c6 266 status = migrate_query_status(who);
2f6d3138 267 completed = strcmp(status, goal) == 0;
e15310ea
DDAG
268 for (ungoal = ungoals; *ungoal; ungoal++) {
269 g_assert_cmpstr(status, !=, *ungoal);
270 }
2f7074c6 271 g_free(status);
6a7724e9
JQ
272 if (completed) {
273 return;
274 }
275 usleep(1000);
276 }
ea0c6d62
DDAG
277}
278
2f6d3138
PX
279static void wait_for_migration_complete(QTestState *who)
280{
e15310ea
DDAG
281 wait_for_migration_status(who, "completed",
282 (const char * []) { "failed", NULL });
2f6d3138
PX
283}
284
863e27a8 285static void wait_for_migration_pass(QTestState *who)
ea0c6d62 286{
863e27a8 287 uint64_t initial_pass = get_migration_pass(who);
ea0c6d62
DDAG
288 uint64_t pass;
289
290 /* Wait for the 1st sync */
6a7724e9
JQ
291 while (!got_stop && !initial_pass) {
292 usleep(1000);
863e27a8 293 initial_pass = get_migration_pass(who);
6a7724e9 294 }
ea0c6d62
DDAG
295
296 do {
6a7724e9 297 usleep(1000);
863e27a8 298 pass = get_migration_pass(who);
ea0c6d62
DDAG
299 } while (pass == initial_pass && !got_stop);
300}
301
7195a871 302static void check_guests_ram(QTestState *who)
ea0c6d62
DDAG
303{
304 /* Our ASM test will have been incrementing one byte from each page from
e51e711b
WH
305 * start_address to < end_address in order. This gives us a constraint
306 * that any page's byte should be equal or less than the previous pages
307 * byte (mod 256); and they should all be equal except for one transition
308 * at the point where we meet the incrementer. (We're running this with
309 * the guest stopped).
ea0c6d62
DDAG
310 */
311 unsigned address;
312 uint8_t first_byte;
313 uint8_t last_byte;
314 bool hit_edge = false;
601b5575 315 int bad = 0;
ea0c6d62 316
7195a871 317 qtest_memread(who, start_address, &first_byte, 1);
ea0c6d62
DDAG
318 last_byte = first_byte;
319
e51e711b
WH
320 for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
321 address += TEST_MEM_PAGE_SIZE)
ea0c6d62
DDAG
322 {
323 uint8_t b;
7195a871 324 qtest_memread(who, address, &b, 1);
ea0c6d62
DDAG
325 if (b != last_byte) {
326 if (((b + 1) % 256) == last_byte && !hit_edge) {
327 /* This is OK, the guest stopped at the point of
328 * incrementing the previous page but didn't get
329 * to us yet.
330 */
331 hit_edge = true;
829db8b4 332 last_byte = b;
ea0c6d62 333 } else {
601b5575
AB
334 bad++;
335 if (bad <= 10) {
336 fprintf(stderr, "Memory content inconsistency at %x"
337 " first_byte = %x last_byte = %x current = %x"
338 " hit_edge = %x\n",
339 address, first_byte, last_byte, b, hit_edge);
340 }
ea0c6d62
DDAG
341 }
342 }
ea0c6d62 343 }
601b5575
AB
344 if (bad >= 10) {
345 fprintf(stderr, "and in another %d pages", bad - 10);
346 }
347 g_assert(bad == 0);
ea0c6d62
DDAG
348}
349
350static void cleanup(const char *filename)
351{
352 char *path = g_strdup_printf("%s/%s", tmpfs, filename);
353
354 unlink(path);
e2dd21e5 355 g_free(path);
ea0c6d62
DDAG
356}
357
660a9b68
YK
358static char *get_shmem_opts(const char *mem_size, const char *shmem_path)
359{
360 return g_strdup_printf("-object memory-backend-file,id=mem0,size=%s"
361 ",mem-path=%s,share=on -numa node,memdev=mem0",
362 mem_size, shmem_path);
363}
364
609d3844
JQ
365static char *SocketAddress_to_str(SocketAddress *addr)
366{
367 switch (addr->type) {
368 case SOCKET_ADDRESS_TYPE_INET:
369 return g_strdup_printf("tcp:%s:%s",
370 addr->u.inet.host,
371 addr->u.inet.port);
372 case SOCKET_ADDRESS_TYPE_UNIX:
373 return g_strdup_printf("unix:%s",
374 addr->u.q_unix.path);
375 case SOCKET_ADDRESS_TYPE_FD:
376 return g_strdup_printf("fd:%s", addr->u.fd.str);
377 case SOCKET_ADDRESS_TYPE_VSOCK:
378 return g_strdup_printf("tcp:%s:%s",
379 addr->u.vsock.cid,
380 addr->u.vsock.port);
381 default:
382 return g_strdup("unknown address type");
383 }
384}
385
386static char *migrate_get_socket_address(QTestState *who, const char *parameter)
387{
388 QDict *rsp;
389 char *result;
390 Error *local_err = NULL;
391 SocketAddressList *addrs;
392 Visitor *iv = NULL;
393 QObject *object;
394
395 rsp = migrate_query(who);
396 object = qdict_get(rsp, parameter);
397
398 iv = qobject_input_visitor_new(object);
399 visit_type_SocketAddressList(iv, NULL, &addrs, &local_err);
1e25879e 400 visit_free(iv);
609d3844
JQ
401
402 /* we are only using a single address */
1e25879e 403 result = SocketAddress_to_str(addrs->value);
609d3844
JQ
404
405 qapi_free_SocketAddressList(addrs);
406 qobject_unref(rsp);
407 return result;
408}
409
8f7798f1
JQ
410static long long migrate_get_parameter_int(QTestState *who,
411 const char *parameter)
609d3844
JQ
412{
413 QDict *rsp;
414 long long result;
415
416 rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
417 result = qdict_get_int(rsp, parameter);
418 qobject_unref(rsp);
419 return result;
420}
421
8f7798f1
JQ
422static void migrate_check_parameter_int(QTestState *who, const char *parameter,
423 long long value)
56b4a42a 424{
609d3844 425 long long result;
56b4a42a 426
8f7798f1 427 result = migrate_get_parameter_int(who, parameter);
609d3844 428 g_assert_cmpint(result, ==, value);
56b4a42a
JQ
429}
430
8f7798f1
JQ
431static void migrate_set_parameter_int(QTestState *who, const char *parameter,
432 long long value)
d62fbe60
JQ
433{
434 QDict *rsp;
d62fbe60 435
c44a56d8
MA
436 rsp = qtest_qmp(who,
437 "{ 'execute': 'migrate-set-parameters',"
438 "'arguments': { %s: %lld } }",
439 parameter, value);
d62fbe60 440 g_assert(qdict_haskey(rsp, "return"));
cb3e7f08 441 qobject_unref(rsp);
8f7798f1 442 migrate_check_parameter_int(who, parameter, value);
d62fbe60
JQ
443}
444
d5f49640
PX
445static void migrate_pause(QTestState *who)
446{
447 QDict *rsp;
448
449 rsp = wait_command(who, "{ 'execute': 'migrate-pause' }");
d5f49640
PX
450 qobject_unref(rsp);
451}
452
453static void migrate_recover(QTestState *who, const char *uri)
454{
455 QDict *rsp;
d5f49640 456
b7281c69
MA
457 rsp = wait_command(who,
458 "{ 'execute': 'migrate-recover', "
459 " 'id': 'recover-cmd', "
460 " 'arguments': { 'uri': %s } }",
461 uri);
d5f49640
PX
462 qobject_unref(rsp);
463}
464
d62fbe60 465static void migrate_set_capability(QTestState *who, const char *capability,
c44a56d8 466 bool value)
d62fbe60
JQ
467{
468 QDict *rsp;
c44a56d8
MA
469
470 rsp = qtest_qmp(who,
471 "{ 'execute': 'migrate-set-capabilities',"
472 "'arguments': { "
473 "'capabilities': [ { "
474 "'capability': %s, 'state': %i } ] } }",
475 capability, value);
d62fbe60 476 g_assert(qdict_haskey(rsp, "return"));
cb3e7f08 477 qobject_unref(rsp);
d62fbe60
JQ
478}
479
b5bbd3f3
MA
480/*
481 * Send QMP command "migrate".
482 * Arguments are built from @fmt... (formatted like
483 * qobject_from_jsonf_nofail()) with "uri": @uri spliced in.
484 */
485GCC_FMT_ATTR(3, 4)
486static void migrate(QTestState *who, const char *uri, const char *fmt, ...)
d62fbe60 487{
b5bbd3f3
MA
488 va_list ap;
489 QDict *args, *rsp;
d62fbe60 490
b5bbd3f3
MA
491 va_start(ap, fmt);
492 args = qdict_from_vjsonf_nofail(fmt, ap);
493 va_end(ap);
494
495 g_assert(!qdict_haskey(args, "uri"));
496 qdict_put_str(args, "uri", uri);
497
a2726593 498 rsp = qtest_qmp(who, "{ 'execute': 'migrate', 'arguments': %p}", args);
24d5588c 499
d62fbe60 500 g_assert(qdict_haskey(rsp, "return"));
cb3e7f08 501 qobject_unref(rsp);
d62fbe60
JQ
502}
503
d131662a 504static void migrate_postcopy_start(QTestState *from, QTestState *to)
eb665d7d
JQ
505{
506 QDict *rsp;
507
d131662a 508 rsp = wait_command(from, "{ 'execute': 'migrate-start-postcopy' }");
cb3e7f08 509 qobject_unref(rsp);
d131662a
PX
510
511 if (!got_stop) {
512 qtest_qmp_eventwait(from, "STOP");
513 }
514
515 qtest_qmp_eventwait(to, "RESUME");
eb665d7d
JQ
516}
517
5fd4a9c9 518static int test_migrate_start(QTestState **from, QTestState **to,
660a9b68 519 const char *uri, bool hide_stderr,
3af31a34
YK
520 bool use_shmem, const char *opts_src,
521 const char *opts_dst)
ea0c6d62 522{
d62fbe60 523 gchar *cmd_src, *cmd_dst;
660a9b68
YK
524 char *bootpath = NULL;
525 char *extra_opts = NULL;
526 char *shmem_path = NULL;
aaf89c8a 527 const char *arch = qtest_get_arch();
63b2d935 528 const char *accel = "kvm:tcg";
ea0c6d62 529
3af31a34
YK
530 opts_src = opts_src ? opts_src : "";
531 opts_dst = opts_dst ? opts_dst : "";
532
660a9b68
YK
533 if (use_shmem) {
534 if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) {
535 g_test_skip("/dev/shm is not supported");
536 return -1;
537 }
538 shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid());
539 }
ea0c6d62 540
660a9b68
YK
541 got_stop = false;
542 bootpath = g_strdup_printf("%s/bootsect", tmpfs);
aaf89c8a 543 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
2785f196
PM
544 /* the assembled x86 boot sector should be exactly one sector large */
545 assert(sizeof(x86_bootsect) == 512);
546 init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect));
660a9b68 547 extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL;
63b2d935 548 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
31a6bb74 549 " -name source,debug-threads=on"
aaf89c8a 550 " -serial file:%s/src_serial"
3af31a34 551 " -drive file=%s,format=raw %s %s",
660a9b68 552 accel, tmpfs, bootpath,
3af31a34 553 extra_opts ? extra_opts : "", opts_src);
63b2d935 554 cmd_dst = g_strdup_printf("-machine accel=%s -m 150M"
31a6bb74 555 " -name target,debug-threads=on"
aaf89c8a 556 " -serial file:%s/dest_serial"
557 " -drive file=%s,format=raw"
3af31a34 558 " -incoming %s %s %s",
660a9b68 559 accel, tmpfs, bootpath, uri,
3af31a34 560 extra_opts ? extra_opts : "", opts_dst);
e51e711b
WH
561 start_address = X86_TEST_MEM_START;
562 end_address = X86_TEST_MEM_END;
5571dc82 563 } else if (g_str_equal(arch, "s390x")) {
2785f196 564 init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf));
660a9b68 565 extra_opts = use_shmem ? get_shmem_opts("128M", shmem_path) : NULL;
5571dc82
TH
566 cmd_src = g_strdup_printf("-machine accel=%s -m 128M"
567 " -name source,debug-threads=on"
3af31a34 568 " -serial file:%s/src_serial -bios %s %s %s",
660a9b68 569 accel, tmpfs, bootpath,
3af31a34 570 extra_opts ? extra_opts : "", opts_src);
5571dc82
TH
571 cmd_dst = g_strdup_printf("-machine accel=%s -m 128M"
572 " -name target,debug-threads=on"
573 " -serial file:%s/dest_serial -bios %s"
3af31a34 574 " -incoming %s %s %s",
660a9b68 575 accel, tmpfs, bootpath, uri,
3af31a34 576 extra_opts ? extra_opts : "", opts_dst);
5571dc82
TH
577 start_address = S390_TEST_MEM_START;
578 end_address = S390_TEST_MEM_END;
aaf89c8a 579 } else if (strcmp(arch, "ppc64") == 0) {
660a9b68 580 extra_opts = use_shmem ? get_shmem_opts("256M", shmem_path) : NULL;
fc71e3e5 581 cmd_src = g_strdup_printf("-machine accel=%s -m 256M -nodefaults"
31a6bb74 582 " -name source,debug-threads=on"
aaf89c8a 583 " -serial file:%s/src_serial"
fc71e3e5
TH
584 " -prom-env 'use-nvramrc?=true' -prom-env "
585 "'nvramrc=hex .\" _\" begin %x %x "
cdf33815 586 "do i c@ 1 + i c! 1000 +loop .\" B\" 0 "
3af31a34
YK
587 "until' %s %s", accel, tmpfs, end_address,
588 start_address, extra_opts ? extra_opts : "",
589 opts_src);
171da9d5 590 cmd_dst = g_strdup_printf("-machine accel=%s -m 256M"
31a6bb74 591 " -name target,debug-threads=on"
aaf89c8a 592 " -serial file:%s/dest_serial"
3af31a34 593 " -incoming %s %s %s",
660a9b68 594 accel, tmpfs, uri,
3af31a34 595 extra_opts ? extra_opts : "", opts_dst);
e51e711b
WH
596
597 start_address = PPC_TEST_MEM_START;
598 end_address = PPC_TEST_MEM_END;
c02b3781 599 } else if (strcmp(arch, "aarch64") == 0) {
2785f196 600 init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel));
660a9b68 601 extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL;
c02b3781
WH
602 cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
603 "-name vmsource,debug-threads=on -cpu max "
604 "-m 150M -serial file:%s/src_serial "
3af31a34 605 "-kernel %s %s %s",
660a9b68 606 accel, tmpfs, bootpath,
3af31a34 607 extra_opts ? extra_opts : "", opts_src);
c02b3781
WH
608 cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
609 "-name vmdest,debug-threads=on -cpu max "
610 "-m 150M -serial file:%s/dest_serial "
611 "-kernel %s "
3af31a34 612 "-incoming %s %s %s",
660a9b68 613 accel, tmpfs, bootpath, uri,
3af31a34 614 extra_opts ? extra_opts : "", opts_dst);
c02b3781
WH
615
616 start_address = ARM_TEST_MEM_START;
617 end_address = ARM_TEST_MEM_END;
618
619 g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
aaf89c8a 620 } else {
621 g_assert_not_reached();
622 }
623
e2dd21e5 624 g_free(bootpath);
660a9b68 625 g_free(extra_opts);
e2dd21e5 626
f96d6651
DDAG
627 if (hide_stderr) {
628 gchar *tmp;
629 tmp = g_strdup_printf("%s 2>/dev/null", cmd_src);
630 g_free(cmd_src);
631 cmd_src = tmp;
632
633 tmp = g_strdup_printf("%s 2>/dev/null", cmd_dst);
634 g_free(cmd_dst);
635 cmd_dst = tmp;
636 }
637
a2726593 638 *from = qtest_init(cmd_src);
aaf89c8a 639 g_free(cmd_src);
640
7195a871 641 *to = qtest_init(cmd_dst);
aaf89c8a 642 g_free(cmd_dst);
660a9b68
YK
643
644 /*
645 * Remove shmem file immediately to avoid memory leak in test failed case.
646 * It's valid becase QEMU has already opened this file
647 */
648 if (use_shmem) {
649 unlink(shmem_path);
650 g_free(shmem_path);
651 }
652
5fd4a9c9 653 return 0;
7195a871
JQ
654}
655
2c9bb297 656static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
7195a871
JQ
657{
658 unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d;
659
660 qtest_quit(from);
661
2c9bb297
DDAG
662 if (test_dest) {
663 qtest_memread(to, start_address, &dest_byte_a, 1);
7195a871 664
2c9bb297
DDAG
665 /* Destination still running, wait for a byte to change */
666 do {
667 qtest_memread(to, start_address, &dest_byte_b, 1);
668 usleep(1000 * 10);
669 } while (dest_byte_a == dest_byte_b);
670
671 qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}");
7195a871 672
2c9bb297
DDAG
673 /* With it stopped, check nothing changes */
674 qtest_memread(to, start_address, &dest_byte_c, 1);
675 usleep(1000 * 200);
676 qtest_memread(to, start_address, &dest_byte_d, 1);
677 g_assert_cmpint(dest_byte_c, ==, dest_byte_d);
7195a871 678
2c9bb297
DDAG
679 check_guests_ram(to);
680 }
7195a871
JQ
681
682 qtest_quit(to);
683
684 cleanup("bootsect");
685 cleanup("migsocket");
686 cleanup("src_serial");
687 cleanup("dest_serial");
688}
689
4c27486d
JQ
690static void deprecated_set_downtime(QTestState *who, const double value)
691{
692 QDict *rsp;
4c27486d 693
015715f5
MA
694 rsp = qtest_qmp(who,
695 "{ 'execute': 'migrate_set_downtime',"
696 " 'arguments': { 'value': %f } }", value);
4c27486d 697 g_assert(qdict_haskey(rsp, "return"));
cb3e7f08 698 qobject_unref(rsp);
8f7798f1 699 migrate_check_parameter_int(who, "downtime-limit", value * 1000);
4c27486d
JQ
700}
701
c44a56d8 702static void deprecated_set_speed(QTestState *who, long long value)
4c27486d
JQ
703{
704 QDict *rsp;
4c27486d 705
c44a56d8
MA
706 rsp = qtest_qmp(who, "{ 'execute': 'migrate_set_speed',"
707 "'arguments': { 'value': %lld } }", value);
4c27486d 708 g_assert(qdict_haskey(rsp, "return"));
cb3e7f08 709 qobject_unref(rsp);
8f7798f1 710 migrate_check_parameter_int(who, "max-bandwidth", value);
4c27486d
JQ
711}
712
cdf84229
JQ
713static void deprecated_set_cache_size(QTestState *who, long long value)
714{
715 QDict *rsp;
716
717 rsp = qtest_qmp(who, "{ 'execute': 'migrate-set-cache-size',"
718 "'arguments': { 'value': %lld } }", value);
719 g_assert(qdict_haskey(rsp, "return"));
720 qobject_unref(rsp);
8f7798f1 721 migrate_check_parameter_int(who, "xbzrle-cache-size", value);
cdf84229
JQ
722}
723
4c27486d
JQ
724static void test_deprecated(void)
725{
726 QTestState *from;
727
a2726593 728 from = qtest_init("-machine none");
4c27486d
JQ
729
730 deprecated_set_downtime(from, 0.12345);
c44a56d8 731 deprecated_set_speed(from, 12345);
cdf84229 732 deprecated_set_cache_size(from, 4096);
4c27486d
JQ
733
734 qtest_quit(from);
735}
736
d131662a 737static int migrate_postcopy_prepare(QTestState **from_ptr,
3e81f73c
PX
738 QTestState **to_ptr,
739 bool hide_error)
7195a871
JQ
740{
741 char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
863e27a8 742 QTestState *from, *to;
7195a871 743
3af31a34 744 if (test_migrate_start(&from, &to, uri, hide_error, false, NULL, NULL)) {
d131662a 745 return -1;
5fd4a9c9 746 }
ea0c6d62 747
c44a56d8
MA
748 migrate_set_capability(from, "postcopy-ram", true);
749 migrate_set_capability(to, "postcopy-ram", true);
750 migrate_set_capability(to, "postcopy-blocktime", true);
ea0c6d62
DDAG
751
752 /* We want to pick a speed slow enough that the test completes
753 * quickly, but that it doesn't complete precopy even on a slow
754 * machine, so also set the downtime.
755 */
8f7798f1
JQ
756 migrate_set_parameter_int(from, "max-bandwidth", 100000000);
757 migrate_set_parameter_int(from, "downtime-limit", 1);
ea0c6d62
DDAG
758
759 /* Wait for the first serial output from the source */
760 wait_for_serial("src_serial");
761
b5bbd3f3 762 migrate(from, uri, "{}");
d131662a 763 g_free(uri);
ea0c6d62 764
863e27a8 765 wait_for_migration_pass(from);
ea0c6d62 766
d131662a
PX
767 *from_ptr = from;
768 *to_ptr = to;
ea0c6d62 769
d131662a
PX
770 return 0;
771}
ea0c6d62 772
d131662a
PX
773static void migrate_postcopy_complete(QTestState *from, QTestState *to)
774{
775 wait_for_migration_complete(from);
ea0c6d62 776
d131662a 777 /* Make sure we get at least one "B" on destination */
ea0c6d62 778 wait_for_serial("dest_serial");
ea0c6d62 779
346f3dab
AP
780 if (uffd_feature_thread_id) {
781 read_blocktime(to);
782 }
ea0c6d62 783
2c9bb297
DDAG
784 test_migrate_end(from, to, true);
785}
786
d131662a
PX
787static void test_postcopy(void)
788{
789 QTestState *from, *to;
790
3e81f73c 791 if (migrate_postcopy_prepare(&from, &to, false)) {
d131662a
PX
792 return;
793 }
794 migrate_postcopy_start(from, to);
795 migrate_postcopy_complete(from, to);
796}
797
d5f49640
PX
798static void test_postcopy_recovery(void)
799{
800 QTestState *from, *to;
801 char *uri;
802
3e81f73c 803 if (migrate_postcopy_prepare(&from, &to, true)) {
d5f49640
PX
804 return;
805 }
806
807 /* Turn postcopy speed down, 4K/s is slow enough on any machines */
8f7798f1 808 migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096);
d5f49640
PX
809
810 /* Now we start the postcopy */
811 migrate_postcopy_start(from, to);
812
813 /*
814 * Wait until postcopy is really started; we can only run the
815 * migrate-pause command during a postcopy
816 */
e15310ea
DDAG
817 wait_for_migration_status(from, "postcopy-active",
818 (const char * []) { "failed",
819 "completed", NULL });
d5f49640
PX
820
821 /*
822 * Manually stop the postcopy migration. This emulates a network
823 * failure with the migration socket
824 */
825 migrate_pause(from);
826
827 /*
828 * Wait for destination side to reach postcopy-paused state. The
829 * migrate-recover command can only succeed if destination machine
830 * is in the paused state
831 */
e15310ea
DDAG
832 wait_for_migration_status(to, "postcopy-paused",
833 (const char * []) { "failed", "active",
834 "completed", NULL });
d5f49640
PX
835
836 /*
837 * Create a new socket to emulate a new channel that is different
838 * from the broken migration channel; tell the destination to
839 * listen to the new port
840 */
841 uri = g_strdup_printf("unix:%s/migsocket-recover", tmpfs);
842 migrate_recover(to, uri);
843
844 /*
845 * Try to rebuild the migration channel using the resume flag and
846 * the newly created channel
847 */
e15310ea
DDAG
848 wait_for_migration_status(from, "postcopy-paused",
849 (const char * []) { "failed", "active",
850 "completed", NULL });
b5bbd3f3 851 migrate(from, uri, "{'resume': true}");
d5f49640
PX
852 g_free(uri);
853
854 /* Restore the postcopy bandwidth to unlimited */
8f7798f1 855 migrate_set_parameter_int(from, "max-postcopy-bandwidth", 0);
d5f49640
PX
856
857 migrate_postcopy_complete(from, to);
858}
859
3af31a34 860static void wait_for_migration_fail(QTestState *from, bool allow_active)
2c9bb297 861{
e1454165 862 QDict *rsp_return;
2f7074c6 863 char *status;
2c9bb297
DDAG
864 bool failed;
865
2c9bb297 866 do {
2f7074c6 867 status = migrate_query_status(from);
3af31a34
YK
868 g_assert(!strcmp(status, "setup") || !strcmp(status, "failed") ||
869 (allow_active && !strcmp(status, "active")));
2c9bb297 870 failed = !strcmp(status, "failed");
2f7074c6 871 g_free(status);
2c9bb297
DDAG
872 } while (!failed);
873
874 /* Is the machine currently running? */
e1454165 875 rsp_return = wait_command(from, "{ 'execute': 'query-status' }");
2c9bb297
DDAG
876 g_assert(qdict_haskey(rsp_return, "running"));
877 g_assert(qdict_get_bool(rsp_return, "running"));
e1454165 878 qobject_unref(rsp_return);
3af31a34
YK
879}
880
881static void test_baddest(void)
882{
883 QTestState *from, *to;
2c9bb297 884
3af31a34
YK
885 if (test_migrate_start(&from, &to, "tcp:0:0", true, false, NULL, NULL)) {
886 return;
887 }
888 migrate(from, "tcp:0:0", "{}");
889 wait_for_migration_fail(from, false);
2c9bb297 890 test_migrate_end(from, to, false);
ea0c6d62
DDAG
891}
892
2884100c
JQ
893static void test_precopy_unix(void)
894{
895 char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
896 QTestState *from, *to;
897
3af31a34 898 if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) {
5fd4a9c9
DDAG
899 return;
900 }
2884100c
JQ
901
902 /* We want to pick a speed slow enough that the test completes
903 * quickly, but that it doesn't complete precopy even on a slow
904 * machine, so also set the downtime.
905 */
906 /* 1 ms should make it not converge*/
8f7798f1 907 migrate_set_parameter_int(from, "downtime-limit", 1);
2884100c 908 /* 1GB/s */
8f7798f1 909 migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
2884100c
JQ
910
911 /* Wait for the first serial output from the source */
912 wait_for_serial("src_serial");
913
b5bbd3f3 914 migrate(from, uri, "{}");
2884100c
JQ
915
916 wait_for_migration_pass(from);
917
918 /* 300 ms should converge */
8f7798f1 919 migrate_set_parameter_int(from, "downtime-limit", 300);
2884100c
JQ
920
921 if (!got_stop) {
922 qtest_qmp_eventwait(from, "STOP");
923 }
924
925 qtest_qmp_eventwait(to, "RESUME");
926
927 wait_for_serial("dest_serial");
928 wait_for_migration_complete(from);
929
930 test_migrate_end(from, to, true);
931 g_free(uri);
932}
933
660a9b68
YK
934#if 0
935/* Currently upset on aarch64 TCG */
936static void test_ignore_shared(void)
937{
938 char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
939 QTestState *from, *to;
940
3af31a34 941 if (test_migrate_start(&from, &to, uri, false, true, NULL, NULL)) {
660a9b68
YK
942 return;
943 }
944
945 migrate_set_capability(from, "x-ignore-shared", true);
946 migrate_set_capability(to, "x-ignore-shared", true);
947
948 /* Wait for the first serial output from the source */
949 wait_for_serial("src_serial");
950
951 migrate(from, uri, "{}");
952
953 wait_for_migration_pass(from);
954
955 if (!got_stop) {
956 qtest_qmp_eventwait(from, "STOP");
957 }
958
959 qtest_qmp_eventwait(to, "RESUME");
960
961 wait_for_serial("dest_serial");
962 wait_for_migration_complete(from);
963
964 /* Check whether shared RAM has been really skipped */
965 g_assert_cmpint(read_ram_property_int(from, "transferred"), <, 1024 * 1024);
966
967 test_migrate_end(from, to, true);
968 g_free(uri);
969}
970#endif
971
cdf84229
JQ
972static void test_xbzrle(const char *uri)
973{
974 QTestState *from, *to;
975
3af31a34 976 if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) {
cdf84229
JQ
977 return;
978 }
979
980 /*
981 * We want to pick a speed slow enough that the test completes
982 * quickly, but that it doesn't complete precopy even on a slow
983 * machine, so also set the downtime.
984 */
985 /* 1 ms should make it not converge*/
8f7798f1 986 migrate_set_parameter_int(from, "downtime-limit", 1);
cdf84229 987 /* 1GB/s */
8f7798f1 988 migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
cdf84229 989
8f7798f1 990 migrate_set_parameter_int(from, "xbzrle-cache-size", 33554432);
cdf84229
JQ
991
992 migrate_set_capability(from, "xbzrle", "true");
993 migrate_set_capability(to, "xbzrle", "true");
994 /* Wait for the first serial output from the source */
995 wait_for_serial("src_serial");
996
997 migrate(from, uri, "{}");
998
999 wait_for_migration_pass(from);
1000
1001 /* 300ms should converge */
8f7798f1 1002 migrate_set_parameter_int(from, "downtime-limit", 300);
cdf84229
JQ
1003
1004 if (!got_stop) {
1005 qtest_qmp_eventwait(from, "STOP");
1006 }
1007 qtest_qmp_eventwait(to, "RESUME");
1008
1009 wait_for_serial("dest_serial");
1010 wait_for_migration_complete(from);
1011
1012 test_migrate_end(from, to, true);
1013}
1014
1015static void test_xbzrle_unix(void)
1016{
1017 char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
1018
1019 test_xbzrle(uri);
1020 g_free(uri);
1021}
1022
609d3844
JQ
1023static void test_precopy_tcp(void)
1024{
1025 char *uri;
1026 QTestState *from, *to;
1027
3af31a34
YK
1028 if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", false, false,
1029 NULL, NULL)) {
609d3844
JQ
1030 return;
1031 }
1032
1033 /*
1034 * We want to pick a speed slow enough that the test completes
1035 * quickly, but that it doesn't complete precopy even on a slow
1036 * machine, so also set the downtime.
1037 */
1038 /* 1 ms should make it not converge*/
8f7798f1 1039 migrate_set_parameter_int(from, "downtime-limit", 1);
609d3844 1040 /* 1GB/s */
8f7798f1 1041 migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
609d3844
JQ
1042
1043 /* Wait for the first serial output from the source */
1044 wait_for_serial("src_serial");
1045
1046 uri = migrate_get_socket_address(to, "socket-address");
1047
1048 migrate(from, uri, "{}");
1049
1050 wait_for_migration_pass(from);
1051
1052 /* 300ms should converge */
8f7798f1 1053 migrate_set_parameter_int(from, "downtime-limit", 300);
609d3844
JQ
1054
1055 if (!got_stop) {
1056 qtest_qmp_eventwait(from, "STOP");
1057 }
1058 qtest_qmp_eventwait(to, "RESUME");
1059
1060 wait_for_serial("dest_serial");
1061 wait_for_migration_complete(from);
1062
1063 test_migrate_end(from, to, true);
1064 g_free(uri);
1065}
1066
24d5588c
YK
1067static void test_migrate_fd_proto(void)
1068{
1069 QTestState *from, *to;
1070 int ret;
1071 int pair[2];
1072 QDict *rsp;
1073 const char *error_desc;
1074
3af31a34 1075 if (test_migrate_start(&from, &to, "defer", false, false, NULL, NULL)) {
24d5588c
YK
1076 return;
1077 }
1078
1079 /*
1080 * We want to pick a speed slow enough that the test completes
1081 * quickly, but that it doesn't complete precopy even on a slow
1082 * machine, so also set the downtime.
1083 */
1084 /* 1 ms should make it not converge */
8f7798f1 1085 migrate_set_parameter_int(from, "downtime-limit", 1);
24d5588c 1086 /* 1GB/s */
8f7798f1 1087 migrate_set_parameter_int(from, "max-bandwidth", 1000000000);
24d5588c
YK
1088
1089 /* Wait for the first serial output from the source */
1090 wait_for_serial("src_serial");
1091
1092 /* Create two connected sockets for migration */
1093 ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair);
1094 g_assert_cmpint(ret, ==, 0);
1095
1096 /* Send the 1st socket to the target */
1097 rsp = wait_command_fd(to, pair[0],
1098 "{ 'execute': 'getfd',"
1099 " 'arguments': { 'fdname': 'fd-mig' }}");
1100 qobject_unref(rsp);
1101 close(pair[0]);
1102
1103 /* Start incoming migration from the 1st socket */
1104 rsp = wait_command(to, "{ 'execute': 'migrate-incoming',"
1105 " 'arguments': { 'uri': 'fd:fd-mig' }}");
1106 qobject_unref(rsp);
1107
1108 /* Send the 2nd socket to the target */
1109 rsp = wait_command_fd(from, pair[1],
1110 "{ 'execute': 'getfd',"
1111 " 'arguments': { 'fdname': 'fd-mig' }}");
1112 qobject_unref(rsp);
1113 close(pair[1]);
1114
1115 /* Start migration to the 2nd socket*/
1116 migrate(from, "fd:fd-mig", "{}");
1117
1118 wait_for_migration_pass(from);
1119
1120 /* 300ms should converge */
8f7798f1 1121 migrate_set_parameter_int(from, "downtime-limit", 300);
24d5588c
YK
1122
1123 if (!got_stop) {
1124 qtest_qmp_eventwait(from, "STOP");
1125 }
1126 qtest_qmp_eventwait(to, "RESUME");
1127
1128 /* Test closing fds */
1129 /* We assume, that QEMU removes named fd from its list,
1130 * so this should fail */
1131 rsp = qtest_qmp(from, "{ 'execute': 'closefd',"
1132 " 'arguments': { 'fdname': 'fd-mig' }}");
1133 g_assert_true(qdict_haskey(rsp, "error"));
1134 error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
1135 g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
1136 qobject_unref(rsp);
1137
1138 rsp = qtest_qmp(to, "{ 'execute': 'closefd',"
1139 " 'arguments': { 'fdname': 'fd-mig' }}");
1140 g_assert_true(qdict_haskey(rsp, "error"));
1141 error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
1142 g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
1143 qobject_unref(rsp);
1144
1145 /* Complete migration */
1146 wait_for_serial("dest_serial");
1147 wait_for_migration_complete(from);
1148 test_migrate_end(from, to, true);
1149}
1150
3af31a34
YK
1151static void do_test_validate_uuid(const char *uuid_arg_src,
1152 const char *uuid_arg_dst,
1153 bool should_fail, bool hide_stderr)
1154{
1155 char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
1156 QTestState *from, *to;
1157
1158 if (test_migrate_start(&from, &to, uri, hide_stderr, false,
1159 uuid_arg_src, uuid_arg_dst)) {
1160 return;
1161 }
1162
1163 /*
1164 * UUID validation is at the begin of migration. So, the main process of
1165 * migration is not interesting for us here. Thus, set huge downtime for
1166 * very fast migration.
1167 */
1168 migrate_set_parameter_int(from, "downtime-limit", 1000000);
1169 migrate_set_capability(from, "validate-uuid", true);
1170
1171 /* Wait for the first serial output from the source */
1172 wait_for_serial("src_serial");
1173
1174 migrate(from, uri, "{}");
1175
1176 if (should_fail) {
1177 qtest_set_expected_status(to, 1);
1178 wait_for_migration_fail(from, true);
1179 } else {
1180 wait_for_migration_complete(from);
1181 }
1182
1183 test_migrate_end(from, to, false);
1184 g_free(uri);
1185}
1186
1187static void test_validate_uuid(void)
1188{
1189 do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111",
1190 "-uuid 11111111-1111-1111-1111-111111111111",
1191 false, false);
1192}
1193
1194static void test_validate_uuid_error(void)
1195{
1196 do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111",
1197 "-uuid 22222222-2222-2222-2222-222222222222",
1198 true, true);
1199}
1200
1201static void test_validate_uuid_src_not_set(void)
1202{
1203 do_test_validate_uuid(NULL, "-uuid 11111111-1111-1111-1111-111111111111",
1204 false, true);
1205}
1206
1207static void test_validate_uuid_dst_not_set(void)
1208{
1209 do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", NULL,
1210 false, true);
1211}
1212
ea0c6d62
DDAG
1213int main(int argc, char **argv)
1214{
2656bfd9 1215 char template[] = "/tmp/migration-test-XXXXXX";
ea0c6d62
DDAG
1216 int ret;
1217
1218 g_test_init(&argc, &argv, NULL);
1219
1220 if (!ufd_version_check()) {
4848cb3d 1221 return g_test_run();
ea0c6d62
DDAG
1222 }
1223
880b169a
TH
1224 /*
1225 * On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
1226 * is touchy due to race conditions on dirty bits (especially on PPC for
1227 * some reason)
1228 */
1229 if (g_str_equal(qtest_get_arch(), "ppc64") &&
1230 access("/sys/module/kvm_hv", F_OK)) {
1231 g_test_message("Skipping test: kvm_hv not available");
4848cb3d 1232 return g_test_run();
880b169a
TH
1233 }
1234
d254b392
TH
1235 /*
1236 * Similar to ppc64, s390x seems to be touchy with TCG, so disable it
1237 * there until the problems are resolved
1238 */
1239 if (g_str_equal(qtest_get_arch(), "s390x")) {
1240#if defined(HOST_S390X)
1241 if (access("/dev/kvm", R_OK | W_OK)) {
1242 g_test_message("Skipping test: kvm not available");
4848cb3d 1243 return g_test_run();
d254b392
TH
1244 }
1245#else
1246 g_test_message("Skipping test: Need s390x host to work properly");
4848cb3d 1247 return g_test_run();
d254b392
TH
1248#endif
1249 }
1250
ea0c6d62
DDAG
1251 tmpfs = mkdtemp(template);
1252 if (!tmpfs) {
13ee9e30 1253 g_test_message("mkdtemp on path (%s): %s", template, strerror(errno));
ea0c6d62
DDAG
1254 }
1255 g_assert(tmpfs);
1256
1257 module_call_init(MODULE_INIT_QOM);
1258
2884100c 1259 qtest_add_func("/migration/postcopy/unix", test_postcopy);
d5f49640 1260 qtest_add_func("/migration/postcopy/recovery", test_postcopy_recovery);
4c27486d 1261 qtest_add_func("/migration/deprecated", test_deprecated);
2c9bb297 1262 qtest_add_func("/migration/bad_dest", test_baddest);
2884100c 1263 qtest_add_func("/migration/precopy/unix", test_precopy_unix);
609d3844 1264 qtest_add_func("/migration/precopy/tcp", test_precopy_tcp);
660a9b68 1265 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
cdf84229 1266 qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix);
24d5588c 1267 qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
3af31a34
YK
1268 qtest_add_func("/migration/validate_uuid", test_validate_uuid);
1269 qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error);
1270 qtest_add_func("/migration/validate_uuid_src_not_set",
1271 test_validate_uuid_src_not_set);
1272 qtest_add_func("/migration/validate_uuid_dst_not_set",
1273 test_validate_uuid_dst_not_set);
ea0c6d62
DDAG
1274
1275 ret = g_test_run();
1276
1277 g_assert_cmpint(ret, ==, 0);
1278
1279 ret = rmdir(tmpfs);
1280 if (ret != 0) {
13ee9e30 1281 g_test_message("unable to rmdir: path (%s): %s",
ea0c6d62
DDAG
1282 tmpfs, strerror(errno));
1283 }
1284
1285 return ret;
1286}