xref: /qemu/tests/qtest/migration/postcopy-tests.c (revision 73f81da0a3628180409a0ae90ece19534bcdf09b)
1 /*
2  * QTest testcases for postcopy migration
3  *
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.
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"
14 #include "libqtest.h"
15 #include "migration/framework.h"
16 #include "migration/migration-util.h"
17 #include "qobject/qlist.h"
18 #include "qemu/module.h"
19 #include "qemu/option.h"
20 #include "qemu/range.h"
21 #include "qemu/sockets.h"
22 
23 static void test_postcopy(void)
24 {
25     MigrateCommon args = { };
26 
27     test_postcopy_common(&args);
28 }
29 
30 static void test_postcopy_suspend(void)
31 {
32     MigrateCommon args = {
33         .start.suspend_me = true,
34     };
35 
36     test_postcopy_common(&args);
37 }
38 
39 static void test_postcopy_preempt(void)
40 {
41     MigrateCommon args = {
42         .start = {
43             .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] = true,
44         },
45     };
46 
47     test_postcopy_common(&args);
48 }
49 
50 static void test_postcopy_recovery(void)
51 {
52     MigrateCommon args = { };
53 
54     test_postcopy_recovery_common(&args);
55 }
56 
57 static void test_postcopy_recovery_fail_handshake(void)
58 {
59     MigrateCommon args = {
60         .postcopy_recovery_fail_stage = POSTCOPY_FAIL_RECOVERY,
61     };
62 
63     test_postcopy_recovery_common(&args);
64 }
65 
66 static void test_postcopy_recovery_fail_reconnect(void)
67 {
68     MigrateCommon args = {
69         .postcopy_recovery_fail_stage = POSTCOPY_FAIL_CHANNEL_ESTABLISH,
70     };
71 
72     test_postcopy_recovery_common(&args);
73 }
74 
75 static void test_postcopy_preempt_recovery(void)
76 {
77     MigrateCommon args = {
78         .start = {
79             .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] = true,
80         },
81     };
82 
83     test_postcopy_recovery_common(&args);
84 }
85 
86 static void migration_test_add_postcopy_smoke(MigrationTestEnv *env)
87 {
88     if (env->has_uffd) {
89         migration_test_add("/migration/postcopy/plain", test_postcopy);
90         migration_test_add("/migration/postcopy/recovery/plain",
91                            test_postcopy_recovery);
92         migration_test_add("/migration/postcopy/preempt/plain",
93                            test_postcopy_preempt);
94     }
95 }
96 
97 void migration_test_add_postcopy(MigrationTestEnv *env)
98 {
99     migration_test_add_postcopy_smoke(env);
100 
101     if (!env->full_set) {
102         return;
103     }
104 
105     if (env->has_uffd) {
106         migration_test_add("/migration/postcopy/preempt/recovery/plain",
107                            test_postcopy_preempt_recovery);
108 
109         migration_test_add(
110             "/migration/postcopy/recovery/double-failures/handshake",
111             test_postcopy_recovery_fail_handshake);
112 
113         migration_test_add(
114             "/migration/postcopy/recovery/double-failures/reconnect",
115             test_postcopy_recovery_fail_reconnect);
116 
117         if (env->is_x86) {
118             migration_test_add("/migration/postcopy/suspend",
119                                test_postcopy_suspend);
120         }
121     }
122 }
123