9pfs: add tests using local fs driver
PATCH v4 6/12 tests/qtest/qos-test: dump environment variables if verbose
In reply to Christian SchoenebeckIf 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.
--- tests/qtest/qos-test.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tests/qtest/qos-test.c +8 -1
@@ -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 );
Signature · 1 line
2.20.1
v4 cover 9pfs: add tests using local fs driver
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(-)
Signature · 1 line
2.20.1
PATCH v4 9/12 tests/9pfs: introduce local tests
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.
--- 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(-)
tests/qtest/libqos/virtio-9p.c +81 -0
@@ -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 ), };
tests/qtest/libqos/virtio-9p.h +5 -0
@@ -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
tests/qtest/virtio-9p-test.c +30 -14
59 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 1/12 libqos/qgraph: add qemu_name to QOSGraphNode
In reply to Christian SchoenebeckAdd 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.
--- tests/qtest/libqos/qgraph.c | 1 + tests/qtest/libqos/qgraph_internal.h | 1 + 2 files changed, 2 insertions(+)
tests/qtest/libqos/qgraph.c +1 -0
@@ -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); }
tests/qtest/libqos/qgraph_internal.h +1 -0
@@ -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 {
Signature · 1 line
2.20.1
PATCH v4 2/12 libqos/qgraph: add qos_node_create_driver_named()
In reply to Christian SchoenebeckSo 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.
--- tests/qtest/libqos/qgraph.c | 53 ++++++++++++++++++++++++++++++++++--- tests/qtest/libqos/qgraph.h | 16 +++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-)
tests/qtest/libqos/qgraph.c +50 -3
@@ -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)
tests/qtest/libqos/qgraph.h +16 -0
@@ -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
Signature · 1 line
2.20.1
PATCH v4 7/12 tests/qtest/qos-test: dump QEMU command if verbose
In reply to Christian SchoenebeckIf 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.
--- tests/qtest/qos-test.c | 3 +++ 1 file changed, 3 insertions(+)
tests/qtest/qos-test.c +3 -0
@@ -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
Signature · 1 line
2.20.1
PATCH v4 5/12 tests/qtest/qos-test: dump qos graph if verbose
In reply to Christian SchoenebeckIf 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.
--- tests/qtest/qos-test.c | 3 +++ 1 file changed, 3 insertions(+)
tests/qtest/qos-test.c +3 -0
@@ -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 ();
Signature · 1 line
2.20.1
PATCH v4 3/12 libqos/qgraph_internal: add qos_printf() and qos_printf_literal()
In reply to Christian SchoenebeckThese 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.
--- tests/qtest/libqos/qgraph_internal.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
tests/qtest/libqos/qgraph_internal.h +11 -0
@@ -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
Signature · 1 line
2.20.1
PATCH v4 8/12 tests/9pfs: change qtest name prefix to synth
In reply to Christian SchoenebeckAll 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.
--- tests/qtest/virtio-9p-test.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
tests/qtest/virtio-9p-test.c +14 -14
@@ -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 ); }
Signature · 1 line
2.20.1
PATCH v4 4/12 libqos/qgraph: add qos_dump_graph()
In reply to Christian SchoenebeckThis 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.
--- tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/qgraph.h | 20 +++++++++++++ 2 files changed, 76 insertions(+)
tests/qtest/libqos/qgraph.c +56 -0
@@ -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" ); +}
tests/qtest/libqos/qgraph.h +20 -0
@@ -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
Signature · 1 line
2.20.1
PATCH v4 12/12 tests/9pfs: add local Tmkdir test
In reply to Christian SchoenebeckThis 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.
--- tests/qtest/virtio-9p-test.c | 139 +++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+)
tests/qtest/virtio-9p-test.c +139 -0
@@ -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);
Signature · 1 line
2.20.1
PATCH v4 11/12 tests/9pfs: add virtio_9p_test_path()
In reply to Christian SchoenebeckThis 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.
--- tests/qtest/libqos/virtio-9p.c | 6 ++++++ tests/qtest/libqos/virtio-9p.h | 5 +++++ 2 files changed, 11 insertions(+)
tests/qtest/libqos/virtio-9p.c +6 -0
@@ -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);
tests/qtest/libqos/virtio-9p.h +5 -0
@@ -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
Signature · 1 line
2.20.1
PATCH v4 10/12 tests/9pfs: wipe local 9pfs test directory
In reply to Christian SchoenebeckBefore 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.
--- tests/qtest/libqos/virtio-9p.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
tests/qtest/libqos/virtio-9p.c +13 -0
@@ -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 = {
Signature · 1 line
2.20.1
Re: [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
In reply to Christian SchoenebeckQuoted 9 lines · 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.
Quoted 4 lines
Signed-off-by Christian Schoenebeck <[email protected]>--- 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
Re: [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
Quoted 10 lines · On Wed, 14 Oct 2020 17:25:35 +0200 Christian Schoenebeck…
Quoted 9 lines · 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.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Christian Schoenebeck <[email protected]>--- tests/qtest/virtio-9p-test.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)Queued patches 8 .. 12 on 9p.next:
Hi Chistian,
I could only have a quick glimpse at the patches and LGTM.
Thanks for taking care.
Cheers,
--
Greg
Quoted 4 lines
Best regards,
Christian Schoenebeck
Re: [PATCH v4 08/12] tests/9pfs: change qtest name prefix to synth
Quoted 27 lines · On Mittwoch, 14. Oktober 2020 21:38:16 CEST Greg Kurz wrote:
On Wed, 14 Oct 2020 17:25:35 +0200
Quoted 15 lines · Christian Schoenebeck
Quoted 14 lines · 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 <[email protected]>---
Quoted 6 lines
Quoted 2 lines
tests/qtest/virtio-9p-test.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)Queued patches 8 .. 12 on 9p.next:
Hi Chistian,
Quoted 9 lines
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
Re: [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
In reply to Christian SchoenebeckQuoted 11 lines · 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 <[email protected]>--- 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
Re: [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables if verbose
In reply to Christian SchoenebeckQuoted 3 lines · Christian Schoenebeck
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
Re: [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose
In reply to Christian SchoenebeckQuoted 17 lines · Christian Schoenebeck
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 <[email protected]>--- tests/qtest/qos-test.c | 3 +++ 1 file changed, 3 insertions(+)tests/qtest/qos-test.c +0
-0
tests/qtest/qos-test.c int main(int argc, char **argv) · line 330
Quoted 9 lines
tests/qtest/qos-test.c +3
-0@@ -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
Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
In reply to Christian SchoenebeckQuoted 21 lines · Christian Schoenebeck
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 <[email protected]>--- tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/qgraph.h | 20 +++++++++++++ 2 files changed, 76 insertions(+)tests/qtest/libqos/qgraph.c +0
-0@@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name) node->command_line =NULL ; } }
tests/qtest/libqos/qgraph.c void qos_delete_cmd_line(const char *name) · line 817
Quoted 10 lines
tests/qtest/libqos/qgraph.c +10
-0+ +#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
Re: [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
In reply to Christian SchoenebeckQuoted 7 lines · Christian Schoenebeck
Quoted 6 lines · 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.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Christian Schoenebeck <[email protected]>--- 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
Re: [PATCH v4 01/12] libqos/qgraph: add qemu_name to QOSGraphNode
Quoted 18 lines · On Samstag, 24. Oktober 2020 08:08:59 CEST Thomas Huth wrote:
Quoted 10 lines · Christian Schoenebeck
Quoted 9 lines · 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 <[email protected]>---
Quoted 6 lines
Quoted 3 lines
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?
Quoted 8 lines
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 theqos_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/[email protected]/
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.
Quoted 4 lines
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
Re: [PATCH v4 06/12] tests/qtest/qos-test: dump environment variables if verbose
In reply to Thomas HuthQuoted 9 lines · On Samstag, 24. Oktober 2020 07:56:10 CEST Thomas Huth wrote:
Quoted 3 lines · Christian Schoenebeck
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
Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
In reply to Thomas HuthQuoted 41 lines · On Samstag, 24. Oktober 2020 08:04:20 CEST Thomas Huth wrote:
Quoted 26 lines · Christian Schoenebeck
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 <[email protected]>---
tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/qgraph.h | 20 +++++++++++++ 2 files changed, 76 insertions(+)tests/qtest/libqos/qgraph.c +0
-0@@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name) node->command_line =NULL ; } }tests/qtest/libqos/qgraph.c void qos_delete_cmd_line(const char *name) · line 817
Quoted 10 lines
tests/qtest/libqos/qgraph.c +10
-0+ +#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?
Quoted 1 line
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
Re: [PATCH v4 05/12] tests/qtest/qos-test: dump qos graph if verbose
In reply to Thomas HuthQuoted 27 lines · On Samstag, 24. Oktober 2020 08:01:55 CEST Thomas Huth wrote:
Quoted 26 lines · Christian Schoenebeck
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 <[email protected]>---
tests/qtest/qos-test.c | 3 +++ 1 file changed, 3 insertions(+)tests/qtest/qos-test.c +3
-0@@ -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 (); + }
Quoted 8 lines
Quoted 3 lines
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
Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
In reply to Christian SchoenebeckQuoted 57 lines · Christian Schoenebeck
Quoted 41 lines · On Samstag, 24. Oktober 2020 08:04:20 CEST Thomas Huth wrote:
Quoted 26 lines · Christian Schoenebeck
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 <[email protected]>---
tests/qtest/libqos/qgraph.c | 56 +++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/qgraph.h | 20 +++++++++++++ 2 files changed, 76 insertions(+)tests/qtest/libqos/qgraph.c +0
-0@@ -805,3 +805,59 @@ void qos_delete_cmd_line(const char *name) node->command_line =NULL ; } }tests/qtest/libqos/qgraph.c void qos_delete_cmd_line(const char *name) · line 817
Quoted 10 lines
tests/qtest/libqos/qgraph.c +10
-0+ +#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?
Quoted 1 line
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.
Quoted 7 lines
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
Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
Quoted 9 lines · Thomas Huth
Quoted 8 lines
Quoted 8 lines
tests/qtest/libqos/qgraph.c void qos_delete_cmd_line(const char *name) · line 817
Quoted 4 lines
tests/qtest/libqos/qgraph.c +4
-0+#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?
Quoted 3 lines
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.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v4 04/12] libqos/qgraph: add qos_dump_graph()
Quoted 13 lines · On Mittwoch, 28. Oktober 2020 14:00:21 CET Eric Blake wrote:
Quoted 11 lines · Thomas Huth
Quoted 7 lines
Quoted 7 lines
tests/qtest/libqos/qgraph.c void qos_delete_cmd_line(const char *name) · line 817
Quoted 4 lines
tests/qtest/libqos/qgraph.c +4
-0+#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.
Quoted 10 lines
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