usb:xhci:fix memory leak in usb_xhci_exit
[qemu.git] / tests / vhost-user-test.c
blobb89a5511266d66e99a53d3db3814467d73c7dba7
1 /*
2 * QTest testcase for the vhost-user
4 * Copyright (c) 2014 Virtual Open Systems Sarl.
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.
9 */
11 #include "qemu/osdep.h"
13 #include "libqtest.h"
14 #include "qemu/option.h"
15 #include "qemu/range.h"
16 #include "qemu/sockets.h"
17 #include "sysemu/char.h"
18 #include "sysemu/sysemu.h"
19 #include "libqos/libqos.h"
20 #include "libqos/pci-pc.h"
21 #include "libqos/virtio-pci.h"
23 #include <linux/vhost.h>
24 #include <linux/virtio_ids.h>
25 #include <linux/virtio_net.h>
26 #include <sys/vfs.h>
28 /* GLIB version compatibility flags */
29 #if !GLIB_CHECK_VERSION(2, 26, 0)
30 #define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000))
31 #endif
33 #if GLIB_CHECK_VERSION(2, 28, 0)
34 #define HAVE_MONOTONIC_TIME
35 #endif
37 #define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM,"\
38 "mem-path=%s,share=on -numa node,memdev=mem"
39 #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s"
40 #define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce"
41 #define QEMU_CMD_NET " -device virtio-net-pci,netdev=net0"
43 #define QEMU_CMD QEMU_CMD_MEM QEMU_CMD_CHR \
44 QEMU_CMD_NETDEV QEMU_CMD_NET
46 #define HUGETLBFS_MAGIC 0x958458f6
48 /*********** FROM hw/virtio/vhost-user.c *************************************/
50 #define VHOST_MEMORY_MAX_NREGIONS 8
52 #define VHOST_USER_F_PROTOCOL_FEATURES 30
53 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
55 #define VHOST_LOG_PAGE 0x1000
57 typedef enum VhostUserRequest {
58 VHOST_USER_NONE = 0,
59 VHOST_USER_GET_FEATURES = 1,
60 VHOST_USER_SET_FEATURES = 2,
61 VHOST_USER_SET_OWNER = 3,
62 VHOST_USER_RESET_OWNER = 4,
63 VHOST_USER_SET_MEM_TABLE = 5,
64 VHOST_USER_SET_LOG_BASE = 6,
65 VHOST_USER_SET_LOG_FD = 7,
66 VHOST_USER_SET_VRING_NUM = 8,
67 VHOST_USER_SET_VRING_ADDR = 9,
68 VHOST_USER_SET_VRING_BASE = 10,
69 VHOST_USER_GET_VRING_BASE = 11,
70 VHOST_USER_SET_VRING_KICK = 12,
71 VHOST_USER_SET_VRING_CALL = 13,
72 VHOST_USER_SET_VRING_ERR = 14,
73 VHOST_USER_GET_PROTOCOL_FEATURES = 15,
74 VHOST_USER_SET_PROTOCOL_FEATURES = 16,
75 VHOST_USER_SET_VRING_ENABLE = 18,
76 VHOST_USER_MAX
77 } VhostUserRequest;
79 typedef struct VhostUserMemoryRegion {
80 uint64_t guest_phys_addr;
81 uint64_t memory_size;
82 uint64_t userspace_addr;
83 uint64_t mmap_offset;
84 } VhostUserMemoryRegion;
86 typedef struct VhostUserMemory {
87 uint32_t nregions;
88 uint32_t padding;
89 VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
90 } VhostUserMemory;
92 typedef struct VhostUserLog {
93 uint64_t mmap_size;
94 uint64_t mmap_offset;
95 } VhostUserLog;
97 typedef struct VhostUserMsg {
98 VhostUserRequest request;
100 #define VHOST_USER_VERSION_MASK (0x3)
101 #define VHOST_USER_REPLY_MASK (0x1<<2)
102 uint32_t flags;
103 uint32_t size; /* the following payload size */
104 union {
105 #define VHOST_USER_VRING_IDX_MASK (0xff)
106 #define VHOST_USER_VRING_NOFD_MASK (0x1<<8)
107 uint64_t u64;
108 struct vhost_vring_state state;
109 struct vhost_vring_addr addr;
110 VhostUserMemory memory;
111 VhostUserLog log;
112 } payload;
113 } QEMU_PACKED VhostUserMsg;
115 static VhostUserMsg m __attribute__ ((unused));
116 #define VHOST_USER_HDR_SIZE (sizeof(m.request) \
117 + sizeof(m.flags) \
118 + sizeof(m.size))
120 #define VHOST_USER_PAYLOAD_SIZE (sizeof(m) - VHOST_USER_HDR_SIZE)
122 /* The version of the protocol we support */
123 #define VHOST_USER_VERSION (0x1)
124 /*****************************************************************************/
126 typedef struct TestServer {
127 gchar *socket_path;
128 gchar *mig_path;
129 gchar *chr_name;
130 CharDriverState *chr;
131 int fds_num;
132 int fds[VHOST_MEMORY_MAX_NREGIONS];
133 VhostUserMemory memory;
134 CompatGMutex data_mutex;
135 CompatGCond data_cond;
136 int log_fd;
137 uint64_t rings;
138 } TestServer;
140 static const char *tmpfs;
141 static const char *root;
143 static void init_virtio_dev(TestServer *s)
145 QPCIBus *bus;
146 QVirtioPCIDevice *dev;
147 uint32_t features;
149 bus = qpci_init_pc();
150 g_assert_nonnull(bus);
152 dev = qvirtio_pci_device_find(bus, VIRTIO_ID_NET);
153 g_assert_nonnull(dev);
155 qvirtio_pci_device_enable(dev);
156 qvirtio_reset(&qvirtio_pci, &dev->vdev);
157 qvirtio_set_acknowledge(&qvirtio_pci, &dev->vdev);
158 qvirtio_set_driver(&qvirtio_pci, &dev->vdev);
160 features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
161 features = features & VIRTIO_NET_F_MAC;
162 qvirtio_set_features(&qvirtio_pci, &dev->vdev, features);
164 qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev);
167 static void wait_for_fds(TestServer *s)
169 gint64 end_time;
171 g_mutex_lock(&s->data_mutex);
173 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
174 while (!s->fds_num) {
175 if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
176 /* timeout has passed */
177 g_assert(s->fds_num);
178 break;
182 /* check for sanity */
183 g_assert_cmpint(s->fds_num, >, 0);
184 g_assert_cmpint(s->fds_num, ==, s->memory.nregions);
186 g_mutex_unlock(&s->data_mutex);
189 static void read_guest_mem(const void *data)
191 TestServer *s = (void *)data;
192 uint32_t *guest_mem;
193 int i, j;
194 size_t size;
196 wait_for_fds(s);
198 g_mutex_lock(&s->data_mutex);
200 /* iterate all regions */
201 for (i = 0; i < s->fds_num; i++) {
203 /* We'll check only the region statring at 0x0*/
204 if (s->memory.regions[i].guest_phys_addr != 0x0) {
205 continue;
208 g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024);
210 size = s->memory.regions[i].memory_size +
211 s->memory.regions[i].mmap_offset;
213 guest_mem = mmap(0, size, PROT_READ | PROT_WRITE,
214 MAP_SHARED, s->fds[i], 0);
216 g_assert(guest_mem != MAP_FAILED);
217 guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem));
219 for (j = 0; j < 256; j++) {
220 uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);
221 uint32_t b = guest_mem[j];
223 g_assert_cmpint(a, ==, b);
226 munmap(guest_mem, s->memory.regions[i].memory_size);
229 g_mutex_unlock(&s->data_mutex);
232 static void *thread_function(void *data)
234 GMainLoop *loop = data;
235 g_main_loop_run(loop);
236 return NULL;
239 static int chr_can_read(void *opaque)
241 return VHOST_USER_HDR_SIZE;
244 static void chr_read(void *opaque, const uint8_t *buf, int size)
246 TestServer *s = opaque;
247 CharDriverState *chr = s->chr;
248 VhostUserMsg msg;
249 uint8_t *p = (uint8_t *) &msg;
250 int fd;
252 if (size != VHOST_USER_HDR_SIZE) {
253 g_test_message("Wrong message size received %d\n", size);
254 return;
257 g_mutex_lock(&s->data_mutex);
258 memcpy(p, buf, VHOST_USER_HDR_SIZE);
260 if (msg.size) {
261 p += VHOST_USER_HDR_SIZE;
262 size = qemu_chr_fe_read_all(chr, p, msg.size);
263 if (size != msg.size) {
264 g_test_message("Wrong message size received %d != %d\n",
265 size, msg.size);
266 return;
270 switch (msg.request) {
271 case VHOST_USER_GET_FEATURES:
272 /* send back features to qemu */
273 msg.flags |= VHOST_USER_REPLY_MASK;
274 msg.size = sizeof(m.payload.u64);
275 msg.payload.u64 = 0x1ULL << VHOST_F_LOG_ALL |
276 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
277 p = (uint8_t *) &msg;
278 qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
279 break;
281 case VHOST_USER_SET_FEATURES:
282 g_assert_cmpint(msg.payload.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
283 !=, 0ULL);
284 break;
286 case VHOST_USER_GET_PROTOCOL_FEATURES:
287 /* send back features to qemu */
288 msg.flags |= VHOST_USER_REPLY_MASK;
289 msg.size = sizeof(m.payload.u64);
290 msg.payload.u64 = 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD;
291 p = (uint8_t *) &msg;
292 qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
293 break;
295 case VHOST_USER_GET_VRING_BASE:
296 /* send back vring base to qemu */
297 msg.flags |= VHOST_USER_REPLY_MASK;
298 msg.size = sizeof(m.payload.state);
299 msg.payload.state.num = 0;
300 p = (uint8_t *) &msg;
301 qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
303 assert(msg.payload.state.index < 2);
304 s->rings &= ~(0x1ULL << msg.payload.state.index);
305 break;
307 case VHOST_USER_SET_MEM_TABLE:
308 /* received the mem table */
309 memcpy(&s->memory, &msg.payload.memory, sizeof(msg.payload.memory));
310 s->fds_num = qemu_chr_fe_get_msgfds(chr, s->fds, G_N_ELEMENTS(s->fds));
312 /* signal the test that it can continue */
313 g_cond_signal(&s->data_cond);
314 break;
316 case VHOST_USER_SET_VRING_KICK:
317 case VHOST_USER_SET_VRING_CALL:
318 /* consume the fd */
319 qemu_chr_fe_get_msgfds(chr, &fd, 1);
321 * This is a non-blocking eventfd.
322 * The receive function forces it to be blocking,
323 * so revert it back to non-blocking.
325 qemu_set_nonblock(fd);
326 break;
328 case VHOST_USER_SET_LOG_BASE:
329 if (s->log_fd != -1) {
330 close(s->log_fd);
331 s->log_fd = -1;
333 qemu_chr_fe_get_msgfds(chr, &s->log_fd, 1);
334 msg.flags |= VHOST_USER_REPLY_MASK;
335 msg.size = 0;
336 p = (uint8_t *) &msg;
337 qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE);
339 g_cond_signal(&s->data_cond);
340 break;
342 case VHOST_USER_SET_VRING_BASE:
343 assert(msg.payload.state.index < 2);
344 s->rings |= 0x1ULL << msg.payload.state.index;
345 break;
347 default:
348 break;
351 g_mutex_unlock(&s->data_mutex);
354 static const char *init_hugepagefs(const char *path)
356 struct statfs fs;
357 int ret;
359 if (access(path, R_OK | W_OK | X_OK)) {
360 g_test_message("access on path (%s): %s\n", path, strerror(errno));
361 return NULL;
364 do {
365 ret = statfs(path, &fs);
366 } while (ret != 0 && errno == EINTR);
368 if (ret != 0) {
369 g_test_message("statfs on path (%s): %s\n", path, strerror(errno));
370 return NULL;
373 if (fs.f_type != HUGETLBFS_MAGIC) {
374 g_test_message("Warning: path not on HugeTLBFS: %s\n", path);
375 return NULL;
378 return path;
381 static TestServer *test_server_new(const gchar *name)
383 TestServer *server = g_new0(TestServer, 1);
385 server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name);
386 server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name);
387 server->chr_name = g_strdup_printf("chr-%s", name);
389 g_mutex_init(&server->data_mutex);
390 g_cond_init(&server->data_cond);
392 server->log_fd = -1;
394 return server;
397 static void test_server_create_chr(TestServer *server, const gchar *opt)
399 gchar *chr_path;
401 chr_path = g_strdup_printf("unix:%s%s", server->socket_path, opt);
402 server->chr = qemu_chr_new(server->chr_name, chr_path, NULL);
403 g_free(chr_path);
405 qemu_chr_add_handlers(server->chr, chr_can_read, chr_read, NULL, server);
408 static void test_server_listen(TestServer *server)
410 test_server_create_chr(server, ",server,nowait");
413 static inline void test_server_connect(TestServer *server)
415 test_server_create_chr(server, ",reconnect=1");
418 #define GET_QEMU_CMD(s) \
419 g_strdup_printf(QEMU_CMD, 512, 512, (root), (s)->chr_name, \
420 (s)->socket_path, "", (s)->chr_name)
422 #define GET_QEMU_CMDE(s, mem, chr_opts, extra, ...) \
423 g_strdup_printf(QEMU_CMD extra, (mem), (mem), (root), (s)->chr_name, \
424 (s)->socket_path, (chr_opts), (s)->chr_name, ##__VA_ARGS__)
426 static gboolean _test_server_free(TestServer *server)
428 int i;
430 qemu_chr_delete(server->chr);
432 for (i = 0; i < server->fds_num; i++) {
433 close(server->fds[i]);
436 if (server->log_fd != -1) {
437 close(server->log_fd);
440 unlink(server->socket_path);
441 g_free(server->socket_path);
443 unlink(server->mig_path);
444 g_free(server->mig_path);
446 g_free(server->chr_name);
447 g_free(server);
449 return FALSE;
452 static void test_server_free(TestServer *server)
454 g_idle_add((GSourceFunc)_test_server_free, server);
457 static void wait_for_log_fd(TestServer *s)
459 gint64 end_time;
461 g_mutex_lock(&s->data_mutex);
462 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
463 while (s->log_fd == -1) {
464 if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
465 /* timeout has passed */
466 g_assert(s->log_fd != -1);
467 break;
471 g_mutex_unlock(&s->data_mutex);
474 static void write_guest_mem(TestServer *s, uint32_t seed)
476 uint32_t *guest_mem;
477 int i, j;
478 size_t size;
480 wait_for_fds(s);
482 /* iterate all regions */
483 for (i = 0; i < s->fds_num; i++) {
485 /* We'll write only the region statring at 0x0 */
486 if (s->memory.regions[i].guest_phys_addr != 0x0) {
487 continue;
490 g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024);
492 size = s->memory.regions[i].memory_size +
493 s->memory.regions[i].mmap_offset;
495 guest_mem = mmap(0, size, PROT_READ | PROT_WRITE,
496 MAP_SHARED, s->fds[i], 0);
498 g_assert(guest_mem != MAP_FAILED);
499 guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem));
501 for (j = 0; j < 256; j++) {
502 guest_mem[j] = seed + j;
505 munmap(guest_mem, s->memory.regions[i].memory_size);
506 break;
510 static guint64 get_log_size(TestServer *s)
512 guint64 log_size = 0;
513 int i;
515 for (i = 0; i < s->memory.nregions; ++i) {
516 VhostUserMemoryRegion *reg = &s->memory.regions[i];
517 guint64 last = range_get_last(reg->guest_phys_addr,
518 reg->memory_size);
519 log_size = MAX(log_size, last / (8 * VHOST_LOG_PAGE) + 1);
522 return log_size;
525 typedef struct TestMigrateSource {
526 GSource source;
527 TestServer *src;
528 TestServer *dest;
529 } TestMigrateSource;
531 static gboolean
532 test_migrate_source_check(GSource *source)
534 TestMigrateSource *t = (TestMigrateSource *)source;
535 gboolean overlap = t->src->rings && t->dest->rings;
537 g_assert(!overlap);
539 return FALSE;
542 #if !GLIB_CHECK_VERSION(2,36,0)
543 /* this callback is unnecessary with glib >2.36, the default
544 * prepare for the source does the same */
545 static gboolean
546 test_migrate_source_prepare(GSource *source, gint *timeout)
548 *timeout = -1;
549 return FALSE;
551 #endif
553 GSourceFuncs test_migrate_source_funcs = {
554 #if !GLIB_CHECK_VERSION(2,36,0)
555 .prepare = test_migrate_source_prepare,
556 #endif
557 .check = test_migrate_source_check,
560 static void test_migrate(void)
562 TestServer *s = test_server_new("src");
563 TestServer *dest = test_server_new("dest");
564 char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path);
565 QTestState *global = global_qtest, *from, *to;
566 GSource *source;
567 gchar *cmd;
568 QDict *rsp;
569 guint8 *log;
570 guint64 size;
572 test_server_listen(s);
573 test_server_listen(dest);
575 cmd = GET_QEMU_CMDE(s, 2, "", "");
576 from = qtest_start(cmd);
577 g_free(cmd);
579 init_virtio_dev(s);
580 wait_for_fds(s);
581 size = get_log_size(s);
582 g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));
584 cmd = GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri);
585 to = qtest_init(cmd);
586 g_free(cmd);
588 source = g_source_new(&test_migrate_source_funcs,
589 sizeof(TestMigrateSource));
590 ((TestMigrateSource *)source)->src = s;
591 ((TestMigrateSource *)source)->dest = dest;
592 g_source_attach(source, NULL);
594 /* slow down migration to have time to fiddle with log */
595 /* TODO: qtest could learn to break on some places */
596 rsp = qmp("{ 'execute': 'migrate_set_speed',"
597 "'arguments': { 'value': 10 } }");
598 g_assert(qdict_haskey(rsp, "return"));
599 QDECREF(rsp);
601 cmd = g_strdup_printf("{ 'execute': 'migrate',"
602 "'arguments': { 'uri': '%s' } }",
603 uri);
604 rsp = qmp(cmd);
605 g_free(cmd);
606 g_assert(qdict_haskey(rsp, "return"));
607 QDECREF(rsp);
609 wait_for_log_fd(s);
611 log = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, s->log_fd, 0);
612 g_assert(log != MAP_FAILED);
614 /* modify first page */
615 write_guest_mem(s, 0x42);
616 log[0] = 1;
617 munmap(log, size);
619 /* speed things up */
620 rsp = qmp("{ 'execute': 'migrate_set_speed',"
621 "'arguments': { 'value': 0 } }");
622 g_assert(qdict_haskey(rsp, "return"));
623 QDECREF(rsp);
625 qmp_eventwait("STOP");
627 global_qtest = to;
628 qmp_eventwait("RESUME");
630 read_guest_mem(dest);
632 g_source_destroy(source);
633 g_source_unref(source);
635 qtest_quit(to);
636 test_server_free(dest);
637 qtest_quit(from);
638 test_server_free(s);
639 g_free(uri);
641 global_qtest = global;
644 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
645 static void wait_for_rings_started(TestServer *s, size_t count)
647 gint64 end_time;
649 g_mutex_lock(&s->data_mutex);
650 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
651 while (ctpop64(s->rings) != count) {
652 if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
653 /* timeout has passed */
654 g_assert_cmpint(ctpop64(s->rings), ==, count);
655 break;
659 g_mutex_unlock(&s->data_mutex);
662 static gboolean
663 reconnect_cb(gpointer user_data)
665 TestServer *s = user_data;
667 qemu_chr_disconnect(s->chr);
669 return FALSE;
672 static gpointer
673 connect_thread(gpointer data)
675 TestServer *s = data;
677 /* wait for qemu to start before first try, to avoid extra warnings */
678 g_usleep(G_USEC_PER_SEC);
679 test_server_connect(s);
681 return NULL;
684 static void test_reconnect_subprocess(void)
686 TestServer *s = test_server_new("reconnect");
687 char *cmd;
689 g_thread_new("connect", connect_thread, s);
690 cmd = GET_QEMU_CMDE(s, 2, ",server", "");
691 qtest_start(cmd);
692 g_free(cmd);
694 init_virtio_dev(s);
695 wait_for_fds(s);
696 wait_for_rings_started(s, 2);
698 /* reconnect */
699 s->fds_num = 0;
700 s->rings = 0;
701 g_idle_add(reconnect_cb, s);
702 wait_for_fds(s);
703 wait_for_rings_started(s, 2);
705 qtest_end();
706 test_server_free(s);
707 return;
710 static void test_reconnect(void)
712 gchar *path = g_strdup_printf("/%s/vhost-user/reconnect/subprocess",
713 qtest_get_arch());
714 g_test_trap_subprocess(path, 0, 0);
715 g_test_trap_assert_passed();
716 g_free(path);
718 #endif
720 int main(int argc, char **argv)
722 QTestState *s = NULL;
723 TestServer *server = NULL;
724 const char *hugefs;
725 char *qemu_cmd = NULL;
726 int ret;
727 char template[] = "/tmp/vhost-test-XXXXXX";
728 GMainLoop *loop;
729 GThread *thread;
731 g_test_init(&argc, &argv, NULL);
733 module_call_init(MODULE_INIT_QOM);
734 qemu_add_opts(&qemu_chardev_opts);
736 tmpfs = mkdtemp(template);
737 if (!tmpfs) {
738 g_test_message("mkdtemp on path (%s): %s\n", template, strerror(errno));
740 g_assert(tmpfs);
742 hugefs = getenv("QTEST_HUGETLBFS_PATH");
743 if (hugefs) {
744 root = init_hugepagefs(hugefs);
745 g_assert(root);
746 } else {
747 root = tmpfs;
750 server = test_server_new("test");
751 test_server_listen(server);
753 loop = g_main_loop_new(NULL, FALSE);
754 /* run the main loop thread so the chardev may operate */
755 thread = g_thread_new(NULL, thread_function, loop);
757 qemu_cmd = GET_QEMU_CMD(server);
759 s = qtest_start(qemu_cmd);
760 g_free(qemu_cmd);
761 init_virtio_dev(server);
763 qtest_add_data_func("/vhost-user/read-guest-mem", server, read_guest_mem);
764 qtest_add_func("/vhost-user/migrate", test_migrate);
765 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
766 qtest_add_func("/vhost-user/reconnect/subprocess",
767 test_reconnect_subprocess);
768 qtest_add_func("/vhost-user/reconnect", test_reconnect);
769 #endif
771 ret = g_test_run();
773 if (s) {
774 qtest_quit(s);
777 /* cleanup */
778 test_server_free(server);
780 /* finish the helper thread and dispatch pending sources */
781 g_main_loop_quit(loop);
782 g_thread_join(thread);
783 while (g_main_context_pending(NULL)) {
784 g_main_context_iteration (NULL, TRUE);
786 g_main_loop_unref(loop);
788 ret = rmdir(tmpfs);
789 if (ret != 0) {
790 g_test_message("unable to rmdir: path (%s): %s\n",
791 tmpfs, strerror(errno));
793 g_assert_cmpint(ret, ==, 0);
795 return ret;