qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables if verbose
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (6 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-24  5:56   ` Thomas Huth
  2020-10-08 18:34 ` [PATCH v4 03/12] libqos/qgraph_internal: add qos_printf() and qos_printf_literal() Christian Schoenebeck
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

If qtests are run in verbose mode (i.e. if --verbose CL argument
was provided) then print all environment variables to stdout
before running the individual tests.

Use qos_printf() instead of g_test_message() to avoid the latter
cluttering the output.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/qos-test.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
index d98ef78613..b279b6f816 100644
--- a/tests/qtest/qos-test.c
+++ b/tests/qtest/qos-test.c
@@ -313,9 +313,16 @@ static void walk_path(QOSGraphNode *orig_path, int len)
  *   machine/drivers/test objects
  * - Cleans up everything
  */
-int main(int argc, char **argv)
+int main(int argc, char **argv, char** envp)
 {
     g_test_init(&argc, &argv, NULL);
+    if (g_test_verbose()) {
+        qos_printf("ENVIRONMENT VARIABLES: {\n");
+        for (char **env = envp; *env != 0; env++) {
+            qos_printf("\t%s\n", *env);
+        }
+        qos_printf("}\n");
+    }
     qos_graph_init();
     module_call_init(MODULE_INIT_QOM);
     module_call_init(MODULE_INIT_LIBQOS);
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 09/12] tests/9pfs: introduce local tests
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (3 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 07/12] tests/qtest/qos-test: dump QEMU command if verbose Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 10/12] tests/9pfs: wipe local 9pfs test directory Christian Schoenebeck
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

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 is only one local test which actually
only checks 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.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/virtio-9p.c | 81 ++++++++++++++++++++++++++++++++++
 tests/qtest/libqos/virtio-9p.h |  5 +++
 tests/qtest/virtio-9p-test.c   | 44 ++++++++++++------
 3 files changed, 116 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 2e300063e3..9cb284cb3c 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -24,6 +24,34 @@
 #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)
+{
+    return g_build_filename(a, b, NULL);
+}
+
+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)
 {
@@ -146,11 +174,64 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
     return obj;
 }
 
+/**
+ * Performs regular expression based search and replace on @a haystack.
+ *
+ * @param haystack - input string to be parsed, result of replacement is
+ *                   stored back to @a haystack
+ * @param pattern - the regular expression pattern for scanning @a haystack
+ * @param replace_fmt - matches of supplied @a pattern are replaced by this,
+ *                      if necessary glib printf format can be used to add
+ *                      variable arguments of this function to this
+ *                      replacement string
+ */
+static void regex_replace(GString *haystack, const char *pattern,
+                          const char *replace_fmt, ...)
+{
+    GRegex *regex;
+    char *replace, *s;
+    va_list argp;
+
+    va_start(argp, replace_fmt);
+    replace = g_strdup_vprintf(replace_fmt, argp);
+    va_end(argp);
+
+    regex = g_regex_new(pattern, 0, 0, NULL);
+    s = g_regex_replace(regex, haystack->str, -1, 0, replace, 0, NULL);
+    g_string_assign(haystack, s);
+    g_free(s);
+    g_regex_unref(regex);
+    g_free(replace);
+}
+
+void virtio_9p_assign_local_driver(GString *cmd_line, const char *args)
+{
+    g_assert_nonnull(local_test_path);
+
+    /* replace 'synth' driver by 'local' driver */
+    regex_replace(cmd_line, "-fsdev synth,", "-fsdev local,");
+
+    /* append 'path=...' to '-fsdev ...' group */
+    regex_replace(cmd_line, "(-fsdev \\w[^ ]*)", "\\1,path='%s'",
+                  local_test_path);
+
+    if (!args) {
+        return;
+    }
+
+    /* append passed args to '-fsdev ...' group */
+    regex_replace(cmd_line, "(-fsdev \\w[^ ]*)", "\\1,%s", args);
+}
+
 static void virtio_9p_register_nodes(void)
 {
     const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG;
     const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG;
 
+    /* make sure test dir for the 'local' tests exists and is clean */
+    init_local_test_path();
+    create_local_test_dir();
+
     QPCIAddress addr = {
         .devfn = QPCI_DEVFN(4, 0),
     };
diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h
index b1e6badc4a..326a603f72 100644
--- a/tests/qtest/libqos/virtio-9p.h
+++ b/tests/qtest/libqos/virtio-9p.h
@@ -44,4 +44,9 @@ struct QVirtio9PDevice {
     QVirtio9P v9p;
 };
 
+/**
+ * Prepares QEMU command line for 9pfs tests using the 'local' fs driver.
+ */
+void virtio_9p_assign_local_driver(GString *cmd_line, const char *args);
+
 #endif
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 3281153b9c..af7e169d3a 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -895,29 +895,45 @@ static void fs_readdir_split_512(void *obj, void *data,
     fs_readdir_split(obj, data, t_alloc, 512);
 }
 
+static void *assign_9p_local_driver(GString *cmd_line, void *arg)
+{
+    virtio_9p_assign_local_driver(cmd_line, "security_model=mapped-xattr");
+    return arg;
+}
+
 static void register_virtio_9p_test(void)
 {
-    qos_add_test("synth/config", "virtio-9p", pci_config, NULL);
-    qos_add_test("synth/version/basic", "virtio-9p", fs_version, NULL);
-    qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, NULL);
-    qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, NULL);
+
+    QOSGraphTestOptions opts = {
+    };
+
+    /* 9pfs test cases using the 'synth' filesystem driver */
+    qos_add_test("synth/config", "virtio-9p", pci_config, &opts);
+    qos_add_test("synth/version/basic", "virtio-9p", fs_version,  &opts);
+    qos_add_test("synth/attach/basic", "virtio-9p", fs_attach,  &opts);
+    qos_add_test("synth/walk/basic", "virtio-9p", fs_walk,  &opts);
     qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash,
-                 NULL);
+                  &opts);
     qos_add_test("synth/walk/dotdot_from_root", "virtio-9p",
-                 fs_walk_dotdot, NULL);
-    qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, NULL);
-    qos_add_test("synth/write/basic", "virtio-9p", fs_write, NULL);
+                 fs_walk_dotdot,  &opts);
+    qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen,  &opts);
+    qos_add_test("synth/write/basic", "virtio-9p", fs_write,  &opts);
     qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,
-                 NULL);
+                  &opts);
     qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored,
