diff mbox

[1/2] tests: Add ivshmem qtest

Message ID 1444515513-3418-1-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Oct. 10, 2015, 10:18 p.m. UTC
Note that it launches two instances, as sharing memory is the purpose
of Nahanni/ivshmem.

Cc: Cam Macdonell <cam@cs.ualberta.ca>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/Makefile       |  3 +++
 tests/ivshmem-test.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 tests/ivshmem-test.c

Comments

Marc-André Lureau Oct. 10, 2015, 11:10 p.m. UTC | #1
Hi Andreas,

Thanks for the patches. I suppose I should insert it in my ivshmem
series, since the second patch requires it.

On Sun, Oct 11, 2015 at 12:18 AM, Andreas Färber <afaerber@suse.de> wrote:
> + * QTest testcase for Nahanni

I think nahanni is an archaic codename (not used in qemu code),
ivshmem is really more clear today.

(I'll try to verify/review your test asap)
diff mbox

Patch

diff --git a/tests/Makefile b/tests/Makefile
index e6474ba..3b7e6ac 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -191,6 +191,8 @@  gcov-files-i386-y += hw/pci-host/q35.c
 ifeq ($(CONFIG_VHOST_NET),y)
 check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF)
 endif
+check-qtest-i386-y += tests/ivshmem-test$(EXESUF)
+gcov-files-i386-y += i386-softmmu/hw/misc/ivshmem.c
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -434,6 +436,7 @@  tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y)
 tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
 tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y)
+tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y)
 tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
new file mode 100644
index 0000000..45fe2ae
--- /dev/null
+++ b/tests/ivshmem-test.c
@@ -0,0 +1,51 @@ 
+/*
+ * QTest testcase for Nahanni
+ *
+ * Copyright (c) 2014 SUSE LINUX Products GmbH
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "libqtest.h"
+#include "qemu/osdep.h"
+
+static char dev_shm_path[] = "/dev/shm/qtest.XXXXXX";
+
+/* Tests only initialization so far. TODO: Replace with functional tests */
+static void nop(void)
+{
+}
+
+int main(int argc, char **argv)
+{
+    QTestState *s1, *s2;
+    char *cmd;
+    int ret, fd;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/ivshmem/nop", nop);
+
+    fd = mkstemp(dev_shm_path);
+    g_assert(fd >= 0);
+    close(fd);
+    unlink(dev_shm_path);
+
+    cmd = g_strdup_printf("-device ivshmem,shm=%s,size=1M", &dev_shm_path[9]);
+    s1 = qtest_start(cmd);
+    s2 = qtest_start(cmd);
+    g_free(cmd);
+
+    ret = g_test_run();
+
+    qtest_quit(s1);
+    qtest_quit(s2);
+
+    unlink(dev_shm_path);
+
+    return ret;
+}