diff mbox series

[v2,7/8] libvhost-user: add a simple link test without glib

Message ID 20201125100640.366523-8-marcandre.lureau@redhat.com
State New
Headers show
Series libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") | expand

Commit Message

Marc-André Lureau Nov. 25, 2020, 10:06 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 subprojects/libvhost-user/link-test.c | 45 +++++++++++++++++++++++++++
 subprojects/libvhost-user/meson.build |  4 +++
 2 files changed, 49 insertions(+)
 create mode 100644 subprojects/libvhost-user/link-test.c

Comments

Stefan Hajnoczi Dec. 2, 2020, 2:28 p.m. UTC | #1
On Wed, Nov 25, 2020 at 02:06:39PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  subprojects/libvhost-user/link-test.c | 45 +++++++++++++++++++++++++++
>  subprojects/libvhost-user/meson.build |  4 +++
>  2 files changed, 49 insertions(+)
>  create mode 100644 subprojects/libvhost-user/link-test.c

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox series

Patch

diff --git a/subprojects/libvhost-user/link-test.c b/subprojects/libvhost-user/link-test.c
new file mode 100644
index 0000000000..e01d6eb1fa
--- /dev/null
+++ b/subprojects/libvhost-user/link-test.c
@@ -0,0 +1,45 @@ 
+/*
+ * A trivial unit test to check linking without glib. A real test suite should
+ * probably based off libvhost-user-glib instead.
+ */
+#include <assert.h>
+#include <stdlib.h>
+#include "libvhost-user.h"
+
+static void
+panic(VuDev *dev, const char *err)
+{
+    abort();
+}
+
+static void
+set_watch(VuDev *dev, int fd, int condition,
+          vu_watch_cb cb, void *data)
+{
+    abort();
+}
+
+static void
+remove_watch(VuDev *dev, int fd)
+{
+    abort();
+}
+
+static const VuDevIface iface = {
+    0,
+};
+
+int
+main(int argc, const char *argv[])
+{
+    bool rc;
+    uint16_t max_queues = 2;
+    int socket = 0;
+    VuDev dev = { 0, };
+
+    rc = vu_init(&dev, max_queues, socket, panic, NULL, set_watch, remove_watch, &iface);
+    assert(rc == true);
+    vu_deinit(&dev);
+
+    return 0;
+}
diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-user/meson.build
index ac228b5ba6..76e83c0cec 100644
--- a/subprojects/libvhost-user/meson.build
+++ b/subprojects/libvhost-user/meson.build
@@ -22,6 +22,10 @@  vhost_user = static_library('vhost-user',
                             include_directories: inc,
                             c_args: '-D_GNU_SOURCE')
 
+executable('link-test', files('link-test.c'),
+           link_whole: vhost_user,
+           include_directories: inc)
+
 vhost_user_glib = static_library('vhost-user-glib',
                                  files('libvhost-user-glib.c'),
                                  include_directories: inc,