-                 NULL);
-    qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, NULL);
+                  &opts);
+    qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir,  &opts);
     qos_add_test("synth/readdir/split_512", "virtio-9p",
-                 fs_readdir_split_512, NULL);
+                 fs_readdir_split_512,  &opts);
     qos_add_test("synth/readdir/split_256", "virtio-9p",
-                 fs_readdir_split_256, NULL);
+                 fs_readdir_split_256,  &opts);
     qos_add_test("synth/readdir/split_128", "virtio-9p",
-                 fs_readdir_split_128, NULL);
+                 fs_readdir_split_128,  &opts);
+
+
+    /* 9pfs test cases using the 'local' filesystem driver */
+    opts.before = assign_9p_local_driver;
+    qos_add_test("local/config", "virtio-9p", pci_config,  &opts);
 }
 
 libqos_init(register_virtio_9p_test);
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (10 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph() Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-19 10:35   ` Christian Schoenebeck
  11 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

Add new member variable 'qemu_name' to struct QOSGraphNode.

This new member may be optionally set in case a different
name for the node (which must always be a unique name) vs.
its actually associated QEMU (QMP) device name is required.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/qgraph.c          | 1 +
 tests/qtest/libqos/qgraph_internal.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
index fc49cfa879..e42f3eaafa 100644
--- a/tests/qtest/libqos/qgraph.c
+++ b/tests/qtest/libqos/qgraph.c
@@ -153,6 +153,7 @@ static QOSGraphNode *create_node(const char *name, QOSNodeType type)
 static void destroy_node(void *val)
 {
     QOSGraphNode *node = val;
+    g_free(node->qemu_name);
     g_free(node->command_line);
     g_free(node);
 }
diff --git a/tests/qtest/libqos/qgraph_internal.h b/tests/qtest/libqos/qgraph_internal.h
index 968fa69450..974985dce9 100644
--- a/tests/qtest/libqos/qgraph_internal.h
+++ b/tests/qtest/libqos/qgraph_internal.h
@@ -56,6 +56,7 @@ struct QOSGraphNode {
     bool available;     /* set by QEMU via QMP, used during graph walk */
     bool visited;       /* used during graph walk */
     char *name;         /* used to identify the node */
+    char *qemu_name;    /* optional: see qos_node_create_driver_named() */
     char *command_line; /* used to start QEMU at test execution */
     union {
         struct {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 02/12] libqos/qgraph: add qos_node_create_driver_named()
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 11/12] tests/9pfs: add virtio_9p_test_path() Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 07/12] tests/qtest/qos-test: dump QEMU command if verbose Christian Schoenebeck
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

So far the qos subsystem of the qtest framework had the limitation
that only one instance of the same official QEMU (QMP) driver name
could be created for qtests. That's because a) the created qos
node names must always be unique, b) the node name must match the
official QEMU driver name being instantiated and c) all nodes are
in a global space shared by all tests.

This patch removes this limitation by introducing a new function
qos_node_create_driver_named() which allows test case authors to
specify a node name being different from the actual associated
QEMU driver name. It fills the new 'qemu_name' field of
QOSGraphNode for that purpose.

Adjust build_driver_cmd_line() and qos_graph_node_set_availability()
to correctly deal with either accessing node name vs. node's
qemu_name correctly.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/qgraph.c | 53 ++++++++++++++++++++++++++++++++++---
 tests/qtest/libqos/qgraph.h | 16 +++++++++++
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
index e42f3eaafa..61faf6b27d 100644
--- a/tests/qtest/libqos/qgraph.c
+++ b/tests/qtest/libqos/qgraph.c
@@ -287,7 +287,8 @@ static void build_machine_cmd_line(QOSGraphNode *node, const char *args)
  */
 static void build_driver_cmd_line(QOSGraphNode *node)
 {
-    node->command_line = g_strconcat(" -device ", node->name, NULL);
+    const char *name = node->qemu_name ?: node->name;
+    node->command_line = g_strconcat(" -device ", name, NULL);
 }
 
 /* qos_print_cb(): callback prints all path found by the DFS algorithm. */
@@ -632,6 +633,15 @@ void qos_node_create_driver(const char *name, QOSCreateDriverFunc function)
     node->u.driver.constructor = function;
 }
 
+void qos_node_create_driver_named(const char *name, const char *qemu_name,
+                                  QOSCreateDriverFunc function)
+{
+    QOSGraphNode *node = create_node(name, QNODE_DRIVER);
+    node->qemu_name = g_strdup(qemu_name);
+    build_driver_cmd_line(node);
+    node->u.driver.constructor = function;
+}
+
 void qos_node_contains(const char *container, const char *contained,
                        QOSGraphEdgeOptions *opts, ...)
 {
@@ -664,7 +674,7 @@ void qos_node_consumes(const char *consumer, const char *interface,
     add_edge(interface, consumer, QEDGE_CONSUMED_BY, opts);
 }
 
-void qos_graph_node_set_availability(const char *node, bool av)
+static void qos_graph_node_set_availability_explicit(const char *node, bool av)
 {
     QOSGraphEdgeList *elist;
     QOSGraphNode *n = search_node(node);
@@ -679,9 +689,46 @@ void qos_graph_node_set_availability(const char *node, bool av)
     }
     QSLIST_FOREACH_SAFE(e, elist, edge_list, next) {
         if (e->type == QEDGE_CONTAINS || e->type == QEDGE_PRODUCES) {
-            qos_graph_node_set_availability(e->dest, av);
+            qos_graph_node_set_availability_explicit(e->dest, av);
+        }
+    }
+}
+
+/*
+ * Behaves as qos_graph_node_set_availability_explicit(), except that the
+ * former always matches by node name only, whereas this function matches both
+ * by node name and node's optional 'qemu_name' field.
+ */
+void qos_graph_node_set_availability(const char *node, bool av)
+{
+    GList *l;
+    QOSGraphEdgeList *elist;
+    QOSGraphEdge *e, *next;
+    QOSGraphNode *n;
+    GList *keys = g_hash_table_get_keys(node_table);
+
+    for (l = keys; l != NULL; l = l->next) {
+        const gchar *key = l->data;
+        n = g_hash_table_lookup(node_table, key);
+        /*
+         * node's 'qemu_name' is set if there is more than one device with
+         * the same QEMU (QMP) device name
+         */
+        const char *node_name = n->qemu_name ?: n->name;
+        if (g_strcmp0(node_name, node) == 0) {
+            n->available = av;
+            elist = get_edgelist(n->name);
+            if (elist) {
+                QSLIST_FOREACH_SAFE(e, elist, edge_list, next) {
+                    if (e->type == QEDGE_CONTAINS || e->type == QEDGE_PRODUCES)
+                    {
+                        qos_graph_node_set_availability_explicit(e->dest, av);
+                    }
+                }
+            }
         }
     }
+    g_list_free(keys);
 }
 
 void qos_graph_foreach_test_path(QOSTestCallback fn)
diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h
index 5f63d352ca..f472949f68 100644
--- a/tests/qtest/libqos/qgraph.h
+++ b/tests/qtest/libqos/qgraph.h
@@ -452,6 +452,22 @@ void qos_node_create_machine_args(const char *name,
  */
 void qos_node_create_driver(const char *name, QOSCreateDriverFunc function);
 
+/**
+ * Behaves as qos_node_create_driver() with the extension of allowing to
+ * specify a different node name vs. associated QEMU device name.
+ *
+ * Use this function instead of qos_node_create_driver() if you need to create
+ * several instances of the same QEMU device. You are free to choose a custom
+ * node name, however the chosen node name must always be unique.
+ *
+ * @param name: custom, unique name of the node to be created
+ * @param qemu_name: actual (official) QEMU driver name the node shall be
+ *                   associated with
+ * @param function: driver constructor
+ */
+void qos_node_create_driver_named(const char *name, const char *qemu_name,
+                                  QOSCreateDriverFunc function);
+
 /**
  * qos_node_contains(): creates one or more edges of type QEDGE_CONTAINS
  * and adds them to the edge list mapped to @container in the
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 07/12] tests/qtest/qos-test: dump QEMU command if verbose
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (2 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 02/12] libqos/qgraph: add qos_node_create_driver_named() Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 09/12] tests/9pfs: introduce local tests Christian Schoenebeck
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

If qtests are run in verbose mode (i.e. if --verbose CL argument
was provided) then print the assembled qemu command line for each
test.

Use qos_printf() instead of g_test_message() to avoid the latter
cluttering the output.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/qos-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
index b279b6f816..f97d0a08fd 100644
--- a/tests/qtest/qos-test.c
+++ b/tests/qtest/qos-test.c
@@ -89,6 +89,9 @@ static void qos_set_machines_devices_available(void)
 
 static void restart_qemu_or_continue(char *path)
 {
+    if (g_test_verbose()) {
+        qos_printf("Run QEMU with: '%s'\n", path);
+    }
     /* compares the current command line with the
      * one previously executed: if they are the same,
      * don't restart QEMU, if they differ, stop previous
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (5 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 10/12] tests/9pfs: wipe local 9pfs test directory Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-24  6:01   ` Thomas Huth
  2020-10-08 18:34 ` [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables " Christian Schoenebeck
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

If qtests were run in verbose mode (i.e. if --verbose CL argument was
provided) then dump the generated qos graph (all nodes and edges,
along with their current individual availability status) to stdout.

See API doc comment on function qos_dump_graph() for details.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/qos-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
index 8fdf87b183..d98ef78613 100644
--- a/tests/qtest/qos-test.c
+++ b/tests/qtest/qos-test.c
@@ -322,6 +322,9 @@ int main(int argc, char **argv)
     qos_set_machines_devices_available();
 
     qos_graph_foreach_test_path(walk_path);
+    if (g_test_verbose()) {
+        qos_dump_graph();
+    }
     g_test_run();
     qtest_end();
     qos_graph_destroy();
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 03/12] libqos/qgraph_internal: add qos_printf() and qos_printf_literal()
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (7 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables " Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 12/12] tests/9pfs: add local Tmkdir test Christian Schoenebeck
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

These two are macros wrapping regular printf() call. They are intended
to be used instead of calling printf() directly in order to avoid
breaking TAP output format.

TAP output format is enabled by using --tap command line argument.
Starting with glib 2.62 it is enabled by default.

Unfortunately there is currently no public glib API available to check
whether TAP output format is enabled. For that reason qos_printf()
simply always prepends a '#' character for now.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/qgraph_internal.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tests/qtest/libqos/qgraph_internal.h b/tests/qtest/libqos/qgraph_internal.h
index 974985dce9..c0025f5ab9 100644
--- a/tests/qtest/libqos/qgraph_internal.h
+++ b/tests/qtest/libqos/qgraph_internal.h
@@ -255,4 +255,15 @@ void qos_delete_cmd_line(const char *name);
  */
 void qos_graph_node_set_availability(const char *node, bool av);
 
+/*
+ * Prepends a '#' character in front for not breaking TAP output format.
+ */
+#define qos_printf(...) printf("# " __VA_ARGS__)
+
+/*
+ * Intended for printing something literally, i.e. for appending text as is
+ * to a line already been started by qos_printf() before.
+ */
+#define qos_printf_literal printf
+
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 11/12] tests/9pfs: add virtio_9p_test_path() Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-14 15:25   ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 02/12] libqos/qgraph: add qos_node_create_driver_named() Christian Schoenebeck
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

All existing 9pfs test cases are using the 'synth' fs driver so far, which
means they are not accessing real files, but a purely simulated (in RAM
only) file system.

Let's make this clear by changing the prefix of the individual qtest case
names from 'fs/' to 'synth/'. That way they'll be easily distinguishable
from upcoming new 9pfs test cases supposed to be using a different fs
driver.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/virtio-9p-test.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index de30b717b6..3281153b9c 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -897,26 +897,26 @@ static void fs_readdir_split_512(void *obj, void *data,
 
 static void register_virtio_9p_test(void)
 {
-    qos_add_test("config", "virtio-9p", pci_config, NULL);
-    qos_add_test("fs/version/basic", "virtio-9p", fs_version, NULL);
-    qos_add_test("fs/attach/basic", "virtio-9p", fs_attach, NULL);
-    qos_add_test("fs/walk/basic", "virtio-9p", fs_walk, NULL);
-    qos_add_test("fs/walk/no_slash", "virtio-9p", fs_walk_no_slash,
+    qos_add_test("synth/config", "virtio-9p", pci_config, NULL);
+    qos_add_test("synth/version/basic", "virtio-9p", fs_version, NULL);
+    qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, NULL);
+    qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, NULL);
+    qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash,
                  NULL);
-    qos_add_test("fs/walk/dotdot_from_root", "virtio-9p",
+    qos_add_test("synth/walk/dotdot_from_root", "virtio-9p",
                  fs_walk_dotdot, NULL);
-    qos_add_test("fs/lopen/basic", "virtio-9p", fs_lopen, NULL);
-    qos_add_test("fs/write/basic", "virtio-9p", fs_write, NULL);
-    qos_add_test("fs/flush/success", "virtio-9p", fs_flush_success,
+    qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, NULL);
+    qos_add_test("synth/write/basic", "virtio-9p", fs_write, NULL);
+    qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,
                  NULL);
-    qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored,
+    qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored,
                  NULL);
-    qos_add_test("fs/readdir/basic", "virtio-9p", fs_readdir, NULL);
-    qos_add_test("fs/readdir/split_512", "virtio-9p",
+    qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, NULL);
+    qos_add_test("synth/readdir/split_512", "virtio-9p",
                  fs_readdir_split_512, NULL);
-    qos_add_test("fs/readdir/split_256", "virtio-9p",
+    qos_add_test("synth/readdir/split_256", "virtio-9p",
                  fs_readdir_split_256, NULL);
-    qos_add_test("fs/readdir/split_128", "virtio-9p",
+    qos_add_test("synth/readdir/split_128", "virtio-9p",
                  fs_readdir_split_128, NULL);
 }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (9 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 12/12] tests/9pfs: add local Tmkdir test Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-24  6:04   ` Thomas Huth
  2020-10-08 18:34 ` [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode Christian Schoenebeck
  11 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

This new function is purely for debugging purposes. It prints the
current qos graph to stdout and allows to identify problems in the
created qos graph e.g. when writing new qos tests.

Coloured output is used to mark available nodes in green colour,
whereas unavailable nodes are marked in red colour.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++
 tests/qtest/libqos/qgraph.h | 20 +++++++++++++
 2 files changed, 76 insertions(+)

diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
index 61faf6b27d..af93e38dcb 100644
--- a/tests/qtest/libqos/qgraph.c
+++ b/tests/qtest/libqos/qgraph.c
@@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name)
         node->command_line = NULL;
     }
 }
+
+#define RED(txt) (    \
+    "\033[0;91m" txt  \
+    "\033[0m"         \
+)
+
+#define GREEN(txt) (  \
+    "\033[0;92m" txt  \
+    "\033[0m"         \
+)
+
+void qos_dump_graph(void)
+{
+    GList *keys;
+    GList *l;
+    QOSGraphEdgeList *list;
+    QOSGraphEdge *e, *next;
+    QOSGraphNode *dest_node, *node;
+
+    qos_printf("ALL QGRAPH EDGES: {\n");
+    keys = g_hash_table_get_keys(edge_table);
+    for (l = keys; l != NULL; l = l->next) {
+        const gchar *key = l->data;
+        qos_printf("\t src='%s'\n", key);
+        list = get_edgelist(key);
+        QSLIST_FOREACH_SAFE(e, list, edge_list, next) {
+            dest_node = g_hash_table_lookup(node_table, e->dest);
+            qos_printf("\t\t|-> dest='%s' type=%d (node=%p)",
+                       e->dest, e->type, dest_node);
+            if (!dest_node) {
+                qos_printf_literal(RED(" <------- ERROR !"));
+            }
+            qos_printf_literal("\n");
+        }
+    }
+    g_list_free(keys);
+    qos_printf("}\n");
+
+    qos_printf("ALL QGRAPH NODES: {\n");
+    keys = g_hash_table_get_keys(node_table);
+    for (l = keys; l != NULL; l = l->next) {
+        const gchar *key = l->data;
+        node = g_hash_table_lookup(node_table, key);
+        qos_printf("\t name='%s' ", key);
+        if (node->qemu_name) {
+            qos_printf_literal("qemu_name='%s' ", node->qemu_name);
+        }
+        qos_printf_literal("type=%d cmd_line='%s' [%s]\n",
+                           node->type, node->command_line,
+                           node->available ? GREEN("available") :
+                                             RED("UNAVAILBLE")
+        );
+    }
+    g_list_free(keys);
+    qos_printf("}\n");
+}
diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h
index f472949f68..07a32535f1 100644
--- a/tests/qtest/libqos/qgraph.h
+++ b/tests/qtest/libqos/qgraph.h
@@ -586,5 +586,25 @@ QOSGraphObject *qos_machine_new(QOSGraphNode *node, QTestState *qts);
 QOSGraphObject *qos_driver_new(QOSGraphNode *node, QOSGraphObject *parent,
                                QGuestAllocator *alloc, void *arg);
 
+/**
+ * Just for debugging purpose: prints all currently existing nodes and
+ * edges to stdout.
+ *
+ * All qtests add themselves to the overall qos graph by calling qgraph
+ * functions that add device nodes and edges between the individual graph
+ * nodes for tests. As the actual graph is assmbled at runtime by the qos
+ * subsystem, it is sometimes not obvious how the overall graph looks like.
+ * E.g. when writing new tests it may happen that those new tests are simply
+ * ignored by the qtest framework.
+ *
+ * This function allows to identify problems in the created qgraph. Keep in
+ * mind: only tests with a path down from the actual test case node (leaf) up
+ * to the graph's root node are actually executed by the qtest framework. And
+ * the qtest framework uses QMP to automatically check which QEMU drivers are
+ * actually currently available, and accordingly qos marks certain pathes as
+ * 'unavailable' in such cases (e.g. when QEMU was compiled without support for
+ * a certain feature).
+ */
+void qos_dump_graph(void);
 
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 12/12] tests/9pfs: add local Tmkdir test
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (8 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 03/12] libqos/qgraph_internal: add qos_printf() and qos_printf_literal() Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph() Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode Christian Schoenebeck
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

This test case uses the 9pfs 'local' driver to create a directory
and then checks if the expected directory was actually created
(as real directory) on host side.

This patch introduces a custom split() implementation, because
the test code requires non empty array elements as result. For
that reason g_strsplit() would not be a good alternative, as
it would require additional filter code for reshuffling the
array, and the resulting code would be even more complex than
this split() function.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/virtio-9p-test.c | 139 +++++++++++++++++++++++++++++++++++
 1 file changed, 139 insertions(+)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index af7e169d3a..c15908f27b 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -18,6 +18,62 @@
 #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
 static QGuestAllocator *alloc;
 
+/*
+ * Used to auto generate new fids. Start with arbitrary high value to avoid
+ * collision with hard coded fids in basic test code.
+ */
+static uint32_t fid_generator = 1000;
+
+static uint32_t genfid(void)
+{
+    return fid_generator++;
+}
+
+/**
+ * Splits the @a in string by @a delim into individual (non empty) strings
+ * and outputs them to @a out. The output array @a out is NULL terminated.
+ *
+ * Output array @a out must be freed by calling split_free().
+ *
+ * @returns number of individual elements in output array @a out (without the
+ *          final NULL terminating element)
+ */
+static int split(const char *in, const char *delim, char ***out)
+{
+    int n = 0, i = 0;
+    char *tmp, *p;
+
+    tmp = g_strdup(in);
+    for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) {
+        if (strlen(p) > 0) {
+            ++n;
+        }
+    }
+    g_free(tmp);
+
+    *out = g_new0(char *, n + 1); /* last element NULL delimiter */
+
+    tmp = g_strdup(in);
+    for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) {
+        if (strlen(p) > 0) {
+            (*out)[i++] = g_strdup(p);
+        }
+    }
+    g_free(tmp);
+
+    return n;
+}
+
+static void split_free(char ***out)
+{
+    int i;
+    for (i = 0; (*out)[i]; ++i) {
+        g_free((*out)[i]);
+    }
+    g_free(*out);
+    *out = NULL;
+}
+
 static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtio9P *v9p = obj;
@@ -201,6 +257,7 @@ static const char *rmessage_name(uint8_t id)
         id == P9_RWALK ? "RWALK" :
         id == P9_RLOPEN ? "RLOPEN" :
         id == P9_RWRITE ? "RWRITE" :
+        id == P9_RMKDIR ? "RMKDIR" :
         id == P9_RFLUSH ? "RFLUSH" :
         id == P9_RREADDIR ? "READDIR" :
         "<unknown>";
@@ -578,6 +635,39 @@ static bool fs_dirents_contain_name(struct V9fsDirent *e, const char* name)
     return false;
 }
 
+/* size[4] Tmkdir tag[2] dfid[4] name[s] mode[4] gid[4] */
+static P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name,
+                          uint32_t mode, uint32_t gid, uint16_t tag)
+{
+    P9Req *req;
+
+    uint32_t body_size = 4 + 4 + 4;
+    uint16_t string_size = v9fs_string_size(name);
+
+    g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
+    body_size += string_size;
+
+    req = v9fs_req_init(v9p, body_size, P9_TMKDIR, tag);
+    v9fs_uint32_write(req, dfid);
+    v9fs_string_write(req, name);
+    v9fs_uint32_write(req, mode);
+    v9fs_uint32_write(req, gid);
+    v9fs_req_send(req);
+    return req;
+}
+
+/* size[4] Rmkdir tag[2] qid[13] */
+static void v9fs_rmkdir(P9Req *req, v9fs_qid *qid)
+{
+    v9fs_req_recv(req, P9_RMKDIR);
+    if (qid) {
+        v9fs_memread(req, qid, 13);
+    } else {
+        v9fs_memskip(req, 13);
+    }
+    v9fs_req_free(req);
+}
+
 /* basic readdir test where reply fits into a single response message */
 static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
 {
@@ -877,6 +967,30 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
     g_free(wnames[0]);
 }
 
+static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc,
+                     const char *path, const char *cname)
+{
+    QVirtio9P *v9p = obj;
+    alloc = t_alloc;
+    char **wnames;
+    char *const name = g_strdup(cname);
+    P9Req *req;
+    const uint32_t fid = genfid();
+
+    int nwnames = split(path, "/", &wnames);
+
+    req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
+    v9fs_req_wait_for_reply(req, NULL);
+    v9fs_rwalk(req, NULL, NULL);
+
+    req = v9fs_tmkdir(v9p, fid, name, 0750, 0, 0);
+    v9fs_req_wait_for_reply(req, NULL);
+    v9fs_rmkdir(req, NULL);
+
+    g_free(name);
+    split_free(&wnames);
+}
+
 static void fs_readdir_split_128(void *obj, void *data,
                                  QGuestAllocator *t_alloc)
 {
@@ -895,6 +1009,30 @@ static void fs_readdir_split_512(void *obj, void *data,
     fs_readdir_split(obj, data, t_alloc, 512);
 }
 
+
+/* tests using the 9pfs 'local' fs driver */
+
+static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+    QVirtio9P *v9p = obj;
+    struct stat st;
+    char *root_path = virtio_9p_test_path("");
+    char *new_dir = virtio_9p_test_path("01");
+
+    g_assert(root_path != NULL);
+
+    fs_attach(v9p, NULL, t_alloc);
+    fs_mkdir(v9p, data, t_alloc, "/", "01");
+
+    /* check if created directory really exists now ... */
+    g_assert(stat(new_dir, &st) == 0);
+    /* ... and is actually a directory */
+    g_assert((st.st_mode & S_IFMT) == S_IFDIR);
+
+    g_free(new_dir);
+    g_free(root_path);
+}
+
 static void *assign_9p_local_driver(GString *cmd_line, void *arg)
 {
     virtio_9p_assign_local_driver(cmd_line, "security_model=mapped-xattr");
@@ -934,6 +1072,7 @@ static void register_virtio_9p_test(void)
     /* 9pfs test cases using the 'local' filesystem driver */
     opts.before = assign_9p_local_driver;
     qos_add_test("local/config", "virtio-9p", pci_config,  &opts);
+    qos_add_test("local/create_dir", "virtio-9p", fs_create_dir, &opts);
 }
 
 libqos_init(register_virtio_9p_test);
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 11/12] tests/9pfs: add virtio_9p_test_path()
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth Christian Schoenebeck
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

This new public function virtio_9p_test_path() allows 9pfs
'local' tests to translate a path from guest scope to host
scope. For instance by passing an empty string it would
return the root path on host of the exported 9pfs tree.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/virtio-9p.c | 6 ++++++
 tests/qtest/libqos/virtio-9p.h | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index bd53498041..1524982634 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -65,6 +65,12 @@ static void remove_local_test_dir(void)
     g_free(cmd);
 }
 
+char *virtio_9p_test_path(const char *path)
+{
+    g_assert(local_test_path);
+    return concat_path(local_test_path, path);
+}
+
 static void virtio_9p_cleanup(QVirtio9P *interface)
 {
     qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc);
diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h
index 326a603f72..19a4d97454 100644
--- a/tests/qtest/libqos/virtio-9p.h
+++ b/tests/qtest/libqos/virtio-9p.h
@@ -49,4 +49,9 @@ struct QVirtio9PDevice {
  */
 void virtio_9p_assign_local_driver(GString *cmd_line, const char *args);
 
+/**
+ * Returns path on host to the passed guest path. Result must be freed.
+ */
+char *virtio_9p_test_path(const char *path);
+
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 10/12] tests/9pfs: wipe local 9pfs test directory
  2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
                   ` (4 preceding siblings ...)
  2020-10-08 18:34 ` [PATCH v4 09/12] tests/9pfs: introduce local tests Christian Schoenebeck
@ 2020-10-08 18:34 ` Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose Christian Schoenebeck
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

Before running the first 9pfs test case, make sure the test directory
for running the 9pfs 'local' tests on is entirely empty. For that
reason simply delete the test directory (if any) before (re)creating
it on test suite startup.

Note: The preferable precise behaviour would be the test directory
only being wiped once *before* a test suite run. Right now the test
directory is also wiped at the *end* of a test suite run because
libqos is calling the virtio_9p_cleanup() callback for some reason
also when a test suite completed. This is suboptimal as developers
cannot immediately see what files and directories the 9pfs local
tests created precisely after the test suite completed. But
fortunately the test directory is not wiped if some test failed.
So it is probably not worth it drilling another hole into libqos
for this issue.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/libqos/virtio-9p.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 9cb284cb3c..bd53498041 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -53,6 +53,18 @@ static void create_local_test_dir(void)
     g_assert((st.st_mode & S_IFMT) == S_IFDIR);
 }
 
