qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Thomas Huth <thuth@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>,
	Greg Kurz <groug@kaod.org>
Subject: [PATCH 09/12] tests/9pfs: introduce local tests
Date: Sun, 27 Sep 2020 12:40:47 +0200	[thread overview]
Message-ID: <44025a54367bc69073295b48b9b8b21bb419ca50.1601203436.git.qemu_oss@crudebyte.com> (raw)
In-Reply-To: <cover.1601203436.git.qemu_oss@crudebyte.com>

This patch introduces 9pfs test cases using the 9pfs 'local'
filesystem driver which reads/writes/creates/deletes real files
and directories.

In this initial version, there are only 2 local tests which actually
only check if the 9pfs 'local' device was created successfully.

Before the 9pfs 'local' tests are run, a test directory 'qtest-9p-local'
is created (with world rwx permissions) under the current working
directory. At this point that test directory is not auto deleted yet.

A different PCI address, fsdev id and mount tag is used for the 'local'
9pfs device. This is not really necessary right now, but might be useful
to avoid potential colissions in future.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/virtio-9p.c | 101 ++++++++++++++++++++++++++++++++-
 tests/qtest/libqos/virtio-9p.h |   1 +
 tests/qtest/virtio-9p-test.c   |  12 +++-
 3 files changed, 110 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 1bda5403ff..400f4b0113 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -24,6 +24,61 @@
 #include "qgraph.h"
 
 static QGuestAllocator *alloc;
+static char *local_test_path;
+
+/* Concatenates the passed 2 pathes. Returned result must be freed. */
+static char *concat_path(const char* a, const char* b)
+{
+    const int len = strlen(a) + strlen("/") + strlen(b);
+    char *path = g_malloc0(len + 1);
+    snprintf(path, len + 1, "%s/%s", a, b);
+    g_assert(strlen(path) == len);
+    return path;
+}
+
+/*
+ * Lazy sprintf() implementation which auto allocates buffer. Returned result
+ * must be freed.
+ */
+static char *strpr(const char* format, ...)
+{
+    va_list argp;
+
+    va_start(argp, format);
+    const int sz = vsnprintf(NULL, 0, format, argp) + 1;
+    va_end(argp);
+
+    g_assert(sz > 0);
+    char *s = g_malloc0(sz);
+
+    va_start(argp, format);
+    const int len = vsnprintf(s, sz, format, argp);
+    va_end(argp);
+
+    g_assert(len + 1 == sz);
+    return s;
+}
+
+static void init_local_test_path(void)
+{
+    char *pwd = get_current_dir_name();
+    local_test_path = concat_path(pwd, "qtest-9p-local");
+    free(pwd);
+}
+
+/* Creates the directory for the 9pfs 'local' filesystem driver to access. */
+static void create_local_test_dir(void)
+{
+    struct stat st;
+
+    g_assert(local_test_path != NULL);
+    mkdir(local_test_path, 0777);
+
+    /* ensure test directory exists now ... */
+    g_assert(stat(local_test_path, &st) == 0);
+    /* ... and is actually a directory */
+    g_assert((st.st_mode & S_IFMT) == S_IFDIR);
+}
 
 static void virtio_9p_cleanup(QVirtio9P *interface)
 {
@@ -62,10 +117,14 @@ static void virtio_9p_device_start_hw(QOSGraphObject *obj)
 static void *virtio_9p_get_driver(QVirtio9P *v_9p,
                                          const char *interface)
 {
-    if (!g_strcmp0(interface, "virtio-9p-synth")) {
+    if (!g_strcmp0(interface, "virtio-9p-synth") ||
+        !g_strcmp0(interface, "virtio-9p-local"))
+    {
         return v_9p;
     }
-    if (!g_strcmp0(interface, "virtio-synth")) {
+    if (!g_strcmp0(interface, "virtio-synth") ||
+        !g_strcmp0(interface, "virtio-local"))
+    {
         return v_9p->vdev;
     }
 
@@ -148,6 +207,12 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
 
 static void virtio_9p_register_nodes(void)
 {
+    /* make sure test dir for the 'local' tests exists and is clean */
+    init_local_test_path();
+    create_local_test_dir();
+
+    /* 9pfs device using the 'synth' fs driver */
+
     const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG_SYNTH;
     const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG_SYNTH;
 
@@ -176,6 +241,38 @@ static void virtio_9p_register_nodes(void)
     qos_node_produces("virtio-9p-pci-synth", "pci-device");
     qos_node_produces("virtio-9p-pci-synth", "virtio-synth");
     qos_node_produces("virtio-9p-pci-synth", "virtio-9p-synth");
+
+
+    /* 9pfs device using the 'local' fs driver */
+
+    const char *local_str_simple = "fsdev=fsdev1,mount_tag=" MOUNT_TAG_LOCAL;
+    const char *local_str_addr = "fsdev=fsdev1,addr=04.1,mount_tag="
+                                 MOUNT_TAG_LOCAL;
+
+    addr.devfn = QPCI_DEVFN(4, 1),
+
+    opts.before_cmd_line = strpr(
+        "-fsdev local,id=fsdev1,path='%s',security_model=mapped-xattr",
+        local_test_path
+    );
+
+    /* virtio-9p-device-local */
+    opts.extra_device_opts = local_str_simple,
+    qos_node_create_driver_named("virtio-9p-device-local", "virtio-9p-device",
+                                 virtio_9p_device_create);
+    qos_node_consumes("virtio-9p-device-local", "virtio-bus", &opts);
+    qos_node_produces("virtio-9p-device-local", "virtio-local");
+    qos_node_produces("virtio-9p-device-local", "virtio-9p-local");
+
+    /* virtio-9p-pci-local */
+    opts.extra_device_opts = local_str_addr;
+    add_qpci_address(&opts, &addr);
+    qos_node_create_driver_named("virtio-9p-pci-local", "virtio-9p-pci",
+                                 virtio_9p_pci_create);
+    qos_node_consumes("virtio-9p-pci-local", "pci-bus", &opts);
+    qos_node_produces("virtio-9p-pci-local", "pci-device");
+    qos_node_produces("virtio-9p-pci-local", "virtio-local");
+    qos_node_produces("virtio-9p-pci-local", "virtio-9p-local");
 }
 
 libqos_init(virtio_9p_register_nodes);
diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h
index d9a815083f..20d1fc6270 100644
--- a/tests/qtest/libqos/virtio-9p.h
+++ b/tests/qtest/libqos/virtio-9p.h
@@ -28,6 +28,7 @@ typedef struct QVirtio9PPCI QVirtio9PPCI;
 typedef struct QVirtio9PDevice QVirtio9PDevice;
 
 #define MOUNT_TAG_SYNTH "qtest-synth"
+#define MOUNT_TAG_LOCAL "qtest-local"
 
 struct QVirtio9P {
     QVirtioDevice *vdev;
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index d46d675309..88451f255f 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -26,13 +26,15 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
     char *tag;
     int i;
 
-    g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG_SYNTH));
+    g_assert(tag_len == strlen(MOUNT_TAG_SYNTH) ||
+             tag_len == strlen(MOUNT_TAG_LOCAL));
 
     tag = g_malloc(tag_len);
     for (i = 0; i < tag_len; i++) {
         tag[i] = qvirtio_config_readb(v9p->vdev, i + 2);
     }
-    g_assert_cmpmem(tag, tag_len, MOUNT_TAG_SYNTH, tag_len);
+    g_assert(strncmp(tag, MOUNT_TAG_SYNTH, tag_len) == 0 ||
+             strncmp(tag, MOUNT_TAG_LOCAL, tag_len) == 0);
     g_free(tag);
 }
 
@@ -918,6 +920,12 @@ static void register_virtio_9p_test(void)
                  NULL);
     qos_add_test("fs/readdir/split_128", synth_driver, fs_readdir_split_128,
                  NULL);
+
+
+    /* selects the 9pfs 'local' filesystem driver for the respective test */
+    const char *local_driver = "virtio-9p-local";
+
+    qos_add_test("config", local_driver, pci_config, NULL);
 }
 
 libqos_init(register_virtio_9p_test);
