aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/vhost-user-test.c90
1 files changed, 26 insertions, 64 deletions
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 128fce302f..a217353e2c 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -18,7 +18,6 @@
#include "qemu/range.h"
#include "qemu/sockets.h"
#include "chardev/char-fe.h"
-#include "qemu/memfd.h"
#include "sysemu/sysemu.h"
#include "libqos/libqos.h"
#include "libqos/pci-pc.h"
@@ -41,14 +40,23 @@
#define HAVE_MONOTONIC_TIME
#endif
-#define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM," \
+#define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM,"\
"mem-path=%s,share=on -numa node,memdev=mem"
-#define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \
- " -numa node,memdev=mem"
#define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s"
#define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce"
#define QEMU_CMD_NET " -device virtio-net-pci,netdev=net0"
+#define QEMU_CMD QEMU_CMD_MEM QEMU_CMD_CHR \
+ QEMU_CMD_NETDEV QEMU_CMD_NET
+
+#define GET_QEMU_CMD(s) \
+ g_strdup_printf(QEMU_CMD, 512, 512, (root), (s)->chr_name, \
+ (s)->socket_path, "", (s)->chr_name)
+
+#define GET_QEMU_CMDE(s, mem, chr_opts, extra, ...) \
+ g_strdup_printf(QEMU_CMD extra, (mem), (mem), (root), (s)->chr_name, \
+ (s)->socket_path, (chr_opts), (s)->chr_name, ##__VA_ARGS__)
+
#define HUGETLBFS_MAGIC 0x958458f6
/*********** FROM hw/virtio/vhost-user.c *************************************/
@@ -167,33 +175,6 @@ static void test_server_listen(TestServer *server);
static const char *tmpfs;
static const char *root;
-enum test_memfd {
- TEST_MEMFD_AUTO,
- TEST_MEMFD_YES,
- TEST_MEMFD_NO,
-};
-
-static char *get_qemu_cmd(TestServer *s,
- int mem, enum test_memfd memfd, const char *mem_path,
- const char *chr_opts, const char *extra)
-{
- if (memfd == TEST_MEMFD_AUTO && qemu_memfd_check()) {
- memfd = TEST_MEMFD_YES;
- }
-
- if (memfd == TEST_MEMFD_YES) {
- return g_strdup_printf(QEMU_CMD_MEMFD QEMU_CMD_CHR
- QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem,
- s->chr_name, s->socket_path,
- chr_opts, s->chr_name, extra);
- } else {
- return g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR
- QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem,
- mem_path, s->chr_name, s->socket_path,
- chr_opts, s->chr_name, extra);
- }
-}
-
static void init_virtio_dev(TestServer *s, uint32_t features_mask)
{
uint32_t features;
@@ -659,9 +640,8 @@ GSourceFuncs test_migrate_source_funcs = {
.check = test_migrate_source_check,
};
-static void test_read_guest_mem(const void *arg)
+static void test_read_guest_mem(void)
{
- enum test_memfd memfd = GPOINTER_TO_INT(arg);
TestServer *server = NULL;
char *qemu_cmd = NULL;
QTestState *s = NULL;
@@ -669,7 +649,7 @@ static void test_read_guest_mem(const void *arg)
server = test_server_new("test");
test_server_listen(server);
- qemu_cmd = get_qemu_cmd(server, 512, memfd, root, "", "");
+ qemu_cmd = GET_QEMU_CMD(server);
s = qtest_start(qemu_cmd);
g_free(qemu_cmd);
@@ -691,7 +671,7 @@ static void test_migrate(void)
char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path);
QTestState *global = global_qtest, *from, *to;
GSource *source;
- gchar *cmd, *tmp;
+ gchar *cmd;
QDict *rsp;
guint8 *log;
guint64 size;
@@ -699,7 +679,7 @@ static void test_migrate(void)
test_server_listen(s);
test_server_listen(dest);
- cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, "", "");
+ cmd = GET_QEMU_CMDE(s, 2, "", "");
from = qtest_start(cmd);
g_free(cmd);
@@ -708,9 +688,7 @@ static void test_migrate(void)
size = get_log_size(s);
g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));
- tmp = g_strdup_printf(" -incoming %s", uri);
- cmd = get_qemu_cmd(dest, 2, TEST_MEMFD_AUTO, root, "", tmp);
- g_free(tmp);
+ cmd = GET_QEMU_CMDE(dest, 2, "", " -incoming %s", uri);
to = qtest_init(cmd);
g_free(cmd);
@@ -823,7 +801,7 @@ static void test_reconnect_subprocess(void)
char *cmd;
g_thread_new("connect", connect_thread, s);
- cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", "");
+ cmd = GET_QEMU_CMDE(s, 2, ",server", "");
qtest_start(cmd);
g_free(cmd);
@@ -861,7 +839,7 @@ static void test_connect_fail_subprocess(void)
s->test_fail = true;
g_thread_new("connect", connect_thread, s);
- cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", "");
+ cmd = GET_QEMU_CMDE(s, 2, ",server", "");
qtest_start(cmd);
g_free(cmd);
@@ -891,7 +869,7 @@ static void test_flags_mismatch_subprocess(void)
s->test_flags = TEST_FLAGS_DISCONNECT;
g_thread_new("connect", connect_thread, s);
- cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", "");
+ cmd = GET_QEMU_CMDE(s, 2, ",server", "");
qtest_start(cmd);
g_free(cmd);
@@ -926,21 +904,11 @@ static void test_multiqueue(void)
s->queues = 2;
test_server_listen(s);
- if (qemu_memfd_check()) {
- cmd = g_strdup_printf(
- QEMU_CMD_MEMFD QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d "
- "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d",
- 512, 512, s->chr_name,
- s->socket_path, "", s->chr_name,
- s->queues, s->queues * 2 + 2);
- } else {
- cmd = g_strdup_printf(
- QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d "
- "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d",
- 512, 512, root, s->chr_name,
- s->socket_path, "", s->chr_name,
- s->queues, s->queues * 2 + 2);
- }
+ cmd = g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d "
+ "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d",
+ 512, 512, root, s->chr_name,
+ s->socket_path, "", s->chr_name,
+ s->queues, s->queues * 2 + 2);
qtest_start(cmd);
g_free(cmd);
@@ -986,13 +954,7 @@ int main(int argc, char **argv)
/* run the main loop thread so the chardev may operate */
thread = g_thread_new(NULL, thread_function, loop);
- if (qemu_memfd_check()) {
- qtest_add_data_func("/vhost-user/read-guest-mem/memfd",
- GINT_TO_POINTER(TEST_MEMFD_YES),
- test_read_guest_mem);
- }
- qtest_add_data_func("/vhost-user/read-guest-mem/memfile",
- GINT_TO_POINTER(TEST_MEMFD_NO), test_read_guest_mem);
+ qtest_add_func("/vhost-user/read-guest-mem", test_read_guest_mem);
qtest_add_func("/vhost-user/migrate", test_migrate);
qtest_add_func("/vhost-user/multiqueue", test_multiqueue);