+/* Deletes directory previously created by create_local_test_dir(). */
+static void remove_local_test_dir(void)
+{
+    g_assert(local_test_path != NULL);
+    char *cmd = g_strdup_printf("rm -r '%s'\n", local_test_path);
+    int res = system(cmd);
+    if (res < 0) {
+        /* ignore error, dummy check to prevent compiler error */
+    }
+    g_free(cmd);
+}
+
 static void virtio_9p_cleanup(QVirtio9P *interface)
 {
     qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc);
@@ -230,6 +242,7 @@ static void virtio_9p_register_nodes(void)
 
     /* make sure test dir for the 'local' tests exists and is clean */
     init_local_test_path();
+    remove_local_test_dir();
     create_local_test_dir();
 
     QPCIAddress addr = {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 00/12] 9pfs: add tests using local fs driver
@ 2020-10-08 18:49 Christian Schoenebeck
  2020-10-08 18:34 ` [PATCH v4 11/12] tests/9pfs: add virtio_9p_test_path() Christian Schoenebeck
                   ` (11 more replies)
  0 siblings, 12 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-08 18:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

The currently existing 9pfs test cases are all solely using the 9pfs 'synth'
fileystem driver, which is a very simple and purely simulated (in RAM only)
filesystem. There are issues though where the 'synth' fs driver is not
sufficient. For example the following two bugs need test cases running the
9pfs 'local' fs driver:

