]>
Commit | Line | Data |
---|---|---|
a77e6b14 NN |
1 | /* |
2 | * QTest testcase for the vhost-user | |
3 | * | |
4 | * Copyright (c) 2014 Virtual Open Systems Sarl. | |
5 | * | |
6 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
7 | * See the COPYING file in the top-level directory. | |
8 | * | |
9 | */ | |
10 | ||
681c28a3 | 11 | #include "qemu/osdep.h" |
bd95939f | 12 | |
a77e6b14 | 13 | #include "libqtest.h" |
5345fdb4 | 14 | #include "qapi/error.h" |
213dcb06 | 15 | #include "qemu/config-file.h" |
a77e6b14 | 16 | #include "qemu/option.h" |
b1819747 | 17 | #include "qemu/range.h" |
a9c94277 | 18 | #include "qemu/sockets.h" |
4d43a603 | 19 | #include "chardev/char-fe.h" |
7e49f5e8 | 20 | #include "qemu/memfd.h" |
a77e6b14 | 21 | #include "sysemu/sysemu.h" |
cdafe929 EH |
22 | #include "libqos/libqos.h" |
23 | #include "libqos/pci-pc.h" | |
24 | #include "libqos/virtio-pci.h" | |
a77e6b14 | 25 | |
ed0a8d92 MAL |
26 | #include "libqos/malloc-pc.h" |
27 | #include "hw/virtio/virtio-net.h" | |
28 | ||
a77e6b14 | 29 | #include <linux/vhost.h> |
cdafe929 EH |
30 | #include <linux/virtio_ids.h> |
31 | #include <linux/virtio_net.h> | |
a77e6b14 | 32 | #include <sys/vfs.h> |
a77e6b14 | 33 | |
30de46db GA |
34 | /* GLIB version compatibility flags */ |
35 | #if !GLIB_CHECK_VERSION(2, 26, 0) | |
36 | #define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) | |
37 | #endif | |
38 | ||
39 | #if GLIB_CHECK_VERSION(2, 28, 0) | |
40 | #define HAVE_MONOTONIC_TIME | |
41 | #endif | |
42 | ||
7e49f5e8 | 43 | #define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM," \ |
a77e6b14 | 44 | "mem-path=%s,share=on -numa node,memdev=mem" |
7e49f5e8 MAL |
45 | #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ |
46 | " -numa node,memdev=mem" | |
4616e359 | 47 | #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" |
704b2168 | 48 | #define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce" |
cdafe929 | 49 | #define QEMU_CMD_NET " -device virtio-net-pci,netdev=net0" |
a77e6b14 | 50 | |
a77e6b14 NN |
51 | #define HUGETLBFS_MAGIC 0x958458f6 |
52 | ||
53 | /*********** FROM hw/virtio/vhost-user.c *************************************/ | |
54 | ||
55 | #define VHOST_MEMORY_MAX_NREGIONS 8 | |
026eb179 | 56 | #define VHOST_MAX_VIRTQUEUES 0x100 |
a77e6b14 | 57 | |
8a9b6b37 | 58 | #define VHOST_USER_F_PROTOCOL_FEATURES 30 |
ed0a8d92 | 59 | #define VHOST_USER_PROTOCOL_F_MQ 0 |
b1819747 MAL |
60 | #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 |
61 | ||
62 | #define VHOST_LOG_PAGE 0x1000 | |
8a9b6b37 | 63 | |
a77e6b14 NN |
64 | typedef enum VhostUserRequest { |
65 | VHOST_USER_NONE = 0, | |
66 | VHOST_USER_GET_FEATURES = 1, | |
67 | VHOST_USER_SET_FEATURES = 2, | |
68 | VHOST_USER_SET_OWNER = 3, | |
60915dc4 | 69 | VHOST_USER_RESET_OWNER = 4, |
a77e6b14 NN |
70 | VHOST_USER_SET_MEM_TABLE = 5, |
71 | VHOST_USER_SET_LOG_BASE = 6, | |
72 | VHOST_USER_SET_LOG_FD = 7, | |
73 | VHOST_USER_SET_VRING_NUM = 8, | |
74 | VHOST_USER_SET_VRING_ADDR = 9, | |
75 | VHOST_USER_SET_VRING_BASE = 10, | |
76 | VHOST_USER_GET_VRING_BASE = 11, | |
77 | VHOST_USER_SET_VRING_KICK = 12, | |
78 | VHOST_USER_SET_VRING_CALL = 13, | |
79 | VHOST_USER_SET_VRING_ERR = 14, | |
8a9b6b37 MT |
80 | VHOST_USER_GET_PROTOCOL_FEATURES = 15, |
81 | VHOST_USER_SET_PROTOCOL_FEATURES = 16, | |
ed0a8d92 | 82 | VHOST_USER_GET_QUEUE_NUM = 17, |
87656d50 | 83 | VHOST_USER_SET_VRING_ENABLE = 18, |
a77e6b14 NN |
84 | VHOST_USER_MAX |
85 | } VhostUserRequest; | |
86 | ||
87 | typedef struct VhostUserMemoryRegion { | |
88 | uint64_t guest_phys_addr; | |
89 | uint64_t memory_size; | |
90 | uint64_t userspace_addr; | |
d6970e3b | 91 | uint64_t mmap_offset; |
a77e6b14 NN |
92 | } VhostUserMemoryRegion; |
93 | ||
94 | typedef struct VhostUserMemory { | |
95 | uint32_t nregions; | |
96 | uint32_t padding; | |
97 | VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS]; | |
98 | } VhostUserMemory; | |
99 | ||
2b8819c6 VK |
100 | typedef struct VhostUserLog { |
101 | uint64_t mmap_size; | |
102 | uint64_t mmap_offset; | |
103 | } VhostUserLog; | |
104 | ||
a77e6b14 NN |
105 | typedef struct VhostUserMsg { |
106 | VhostUserRequest request; | |
107 | ||
108 | #define VHOST_USER_VERSION_MASK (0x3) | |
109 | #define VHOST_USER_REPLY_MASK (0x1<<2) | |
110 | uint32_t flags; | |
111 | uint32_t size; /* the following payload size */ | |
112 | union { | |
2b8819c6 VK |
113 | #define VHOST_USER_VRING_IDX_MASK (0xff) |
114 | #define VHOST_USER_VRING_NOFD_MASK (0x1<<8) | |
a77e6b14 NN |
115 | uint64_t u64; |
116 | struct vhost_vring_state state; | |
117 | struct vhost_vring_addr addr; | |
118 | VhostUserMemory memory; | |
2b8819c6 | 119 | VhostUserLog log; |
12ebf690 | 120 | } payload; |
a77e6b14 NN |
121 | } QEMU_PACKED VhostUserMsg; |
122 | ||
123 | static VhostUserMsg m __attribute__ ((unused)); | |
124 | #define VHOST_USER_HDR_SIZE (sizeof(m.request) \ | |
125 | + sizeof(m.flags) \ | |
126 | + sizeof(m.size)) | |
127 | ||
128 | #define VHOST_USER_PAYLOAD_SIZE (sizeof(m) - VHOST_USER_HDR_SIZE) | |
129 | ||
130 | /* The version of the protocol we support */ | |
131 | #define VHOST_USER_VERSION (0x1) | |
132 | /*****************************************************************************/ | |
133 | ||
9294d76c MAL |
134 | enum { |
135 | TEST_FLAGS_OK, | |
136 | TEST_FLAGS_DISCONNECT, | |
137 | TEST_FLAGS_BAD, | |
138 | TEST_FLAGS_END, | |
139 | }; | |
140 | ||
ae31fb54 | 141 | typedef struct TestServer { |
0c0eb302 | 142 | QPCIBus *bus; |
026eb179 MC |
143 | QVirtioPCIDevice *dev; |
144 | QVirtQueue *vq[VHOST_MAX_VIRTQUEUES]; | |
ae31fb54 | 145 | gchar *socket_path; |
a899b1ea | 146 | gchar *mig_path; |
ae31fb54 | 147 | gchar *chr_name; |
32a6ebec | 148 | CharBackend chr; |
ae31fb54 MAL |
149 | int fds_num; |
150 | int fds[VHOST_MEMORY_MAX_NREGIONS]; | |
151 | VhostUserMemory memory; | |
634d39b4 PB |
152 | CompatGMutex data_mutex; |
153 | CompatGCond data_cond; | |
b1819747 | 154 | int log_fd; |
d08e42a1 | 155 | uint64_t rings; |
5d443f5a | 156 | bool test_fail; |
9294d76c | 157 | int test_flags; |
ed0a8d92 | 158 | int queues; |
026eb179 | 159 | QGuestAllocator *alloc; |
ae31fb54 | 160 | } TestServer; |
bd95939f | 161 | |
83265145 MAL |
162 | static TestServer *test_server_new(const gchar *name); |
163 | static void test_server_free(TestServer *server); | |
164 | static void test_server_listen(TestServer *server); | |
165 | ||
704b2168 MAL |
166 | static const char *tmpfs; |
167 | static const char *root; | |
168 | ||
7e49f5e8 MAL |
169 | enum test_memfd { |
170 | TEST_MEMFD_AUTO, | |
171 | TEST_MEMFD_YES, | |
172 | TEST_MEMFD_NO, | |
173 | }; | |
174 | ||
175 | static char *get_qemu_cmd(TestServer *s, | |
176 | int mem, enum test_memfd memfd, const char *mem_path, | |
177 | const char *chr_opts, const char *extra) | |
178 | { | |
179 | if (memfd == TEST_MEMFD_AUTO && qemu_memfd_check()) { | |
180 | memfd = TEST_MEMFD_YES; | |
181 | } | |
182 | ||
183 | if (memfd == TEST_MEMFD_YES) { | |
184 | return g_strdup_printf(QEMU_CMD_MEMFD QEMU_CMD_CHR | |
185 | QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem, | |
186 | s->chr_name, s->socket_path, | |
187 | chr_opts, s->chr_name, extra); | |
188 | } else { | |
189 | return g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR | |
190 | QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem, | |
191 | mem_path, s->chr_name, s->socket_path, | |
192 | chr_opts, s->chr_name, extra); | |
193 | } | |
194 | } | |
195 | ||
d3b2a5d1 | 196 | static void init_virtio_dev(TestServer *s, uint32_t features_mask) |
cdafe929 | 197 | { |
cdafe929 | 198 | uint32_t features; |
026eb179 | 199 | int i; |
cdafe929 | 200 | |
0c0eb302 MAL |
201 | s->bus = qpci_init_pc(NULL); |
202 | g_assert_nonnull(s->bus); | |
cdafe929 | 203 | |
026eb179 MC |
204 | s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET); |
205 | g_assert_nonnull(s->dev); | |
cdafe929 | 206 | |
026eb179 MC |
207 | qvirtio_pci_device_enable(s->dev); |
208 | qvirtio_reset(&s->dev->vdev); | |
209 | qvirtio_set_acknowledge(&s->dev->vdev); | |
210 | qvirtio_set_driver(&s->dev->vdev); | |
cdafe929 | 211 | |
026eb179 MC |
212 | s->alloc = pc_alloc_init(); |
213 | ||
214 | for (i = 0; i < s->queues * 2; i++) { | |
215 | s->vq[i] = qvirtqueue_setup(&s->dev->vdev, s->alloc, i); | |
216 | } | |
217 | ||
218 | features = qvirtio_get_features(&s->dev->vdev); | |
d3b2a5d1 | 219 | features = features & features_mask; |
026eb179 MC |
220 | qvirtio_set_features(&s->dev->vdev, features); |
221 | ||
222 | qvirtio_set_driver_ok(&s->dev->vdev); | |
223 | } | |
224 | ||
225 | static void uninit_virtio_dev(TestServer *s) | |
226 | { | |
227 | int i; | |
cdafe929 | 228 | |
026eb179 MC |
229 | for (i = 0; i < s->queues * 2; i++) { |
230 | qvirtqueue_cleanup(s->dev->vdev.bus, s->vq[i], s->alloc); | |
231 | } | |
232 | pc_alloc_uninit(s->alloc); | |
233 | ||
234 | qvirtio_pci_device_free(s->dev); | |
cdafe929 EH |
235 | } |
236 | ||
ae31fb54 | 237 | static void wait_for_fds(TestServer *s) |
a77e6b14 | 238 | { |
a77e6b14 | 239 | gint64 end_time; |
a77e6b14 | 240 | |
ae31fb54 | 241 | g_mutex_lock(&s->data_mutex); |
a77e6b14 | 242 | |
ca06d9cc | 243 | end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; |
ae31fb54 MAL |
244 | while (!s->fds_num) { |
245 | if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) { | |
a77e6b14 | 246 | /* timeout has passed */ |
ae31fb54 | 247 | g_assert(s->fds_num); |
a77e6b14 NN |
248 | break; |
249 | } | |
250 | } | |
251 | ||
252 | /* check for sanity */ | |
ae31fb54 MAL |
253 | g_assert_cmpint(s->fds_num, >, 0); |
254 | g_assert_cmpint(s->fds_num, ==, s->memory.nregions); | |
a77e6b14 | 255 | |
ae31fb54 | 256 | g_mutex_unlock(&s->data_mutex); |
cf72b57f MAL |
257 | } |
258 | ||
83265145 | 259 | static void read_guest_mem_server(TestServer *s) |
cf72b57f MAL |
260 | { |
261 | uint32_t *guest_mem; | |
262 | int i, j; | |
263 | size_t size; | |
264 | ||
ae31fb54 | 265 | wait_for_fds(s); |
cf72b57f | 266 | |
ae31fb54 | 267 | g_mutex_lock(&s->data_mutex); |
cf72b57f | 268 | |
a77e6b14 | 269 | /* iterate all regions */ |
ae31fb54 | 270 | for (i = 0; i < s->fds_num; i++) { |
a77e6b14 NN |
271 | |
272 | /* We'll check only the region statring at 0x0*/ | |
ae31fb54 | 273 | if (s->memory.regions[i].guest_phys_addr != 0x0) { |
a77e6b14 NN |
274 | continue; |
275 | } | |
276 | ||
ae31fb54 | 277 | g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024); |
a77e6b14 | 278 | |
ae31fb54 MAL |
279 | size = s->memory.regions[i].memory_size + |
280 | s->memory.regions[i].mmap_offset; | |
d6970e3b NN |
281 | |
282 | guest_mem = mmap(0, size, PROT_READ | PROT_WRITE, | |
ae31fb54 | 283 | MAP_SHARED, s->fds[i], 0); |
d6970e3b NN |
284 | |
285 | g_assert(guest_mem != MAP_FAILED); | |
ae31fb54 | 286 | guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem)); |
a77e6b14 NN |
287 | |
288 | for (j = 0; j < 256; j++) { | |
ae31fb54 | 289 | uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4); |
a77e6b14 NN |
290 | uint32_t b = guest_mem[j]; |
291 | ||
292 | g_assert_cmpint(a, ==, b); | |
293 | } | |
294 | ||
ae31fb54 | 295 | munmap(guest_mem, s->memory.regions[i].memory_size); |
a77e6b14 NN |
296 | } |
297 | ||
ae31fb54 | 298 | g_mutex_unlock(&s->data_mutex); |
a77e6b14 NN |
299 | } |
300 | ||
301 | static void *thread_function(void *data) | |
302 | { | |
9732baf6 | 303 | GMainLoop *loop = data; |
a77e6b14 NN |
304 | g_main_loop_run(loop); |
305 | return NULL; | |
306 | } | |
307 | ||
308 | static int chr_can_read(void *opaque) | |
309 | { | |
310 | return VHOST_USER_HDR_SIZE; | |
311 | } | |
312 | ||
313 | static void chr_read(void *opaque, const uint8_t *buf, int size) | |
314 | { | |
ae31fb54 | 315 | TestServer *s = opaque; |
32a6ebec | 316 | CharBackend *chr = &s->chr; |
a77e6b14 NN |
317 | VhostUserMsg msg; |
318 | uint8_t *p = (uint8_t *) &msg; | |
319 | int fd; | |
320 | ||
5d443f5a | 321 | if (s->test_fail) { |
5345fdb4 | 322 | qemu_chr_fe_disconnect(chr); |
5d443f5a MAL |
323 | /* now switch to non-failure */ |
324 | s->test_fail = false; | |
325 | } | |
326 | ||
a77e6b14 NN |
327 | if (size != VHOST_USER_HDR_SIZE) { |
328 | g_test_message("Wrong message size received %d\n", size); | |
329 | return; | |
330 | } | |
331 | ||
ae31fb54 | 332 | g_mutex_lock(&s->data_mutex); |
a77e6b14 NN |
333 | memcpy(p, buf, VHOST_USER_HDR_SIZE); |
334 | ||
335 | if (msg.size) { | |
336 | p += VHOST_USER_HDR_SIZE; | |
5345fdb4 | 337 | size = qemu_chr_fe_read_all(chr, p, msg.size); |
4616e359 MAL |
338 | if (size != msg.size) { |
339 | g_test_message("Wrong message size received %d != %d\n", | |
340 | size, msg.size); | |
341 | return; | |
342 | } | |
a77e6b14 NN |
343 | } |
344 | ||
345 | switch (msg.request) { | |
346 | case VHOST_USER_GET_FEATURES: | |
8a9b6b37 MT |
347 | /* send back features to qemu */ |
348 | msg.flags |= VHOST_USER_REPLY_MASK; | |
12ebf690 MT |
349 | msg.size = sizeof(m.payload.u64); |
350 | msg.payload.u64 = 0x1ULL << VHOST_F_LOG_ALL | | |
b1819747 | 351 | 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES; |
ed0a8d92 MAL |
352 | if (s->queues > 1) { |
353 | msg.payload.u64 |= 0x1ULL << VIRTIO_NET_F_MQ; | |
354 | } | |
9294d76c MAL |
355 | if (s->test_flags >= TEST_FLAGS_BAD) { |
356 | msg.payload.u64 = 0; | |
357 | s->test_flags = TEST_FLAGS_END; | |
358 | } | |
8a9b6b37 | 359 | p = (uint8_t *) &msg; |
5345fdb4 | 360 | qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); |
8a9b6b37 MT |
361 | break; |
362 | ||
363 | case VHOST_USER_SET_FEATURES: | |
12ebf690 | 364 | g_assert_cmpint(msg.payload.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES), |
8a9b6b37 | 365 | !=, 0ULL); |
9294d76c | 366 | if (s->test_flags == TEST_FLAGS_DISCONNECT) { |
5345fdb4 | 367 | qemu_chr_fe_disconnect(chr); |
9294d76c MAL |
368 | s->test_flags = TEST_FLAGS_BAD; |
369 | } | |
8a9b6b37 MT |
370 | break; |
371 | ||
372 | case VHOST_USER_GET_PROTOCOL_FEATURES: | |
a77e6b14 NN |
373 | /* send back features to qemu */ |
374 | msg.flags |= VHOST_USER_REPLY_MASK; | |
12ebf690 MT |
375 | msg.size = sizeof(m.payload.u64); |
376 | msg.payload.u64 = 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD; | |
ed0a8d92 MAL |
377 | if (s->queues > 1) { |
378 | msg.payload.u64 |= 1 << VHOST_USER_PROTOCOL_F_MQ; | |
379 | } | |
a77e6b14 | 380 | p = (uint8_t *) &msg; |
5345fdb4 | 381 | qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); |
a77e6b14 NN |
382 | break; |
383 | ||
384 | case VHOST_USER_GET_VRING_BASE: | |
385 | /* send back vring base to qemu */ | |
386 | msg.flags |= VHOST_USER_REPLY_MASK; | |
12ebf690 MT |
387 | msg.size = sizeof(m.payload.state); |
388 | msg.payload.state.num = 0; | |
a77e6b14 | 389 | p = (uint8_t *) &msg; |
5345fdb4 | 390 | qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); |
d08e42a1 | 391 | |
ed0a8d92 | 392 | assert(msg.payload.state.index < s->queues * 2); |
d08e42a1 | 393 | s->rings &= ~(0x1ULL << msg.payload.state.index); |
a77e6b14 NN |
394 | break; |
395 | ||
396 | case VHOST_USER_SET_MEM_TABLE: | |
397 | /* received the mem table */ | |
12ebf690 | 398 | memcpy(&s->memory, &msg.payload.memory, sizeof(msg.payload.memory)); |
5345fdb4 | 399 | s->fds_num = qemu_chr_fe_get_msgfds(chr, s->fds, |
32a6ebec | 400 | G_N_ELEMENTS(s->fds)); |
a77e6b14 NN |
401 | |
402 | /* signal the test that it can continue */ | |
ae31fb54 | 403 | g_cond_signal(&s->data_cond); |
a77e6b14 NN |
404 | break; |
405 | ||
406 | case VHOST_USER_SET_VRING_KICK: | |
407 | case VHOST_USER_SET_VRING_CALL: | |
408 | /* consume the fd */ | |
5345fdb4 | 409 | qemu_chr_fe_get_msgfds(chr, &fd, 1); |
a77e6b14 NN |
410 | /* |
411 | * This is a non-blocking eventfd. | |
412 | * The receive function forces it to be blocking, | |
413 | * so revert it back to non-blocking. | |
414 | */ | |
415 | qemu_set_nonblock(fd); | |
416 | break; | |
b1819747 MAL |
417 | |
418 | case VHOST_USER_SET_LOG_BASE: | |
419 | if (s->log_fd != -1) { | |
420 | close(s->log_fd); | |
421 | s->log_fd = -1; | |
422 | } | |
5345fdb4 | 423 | qemu_chr_fe_get_msgfds(chr, &s->log_fd, 1); |
b1819747 MAL |
424 | msg.flags |= VHOST_USER_REPLY_MASK; |
425 | msg.size = 0; | |
426 | p = (uint8_t *) &msg; | |
5345fdb4 | 427 | qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE); |
b1819747 MAL |
428 | |
429 | g_cond_signal(&s->data_cond); | |
430 | break; | |
431 | ||
d08e42a1 | 432 | case VHOST_USER_SET_VRING_BASE: |
ed0a8d92 | 433 | assert(msg.payload.state.index < s->queues * 2); |
d08e42a1 | 434 | s->rings |= 0x1ULL << msg.payload.state.index; |
1d9edff7 MAL |
435 | break; |
436 | ||
ed0a8d92 MAL |
437 | case VHOST_USER_GET_QUEUE_NUM: |
438 | msg.flags |= VHOST_USER_REPLY_MASK; | |
439 | msg.size = sizeof(m.payload.u64); | |
440 | msg.payload.u64 = s->queues; | |
441 | p = (uint8_t *) &msg; | |
5345fdb4 | 442 | qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); |
ed0a8d92 MAL |
443 | break; |
444 | ||
a77e6b14 NN |
445 | default: |
446 | break; | |
447 | } | |
ae31fb54 MAL |
448 | |
449 | g_mutex_unlock(&s->data_mutex); | |
a77e6b14 NN |
450 | } |
451 | ||
1b7e1e3b | 452 | static const char *init_hugepagefs(const char *path) |
a77e6b14 | 453 | { |
a77e6b14 NN |
454 | struct statfs fs; |
455 | int ret; | |
456 | ||
a77e6b14 NN |
457 | if (access(path, R_OK | W_OK | X_OK)) { |
458 | g_test_message("access on path (%s): %s\n", path, strerror(errno)); | |
459 | return NULL; | |
460 | } | |
461 | ||
462 | do { | |
463 | ret = statfs(path, &fs); | |
464 | } while (ret != 0 && errno == EINTR); | |
465 | ||
466 | if (ret != 0) { | |
467 | g_test_message("statfs on path (%s): %s\n", path, strerror(errno)); | |
468 | return NULL; | |
469 | } | |
470 | ||
471 | if (fs.f_type != HUGETLBFS_MAGIC) { | |
472 | g_test_message("Warning: path not on HugeTLBFS: %s\n", path); | |
473 | return NULL; | |
474 | } | |
475 | ||
476 | return path; | |
477 | } | |
478 | ||
704b2168 | 479 | static TestServer *test_server_new(const gchar *name) |
ae31fb54 MAL |
480 | { |
481 | TestServer *server = g_new0(TestServer, 1); | |
ae31fb54 MAL |
482 | |
483 | server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name); | |
a899b1ea | 484 | server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name); |
ae31fb54 | 485 | server->chr_name = g_strdup_printf("chr-%s", name); |
ae31fb54 MAL |
486 | |
487 | g_mutex_init(&server->data_mutex); | |
488 | g_cond_init(&server->data_cond); | |
489 | ||
b1819747 | 490 | server->log_fd = -1; |
ed0a8d92 | 491 | server->queues = 1; |
b1819747 | 492 | |
ae31fb54 MAL |
493 | return server; |
494 | } | |
495 | ||
9294d76c MAL |
496 | static void chr_event(void *opaque, int event) |
497 | { | |
498 | TestServer *s = opaque; | |
499 | ||
500 | if (s->test_flags == TEST_FLAGS_END && | |
501 | event == CHR_EVENT_CLOSED) { | |
502 | s->test_flags = TEST_FLAGS_OK; | |
503 | } | |
504 | } | |
505 | ||
4616e359 MAL |
506 | static void test_server_create_chr(TestServer *server, const gchar *opt) |
507 | { | |
508 | gchar *chr_path; | |
0ec7b3e7 | 509 | Chardev *chr; |
5345fdb4 | 510 | |
4616e359 | 511 | chr_path = g_strdup_printf("unix:%s%s", server->socket_path, opt); |
32a6ebec | 512 | chr = qemu_chr_new(server->chr_name, chr_path); |
4616e359 MAL |
513 | g_free(chr_path); |
514 | ||
5345fdb4 MAL |
515 | qemu_chr_fe_init(&server->chr, chr, &error_abort); |
516 | qemu_chr_fe_set_handlers(&server->chr, chr_can_read, chr_read, | |
81517ba3 | 517 | chr_event, NULL, server, NULL, true); |
4616e359 MAL |
518 | } |
519 | ||
520 | static void test_server_listen(TestServer *server) | |
521 | { | |
522 | test_server_create_chr(server, ",server,nowait"); | |
523 | } | |
524 | ||
9732baf6 | 525 | static gboolean _test_server_free(TestServer *server) |
ae31fb54 MAL |
526 | { |
527 | int i; | |
528 | ||
1ce2610c | 529 | qemu_chr_fe_deinit(&server->chr, true); |
ae31fb54 MAL |
530 | |
531 | for (i = 0; i < server->fds_num; i++) { | |
532 | close(server->fds[i]); | |
533 | } | |
534 | ||
b1819747 MAL |
535 | if (server->log_fd != -1) { |
536 | close(server->log_fd); | |
537 | } | |
538 | ||
ae31fb54 MAL |
539 | unlink(server->socket_path); |
540 | g_free(server->socket_path); | |
541 | ||
a899b1ea MAL |
542 | unlink(server->mig_path); |
543 | g_free(server->mig_path); | |
544 | ||
b1819747 | 545 | g_free(server->chr_name); |
0c0eb302 MAL |
546 | qpci_free_pc(server->bus); |
547 | ||
ae31fb54 | 548 | g_free(server); |
9732baf6 MAL |
549 | |
550 | return FALSE; | |
551 | } | |
552 | ||
553 | static void test_server_free(TestServer *server) | |
554 | { | |
555 | g_idle_add((GSourceFunc)_test_server_free, server); | |
ae31fb54 MAL |
556 | } |
557 | ||
b1819747 MAL |
558 | static void wait_for_log_fd(TestServer *s) |
559 | { | |
560 | gint64 end_time; | |
561 | ||
562 | g_mutex_lock(&s->data_mutex); | |
563 | end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; | |
564 | while (s->log_fd == -1) { | |
565 | if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) { | |
566 | /* timeout has passed */ | |
567 | g_assert(s->log_fd != -1); | |
568 | break; | |
569 | } | |
570 | } | |
571 | ||
572 | g_mutex_unlock(&s->data_mutex); | |
573 | } | |
574 | ||
3a87d009 | 575 | static void write_guest_mem(TestServer *s, uint32_t seed) |
b1819747 MAL |
576 | { |
577 | uint32_t *guest_mem; | |
578 | int i, j; | |
579 | size_t size; | |
580 | ||
581 | wait_for_fds(s); | |
582 | ||
583 | /* iterate all regions */ | |
584 | for (i = 0; i < s->fds_num; i++) { | |
585 | ||
586 | /* We'll write only the region statring at 0x0 */ | |
587 | if (s->memory.regions[i].guest_phys_addr != 0x0) { | |
588 | continue; | |
589 | } | |
590 | ||
591 | g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024); | |
592 | ||
593 | size = s->memory.regions[i].memory_size + | |
594 | s->memory.regions[i].mmap_offset; | |
595 | ||
596 | guest_mem = mmap(0, size, PROT_READ | PROT_WRITE, | |
597 | MAP_SHARED, s->fds[i], 0); | |
598 | ||
599 | g_assert(guest_mem != MAP_FAILED); | |
600 | guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem)); | |
601 | ||
602 | for (j = 0; j < 256; j++) { | |
603 | guest_mem[j] = seed + j; | |
604 | } | |
605 | ||
606 | munmap(guest_mem, s->memory.regions[i].memory_size); | |
607 | break; | |
608 | } | |
609 | } | |
610 | ||
611 | static guint64 get_log_size(TestServer *s) | |
612 | { | |
613 | guint64 log_size = 0; | |
614 | int i; | |
615 | ||
616 | for (i = 0; i < s->memory.nregions; ++i) { | |
617 | VhostUserMemoryRegion *reg = &s->memory.regions[i]; | |
618 | guint64 last = range_get_last(reg->guest_phys_addr, | |
619 | reg->memory_size); | |
620 | log_size = MAX(log_size, last / (8 * VHOST_LOG_PAGE) + 1); | |
621 | } | |
622 | ||
623 | return log_size; | |
624 | } | |
625 | ||
1d9edff7 MAL |
626 | typedef struct TestMigrateSource { |
627 | GSource source; | |
628 | TestServer *src; | |
629 | TestServer *dest; | |
630 | } TestMigrateSource; | |
631 | ||
632 | static gboolean | |
633 | test_migrate_source_check(GSource *source) | |
634 | { | |
635 | TestMigrateSource *t = (TestMigrateSource *)source; | |
d08e42a1 | 636 | gboolean overlap = t->src->rings && t->dest->rings; |
1d9edff7 MAL |
637 | |
638 | g_assert(!overlap); | |
639 | ||
640 | return FALSE; | |
641 | } | |
642 | ||
45ce5126 MAL |
643 | #if !GLIB_CHECK_VERSION(2,36,0) |
644 | /* this callback is unnecessary with glib >2.36, the default | |
645 | * prepare for the source does the same */ | |
646 | static gboolean | |
647 | test_migrate_source_prepare(GSource *source, gint *timeout) | |
648 | { | |
649 | *timeout = -1; | |
650 | return FALSE; | |
651 | } | |
652 | #endif | |
653 | ||
1d9edff7 | 654 | GSourceFuncs test_migrate_source_funcs = { |
45ce5126 MAL |
655 | #if !GLIB_CHECK_VERSION(2,36,0) |
656 | .prepare = test_migrate_source_prepare, | |
657 | #endif | |
658 | .check = test_migrate_source_check, | |
1d9edff7 MAL |
659 | }; |
660 | ||
7e49f5e8 | 661 | static void test_read_guest_mem(const void *arg) |
e364c703 | 662 | { |
7e49f5e8 | 663 | enum test_memfd memfd = GPOINTER_TO_INT(arg); |
e364c703 MC |
664 | TestServer *server = NULL; |
665 | char *qemu_cmd = NULL; | |
666 | QTestState *s = NULL; | |
667 | ||
668 | server = test_server_new("test"); | |
669 | test_server_listen(server); | |
670 | ||
7e49f5e8 | 671 | qemu_cmd = get_qemu_cmd(server, 512, memfd, root, "", ""); |
e364c703 MC |
672 | |
673 | s = qtest_start(qemu_cmd); | |
674 | g_free(qemu_cmd); | |
675 | ||
d3b2a5d1 | 676 | init_virtio_dev(server, 1u << VIRTIO_NET_F_MAC); |
e364c703 | 677 | |
83265145 | 678 | read_guest_mem_server(server); |
e364c703 | 679 | |
026eb179 MC |
680 | uninit_virtio_dev(server); |
681 | ||
e364c703 MC |
682 | qtest_quit(s); |
683 | test_server_free(server); | |
684 | } | |
685 | ||
b1819747 MAL |
686 | static void test_migrate(void) |
687 | { | |
688 | TestServer *s = test_server_new("src"); | |
689 | TestServer *dest = test_server_new("dest"); | |
a899b1ea | 690 | char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path); |
b1819747 | 691 | QTestState *global = global_qtest, *from, *to; |
1d9edff7 | 692 | GSource *source; |
7e49f5e8 | 693 | gchar *cmd, *tmp; |
b1819747 MAL |
694 | QDict *rsp; |
695 | guint8 *log; | |
696 | guint64 size; | |
697 | ||
4616e359 MAL |
698 | test_server_listen(s); |
699 | test_server_listen(dest); | |
700 | ||
7e49f5e8 | 701 | cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, "", ""); |
b1819747 MAL |
702 | from = qtest_start(cmd); |
703 | g_free(cmd); | |
704 | ||
d3b2a5d1 | 705 | init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); |
b1819747 MAL |
706 | wait_for_fds(s); |
707 | size = get_log_size(s); | |
708 | g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); | |
709 | ||
7e49f5e8 MAL |
710 | tmp = g_strdup_printf(" -incoming %s", uri); |
711 | cmd = get_qemu_cmd(dest, 2, TEST_MEMFD_AUTO, root, "", tmp); | |
712 | g_free(tmp); | |
b1819747 MAL |
713 | to = qtest_init(cmd); |
714 | g_free(cmd); | |
715 | ||
1d9edff7 MAL |
716 | source = g_source_new(&test_migrate_source_funcs, |
717 | sizeof(TestMigrateSource)); | |
718 | ((TestMigrateSource *)source)->src = s; | |
719 | ((TestMigrateSource *)source)->dest = dest; | |
720 | g_source_attach(source, NULL); | |
721 | ||
b1819747 MAL |
722 | /* slow down migration to have time to fiddle with log */ |
723 | /* TODO: qtest could learn to break on some places */ | |
724 | rsp = qmp("{ 'execute': 'migrate_set_speed'," | |
725 | "'arguments': { 'value': 10 } }"); | |
726 | g_assert(qdict_haskey(rsp, "return")); | |
727 | QDECREF(rsp); | |
728 | ||
729 | cmd = g_strdup_printf("{ 'execute': 'migrate'," | |
730 | "'arguments': { 'uri': '%s' } }", | |
731 | uri); | |
732 | rsp = qmp(cmd); | |
733 | g_free(cmd); | |
734 | g_assert(qdict_haskey(rsp, "return")); | |
735 | QDECREF(rsp); | |
736 | ||
737 | wait_for_log_fd(s); | |
738 | ||
739 | log = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, s->log_fd, 0); | |
740 | g_assert(log != MAP_FAILED); | |
741 | ||
742 | /* modify first page */ | |
743 | write_guest_mem(s, 0x42); | |
744 | log[0] = 1; | |
745 | munmap(log, size); | |
746 | ||
747 | /* speed things up */ | |
748 | rsp = qmp("{ 'execute': 'migrate_set_speed'," | |
749 | "'arguments': { 'value': 0 } }"); | |
750 | g_assert(qdict_haskey(rsp, "return")); | |
751 | QDECREF(rsp); | |
752 | ||
753 | qmp_eventwait("STOP"); | |
754 | ||
755 | global_qtest = to; | |
756 | qmp_eventwait("RESUME"); | |
757 | ||
83265145 | 758 | read_guest_mem_server(dest); |
b1819747 | 759 | |
026eb179 MC |
760 | uninit_virtio_dev(s); |
761 | ||
1d9edff7 MAL |
762 | g_source_destroy(source); |
763 | g_source_unref(source); | |
764 | ||
b1819747 MAL |
765 | qtest_quit(to); |
766 | test_server_free(dest); | |
767 | qtest_quit(from); | |
768 | test_server_free(s); | |
a899b1ea | 769 | g_free(uri); |
b1819747 MAL |
770 | |
771 | global_qtest = global; | |
772 | } | |
773 | ||
4616e359 MAL |
774 | static void wait_for_rings_started(TestServer *s, size_t count) |
775 | { | |
776 | gint64 end_time; | |
777 | ||
778 | g_mutex_lock(&s->data_mutex); | |
779 | end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; | |
780 | while (ctpop64(s->rings) != count) { | |
781 | if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) { | |
782 | /* timeout has passed */ | |
783 | g_assert_cmpint(ctpop64(s->rings), ==, count); | |
784 | break; | |
785 | } | |
786 | } | |
787 | ||
788 | g_mutex_unlock(&s->data_mutex); | |
789 | } | |
790 | ||
7a9ec654 | 791 | #if defined(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) |
20784087 PMD |
792 | static inline void test_server_connect(TestServer *server) |
793 | { | |
794 | test_server_create_chr(server, ",reconnect=1"); | |
795 | } | |
796 | ||
4616e359 MAL |
797 | static gboolean |
798 | reconnect_cb(gpointer user_data) | |
799 | { | |
800 | TestServer *s = user_data; | |
801 | ||
5345fdb4 | 802 | qemu_chr_fe_disconnect(&s->chr); |
4616e359 MAL |
803 | |
804 | return FALSE; | |
805 | } | |
806 | ||
807 | static gpointer | |
808 | connect_thread(gpointer data) | |
809 | { | |
810 | TestServer *s = data; | |
811 | ||
812 | /* wait for qemu to start before first try, to avoid extra warnings */ | |
813 | g_usleep(G_USEC_PER_SEC); | |
814 | test_server_connect(s); | |
815 | ||
816 | return NULL; | |
817 | } | |
818 | ||
819 | static void test_reconnect_subprocess(void) | |
820 | { | |
821 | TestServer *s = test_server_new("reconnect"); | |
822 | char *cmd; | |
823 | ||
824 | g_thread_new("connect", connect_thread, s); | |
7e49f5e8 | 825 | cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", ""); |
4616e359 MAL |
826 | qtest_start(cmd); |
827 | g_free(cmd); | |
828 | ||
d3b2a5d1 | 829 | init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); |
4616e359 MAL |
830 | wait_for_fds(s); |
831 | wait_for_rings_started(s, 2); | |
832 | ||
833 | /* reconnect */ | |
834 | s->fds_num = 0; | |
835 | s->rings = 0; | |
836 | g_idle_add(reconnect_cb, s); | |
837 | wait_for_fds(s); | |
838 | wait_for_rings_started(s, 2); | |
839 | ||
026eb179 MC |
840 | uninit_virtio_dev(s); |
841 | ||
4616e359 MAL |
842 | qtest_end(); |
843 | test_server_free(s); | |
844 | return; | |
845 | } | |
846 | ||
847 | static void test_reconnect(void) | |
848 | { | |
849 | gchar *path = g_strdup_printf("/%s/vhost-user/reconnect/subprocess", | |
850 | qtest_get_arch()); | |
851 | g_test_trap_subprocess(path, 0, 0); | |
852 | g_test_trap_assert_passed(); | |
69179fe2 | 853 | g_free(path); |
4616e359 | 854 | } |
5d443f5a MAL |
855 | |
856 | static void test_connect_fail_subprocess(void) | |
857 | { | |
858 | TestServer *s = test_server_new("connect-fail"); | |
859 | char *cmd; | |
860 | ||
861 | s->test_fail = true; | |
862 | g_thread_new("connect", connect_thread, s); | |
7e49f5e8 | 863 | cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", ""); |
5d443f5a MAL |
864 | qtest_start(cmd); |
865 | g_free(cmd); | |
866 | ||
d3b2a5d1 | 867 | init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); |
5d443f5a MAL |
868 | wait_for_fds(s); |
869 | wait_for_rings_started(s, 2); | |
870 | ||
026eb179 MC |
871 | uninit_virtio_dev(s); |
872 | ||
5d443f5a MAL |
873 | qtest_end(); |
874 | test_server_free(s); | |
875 | } | |
876 | ||
877 | static void test_connect_fail(void) | |
878 | { | |
879 | gchar *path = g_strdup_printf("/%s/vhost-user/connect-fail/subprocess", | |
880 | qtest_get_arch()); | |
881 | g_test_trap_subprocess(path, 0, 0); | |
882 | g_test_trap_assert_passed(); | |
883 | g_free(path); | |
884 | } | |
885 | ||
9294d76c MAL |
886 | static void test_flags_mismatch_subprocess(void) |
887 | { | |
888 | TestServer *s = test_server_new("flags-mismatch"); | |
889 | char *cmd; | |
890 | ||
891 | s->test_flags = TEST_FLAGS_DISCONNECT; | |
892 | g_thread_new("connect", connect_thread, s); | |
7e49f5e8 | 893 | cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", ""); |
9294d76c MAL |
894 | qtest_start(cmd); |
895 | g_free(cmd); | |
896 | ||
d3b2a5d1 | 897 | init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); |
9294d76c MAL |
898 | wait_for_fds(s); |
899 | wait_for_rings_started(s, 2); | |
900 | ||
026eb179 MC |
901 | uninit_virtio_dev(s); |
902 | ||
9294d76c MAL |
903 | qtest_end(); |
904 | test_server_free(s); | |
905 | } | |
906 | ||
907 | static void test_flags_mismatch(void) | |
908 | { | |
909 | gchar *path = g_strdup_printf("/%s/vhost-user/flags-mismatch/subprocess", | |
910 | qtest_get_arch()); | |
911 | g_test_trap_subprocess(path, 0, 0); | |
912 | g_test_trap_assert_passed(); | |
913 | g_free(path); | |
914 | } | |
915 | ||
4616e359 MAL |
916 | #endif |
917 | ||
ed0a8d92 MAL |
918 | static void test_multiqueue(void) |
919 | { | |
ed0a8d92 | 920 | TestServer *s = test_server_new("mq"); |
ed0a8d92 | 921 | char *cmd; |
459f5d29 MC |
922 | uint32_t features_mask = ~(QVIRTIO_F_BAD_FEATURE | |
923 | (1u << VIRTIO_RING_F_INDIRECT_DESC) | | |
924 | (1u << VIRTIO_RING_F_EVENT_IDX)); | |
925 | s->queues = 2; | |
ed0a8d92 MAL |
926 | test_server_listen(s); |
927 | ||
7e49f5e8 MAL |
928 | if (qemu_memfd_check()) { |
929 | cmd = g_strdup_printf( | |
930 | QEMU_CMD_MEMFD QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d " | |
931 | "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d", | |
932 | 512, 512, s->chr_name, | |
933 | s->socket_path, "", s->chr_name, | |
934 | s->queues, s->queues * 2 + 2); | |
935 | } else { | |
936 | cmd = g_strdup_printf( | |
937 | QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d " | |
938 | "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d", | |
939 | 512, 512, root, s->chr_name, | |
940 | s->socket_path, "", s->chr_name, | |
941 | s->queues, s->queues * 2 + 2); | |
942 | } | |
ed0a8d92 MAL |
943 | qtest_start(cmd); |
944 | g_free(cmd); | |
945 | ||
459f5d29 | 946 | init_virtio_dev(s, features_mask); |
ed0a8d92 | 947 | |
459f5d29 | 948 | wait_for_rings_started(s, s->queues * 2); |
ed0a8d92 | 949 | |
459f5d29 | 950 | uninit_virtio_dev(s); |
ed0a8d92 | 951 | |
ed0a8d92 MAL |
952 | qtest_end(); |
953 | ||
954 | test_server_free(s); | |
955 | } | |
956 | ||
a77e6b14 NN |
957 | int main(int argc, char **argv) |
958 | { | |
1b7e1e3b | 959 | const char *hugefs; |
a77e6b14 | 960 | int ret; |
1b7e1e3b | 961 | char template[] = "/tmp/vhost-test-XXXXXX"; |
9732baf6 MAL |
962 | GMainLoop *loop; |
963 | GThread *thread; | |
a77e6b14 NN |
964 | |
965 | g_test_init(&argc, &argv, NULL); | |
966 | ||
967 | module_call_init(MODULE_INIT_QOM); | |
ae31fb54 | 968 | qemu_add_opts(&qemu_chardev_opts); |
a77e6b14 | 969 | |
1b7e1e3b MT |
970 | tmpfs = mkdtemp(template); |
971 | if (!tmpfs) { | |
ae31fb54 | 972 | g_test_message("mkdtemp on path (%s): %s\n", template, strerror(errno)); |
1b7e1e3b MT |
973 | } |
974 | g_assert(tmpfs); | |
975 | ||
976 | hugefs = getenv("QTEST_HUGETLBFS_PATH"); | |
977 | if (hugefs) { | |
978 | root = init_hugepagefs(hugefs); | |
979 | g_assert(root); | |
980 | } else { | |
981 | root = tmpfs; | |
a77e6b14 NN |
982 | } |
983 | ||
9732baf6 | 984 | loop = g_main_loop_new(NULL, FALSE); |
a77e6b14 | 985 | /* run the main loop thread so the chardev may operate */ |
9732baf6 | 986 | thread = g_thread_new(NULL, thread_function, loop); |
a77e6b14 | 987 | |
7e49f5e8 MAL |
988 | if (qemu_memfd_check()) { |
989 | qtest_add_data_func("/vhost-user/read-guest-mem/memfd", | |
990 | GINT_TO_POINTER(TEST_MEMFD_YES), | |
991 | test_read_guest_mem); | |
992 | } | |
993 | qtest_add_data_func("/vhost-user/read-guest-mem/memfile", | |
994 | GINT_TO_POINTER(TEST_MEMFD_NO), test_read_guest_mem); | |
b1819747 | 995 | qtest_add_func("/vhost-user/migrate", test_migrate); |
ed0a8d92 | 996 | qtest_add_func("/vhost-user/multiqueue", test_multiqueue); |
20784087 | 997 | |
7a9ec654 MAL |
998 | #if defined(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) |
999 | /* keeps failing on build-system since Aug 15 2017 */ | |
1000 | if (getenv("QTEST_VHOST_USER_FIXME")) { | |
1001 | qtest_add_func("/vhost-user/reconnect/subprocess", | |
1002 | test_reconnect_subprocess); | |
1003 | qtest_add_func("/vhost-user/reconnect", test_reconnect); | |
1004 | qtest_add_func("/vhost-user/connect-fail/subprocess", | |
1005 | test_connect_fail_subprocess); | |
1006 | qtest_add_func("/vhost-user/connect-fail", test_connect_fail); | |
1007 | qtest_add_func("/vhost-user/flags-mismatch/subprocess", | |
1008 | test_flags_mismatch_subprocess); | |
1009 | qtest_add_func("/vhost-user/flags-mismatch", test_flags_mismatch); | |
1010 | } | |
4616e359 | 1011 | #endif |
a77e6b14 NN |
1012 | |
1013 | ret = g_test_run(); | |
1014 | ||
a77e6b14 | 1015 | /* cleanup */ |
a77e6b14 | 1016 | |
9732baf6 MAL |
1017 | /* finish the helper thread and dispatch pending sources */ |
1018 | g_main_loop_quit(loop); | |
1019 | g_thread_join(thread); | |
1020 | while (g_main_context_pending(NULL)) { | |
1021 | g_main_context_iteration (NULL, TRUE); | |
1022 | } | |
1023 | g_main_loop_unref(loop); | |
1024 | ||
1b7e1e3b MT |
1025 | ret = rmdir(tmpfs); |
1026 | if (ret != 0) { | |
1027 | g_test_message("unable to rmdir: path (%s): %s\n", | |
1028 | tmpfs, strerror(errno)); | |
1029 | } | |
1030 | g_assert_cmpint(ret, ==, 0); | |
1031 | ||
a77e6b14 NN |
1032 | return ret; |
1033 | } |