]>
Commit | Line | Data |
---|---|---|
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" |
ea0c6d62 DDAG |
17 | #include "qemu/option.h" |
18 | #include "qemu/range.h" | |
a9c94277 | 19 | #include "qemu/sockets.h" |
8228e353 | 20 | #include "chardev/char.h" |
ea0c6d62 | 21 | #include "sysemu/sysemu.h" |
ad723fe5 | 22 | #include "hw/nvram/chrp_nvram.h" |
aaf89c8a | 23 | |
24 | #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */ | |
ea0c6d62 | 25 | |
ea0c6d62 DDAG |
26 | const unsigned start_address = 1024 * 1024; |
27 | const unsigned end_address = 100 * 1024 * 1024; | |
28 | bool got_stop; | |
29 | ||
30 | #if defined(__linux__) | |
ea0c6d62 DDAG |
31 | #include <sys/syscall.h> |
32 | #include <sys/vfs.h> | |
33 | #endif | |
34 | ||
35 | #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD) | |
36 | #include <sys/eventfd.h> | |
37 | #include <sys/ioctl.h> | |
38 | #include <linux/userfaultfd.h> | |
39 | ||
40 | static bool ufd_version_check(void) | |
41 | { | |
42 | struct uffdio_api api_struct; | |
43 | uint64_t ioctl_mask; | |
44 | ||
e1ae9fb6 | 45 | int ufd = syscall(__NR_userfaultfd, O_CLOEXEC); |
ea0c6d62 DDAG |
46 | |
47 | if (ufd == -1) { | |
48 | g_test_message("Skipping test: userfaultfd not available"); | |
49 | return false; | |
50 | } | |
51 | ||
52 | api_struct.api = UFFD_API; | |
53 | api_struct.features = 0; | |
54 | if (ioctl(ufd, UFFDIO_API, &api_struct)) { | |
55 | g_test_message("Skipping test: UFFDIO_API failed"); | |
56 | return false; | |
57 | } | |
58 | ||
59 | ioctl_mask = (__u64)1 << _UFFDIO_REGISTER | | |
60 | (__u64)1 << _UFFDIO_UNREGISTER; | |
61 | if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) { | |
62 | g_test_message("Skipping test: Missing userfault feature"); | |
63 | return false; | |
64 | } | |
65 | ||
66 | return true; | |
67 | } | |
68 | ||
69 | #else | |
70 | static bool ufd_version_check(void) | |
71 | { | |
72 | g_test_message("Skipping test: Userfault not available (builtdtime)"); | |
73 | return false; | |
74 | } | |
75 | ||
76 | #endif | |
77 | ||
78 | static const char *tmpfs; | |
79 | ||
80 | /* A simple PC boot sector that modifies memory (1-100MB) quickly | |
17ca7746 | 81 | * outputting a 'B' every so often if it's still running. |
ea0c6d62 | 82 | */ |
17ca7746 | 83 | #include "tests/migration/x86-a-b-bootblock.h" |
ea0c6d62 | 84 | |
aaf89c8a | 85 | static void init_bootfile_x86(const char *bootpath) |
86 | { | |
87 | FILE *bootfile = fopen(bootpath, "wb"); | |
88 | ||
17ca7746 | 89 | g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1); |
aaf89c8a | 90 | fclose(bootfile); |
91 | } | |
92 | ||
93 | static void init_bootfile_ppc(const char *bootpath) | |
94 | { | |
95 | FILE *bootfile; | |
96 | char buf[MIN_NVRAM_SIZE]; | |
ad723fe5 | 97 | ChrpNvramPartHdr *header = (ChrpNvramPartHdr *)buf; |
aaf89c8a | 98 | |
99 | memset(buf, 0, MIN_NVRAM_SIZE); | |
100 | ||
101 | /* Create a "common" partition in nvram to store boot-command property */ | |
102 | ||
ad723fe5 | 103 | header->signature = CHRP_NVPART_SYSTEM; |
aaf89c8a | 104 | memcpy(header->name, "common", 6); |
ad723fe5 | 105 | chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE); |
aaf89c8a | 106 | |
107 | /* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB, | |
108 | * so let's modify memory between 1MB and 100MB | |
109 | * to do like PC bootsector | |
110 | */ | |
111 | ||
112 | sprintf(buf + 16, | |
113 | "boot-command=hex .\" _\" begin %x %x do i c@ 1 + i c! 1000 +loop " | |
114 | ".\" B\" 0 until", end_address, start_address); | |
115 | ||
116 | /* Write partition to the NVRAM file */ | |
117 | ||
118 | bootfile = fopen(bootpath, "wb"); | |
119 | g_assert_cmpint(fwrite(buf, MIN_NVRAM_SIZE, 1, bootfile), ==, 1); | |
120 | fclose(bootfile); | |
121 | } | |
122 | ||
ea0c6d62 DDAG |
123 | /* |
124 | * Wait for some output in the serial output file, | |
125 | * we get an 'A' followed by an endless string of 'B's | |
126 | * but on the destination we won't have the A. | |
127 | */ | |
128 | static void wait_for_serial(const char *side) | |
129 | { | |
130 | char *serialpath = g_strdup_printf("%s/%s", tmpfs, side); | |
131 | FILE *serialfile = fopen(serialpath, "r"); | |
aaf89c8a | 132 | const char *arch = qtest_get_arch(); |
133 | int started = (strcmp(side, "src_serial") == 0 && | |
134 | strcmp(arch, "ppc64") == 0) ? 0 : 1; | |
ea0c6d62 | 135 | |
e2dd21e5 | 136 | g_free(serialpath); |
ea0c6d62 DDAG |
137 | do { |
138 | int readvalue = fgetc(serialfile); | |
139 | ||
aaf89c8a | 140 | if (!started) { |
141 | /* SLOF prints its banner before starting test, | |
142 | * to ignore it, mark the start of the test with '_', | |
143 | * ignore all characters until this marker | |
144 | */ | |
145 | switch (readvalue) { | |
146 | case '_': | |
147 | started = 1; | |
148 | break; | |
149 | case EOF: | |
150 | fseek(serialfile, 0, SEEK_SET); | |
151 | usleep(1000); | |
152 | break; | |
153 | } | |
154 | continue; | |
155 | } | |
ea0c6d62 DDAG |
156 | switch (readvalue) { |
157 | case 'A': | |
158 | /* Fine */ | |
159 | break; | |
160 | ||
161 | case 'B': | |
162 | /* It's alive! */ | |
163 | fclose(serialfile); | |
ea0c6d62 DDAG |
164 | return; |
165 | ||
166 | case EOF: | |
aaf89c8a | 167 | started = (strcmp(side, "src_serial") == 0 && |
168 | strcmp(arch, "ppc64") == 0) ? 0 : 1; | |
ea0c6d62 DDAG |
169 | fseek(serialfile, 0, SEEK_SET); |
170 | usleep(1000); | |
171 | break; | |
172 | ||
173 | default: | |
174 | fprintf(stderr, "Unexpected %d on %s serial\n", readvalue, side); | |
175 | g_assert_not_reached(); | |
176 | } | |
177 | } while (true); | |
178 | } | |
179 | ||
180 | /* | |
181 | * Events can get in the way of responses we are actually waiting for. | |
182 | */ | |
863e27a8 | 183 | static QDict *wait_command(QTestState *who, const char *command) |
ea0c6d62 DDAG |
184 | { |
185 | const char *event_string; | |
863e27a8 JQ |
186 | QDict *response; |
187 | ||
188 | response = qtest_qmp(who, command); | |
ea0c6d62 | 189 | |
863e27a8 JQ |
190 | while (qdict_haskey(response, "event")) { |
191 | /* OK, it was an event */ | |
192 | event_string = qdict_get_str(response, "event"); | |
193 | if (!strcmp(event_string, "STOP")) { | |
194 | got_stop = true; | |
195 | } | |
196 | QDECREF(response); | |
197 | response = qtest_qmp_receive(who); | |
ea0c6d62 | 198 | } |
863e27a8 | 199 | return response; |
ea0c6d62 DDAG |
200 | } |
201 | ||
202 | ||
203 | /* | |
204 | * It's tricky to use qemu's migration event capability with qtest, | |
205 | * events suddenly appearing confuse the qmp()/hmp() responses. | |
ea0c6d62 DDAG |
206 | */ |
207 | ||
863e27a8 | 208 | static uint64_t get_migration_pass(QTestState *who) |
ea0c6d62 DDAG |
209 | { |
210 | QDict *rsp, *rsp_return, *rsp_ram; | |
211 | uint64_t result; | |
212 | ||
863e27a8 | 213 | rsp = wait_command(who, "{ 'execute': 'query-migrate' }"); |
ea0c6d62 DDAG |
214 | rsp_return = qdict_get_qdict(rsp, "return"); |
215 | if (!qdict_haskey(rsp_return, "ram")) { | |
216 | /* Still in setup */ | |
217 | result = 0; | |
218 | } else { | |
219 | rsp_ram = qdict_get_qdict(rsp_return, "ram"); | |
220 | result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0); | |
ea0c6d62 | 221 | } |
5b1ded22 | 222 | QDECREF(rsp); |
ea0c6d62 DDAG |
223 | return result; |
224 | } | |
225 | ||
863e27a8 | 226 | static void wait_for_migration_complete(QTestState *who) |
ea0c6d62 | 227 | { |
6a7724e9 JQ |
228 | while (true) { |
229 | QDict *rsp, *rsp_return; | |
230 | bool completed; | |
ea0c6d62 DDAG |
231 | const char *status; |
232 | ||
863e27a8 | 233 | rsp = wait_command(who, "{ 'execute': 'query-migrate' }"); |
ea0c6d62 DDAG |
234 | rsp_return = qdict_get_qdict(rsp, "return"); |
235 | status = qdict_get_str(rsp_return, "status"); | |
236 | completed = strcmp(status, "completed") == 0; | |
237 | g_assert_cmpstr(status, !=, "failed"); | |
238 | QDECREF(rsp); | |
6a7724e9 JQ |
239 | if (completed) { |
240 | return; | |
241 | } | |
242 | usleep(1000); | |
243 | } | |
ea0c6d62 DDAG |
244 | } |
245 | ||
863e27a8 | 246 | static void wait_for_migration_pass(QTestState *who) |
ea0c6d62 | 247 | { |
863e27a8 | 248 | uint64_t initial_pass = get_migration_pass(who); |
ea0c6d62 DDAG |
249 | uint64_t pass; |
250 | ||
251 | /* Wait for the 1st sync */ | |
6a7724e9 JQ |
252 | while (!got_stop && !initial_pass) { |
253 | usleep(1000); | |
863e27a8 | 254 | initial_pass = get_migration_pass(who); |
6a7724e9 | 255 | } |
ea0c6d62 DDAG |
256 | |
257 | do { | |
6a7724e9 | 258 | usleep(1000); |
863e27a8 | 259 | pass = get_migration_pass(who); |
ea0c6d62 DDAG |
260 | } while (pass == initial_pass && !got_stop); |
261 | } | |
262 | ||
7195a871 | 263 | static void check_guests_ram(QTestState *who) |
ea0c6d62 DDAG |
264 | { |
265 | /* Our ASM test will have been incrementing one byte from each page from | |
266 | * 1MB to <100MB in order. | |
267 | * This gives us a constraint that any page's byte should be equal or less | |
268 | * than the previous pages byte (mod 256); and they should all be equal | |
269 | * except for one transition at the point where we meet the incrementer. | |
270 | * (We're running this with the guest stopped). | |
271 | */ | |
272 | unsigned address; | |
273 | uint8_t first_byte; | |
274 | uint8_t last_byte; | |
275 | bool hit_edge = false; | |
276 | bool bad = false; | |
277 | ||
7195a871 | 278 | qtest_memread(who, start_address, &first_byte, 1); |
ea0c6d62 DDAG |
279 | last_byte = first_byte; |
280 | ||
281 | for (address = start_address + 4096; address < end_address; address += 4096) | |
282 | { | |
283 | uint8_t b; | |
7195a871 | 284 | qtest_memread(who, address, &b, 1); |
ea0c6d62 DDAG |
285 | if (b != last_byte) { |
286 | if (((b + 1) % 256) == last_byte && !hit_edge) { | |
287 | /* This is OK, the guest stopped at the point of | |
288 | * incrementing the previous page but didn't get | |
289 | * to us yet. | |
290 | */ | |
291 | hit_edge = true; | |
292 | } else { | |
293 | fprintf(stderr, "Memory content inconsistency at %x" | |
294 | " first_byte = %x last_byte = %x current = %x" | |
295 | " hit_edge = %x\n", | |
296 | address, first_byte, last_byte, b, hit_edge); | |
297 | bad = true; | |
298 | } | |
299 | } | |
300 | last_byte = b; | |
301 | } | |
302 | g_assert_false(bad); | |
303 | } | |
304 | ||
305 | static void cleanup(const char *filename) | |
306 | { | |
307 | char *path = g_strdup_printf("%s/%s", tmpfs, filename); | |
308 | ||
309 | unlink(path); | |
e2dd21e5 | 310 | g_free(path); |
ea0c6d62 DDAG |
311 | } |
312 | ||
56b4a42a JQ |
313 | static void migrate_check_parameter(QTestState *who, const char *parameter, |
314 | const char *value) | |
315 | { | |
316 | QDict *rsp, *rsp_return; | |
9c43435d | 317 | char *result; |
56b4a42a JQ |
318 | |
319 | rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); | |
320 | rsp_return = qdict_get_qdict(rsp, "return"); | |
321 | result = g_strdup_printf("%" PRId64, | |
322 | qdict_get_try_int(rsp_return, parameter, -1)); | |
323 | g_assert_cmpstr(result, ==, value); | |
9c43435d | 324 | g_free(result); |
56b4a42a JQ |
325 | QDECREF(rsp); |
326 | } | |
327 | ||
1f90d797 JQ |
328 | static void migrate_set_parameter(QTestState *who, const char *parameter, |
329 | const char *value) | |
d62fbe60 JQ |
330 | { |
331 | QDict *rsp; | |
332 | gchar *cmd; | |
333 | ||
1f90d797 JQ |
334 | cmd = g_strdup_printf("{ 'execute': 'migrate-set-parameters'," |
335 | "'arguments': { '%s': %s } }", | |
336 | parameter, value); | |
d62fbe60 JQ |
337 | rsp = qtest_qmp(who, cmd); |
338 | g_free(cmd); | |
339 | g_assert(qdict_haskey(rsp, "return")); | |
340 | QDECREF(rsp); | |
1f90d797 | 341 | migrate_check_parameter(who, parameter, value); |
d62fbe60 JQ |
342 | } |
343 | ||
344 | static void migrate_set_capability(QTestState *who, const char *capability, | |
345 | const char *value) | |
346 | { | |
347 | QDict *rsp; | |
348 | gchar *cmd; | |
349 | ||
350 | cmd = g_strdup_printf("{ 'execute': 'migrate-set-capabilities'," | |
351 | "'arguments': { " | |
352 | "'capabilities': [ { " | |
353 | "'capability': '%s', 'state': %s } ] } }", | |
354 | capability, value); | |
355 | rsp = qtest_qmp(who, cmd); | |
356 | g_free(cmd); | |
357 | g_assert(qdict_haskey(rsp, "return")); | |
358 | QDECREF(rsp); | |
359 | } | |
360 | ||
361 | static void migrate(QTestState *who, const char *uri) | |
362 | { | |
363 | QDict *rsp; | |
364 | gchar *cmd; | |
365 | ||
366 | cmd = g_strdup_printf("{ 'execute': 'migrate'," | |
367 | "'arguments': { 'uri': '%s' } }", | |
368 | uri); | |
369 | rsp = qtest_qmp(who, cmd); | |
370 | g_free(cmd); | |
371 | g_assert(qdict_haskey(rsp, "return")); | |
372 | QDECREF(rsp); | |
373 | } | |
374 | ||
eb665d7d JQ |
375 | static void migrate_start_postcopy(QTestState *who) |
376 | { | |
377 | QDict *rsp; | |
378 | ||
379 | rsp = wait_command(who, "{ 'execute': 'migrate-start-postcopy' }"); | |
380 | g_assert(qdict_haskey(rsp, "return")); | |
381 | QDECREF(rsp); | |
382 | } | |
383 | ||
7195a871 JQ |
384 | static void test_migrate_start(QTestState **from, QTestState **to, |
385 | const char *uri) | |
ea0c6d62 | 386 | { |
d62fbe60 | 387 | gchar *cmd_src, *cmd_dst; |
ea0c6d62 | 388 | char *bootpath = g_strdup_printf("%s/bootsect", tmpfs); |
aaf89c8a | 389 | const char *arch = qtest_get_arch(); |
63b2d935 | 390 | const char *accel = "kvm:tcg"; |
ea0c6d62 DDAG |
391 | |
392 | got_stop = false; | |
ea0c6d62 | 393 | |
aaf89c8a | 394 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
395 | init_bootfile_x86(bootpath); | |
63b2d935 | 396 | cmd_src = g_strdup_printf("-machine accel=%s -m 150M" |
31a6bb74 | 397 | " -name source,debug-threads=on" |
aaf89c8a | 398 | " -serial file:%s/src_serial" |
399 | " -drive file=%s,format=raw", | |
63b2d935 JQ |
400 | accel, tmpfs, bootpath); |
401 | cmd_dst = g_strdup_printf("-machine accel=%s -m 150M" | |
31a6bb74 | 402 | " -name target,debug-threads=on" |
aaf89c8a | 403 | " -serial file:%s/dest_serial" |
404 | " -drive file=%s,format=raw" | |
405 | " -incoming %s", | |
63b2d935 | 406 | accel, tmpfs, bootpath, uri); |
aaf89c8a | 407 | } else if (strcmp(arch, "ppc64") == 0) { |
171da9d5 TH |
408 | |
409 | /* On ppc64, the test only works with kvm-hv, but not with kvm-pr */ | |
63b2d935 JQ |
410 | if (access("/sys/module/kvm_hv", F_OK)) { |
411 | accel = "tcg"; | |
412 | } | |
aaf89c8a | 413 | init_bootfile_ppc(bootpath); |
171da9d5 | 414 | cmd_src = g_strdup_printf("-machine accel=%s -m 256M" |
31a6bb74 | 415 | " -name source,debug-threads=on" |
aaf89c8a | 416 | " -serial file:%s/src_serial" |
417 | " -drive file=%s,if=pflash,format=raw", | |
171da9d5 TH |
418 | accel, tmpfs, bootpath); |
419 | cmd_dst = g_strdup_printf("-machine accel=%s -m 256M" | |
31a6bb74 | 420 | " -name target,debug-threads=on" |
aaf89c8a | 421 | " -serial file:%s/dest_serial" |
422 | " -incoming %s", | |
171da9d5 | 423 | accel, tmpfs, uri); |
aaf89c8a | 424 | } else { |
425 | g_assert_not_reached(); | |
426 | } | |
427 | ||
e2dd21e5 MAL |
428 | g_free(bootpath); |
429 | ||
7195a871 | 430 | *from = qtest_start(cmd_src); |
aaf89c8a | 431 | g_free(cmd_src); |
432 | ||
7195a871 | 433 | *to = qtest_init(cmd_dst); |
aaf89c8a | 434 | g_free(cmd_dst); |
7195a871 JQ |
435 | } |
436 | ||
437 | static void test_migrate_end(QTestState *from, QTestState *to) | |
438 | { | |
439 | unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; | |
440 | ||
441 | qtest_quit(from); | |
442 | ||
443 | qtest_memread(to, start_address, &dest_byte_a, 1); | |
444 | ||
445 | /* Destination still running, wait for a byte to change */ | |
446 | do { | |
447 | qtest_memread(to, start_address, &dest_byte_b, 1); | |
6a7724e9 | 448 | usleep(1000 * 10); |
7195a871 JQ |
449 | } while (dest_byte_a == dest_byte_b); |
450 | ||
451 | qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}"); | |
452 | /* With it stopped, check nothing changes */ | |
453 | qtest_memread(to, start_address, &dest_byte_c, 1); | |
6a7724e9 | 454 | usleep(1000 * 200); |
7195a871 JQ |
455 | qtest_memread(to, start_address, &dest_byte_d, 1); |
456 | g_assert_cmpint(dest_byte_c, ==, dest_byte_d); | |
457 | ||
458 | check_guests_ram(to); | |
459 | ||
460 | qtest_quit(to); | |
461 | ||
462 | cleanup("bootsect"); | |
463 | cleanup("migsocket"); | |
464 | cleanup("src_serial"); | |
465 | cleanup("dest_serial"); | |
466 | } | |
467 | ||
4c27486d JQ |
468 | static void deprecated_set_downtime(QTestState *who, const double value) |
469 | { | |
470 | QDict *rsp; | |
471 | gchar *cmd; | |
472 | char *expected; | |
473 | int64_t result_int; | |
474 | ||
475 | cmd = g_strdup_printf("{ 'execute': 'migrate_set_downtime'," | |
476 | "'arguments': { 'value': %g } }", value); | |
477 | rsp = qtest_qmp(who, cmd); | |
478 | g_free(cmd); | |
479 | g_assert(qdict_haskey(rsp, "return")); | |
480 | QDECREF(rsp); | |
481 | result_int = value * 1000L; | |
482 | expected = g_strdup_printf("%" PRId64, result_int); | |
483 | migrate_check_parameter(who, "downtime-limit", expected); | |
484 | g_free(expected); | |
485 | } | |
486 | ||
487 | static void deprecated_set_speed(QTestState *who, const char *value) | |
488 | { | |
489 | QDict *rsp; | |
490 | gchar *cmd; | |
491 | ||
492 | cmd = g_strdup_printf("{ 'execute': 'migrate_set_speed'," | |
493 | "'arguments': { 'value': %s } }", value); | |
494 | rsp = qtest_qmp(who, cmd); | |
495 | g_free(cmd); | |
496 | g_assert(qdict_haskey(rsp, "return")); | |
497 | QDECREF(rsp); | |
498 | migrate_check_parameter(who, "max-bandwidth", value); | |
499 | } | |
500 | ||
501 | static void test_deprecated(void) | |
502 | { | |
503 | QTestState *from; | |
504 | ||
505 | from = qtest_start(""); | |
506 | ||
507 | deprecated_set_downtime(from, 0.12345); | |
508 | deprecated_set_speed(from, "12345"); | |
509 | ||
510 | qtest_quit(from); | |
511 | } | |
512 | ||
7195a871 JQ |
513 | static void test_migrate(void) |
514 | { | |
515 | char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); | |
863e27a8 | 516 | QTestState *from, *to; |
7195a871 JQ |
517 | |
518 | test_migrate_start(&from, &to, uri); | |
ea0c6d62 | 519 | |
d62fbe60 JQ |
520 | migrate_set_capability(from, "postcopy-ram", "true"); |
521 | migrate_set_capability(to, "postcopy-ram", "true"); | |
ea0c6d62 DDAG |
522 | |
523 | /* We want to pick a speed slow enough that the test completes | |
524 | * quickly, but that it doesn't complete precopy even on a slow | |
525 | * machine, so also set the downtime. | |
526 | */ | |
1f90d797 JQ |
527 | migrate_set_parameter(from, "max-bandwidth", "100000000"); |
528 | migrate_set_parameter(from, "downtime-limit", "1"); | |
ea0c6d62 DDAG |
529 | |
530 | /* Wait for the first serial output from the source */ | |
531 | wait_for_serial("src_serial"); | |
532 | ||
d62fbe60 | 533 | migrate(from, uri); |
ea0c6d62 | 534 | |
863e27a8 | 535 | wait_for_migration_pass(from); |
ea0c6d62 | 536 | |
eb665d7d | 537 | migrate_start_postcopy(from); |
ea0c6d62 DDAG |
538 | |
539 | if (!got_stop) { | |
863e27a8 | 540 | qtest_qmp_eventwait(from, "STOP"); |
ea0c6d62 DDAG |
541 | } |
542 | ||
863e27a8 | 543 | qtest_qmp_eventwait(to, "RESUME"); |
ea0c6d62 DDAG |
544 | |
545 | wait_for_serial("dest_serial"); | |
863e27a8 | 546 | wait_for_migration_complete(from); |
ea0c6d62 | 547 | |
ea0c6d62 | 548 | g_free(uri); |
ea0c6d62 | 549 | |
7195a871 | 550 | test_migrate_end(from, to); |
ea0c6d62 DDAG |
551 | } |
552 | ||
553 | int main(int argc, char **argv) | |
554 | { | |
2656bfd9 | 555 | char template[] = "/tmp/migration-test-XXXXXX"; |
ea0c6d62 DDAG |
556 | int ret; |
557 | ||
558 | g_test_init(&argc, &argv, NULL); | |
559 | ||
560 | if (!ufd_version_check()) { | |
561 | return 0; | |
562 | } | |
563 | ||
564 | tmpfs = mkdtemp(template); | |
565 | if (!tmpfs) { | |
566 | g_test_message("mkdtemp on path (%s): %s\n", template, strerror(errno)); | |
567 | } | |
568 | g_assert(tmpfs); | |
569 | ||
570 | module_call_init(MODULE_INIT_QOM); | |
571 | ||
2656bfd9 | 572 | qtest_add_func("/migration/postcopy/unix", test_migrate); |
4c27486d | 573 | qtest_add_func("/migration/deprecated", test_deprecated); |
ea0c6d62 DDAG |
574 | |
575 | ret = g_test_run(); | |
576 | ||
577 | g_assert_cmpint(ret, ==, 0); | |
578 | ||
579 | ret = rmdir(tmpfs); | |
580 | if (ret != 0) { | |
581 | g_test_message("unable to rmdir: path (%s): %s\n", | |
582 | tmpfs, strerror(errno)); | |
583 | } | |
584 | ||
585 | return ret; | |
586 | } |