https://bugs.launchpad.net/qemu/+bug/1336794
https://bugs.launchpad.net/qemu/+bug/1877384

This patch set for that reason introduces 9pfs test cases using the 9pfs
'local' filesystem driver along to the already existing tests on 'synth'.
It consists of 3 parts:

1. libqos patches 1 and 2 remove a limitation of the qtest/libqos subsystem:
   support for more than one device using the same (official) QEMU device
   name.

2. Patches 3 to 7 enhance debugging issues with the qtest framework.

3. Patches 8 to 12 actually introduce 9pfs 'local' test cases using the qtest
   framework. These 'local' tests are adding a test directory 'qtest-9p-local'
   inside the current working directory (using get_current_dir()), which is
   typically the build directory, before running the tests. That test
   directory is automatically recreated next time the test suite is run again,
   to ensure the 9pfs 'local' tests always run consistently on a clean test
   directory. The test directory is used by the 'local' driver as root of its
   export path. So it will add/read/write/delete real files and directories
   inside that test directory.

v3->v4:

  * Added qos_printf() and qos_printf_literal() (NEW patch 3).

  * Use qos_printf() and qos_printf_literal() instead of printf() for not
    breaking TAP output (patch 4, 6, 7).

  * Added private function regex_replace() to simplify and deduplicate code
    (patch 9).

  * RegEx pattern hardening in virtio_9p_assign_local_driver() to avoid
    potential issues with future changes (patch 9).

  * Updated commit log comments.

