diff mbox

[RFC] tests/pxe-test: add pxe vhost user test

Message ID 1455814799-19691-1-git-send-email-victork@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Victor Kaplansky Feb. 18, 2016, 5:05 p.m. UTC
Add one more testcase to pxe-test for checking vhost-user
interface. The test is based on spawning vhost-user-bridge
process in addition to qemu under test.

Suggested-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Victor Kaplansky <victork@redhat.com>
---
The patch is a quick and dirty, but working implementation of
Michal's idea. It is based on latest vhost-user-bridge test and
latest change in rules: "[PATCH] rules: filter out irrelevant
files".


 tests/pxe-test.c | 39 +++++++++++++++++++++++++++++++++++++++
 tests/Makefile   |  4 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)

Comments

Michael S. Tsirkin Feb. 18, 2016, 11:33 p.m. UTC | #1
On Thu, Feb 18, 2016 at 07:05:47PM +0200, Victor Kaplansky wrote:
> Add one more testcase to pxe-test for checking vhost-user
> interface. The test is based on spawning vhost-user-bridge
> process in addition to qemu under test.
> 
> Suggested-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Victor Kaplansky <victork@redhat.com>
> ---
> The patch is a quick and dirty, but working implementation of
> Michal's idea. It is based on latest vhost-user-bridge test and
> latest change in rules: "[PATCH] rules: filter out irrelevant
> files".

you asked how to fix warning about no nics being there.
I think that maybe we should just drop this warning.
It's bogus in case of a hotplug, anyway.
Or, check qtest_enabled and print if not there only.

> 
>  tests/pxe-test.c | 39 +++++++++++++++++++++++++++++++++++++++
>  tests/Makefile   |  4 +++-
>  2 files changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/pxe-test.c b/tests/pxe-test.c
> index fa430958..d01965f8 100644
> --- a/tests/pxe-test.c
> +++ b/tests/pxe-test.c
> @@ -48,6 +48,44 @@ static void test_pxe_virtio_pci(void)
>      test_pxe_one("-device virtio-net-pci,netdev=" NETNAME);
>  }
>  
> +static void test_pxe_vhost_user(void)
> +{
> +    pid_t pid;
> +    int status;
> +
> +    pid = fork();
> +    if (!pid) {
> +        char *vubr_binary;
> +        char *args;
> +
> +        vubr_binary = getenv("QTEST_VUBR_BINARY");
> +        assert(vubr_binary);
> +
> +        args =
> +            g_strdup_printf("%s -u /tmp/vubr.sock -l 127.0.0.1:4444 "
> +                            "-r 127.0.0.1:5555 1> /dev/null 2>&1",

Don't hard-code port numbers. open sockets and pass their FDs around.


> +                            vubr_binary);


Pls don't use /tmp like this, this is a security problem.
Pls use g_file_open_tmp, mkdtemp or some such.
See tests/vhost-user-test.c as one example.

> +        system(args);
> +        free(args);
> +        exit(0);
> +    }
> +
> +    g_usleep(1 * G_USEC_PER_SEC);
> +    qtest_start(
> +        "-enable-kvm "
> +        "-m 1024 "

1G for a pxe test? seems way too much.

> +        "-object memory-backend-file,id=mem,size=1024M,mem-path=/tmp/hugepages,share=on "

again, look at vhost-user test for a clean way to do this.

> +        "-numa node,memdev=mem -mem-prealloc "
> +        "-device virtio-net-pci,netdev=net0 "
> +        "-chardev socket,id=char0,path=/tmp/vubr.sock "
> +        "-netdev type=vhost-user,id=net0,chardev=char0,vhostforce "
> +        "-net user,vlan=5,tftp=./,bootfile=tests/pxe-test-disk.raw "
> +        "-net socket,vlan=5,udp=localhost:4444,localaddr=localhost:5555 ");
> +    boot_sector_test();
> +    qtest_quit(global_qtest);
> +    waitpid(pid, &status, 0);
> +}
> +
>  int main(int argc, char *argv[])
>  {
>      int ret;
> @@ -60,6 +98,7 @@ int main(int argc, char *argv[])
>      g_test_init(&argc, &argv, NULL);
>  
>      if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
> +        qtest_add_func("pxe/vhost-user", test_pxe_vhost_user);
>          qtest_add_func("pxe/e1000", test_pxe_e1000);
>          qtest_add_func("pxe/virtio", test_pxe_virtio_pci);
>      }
> diff --git a/tests/Makefile b/tests/Makefile
> index 839d357d..40d9d8cc 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -521,7 +521,8 @@ tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
>  tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
>  tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
>  	tests/boot-sector.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/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
> @@ -620,6 +621,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 % 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 \
> -- 
> Victor
diff mbox

Patch

diff --git a/tests/pxe-test.c b/tests/pxe-test.c
index fa430958..d01965f8 100644
--- a/tests/pxe-test.c
+++ b/tests/pxe-test.c
@@ -48,6 +48,44 @@  static void test_pxe_virtio_pci(void)
     test_pxe_one("-device virtio-net-pci,netdev=" NETNAME);
 }
 
+static void test_pxe_vhost_user(void)
+{
+    pid_t pid;
+    int status;
+
+    pid = fork();
+    if (!pid) {
+        char *vubr_binary;
+        char *args;
+
+        vubr_binary = getenv("QTEST_VUBR_BINARY");
+        assert(vubr_binary);
+
+        args =
+            g_strdup_printf("%s -u /tmp/vubr.sock -l 127.0.0.1:4444 "
+                            "-r 127.0.0.1:5555 1> /dev/null 2>&1",
+                            vubr_binary);
+        system(args);
+        free(args);
+        exit(0);
+    }
+
+    g_usleep(1 * G_USEC_PER_SEC);
+    qtest_start(
+        "-enable-kvm "
+        "-m 1024 "
+        "-object memory-backend-file,id=mem,size=1024M,mem-path=/tmp/hugepages,share=on "
+        "-numa node,memdev=mem -mem-prealloc "
+        "-device virtio-net-pci,netdev=net0 "
+        "-chardev socket,id=char0,path=/tmp/vubr.sock "
+        "-netdev type=vhost-user,id=net0,chardev=char0,vhostforce "
+        "-net user,vlan=5,tftp=./,bootfile=tests/pxe-test-disk.raw "
+        "-net socket,vlan=5,udp=localhost:4444,localaddr=localhost:5555 ");
+    boot_sector_test();
+    qtest_quit(global_qtest);
+    waitpid(pid, &status, 0);
+}
+
 int main(int argc, char *argv[])
 {
     int ret;
@@ -60,6 +98,7 @@  int main(int argc, char *argv[])
     g_test_init(&argc, &argv, NULL);
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        qtest_add_func("pxe/vhost-user", test_pxe_vhost_user);
         qtest_add_func("pxe/e1000", test_pxe_e1000);
         qtest_add_func("pxe/virtio", test_pxe_virtio_pci);
     }
diff --git a/tests/Makefile b/tests/Makefile
index 839d357d..40d9d8cc 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -521,7 +521,8 @@  tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
 tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
 	tests/boot-sector.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/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
@@ -620,6 +621,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 % 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 \