-- 
2.20.1



  parent reply	other threads:[~2020-09-27 12:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-27 10:43 [PATCH 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
2020-09-27 10:38 ` [PATCH 01/12] tests/qtest/qgraph: add qemu_name to QOSGraphNode Christian Schoenebeck
2020-09-27 10:39 ` [PATCH 02/12] tests/qtest/qgraph: add qos_node_create_driver_named() Christian Schoenebeck
2020-09-27 10:39 ` [PATCH 03/12] tests/qtest/qos: add qos_dump_graph() Christian Schoenebeck
2020-09-27 10:39 ` [PATCH 04/12] tests/qtest/qos-test: new QTEST_DUMP_GRAPH environment variable Christian Schoenebeck
2020-09-27 10:39 ` [PATCH 05/12] tests/qtest/qos-test: add QTEST_DUMP_ENV " Christian Schoenebeck
2020-09-27 10:40 ` [PATCH 06/12] tests/qtest/qos-test: add environment variable QTEST_DEBUG Christian Schoenebeck
2020-09-28  8:31   ` Paolo Bonzini
2020-09-28 12:11     ` Christian Schoenebeck
2020-09-27 10:40 ` [PATCH 07/12] test/9pfs: change export tag name to qtest-synth Christian Schoenebeck
2020-09-27 10:40 ` [PATCH 08/12] tests/9pfs: refactor test names and test devices Christian Schoenebeck
2020-09-28  8:36   ` Paolo Bonzini
2020-09-28  8:37   ` Paolo Bonzini
2020-09-28 11:56     ` Christian Schoenebeck
2020-09-28 12:42       ` Paolo Bonzini
2020-09-28 13:35         ` Christian Schoenebeck
2020-09-28 16:38           ` Paolo Bonzini
2020-10-01 11:34             ` Christian Schoenebeck
2020-10-01 11:56               ` Paolo Bonzini
2020-10-01 12:15                 ` Christian Schoenebeck
2020-10-01 14:04                   ` Paolo Bonzini
2020-10-01 15:26                     ` Christian Schoenebeck
2020-09-27 10:40 ` Christian Schoenebeck [this message]
2020-09-27 10:41 ` [PATCH 10/12] tests/9pfs: wipe local 9pfs test directory Christian Schoenebeck
2020-09-27 10:41 ` [PATCH 11/12] tests/9pfs: add virtio_9p_test_path() Christian Schoenebeck
2020-09-27 10:41 ` [PATCH 12/12] tests/9pfs: add local Tmkdir test Christian Schoenebeck

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=44025a54367bc69073295b48b9b8b21bb419ca50.1601203436.git.qemu_oss@crudebyte.com \
    --to=qemu_oss@crudebyte.com \
    --cc=e.emanuelegiuseppe@gmail.com \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@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).