v2->v3:

  * concat_path() is now just a wrapper for g_build_filename() (patch 8).

  * Dropped function strpr(), using g_strdup_printf() instead (patch 8, 9).

  * Fixed incorrect size for array allocation in split() function
    (patch 11).

v1->v2:

  * The libqos debugging features are now turned on by command line argument
    '--verbose' instead of using environment variables (patches 4, 5, 6).

  * The new 9pfs 'local' tests no longer depend on patches 1 and 2 by no
    longer using a libqos multi-device approach, but rather modifying the
    final QEMU command line for each test instead; see discussion of v1
    for reason (patches 7 to 11).

  * Use GCC_FMT_ATTR on helper function strpr() (patch 8).

  * Updated commit log comments.

Christian Schoenebeck (12):
  libqos/qgraph: add qemu_name to QOSGraphNode
  libqos/qgraph: add qos_node_create_driver_named()
  libqos/qgraph_internal: add qos_printf() and qos_printf_literal()
  libqos/qgraph: add qos_dump_graph()
  tests/qtest/qos-test: dump qos graph if verbose
  tests/qtest/qos-test: dump environment variables if verbose
  tests/qtest/qos-test: dump QEMU command if verbose
  tests/9pfs: change qtest name prefix to synth
  tests/9pfs: introduce local tests
  tests/9pfs: wipe local 9pfs test directory
  tests/9pfs: add virtio_9p_test_path()
  tests/9pfs: add local Tmkdir test

 tests/qtest/libqos/qgraph.c          | 110 ++++++++++++++-
 tests/qtest/libqos/qgraph.h          |  36 +++++
 tests/qtest/libqos/qgraph_internal.h |  12 ++
 tests/qtest/libqos/virtio-9p.c       | 100 ++++++++++++++
 tests/qtest/libqos/virtio-9p.h       |  10 ++
 tests/qtest/qos-test.c               |  15 +-
 tests/qtest/virtio-9p-test.c         | 197 ++++++++++++++++++++++++---
 7 files changed, 455 insertions(+), 25 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
  2020-10-08 18:34 ` [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth Christian Schoenebeck
@ 2020-10-14 15:25   ` Christian Schoenebeck
  2020-10-14 19:38     ` Greg Kurz
  0 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-14 15:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz, Daniel P. Berrangé

On Donnerstag, 8. Oktober 2020 20:34:56 CEST Christian Schoenebeck wrote:
> All existing 9pfs test cases are using the 'synth' fs driver so far, which
> means they are not accessing real files, but a purely simulated (in RAM
> only) file system.
> 
> Let's make this clear by changing the prefix of the individual qtest case
> names from 'fs/' to 'synth/'. That way they'll be easily distinguishable
> from upcoming new 9pfs test cases supposed to be using a different fs
> driver.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>  tests/qtest/virtio-9p-test.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)

Queued patches 8 .. 12 on 9p.next:

https://github.com/cschoenebeck/qemu/commits/9p.next

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
  2020-10-14 15:25   ` Christian Schoenebeck
@ 2020-10-14 19:38     ` Greg Kurz
  2020-10-15  9:16       ` Christian Schoenebeck
  0 siblings, 1 reply; 28+ messages in thread
From: Greg Kurz @ 2020-10-14 19:38 UTC (permalink / raw)
  To: Christian Schoenebeck
  Cc: Laurent Vivier, Thomas Huth, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, qemu-devel, Paolo Bonzini

