diff options
Diffstat (limited to 'tests/vhost-user-test.c')
-rw-r--r-- | tests/vhost-user-test.c | 104 |
1 files changed, 68 insertions, 36 deletions
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 84e50d84e7..7d5f234646 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -51,6 +51,7 @@ #define VHOST_USER_F_PROTOCOL_FEATURES 30 #define VHOST_USER_PROTOCOL_F_MQ 0 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 +#define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 #define VHOST_LOG_PAGE 0x1000 @@ -186,12 +187,12 @@ static char *get_qemu_cmd(TestServer *s, } } -static void init_virtio_dev(TestServer *s, uint32_t features_mask) +static void init_virtio_dev(QTestState *qts, TestServer *s, uint32_t features_mask) { uint32_t features; int i; - s->bus = qpci_init_pc(global_qtest, NULL); + s->bus = qpci_init_pc(qts, NULL); g_assert_nonnull(s->bus); s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET); @@ -202,7 +203,7 @@ static void init_virtio_dev(TestServer *s, uint32_t features_mask) qvirtio_set_acknowledge(&s->dev->vdev); qvirtio_set_driver(&s->dev->vdev); - s->alloc = pc_alloc_init(global_qtest); + s->alloc = pc_alloc_init(qts); for (i = 0; i < s->queues * 2; i++) { s->vq[i] = qvirtqueue_setup(&s->dev->vdev, s->alloc, i); @@ -227,9 +228,11 @@ static void uninit_virtio_dev(TestServer *s) qvirtio_pci_device_free(s->dev); } -static void wait_for_fds(TestServer *s) +static bool wait_for_fds(TestServer *s) { gint64 end_time; + bool got_region; + int i; g_mutex_lock(&s->data_mutex); @@ -247,16 +250,27 @@ static void wait_for_fds(TestServer *s) g_assert_cmpint(s->fds_num, ==, s->memory.nregions); g_mutex_unlock(&s->data_mutex); + + got_region = false; + for (i = 0; i < s->memory.nregions; ++i) { + VhostUserMemoryRegion *reg = &s->memory.regions[i]; + if (reg->guest_phys_addr == 0) { + got_region = true; + break; + } + } + if (!got_region) { + g_test_skip("No memory at address 0x0"); + } + return got_region; } -static void read_guest_mem_server(TestServer *s) +static void read_guest_mem_server(QTestState *qts, TestServer *s) { - uint32_t *guest_mem; + uint8_t *guest_mem; int i, j; size_t size; - wait_for_fds(s); - g_mutex_lock(&s->data_mutex); /* iterate all regions */ @@ -278,8 +292,8 @@ static void read_guest_mem_server(TestServer *s) g_assert(guest_mem != MAP_FAILED); guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem)); - for (j = 0; j < 256; j++) { - uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4); + for (j = 0; j < 1024; j++) { + uint32_t a = qtest_readb(qts, s->memory.regions[i].guest_phys_addr + j); uint32_t b = guest_mem[j]; g_assert_cmpint(a, ==, b); @@ -367,6 +381,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) msg.flags |= VHOST_USER_REPLY_MASK; msg.size = sizeof(m.payload.u64); msg.payload.u64 = 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD; + msg.payload.u64 |= 1 << VHOST_USER_PROTOCOL_F_CROSS_ENDIAN; if (s->queues > 1) { msg.payload.u64 |= 1 << VHOST_USER_PROTOCOL_F_MQ; } @@ -384,6 +399,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) assert(msg.payload.state.index < s->queues * 2); s->rings &= ~(0x1ULL << msg.payload.state.index); + g_cond_broadcast(&s->data_cond); break; case VHOST_USER_SET_MEM_TABLE: @@ -393,7 +409,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) G_N_ELEMENTS(s->fds)); /* signal the test that it can continue */ - g_cond_signal(&s->data_cond); + g_cond_broadcast(&s->data_cond); break; case VHOST_USER_SET_VRING_KICK: @@ -419,12 +435,13 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) p = (uint8_t *) &msg; qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE); - g_cond_signal(&s->data_cond); + g_cond_broadcast(&s->data_cond); break; case VHOST_USER_SET_VRING_BASE: assert(msg.payload.state.index < s->queues * 2); s->rings |= 0x1ULL << msg.payload.state.index; + g_cond_broadcast(&s->data_cond); break; case VHOST_USER_GET_QUEUE_NUM: @@ -573,8 +590,6 @@ static void write_guest_mem(TestServer *s, uint32_t seed) int i, j; size_t size; - wait_for_fds(s); - /* iterate all regions */ for (i = 0; i < s->fds_num; i++) { @@ -655,10 +670,15 @@ static void test_read_guest_mem(const void *arg) s = qtest_start(qemu_cmd); g_free(qemu_cmd); - init_virtio_dev(server, 1u << VIRTIO_NET_F_MAC); + init_virtio_dev(global_qtest, server, 1u << VIRTIO_NET_F_MAC); + + if (!wait_for_fds(server)) { + goto exit; + } - read_guest_mem_server(server); + read_guest_mem_server(global_qtest, server); +exit: uninit_virtio_dev(server); qtest_quit(s); @@ -670,7 +690,7 @@ static void test_migrate(void) TestServer *s = test_server_new("src"); TestServer *dest = test_server_new("dest"); char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path); - QTestState *global = global_qtest, *from, *to; + QTestState *from, *to; GSource *source; gchar *cmd, *tmp; QDict *rsp; @@ -684,9 +704,11 @@ static void test_migrate(void) from = qtest_start(cmd); g_free(cmd); - init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); - init_virtio_dev(dest, 1u << VIRTIO_NET_F_MAC); - wait_for_fds(s); + init_virtio_dev(from, s, 1u << VIRTIO_NET_F_MAC); + if (!wait_for_fds(s)) { + goto exit; + } + size = get_log_size(s); g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); @@ -695,6 +717,7 @@ static void test_migrate(void) g_free(tmp); to = qtest_init(cmd); g_free(cmd); + init_virtio_dev(to, dest, 1u << VIRTIO_NET_F_MAC); source = g_source_new(&test_migrate_source_funcs, sizeof(TestMigrateSource)); @@ -730,25 +753,24 @@ static void test_migrate(void) qobject_unref(rsp); qmp_eventwait("STOP"); + qtest_qmp_eventwait(to, "RESUME"); - global_qtest = to; - qmp_eventwait("RESUME"); + g_assert(wait_for_fds(dest)); + read_guest_mem_server(to, dest); - read_guest_mem_server(dest); - - uninit_virtio_dev(s); uninit_virtio_dev(dest); + qtest_quit(to); g_source_destroy(source); g_source_unref(source); - qtest_quit(to); +exit: + uninit_virtio_dev(s); + test_server_free(dest); qtest_quit(from); test_server_free(s); g_free(uri); - - global_qtest = global; } static void wait_for_rings_started(TestServer *s, size_t count) @@ -805,17 +827,21 @@ static void test_reconnect_subprocess(void) qtest_start(cmd); g_free(cmd); - init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); - wait_for_fds(s); + init_virtio_dev(global_qtest, s, 1u << VIRTIO_NET_F_MAC); + if (!wait_for_fds(s)) { + goto exit; + } + wait_for_rings_started(s, 2); /* reconnect */ s->fds_num = 0; s->rings = 0; g_idle_add(reconnect_cb, s); - wait_for_fds(s); + g_assert(wait_for_fds(s)); wait_for_rings_started(s, 2); +exit: uninit_virtio_dev(s); qtest_end(); @@ -843,10 +869,13 @@ static void test_connect_fail_subprocess(void) qtest_start(cmd); g_free(cmd); - init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); - wait_for_fds(s); + init_virtio_dev(global_qtest, s, 1u << VIRTIO_NET_F_MAC); + if (!wait_for_fds(s)) { + goto exit; + } wait_for_rings_started(s, 2); +exit: uninit_virtio_dev(s); qtest_end(); @@ -873,10 +902,13 @@ static void test_flags_mismatch_subprocess(void) qtest_start(cmd); g_free(cmd); - init_virtio_dev(s, 1u << VIRTIO_NET_F_MAC); - wait_for_fds(s); + init_virtio_dev(global_qtest, s, 1u << VIRTIO_NET_F_MAC); + if (!wait_for_fds(s)) { + goto exit; + } wait_for_rings_started(s, 2); +exit: uninit_virtio_dev(s); qtest_end(); @@ -921,7 +953,7 @@ static void test_multiqueue(void) qtest_start(cmd); g_free(cmd); - init_virtio_dev(s, features_mask); + init_virtio_dev(global_qtest, s, features_mask); wait_for_rings_started(s, s->queues * 2); |