1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
/*
* Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
* based on the vhost-user-test.c that is:
* Copyright (c) 2014 Virtual Open Systems Sarl.
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
*/
#ifndef TEST_FRAMEWORK_H
#define TEST_FRAMEWORK_H
#include "libqtest.h"
#define FILE_TEST_FILENAME "migfile"
#define FILE_TEST_OFFSET 0x1000
#define FILE_TEST_MARKER 'X'
typedef struct MigrationTestEnv {
bool has_kvm;
bool has_tcg;
bool has_uffd;
bool uffd_feature_thread_id;
bool has_dirty_ring;
bool is_x86;
const char *arch;
const char *qemu_src;
const char *qemu_dst;
char *tmpfs;
} MigrationTestEnv;
MigrationTestEnv *migration_get_env(void);
int migration_env_clean(MigrationTestEnv *env);
/*
* A hook that runs after the src and dst QEMUs have been
* created, but before the migration is started. This can
* be used to set migration parameters and capabilities.
*
* Returns: NULL, or a pointer to opaque state to be
* later passed to the TestMigrateEndHook
*/
typedef void * (*TestMigrateStartHook)(QTestState *from,
QTestState *to);
/*
* A hook that runs after the migration has finished,
* regardless of whether it succeeded or failed, but
* before QEMU has terminated (unless it self-terminated
* due to migration error)
*
* @opaque is a pointer to state previously returned
* by the TestMigrateStartHook if any, or NULL.
*/
typedef void (*TestMigrateEndHook)(QTestState *from,
QTestState *to,
void *opaque);
/*
* Our goal is to ensure that we run a single full migration
* iteration, and also dirty memory, ensuring that at least
* one further iteration is required.
*
* We can't directly synchronize with the start of a migration
* so we have to apply some tricks monitoring memory that is
* transferred.
*
* Initially we set the migration bandwidth to an insanely
* low value, with tiny max downtime too. This basically
* guarantees migration will never complete.
*
* This will result in a test that is unacceptably slow though,
* so we can't let the entire migration pass run at this speed.
* Our intent is to let it run just long enough that we can
* prove data prior to the marker has been transferred *AND*
* also prove this transferred data is dirty again.
*
* Before migration starts, we write a 64-bit magic marker
* into a fixed location in the src VM RAM.
*
* Then watch dst memory until the marker appears. This is
* proof that start_address -> MAGIC_OFFSET_BASE has been
* transferred.
*
* Finally we go back to the source and read a byte just
* before the marker until we see it flip in value. This
* is proof that start_address -> MAGIC_OFFSET_BASE
* is now dirty again.
*
* IOW, we're guaranteed at least a 2nd migration pass
* at this point.
*
* We can now let migration run at full speed to finish
* the test
*/
typedef struct {
/*
* QTEST_LOG=1 may override this. When QTEST_LOG=1, we always dump errors
* unconditionally, because it means the user would like to be verbose.
*/
bool hide_stderr;
bool use_shmem;
/* only launch the target process */
bool only_target;
/* Use dirty ring if true; dirty logging otherwise */
bool use_dirty_ring;
const char *opts_source;
const char *opts_target;
/* suspend the src before migrating to dest. */
bool suspend_me;
} MigrateStart;
typedef enum PostcopyRecoveryFailStage {
/*
* "no failure" must be 0 as it's the default. OTOH, real failure
* cases must be >0 to make sure they trigger by a "if" test.
*/
POSTCOPY_FAIL_NONE = 0,
POSTCOPY_FAIL_CHANNEL_ESTABLISH,
POSTCOPY_FAIL_RECOVERY,
POSTCOPY_FAIL_MAX
} PostcopyRecoveryFailStage;
typedef struct {
/* Optional: fine tune start parameters */
MigrateStart start;
/* Required: the URI for the dst QEMU to listen on */
const char *listen_uri;
/*
* Optional: the URI for the src QEMU to connect to
* If NULL, then it will query the dst QEMU for its actual
* listening address and use that as the connect address.
* This allows for dynamically picking a free TCP port.
*/
const char *connect_uri;
/*
* Optional: JSON-formatted list of src QEMU URIs. If a port is
* defined as '0' in any QDict key a value of '0' will be
* automatically converted to the correct destination port.
*/
const char *connect_channels;
/* Optional: callback to run at start to set migration parameters */
TestMigrateStartHook start_hook;
/* Optional: callback to run at finish to cleanup */
TestMigrateEndHook end_hook;
/*
* Optional: normally we expect the migration process to complete.
*
* There can be a variety of reasons and stages in which failure
* can happen during tests.
*
* If a failure is expected to happen at time of establishing
* the connection, then MIG_TEST_FAIL will indicate that the dst
* QEMU is expected to stay running and accept future migration
* connections.
*
* If a failure is expected to happen while processing the
* migration stream, then MIG_TEST_FAIL_DEST_QUIT_ERR will indicate
* that the dst QEMU is expected to quit with non-zero exit status
*/
enum {
/* This test should succeed, the default */
MIG_TEST_SUCCEED = 0,
/* This test should fail, dest qemu should keep alive */
MIG_TEST_FAIL,
/* This test should fail, dest qemu should fail with abnormal status */
MIG_TEST_FAIL_DEST_QUIT_ERR,
/* The QMP command for this migration should fail with an error */
MIG_TEST_QMP_ERROR,
} result;
/*
* Optional: set number of migration passes to wait for, if live==true.
* If zero, then merely wait for a few MB of dirty data
*/
unsigned int iterations;
/*
* Optional: whether the guest CPUs should be running during a precopy
* migration test. We used to always run with live but it took much
* longer so we reduced live tests to only the ones that have solid
* reason to be tested live-only. For each of the new test cases for
* precopy please provide justifications to use live explicitly (please
* refer to existing ones with live=true), or use live=off by default.
*/
bool live;
/* Postcopy specific fields */
void *postcopy_data;
bool postcopy_preempt;
PostcopyRecoveryFailStage postcopy_recovery_fail_stage;
} MigrateCommon;
void wait_for_serial(const char *side);
void migrate_prepare_for_dirty_mem(QTestState *from);
void migrate_wait_for_dirty_mem(QTestState *from, QTestState *to);
int migrate_start(QTestState **from, QTestState **to, const char *uri,
MigrateStart *args);
void migrate_end(QTestState *from, QTestState *to, bool test_dest);
void test_postcopy_common(MigrateCommon *args);
void test_postcopy_recovery_common(MigrateCommon *args);
void test_precopy_common(MigrateCommon *args);
void test_file_common(MigrateCommon *args, bool stop_src);
void *migrate_hook_start_precopy_tcp_multifd_common(QTestState *from,
QTestState *to,
const char *method);
typedef struct QTestMigrationState QTestMigrationState;
QTestMigrationState *get_src(void);
#ifdef CONFIG_GNUTLS
void migration_test_add_tls(MigrationTestEnv *env);
#else
static inline void migration_test_add_tls(MigrationTestEnv *env) {};
#endif
void migration_test_add_compression(MigrationTestEnv *env);
void migration_test_add_postcopy(MigrationTestEnv *env);
void migration_test_add_file(MigrationTestEnv *env);
void migration_test_add_precopy(MigrationTestEnv *env);
#endif /* TEST_FRAMEWORK_H */
|