On Wed, 14 Oct 2020 17:25:35 +0200
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> On Donnerstag, 8. Oktober 2020 20:34:56 CEST Christian Schoenebeck wrote:
> > All existing 9pfs test cases are using the 'synth' fs driver so far, which
> > means they are not accessing real files, but a purely simulated (in RAM
> > only) file system.
> > 
> > Let's make this clear by changing the prefix of the individual qtest case
> > names from 'fs/' to 'synth/'. That way they'll be easily distinguishable
> > from upcoming new 9pfs test cases supposed to be using a different fs
> > driver.
> > 
> > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > ---
> >  tests/qtest/virtio-9p-test.c | 28 ++++++++++++++--------------
> >  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> Queued patches 8 .. 12 on 9p.next:
> 
> https://github.com/cschoenebeck/qemu/commits/9p.next
> 

Hi Chistian,

I could only have a quick glimpse at the patches and LGTM.

Thanks for taking care.

Cheers,

--
Greg

> Best regards,
> Christian Schoenebeck
> 
> 



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
  2020-10-14 19:38     ` Greg Kurz
@ 2020-10-15  9:16       ` Christian Schoenebeck
  0 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-15  9:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Greg Kurz, Laurent Vivier, Thomas Huth, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Paolo Bonzini

On Mittwoch, 14. Oktober 2020 21:38:16 CEST Greg Kurz wrote:
> On Wed, 14 Oct 2020 17:25:35 +0200
> 
> Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
> > On Donnerstag, 8. Oktober 2020 20:34:56 CEST Christian Schoenebeck wrote:
> > > All existing 9pfs test cases are using the 'synth' fs driver so far,
> > > which
> > > means they are not accessing real files, but a purely simulated (in RAM
> > > only) file system.
> > > 
> > > Let's make this clear by changing the prefix of the individual qtest
> > > case
> > > names from 'fs/' to 'synth/'. That way they'll be easily distinguishable
> > > from upcoming new 9pfs test cases supposed to be using a different fs
> > > driver.
> > > 
> > > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > > ---
> > > 
> > >  tests/qtest/virtio-9p-test.c | 28 ++++++++++++++--------------
> > >  1 file changed, 14 insertions(+), 14 deletions(-)
> > 
> > Queued patches 8 .. 12 on 9p.next:
> > 
> > https://github.com/cschoenebeck/qemu/commits/9p.next
> 
> Hi Chistian,
> 
> I could only have a quick glimpse at the patches and LGTM.
> 
> Thanks for taking care.
> 
> Cheers,
> 
> --
> Greg
>

Thanks, I appreciate it.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
  2020-10-08 18:34 ` [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode Christian Schoenebeck
@ 2020-10-19 10:35   ` Christian Schoenebeck
  2020-10-24  6:08     ` Thomas Huth
  0 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-19 10:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Emanuele Giuseppe Esposito, Greg Kurz,
	Daniel P. Berrangé

On Donnerstag, 8. Oktober 2020 20:34:56 CEST Christian Schoenebeck wrote:
> Add new member variable 'qemu_name' to struct QOSGraphNode.
> 
> This new member may be optionally set in case a different
> name for the node (which must always be a unique name) vs.
> its actually associated QEMU (QMP) device name is required.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>  tests/qtest/libqos/qgraph.c          | 1 +
>  tests/qtest/libqos/qgraph_internal.h | 1 +
>  2 files changed, 2 insertions(+)

So what shall happen with these libqos patches 1..7? Is that a nack, or 
postpone for now?

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables if verbose
  2020-10-08 18:34 ` [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables " Christian Schoenebeck
@ 2020-10-24  5:56   ` Thomas Huth
  2020-10-24 10:57     ` Christian Schoenebeck
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Huth @ 2020-10-24  5:56 UTC (permalink / raw)
  To: Christian Schoenebeck, qemu-devel
  Cc: Laurent Vivier, Paolo Bonzini, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz

On 08/10/2020 20.34, Christian Schoenebeck wrote:
> If qtests are run in verbose mode (i.e. if --verbose CL argument
> was provided) then print all environment variables to stdout
> before running the individual tests.

Why? ... you should provide some rationale in the patch description here, at
least to me this is not obvious why it is needed / desired.

 Thomas



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose
  2020-10-08 18:34 ` [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose Christian Schoenebeck
@ 2020-10-24  6:01   ` Thomas Huth
  2020-10-24 11:34     ` Christian Schoenebeck
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Huth @ 2020-10-24  6:01 UTC (permalink / raw)
  To: Christian Schoenebeck, qemu-devel
  Cc: Laurent Vivier, Paolo Bonzini, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz

On 08/10/2020 20.34, Christian Schoenebeck wrote:
> If qtests were run in verbose mode (i.e. if --verbose CL argument was
> provided) then dump the generated qos graph (all nodes and edges,
> along with their current individual availability status) to stdout.
> 
> See API doc comment on function qos_dump_graph() for details.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>  tests/qtest/qos-test.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
> index 8fdf87b183..d98ef78613 100644
> --- a/tests/qtest/qos-test.c
> +++ b/tests/qtest/qos-test.c
> @@ -322,6 +322,9 @@ int main(int argc, char **argv)
>      qos_set_machines_devices_available();
>  
>      qos_graph_foreach_test_path(walk_path);
> +    if (g_test_verbose()) {
> +        qos_dump_graph();
> +    }
>      g_test_run();
>      qtest_end();
>      qos_graph_destroy();
> 

I'd squash this into the previous patch, so that it is clear there where the
function gets used.

 Thomas



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
  2020-10-08 18:34 ` [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph() Christian Schoenebeck
@ 2020-10-24  6:04   ` Thomas Huth
  2020-10-24 11:24     ` Christian Schoenebeck
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Huth @ 2020-10-24  6:04 UTC (permalink / raw)
  To: Christian Schoenebeck, qemu-devel
  Cc: Laurent Vivier, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz, Paolo Bonzini

On 08/10/2020 20.34, Christian Schoenebeck wrote:
> This new function is purely for debugging purposes. It prints the
> current qos graph to stdout and allows to identify problems in the
> created qos graph e.g. when writing new qos tests.
> 
> Coloured output is used to mark available nodes in green colour,
> whereas unavailable nodes are marked in red colour.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>  tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++
>  tests/qtest/libqos/qgraph.h | 20 +++++++++++++
>  2 files changed, 76 insertions(+)
> 
> diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
> index 61faf6b27d..af93e38dcb 100644
> --- a/tests/qtest/libqos/qgraph.c
> +++ b/tests/qtest/libqos/qgraph.c
> @@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name)
>          node->command_line = NULL;
>      }
>  }
> +
> +#define RED(txt) (    \
> +    "\033[0;91m" txt  \
> +    "\033[0m"         \
> +)
> +
> +#define GREEN(txt) (  \
> +    "\033[0;92m" txt  \
> +    "\033[0m"         \
> +)

I don't think this is very portable - and it will only make logs ugly to
read in text editors. Could you please simply drop these macros?

 Thomas



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
  2020-10-19 10:35   ` Christian Schoenebeck
@ 2020-10-24  6:08     ` Thomas Huth
  2020-10-24 10:39       ` Christian Schoenebeck
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Huth @ 2020-10-24  6:08 UTC (permalink / raw)
  To: Christian Schoenebeck, qemu-devel
  Cc: Laurent Vivier, Paolo Bonzini, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz

On 19/10/2020 12.35, Christian Schoenebeck wrote:
> On Donnerstag, 8. Oktober 2020 20:34:56 CEST Christian Schoenebeck wrote:
>> Add new member variable 'qemu_name' to struct QOSGraphNode.
>>
>> This new member may be optionally set in case a different
>> name for the node (which must always be a unique name) vs.
>> its actually associated QEMU (QMP) device name is required.
>>
>> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
>> ---
>>  tests/qtest/libqos/qgraph.c          | 1 +
>>  tests/qtest/libqos/qgraph_internal.h | 1 +
>>  2 files changed, 2 insertions(+)
> 
> So what shall happen with these libqos patches 1..7? Is that a nack, or 
> postpone for now?

I was hoping to see a review by Paolo or Laurent, who are much more familiar
with qos than I am ... but after having a look at the patches, I think I can
also give some feedback, too:

Patch 1 and 2 sound basically ok to me (should maybe be squashed together,
though), but the qos_node_create_driver_named() function currently seems to
be unused so far? So I'd postpone these two patches to the point in time
when you really need the qos_node_create_driver_named() function.

The other patches are basically fine with me, too, but please avoid the
hard-coded ESC codes that only work with certain terminals.

 Thomas



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
  2020-10-24  6:08     ` Thomas Huth
