From: Jens Freimann <jfreimann@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mst@redhat.com, victork@redhat.com,
maxime.coquelin@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 4/4] tests/pxe-test: add testcase using vhost-user-bridge
Date: Fri, 21 Jul 2017 11:55:53 +0200 [thread overview]
Message-ID: <20170721095553.10717-5-jfreimann@redhat.com> (raw)
In-Reply-To: <20170721095553.10717-1-jfreimann@redhat.com>
From: Jens Freimann <jfreiman@redhat.com>
Add a PXE testcase tunneling traffic through vhost-user-bridge process.
Create a vhost-user-bridge process and connect it to qemu via a socket.
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
---
tests/Makefile.include | 4 +-
tests/pxe-test.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 142 insertions(+), 2 deletions(-)
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 7af278d..e40550c 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -705,7 +705,8 @@ tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y)
tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y)
-tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y)
+tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o \
+ tests/vhost-user-bridge$(EXESUF) $(libqos-obj-y)
tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
tests/m25p80-test$(EXESUF): tests/m25p80-test.o
@@ -834,6 +835,7 @@ $(patsubst %, check-qtest-%, $(QTEST_TARGETS)): check-qtest-%: $(check-qtest-y)
$(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,)
$(call quiet-command,QTEST_QEMU_BINARY=$*-softmmu/qemu-system-$* \
QTEST_QEMU_IMG=qemu-img$(EXESUF) \
+ QTEST_VUBR_BINARY=./tests/vhost-user-bridge$(EXESUF) \
MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} \
gtester $(GTESTER_OPTIONS) -m=$(SPEED) $(check-qtest-$*-y) $(check-qtest-generic-y),"GTESTER","$@")
$(if $(CONFIG_GCOV),@for f in $(gcov-files-$*-y) $(gcov-files-generic-y); do \
diff --git a/tests/pxe-test.c b/tests/pxe-test.c
index 34282d3..d6379a8 100644
--- a/tests/pxe-test.c
+++ b/tests/pxe-test.c
@@ -5,7 +5,8 @@
*
* Authors:
* Michael S. Tsirkin <mst@redhat.com>,
- * Victor Kaplansky <victork@redhat.com>
+ * Victor Kaplansky <victork@redhat.com>,
+ * Jens Freimann <jfreiman@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
@@ -13,14 +14,150 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
+#include <glib.h>
#include "qemu-common.h"
#include "libqtest.h"
#include "boot-sector.h"
+#include <sys/vfs.h>
+#define LPORT 5555
+#define RPORT 4444
#define NETNAME "net0"
+#define QEMU_CMD_MEM "--enable-kvm -m %d "\
+ "-object memory-backend-file,id=mem,size=%dM,"\
+ "mem-path=%s,share=on -numa node,memdev=mem -mem-prealloc "
+#define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s"
+#define QEMU_CMD_NETDEV " -device virtio-net-pci,netdev=net0 "\
+ " -netdev vhost-user,id=net0,chardev=%s,vhostforce "\
+ " -netdev user,id=n0,tftp=./,bootfile=%s "\
+ " -netdev socket,id=n1,fd=%d"
+#define QEMU_CMD_NET " -device virtio-net-pci,netdev=n0 "\
+ " -device virtio-net-pci,netdev=n1 "
+
+#define QEMU_CMD QEMU_CMD_MEM QEMU_CMD_CHR \
+ QEMU_CMD_NETDEV QEMU_CMD_NET
+
+#define HUGETLBFS_MAGIC 0x958458f6
+#define VUBR_SOCK "vubr.sock"
+#define MEMSZ 1024
static char disk[] = "tests/pxe-test-disk-XXXXXX";
+static const char *init_hugepagefs(const char *path)
+{
+ struct statfs fs;
+ int ret;
+
+ if (access(path, R_OK | W_OK | X_OK)) {
+ g_test_message("access on path (%s): %s\n", path, strerror(errno));
+ return NULL;
+ }
+
+ do {
+ ret = statfs(path, &fs);
+ } while (ret != 0 && errno == EINTR);
+
+ if (ret != 0) {
+ g_test_message("statfs on path (%s): %s\n", path, strerror(errno));
+ return NULL;
+ }
+
+ if (fs.f_type != HUGETLBFS_MAGIC) {
+ g_test_message("Warning: path not on HugeTLBFS: %s\n", path);
+ return NULL;
+ }
+
+ return path;
+}
+
+static int vubr_create_socket(struct sockaddr_in *si_remote, int rport)
+{
+ int sock;
+
+ if (inet_aton("127.0.0.1", (struct in_addr *) &si_remote->sin_addr.s_addr)
+ == 0) {
+ g_test_message("inet_aton failed\n");
+ return -1;
+ }
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (sock == -1) {
+ g_test_message("socket creation failed\n");
+ return -1;
+ }
+ if (connect(sock, (struct sockaddr *) si_remote, sizeof(*si_remote))) {
+ g_test_message("connect failed: %s", strerror(errno));
+ return -1;
+ }
+
+ return sock;
+}
+
+static void test_pxe_vhost_user(void)
+{
+ char template[] = "/tmp/vhost-user-bridge-XXXXXX";
+ char template2[] = "/tmp/hugepages-XXXXXX";
+ gchar * vubr_args[] = {NULL, NULL, NULL, NULL};
+ struct sockaddr_in si_remote = {
+ .sin_family = AF_INET,
+ .sin_port = htons(RPORT),
+ };
+ const char *hugefs = NULL;
+ const char *tmpfs2 = NULL;
+ const char *tmpfs = NULL;
+ const char *root = NULL;
+ GError *error = NULL;
+ char *vubr_binary;
+ char *qemu_args;
+ GPid vubr_pid;
+ int sock = -1;
+
+ tmpfs = mkdtemp(template);
+ if (!tmpfs) {
+ g_test_message("mkdtemp on path(%s): %s\n",
+ template, strerror(errno));
+ }
+ vubr_binary = getenv("QTEST_VUBR_BINARY");
+ g_assert(vubr_binary);
+ vubr_args[0] = g_strdup_printf("%s", vubr_binary);
+ vubr_args[1] = g_strdup_printf("-u");
+ vubr_args[2] = g_strdup_printf("%s/%s", tmpfs, VUBR_SOCK);
+ g_spawn_async(NULL, vubr_args, NULL,
+ G_SPAWN_SEARCH_PATH_FROM_ENVP |
+ G_SPAWN_SEARCH_PATH,
+ NULL, NULL, &vubr_pid, &error);
+ g_assert_no_error(error);
+
+ hugefs = getenv("QTEST_HUGETLBFS_PATH");
+ if (hugefs) {
+ root = init_hugepagefs(hugefs);
+ g_assert(root);
+ } else {
+ tmpfs2 = mkdtemp(template2);
+ g_assert(tmpfs2);
+ root = tmpfs2;
+ }
+
+ sock = vubr_create_socket(&si_remote, RPORT);
+ g_assert_cmpint(sock, !=, -1);
+
+ qemu_args = g_strdup_printf(QEMU_CMD, MEMSZ, MEMSZ, (root),
+ "char0", vubr_args[2], "char0",
+ disk, sock);
+ qtest_start(qemu_args);
+ boot_sector_test();
+ qtest_quit(global_qtest);
+ g_free(qemu_args);
+ g_free(vubr_args[0]);
+ g_free(vubr_args[1]);
+ g_free(vubr_args[2]);
+ g_assert_cmpint(g_remove(g_strdup_printf("%s/%s", tmpfs, VUBR_SOCK)),
+ ==, 0);
+ if (tmpfs2) {
+ g_assert_cmpint(rmdir(tmpfs2), ==, 0);
+ }
+ g_assert_cmpint(g_rmdir(tmpfs), ==, 0);
+}
+
static void test_pxe_one(const char *params, bool ipv6)
{
char *args;
@@ -65,6 +202,7 @@ int main(int argc, char *argv[])
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
qtest_add_func("pxe/e1000", test_pxe_e1000);
qtest_add_func("pxe/virtio", test_pxe_virtio_pci);
+ qtest_add_func("pxe/vhost-user", test_pxe_vhost_user);
} else if (strcmp(arch, "ppc64") == 0) {
qtest_add_func("pxe/virtio", test_pxe_virtio_pci);
qtest_add_func("pxe/spapr-vlan", test_pxe_spapr_vlan);
--
2.9.4
next prev parent reply other threads:[~2017-07-21 9:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 9:55 [Qemu-devel] [PATCH 0/4] tests/pxe-test: add testcase using vhost-user-bridge Jens Freimann
2017-07-21 9:55 ` [Qemu-devel] [PATCH 1/4] tests/vhost-user-bridge: disable debug output by default Jens Freimann
2017-07-21 9:55 ` [Qemu-devel] [PATCH 2/4] net: fix -netdev socket, fd= for UDP sockets Jens Freimann
2017-07-25 13:14 ` Michael S. Tsirkin
2017-07-25 13:15 ` Michael S. Tsirkin
2017-07-21 9:55 ` [Qemu-devel] [PATCH 3/4] libvhost-user: quit when no more data received Jens Freimann
2017-07-21 10:59 ` Marc-André Lureau
2017-07-21 11:39 ` Jens Freimann
2017-07-21 9:55 ` Jens Freimann [this message]
2017-07-24 13:42 ` [Qemu-devel] [PATCH 4/4] tests/pxe-test: add testcase using vhost-user-bridge Stefan Hajnoczi
2017-07-25 19:43 ` Jens Freimann
2017-07-24 22:06 ` Michael S. Tsirkin
2017-07-25 9:17 ` Jens Freimann
2017-07-27 12:57 ` [Qemu-devel] [PATCH 0/4] " no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170721095553.10717-5-jfreimann@redhat.com \
--to=jfreimann@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=maxime.coquelin@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=victork@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).