@ 2020-10-24 10:39       ` Christian Schoenebeck
  0 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-24 10:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz

On Samstag, 24. Oktober 2020 08:08:59 CEST Thomas Huth wrote:
> On 19/10/2020 12.35, Christian Schoenebeck wrote:
> > On Donnerstag, 8. Oktober 2020 20:34:56 CEST Christian Schoenebeck wrote:
> >> Add new member variable 'qemu_name' to struct QOSGraphNode.
> >> 
> >> This new member may be optionally set in case a different
> >> name for the node (which must always be a unique name) vs.
> >> its actually associated QEMU (QMP) device name is required.
> >> 
> >> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> >> ---
> >> 
> >>  tests/qtest/libqos/qgraph.c          | 1 +
> >>  tests/qtest/libqos/qgraph_internal.h | 1 +
> >>  2 files changed, 2 insertions(+)
> > 
> > So what shall happen with these libqos patches 1..7? Is that a nack, or
> > postpone for now?
> 
> I was hoping to see a review by Paolo or Laurent, who are much more familiar
> with qos than I am ... but after having a look at the patches, I think I
> can also give some feedback, too:
> 
> Patch 1 and 2 sound basically ok to me (should maybe be squashed together,
> though), but the qos_node_create_driver_named() function currently seems to
> be unused so far? So I'd postpone these two patches to the point in time
> when you really need the qos_node_create_driver_named() function.

I did use patches 1 & 2 in v1 of this series, as of v2 and higher I used a
workaround for the actual 9pfs test case patches not to depend on these 2
libqos patches. This happened after Paolo's feedback, who wrote that qos
patches 1 & 2 would be useful for other, future use cases, but argued it
would not be appropriate for my intended use case:

https://lore.kernel.org/qemu-devel/95ef57d0-b35e-f16a-f957-06bc3692cb7c@redhat.com/

I preserved patches 1 & 2 in this series though as he noted they might be
useful for future purposes and applied his requested changes. I personally
probably won't need thise 2 patches any time soon. So it's up to you what
shall happen with them. I don't mind if you postpone or nack them.

> The other patches are basically fine with me, too, but please avoid the
> hard-coded ESC codes that only work with certain terminals.
> 
>  Thomas

I'll respond to that on your patch 4 response.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables if verbose
  2020-10-24  5:56   ` Thomas Huth
@ 2020-10-24 10:57     ` Christian Schoenebeck
  0 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-24 10:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz

On Samstag, 24. Oktober 2020 07:56:10 CEST Thomas Huth wrote:
> On 08/10/2020 20.34, Christian Schoenebeck wrote:
> > If qtests are run in verbose mode (i.e. if --verbose CL argument
> > was provided) then print all environment variables to stdout
> > before running the individual tests.
> 
> Why? ... you should provide some rationale in the patch description here, at
> least to me this is not obvious why it is needed / desired.
> 
>  Thomas

In my particular case I wanted to know whether there is already some config 
vector for 'please use this test directory for file tests'. As I didn't find 
one in any API, I also looked for environment variables to be sure. Especially 
as there are a bunch of qtest related environment variables already.

In general though it is common nowadays, at least being able to output all 
config vectors in a build chain, especially if it is required to investigate 
build- and test-issues on foreign/remote machines, which includes environment 
variables.

Staying in the context of writing test cases: there are a bunch of other use 
cases that would come to my mind from the PoV of a test case author:
"Is there an option for short vs. long tests?", "Is there a desired size 
limitation for large file tests?", "Is there a deadline for the runtime of 
tests?", ...

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
  2020-10-24  6:04   ` Thomas Huth
@ 2020-10-24 11:24     ` Christian Schoenebeck
  2020-10-28  5:51       ` Thomas Huth
  0 siblings, 1 reply; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-24 11:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz, Paolo Bonzini

On Samstag, 24. Oktober 2020 08:04:20 CEST Thomas Huth wrote:
> On 08/10/2020 20.34, Christian Schoenebeck wrote:
> > This new function is purely for debugging purposes. It prints the
> > current qos graph to stdout and allows to identify problems in the
> > created qos graph e.g. when writing new qos tests.
> > 
> > Coloured output is used to mark available nodes in green colour,
> > whereas unavailable nodes are marked in red colour.
> > 
> > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > ---
> > 
> >  tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++
> >  tests/qtest/libqos/qgraph.h | 20 +++++++++++++
> >  2 files changed, 76 insertions(+)
> > 
> > diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
> > index 61faf6b27d..af93e38dcb 100644
> > --- a/tests/qtest/libqos/qgraph.c
> > +++ b/tests/qtest/libqos/qgraph.c
> > @@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name)
> > 
> >          node->command_line = NULL;
> >      
> >      }
> >  
> >  }
> > 
> > +
> > +#define RED(txt) (    \
> > +    "\033[0;91m" txt  \
> > +    "\033[0m"         \
> > +)
> > +
> > +#define GREEN(txt) (  \
> > +    "\033[0;92m" txt  \
> > +    "\033[0m"         \
> > +)
> 
> I don't think this is very portable - and it will only make logs ugly to
> read in text editors. Could you please simply drop these macros?
> 
>  Thomas

The precise way I did it here is definitely unclean. And the use case is 
trivial, so on doubt I could just drop it of course.

But allow me one attempt to promote coloured terminal output in general: These 
are ANSI color escape sequences, a standard with its youngest revision dating 
back to 1991. It is a well supported standard on all major platforms nowadays:

	https://en.wikipedia.org/wiki/ANSI_escape_code

It works on macOS's standard terminal for at least 20 years, with cmd.exe on 
Windows 10, on essentially all Linux and BSD distros, and even on many web 
based CI platforms.

So what about introducing some globally shared macros for coloured output 
instead? Then there would be one central place for changing coloured output 
support for the entire code base; and I would change the macros to fallback to 
plain text output if there is any doubt the terminal would not support it.

Besides, QEMU just switched to meson which uses coloured output as well, as do 
clang, GCC, git and many other tools in your build chain.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose
  2020-10-24  6:01   ` Thomas Huth
@ 2020-10-24 11:34     ` Christian Schoenebeck
  0 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-24 11:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz

On Samstag, 24. Oktober 2020 08:01:55 CEST Thomas Huth wrote:
> On 08/10/2020 20.34, Christian Schoenebeck wrote:
> > If qtests were run in verbose mode (i.e. if --verbose CL argument was
> > provided) then dump the generated qos graph (all nodes and edges,
> > along with their current individual availability status) to stdout.
> > 
> > See API doc comment on function qos_dump_graph() for details.
> > 
> > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > ---
> > 
> >  tests/qtest/qos-test.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
> > index 8fdf87b183..d98ef78613 100644
> > --- a/tests/qtest/qos-test.c
> > +++ b/tests/qtest/qos-test.c
> > @@ -322,6 +322,9 @@ int main(int argc, char **argv)
> > 
> >      qos_set_machines_devices_available();
> >      
> >      qos_graph_foreach_test_path(walk_path);
> > 
> > +    if (g_test_verbose()) {
> > +        qos_dump_graph();
> > +    }
> > 
> >      g_test_run();
> >      qtest_end();
> >      qos_graph_destroy();
> 
> I'd squash this into the previous patch, so that it is clear there where the
> function gets used.
> 
>  Thomas

Sure, np.

Thanks for your feedback Thomas.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
  2020-10-24 11:24     ` Christian Schoenebeck
@ 2020-10-28  5:51       ` Thomas Huth
  2020-10-28 13:00         ` Eric Blake
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Huth @ 2020-10-28  5:51 UTC (permalink / raw)
  To: Christian Schoenebeck, qemu-devel
  Cc: Laurent Vivier, Emanuele Giuseppe Esposito,
	Daniel P. Berrangé,
	Greg Kurz, Paolo Bonzini

On 24/10/2020 13.24, Christian Schoenebeck wrote:
> On Samstag, 24. Oktober 2020 08:04:20 CEST Thomas Huth wrote:
>> On 08/10/2020 20.34, Christian Schoenebeck wrote:
>>> This new function is purely for debugging purposes. It prints the
>>> current qos graph to stdout and allows to identify problems in the
>>> created qos graph e.g. when writing new qos tests.
>>>
>>> Coloured output is used to mark available nodes in green colour,
>>> whereas unavailable nodes are marked in red colour.
>>>
>>> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
>>> ---
>>>
>>>  tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++
>>>  tests/qtest/libqos/qgraph.h | 20 +++++++++++++
>>>  2 files changed, 76 insertions(+)
>>>
>>> diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
>>> index 61faf6b27d..af93e38dcb 100644
>>> --- a/tests/qtest/libqos/qgraph.c
>>> +++ b/tests/qtest/libqos/qgraph.c
>>> @@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name)
>>>
>>>          node->command_line = NULL;
>>>      
>>>      }
>>>  
>>>  }
>>>
>>> +
>>> +#define RED(txt) (    \
>>> +    "\033[0;91m" txt  \
>>> +    "\033[0m"         \
>>> +)
>>> +
>>> +#define GREEN(txt) (  \
>>> +    "\033[0;92m" txt  \
>>> +    "\033[0m"         \
>>> +)
>>
>> I don't think this is very portable - and it will only make logs ugly to
>> read in text editors. Could you please simply drop these macros?
>>
>>  Thomas
> 
> The precise way I did it here is definitely unclean. And the use case is 
> trivial, so on doubt I could just drop it of course.
> 
> But allow me one attempt to promote coloured terminal output in general: These 
> are ANSI color escape sequences, a standard with its youngest revision dating 
> back to 1991. It is a well supported standard on all major platforms nowadays:
> 
> 	https://en.wikipedia.org/wiki/ANSI_escape_code
> 
> It works on macOS's standard terminal for at least 20 years, with cmd.exe on 
> Windows 10, on essentially all Linux and BSD distros, and even on many web 
> based CI platforms.
> 
> So what about introducing some globally shared macros for coloured output 
> instead? Then there would be one central place for changing coloured output 
> support for the entire code base; and I would change the macros to fallback to 
> plain text output if there is any doubt the terminal would not support it.
> 
> Besides, QEMU just switched to meson which uses coloured output as well, as do 
> clang, GCC, git and many other tools in your build chain.

Sure, colored output is nice, but we certainly also need a way to disable
it, e.g. if you want to collect the log in a file and then have a look at it
in a text editor.

 Thomas



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
  2020-10-28  5:51       ` Thomas Huth
@ 2020-10-28 13:00         ` Eric Blake
  2020-10-28 13:28           ` Christian Schoenebeck
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Blake @ 2020-10-28 13:00 UTC (permalink / raw)
  To: Thomas Huth, Christian Schoenebeck, qemu-devel
  Cc: Laurent Vivier, Daniel P. Berrangé,
	Emanuele Giuseppe Esposito, Greg Kurz, Paolo Bonzini

On 10/28/20 12:51 AM, Thomas Huth wrote:

>>>> +#define GREEN(txt) (  \
>>>> +    "\033[0;92m" txt  \
>>>> +    "\033[0m"         \
>>>> +)
>>>
>>> I don't think this is very portable - and it will only make logs ugly to
>>> read in text editors. Could you please simply drop these macros?
>>>

> Sure, colored output is nice, but we certainly also need a way to disable
> it, e.g. if you want to collect the log in a file and then have a look at it
> in a text editor.

Agreed. GNU libtextstyle
(https://www.gnu.org/software/gettext/libtextstyle/manual/libtextstyle.html)
is a much more portable way to do colored output where it becomes easy
to enable/disable or even adjust the colors to user preferences.  Sadly,
it is GPLv3+, and thus unusable for qemu.  But the bare minimum that you
must have when making colored output gated on whether stdout is a
terminal (that is, any program that does color should have a
--color=off|auto|on command-line option, and that in turn implies
function calls rather than macros to properly encapsulate the decision
logic.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
  2020-10-28 13:00         ` Eric Blake
@ 2020-10-28 13:28           ` Christian Schoenebeck
  0 siblings, 0 replies; 28+ messages in thread
From: Christian Schoenebeck @ 2020-10-28 13:28 UTC (permalink / raw)
  To: Eric Blake
  Cc: Thomas Huth, qemu-devel, Laurent Vivier,
	Emanuele Giuseppe Esposito, Daniel P. Berrangé,
	Greg Kurz, Paolo Bonzini

On Mittwoch, 28. Oktober 2020 14:00:21 CET Eric Blake wrote:
> On 10/28/20 12:51 AM, Thomas Huth wrote:
> >>>> +#define GREEN(txt) (  \
> >>>> +    "\033[0;92m" txt  \
> >>>> +    "\033[0m"         \
> >>>> +)
> >>> 
> >>> I don't think this is very portable - and it will only make logs ugly to
> >>> read in text editors. Could you please simply drop these macros?
> > 
> > Sure, colored output is nice, but we certainly also need a way to disable
> > it, e.g. if you want to collect the log in a file and then have a look at
> > it in a text editor.
> 
> Agreed. GNU libtextstyle
> (https://www.gnu.org/software/gettext/libtextstyle/manual/libtextstyle.html)
> is a much more portable way to do colored output where it becomes easy to
> enable/disable or even adjust the colors to user preferences.  Sadly, it is
> GPLv3+, and thus unusable for qemu.  But the bare minimum that you must
> have when making colored output gated on whether stdout is a
> terminal (that is, any program that does color should have a
> --color=off|auto|on command-line option, and that in turn implies
> function calls rather than macros to properly encapsulate the decision
> logic.

Not sure if it would make sense adding another dependency just for colour 
support in QEMU anyway, because rendering the right output sequence is not the 
big issue, nor auto detecting tty colour support, nor handling user configs. A 
large number of apps already do that in-tree / inline.

The challenge in QEMU though (in contrast to stand-alone apps) is integrating 
this meaningful for all the (quite different) output channels in QEMU, e.g. 
host logs, test case output, different modes, etc., while catching misusage 
and retaining a simple API.

I postpone the colour issue for that reason and drop colour from these patches 
for now. I'll probably rather come up with a dedicated series attempt just for 
colour at some later point.

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2020-10-28 13:29 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 18:49 [PATCH v4 00/12] 9pfs: add tests using local fs driver Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 11/12] tests/9pfs: add virtio_9p_test_path() Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth Christian Schoenebeck
2020-10-14 15:25   ` Christian Schoenebeck
2020-10-14 19:38     ` Greg Kurz
2020-10-15  9:16       ` Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 02/12] libqos/qgraph: add qos_node_create_driver_named() Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 07/12] tests/qtest/qos-test: dump QEMU command if verbose Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 09/12] tests/9pfs: introduce local tests Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 10/12] tests/9pfs: wipe local 9pfs test directory Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose Christian Schoenebeck
2020-10-24  6:01   ` Thomas Huth
2020-10-24 11:34     ` Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables " Christian Schoenebeck
2020-10-24  5:56   ` Thomas Huth
2020-10-24 10:57     ` Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 03/12] libqos/qgraph_internal: add qos_printf() and qos_printf_literal() Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 12/12] tests/9pfs: add local Tmkdir test Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph() Christian Schoenebeck
2020-10-24  6:04   ` Thomas Huth
2020-10-24 11:24     ` Christian Schoenebeck
2020-10-28  5:51       ` Thomas Huth
2020-10-28 13:00         ` Eric Blake
2020-10-28 13:28           ` Christian Schoenebeck
2020-10-08 18:34 ` [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode Christian Schoenebeck
2020-10-19 10:35   ` Christian Schoenebeck
2020-10-24  6:08     ` Thomas Huth
2020-10-24 10:39       ` Christian Schoenebeck

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).