9pfs: add tests using local fs driver
v3 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 6 enhance debugging issues with the qtest framework.
3. Patches 7 to 11 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.
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 (11):
libqos/qgraph: add qemu_name to QOSGraphNode libqos/qgraph: add qos_node_create_driver_named() 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 | 108 ++++++++++++++- tests/qtest/libqos/qgraph.h | 36 +++++ tests/qtest/libqos/qgraph_internal.h | 1 + tests/qtest/libqos/virtio-9p.c | 90 ++++++++++++ tests/qtest/libqos/virtio-9p.h | 10 ++ tests/qtest/qos-test.c | 15 +- tests/qtest/virtio-9p-test.c | 197 ++++++++++++++++++++++++--- 7 files changed, 432 insertions(+), 25 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/11 libqos/qgraph: add qemu_name to QOSGraphNode
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.
--- 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 v3 2/11 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 v3 3/11 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 | 54 +++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/qgraph.h | 20 ++++++++++++++ 2 files changed, 74 insertions(+)
tests/qtest/libqos/qgraph.c +54 -0
@@ -805,3 +805,57 @@ 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; + +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; +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); +printf ("\t\t|-> dest='%s' type=%d (node=%p)" , + e->dest, e->type, dest_node); +if (!dest_node) { +printf (RED (" <------- ERROR !" )); + } +printf ("\n" ); + } + } +g_list_free (keys); +printf ("}\n" ); + +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); +printf ("\t name='%s' " , key); +if (node->qemu_name) { +printf ("qemu_name='%s' " , node->qemu_name); + } +printf ("type=%d cmd_line='%s' [%s]\n" , + node->type, node->command_line, + node->available ?GREEN ("available" ) :RED ("UNAVAILBLE" )); + } +g_list_free (keys); +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 v3 4/11 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 v3 5/11 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.
Instead of using g_test_message() rather use printf() in combination with g_test_verbose(), to avoid g_test_message() 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 ()) { +printf ("ENVIRONMENT VARIABLES: {\n" ); +for (char **env = envp; *env !=0 ; env++) { +printf ("\t%s\n" , *env); + } +printf ("}\n" ); + }qos_graph_init ();module_call_init (MODULE_INIT_QOM );module_call_init (MODULE_INIT_LIBQOS );
Signature · 1 line
2.20.1
Re: [PATCH v3 05/11] tests/qtest/qos-test: dump environment variables if verbose
tests/qtest/qos-test.c static void walk_path(QOSGraphNode *orig_path, int len) · line 325
Quoted 11 lines · Christian Schoenebeck
tests/qtest/qos-test.c +8
-1-int main (int argc,char **argv) +int main (int argc,char **argv,char ** envp) {g_test_init (&argc, &argv,NULL ); +if (g_test_verbose ()) { +printf ("ENVIRONMENT VARIABLES: {\n" ); +for (char **env = envp; *env !=0 ; env++) { +printf ("\t%s\n" , *env); + } +printf ("}\n" ); + }
But doesn't this (and patch 6 as well) break TAP output? Using g_test_message + g_test_verbose would be the best of both worlds.
In fact using printf in tests should be forbidden, since glib 2.62 and newer _always_ emit TAP.
Paolo
Re: [PATCH v3 05/11] tests/qtest/qos-test: dump environment variables if verbose
Quoted 8 lines · On Donnerstag, 8. Oktober 2020 14:37:00 CEST Paolo Bonzini wrote:
Quoted 7 lines · Christian Schoenebeck
tests/qtest/qos-test.c +1
-1-int main (int argc,char **argv) +int main (int argc,char **argv,char ** envp) {g_test_init (&argc, &argv,NULL );
Quoted 10 lines
tests/qtest/qos-test.c static void walk_path(QOSGraphNode *orig_path, int len) · line 325
Quoted 7 lines
tests/qtest/qos-test.c +7
-0+if (g_test_verbose ()) { +printf ("ENVIRONMENT VARIABLES: {\n" ); +for (char **env = envp; *env !=0 ; env++) { +printf ("\t%s\n" , *env); + } +printf ("}\n" ); + }But doesn't this (and patch 6 as well) break TAP output? Using
g_test_message+g_test_verbosewould be the best of both worlds.
If there was TAP output then yes, patches 4, 5, 6 would probably break it.
How/when is TAP output enabled? I don't see any TAP output by default.
Quoted 4 lines
In fact using printf in tests should be forbidden, since glib 2.62 and newer _always_ emit TAP.
Paolo
The reason why I used printf() was because g_test_message() clutters the output tremendously, as it always wraps the text of each g_test_message() call into:
"(MSG: %s)\n"
which is inappropriate for multi-line messages as these proposed patches do.
Is that actually a real-life problem? I mean these patches only output anything if --verbose CL switch is used, and I don't see any TAP output enabled by default. And the --verbose CL switch is usually just used by developers for debugging test case issues, isn't it?
Best regards,
Christian Schoenebeck
Re: [PATCH v3 05/11] tests/qtest/qos-test: dump environment variables if verbose
Quoted 6 lines · Christian Schoenebeck
Quoted 2 lines
But doesn't this (and patch 6 as well) break TAP output? Using
g_test_message+g_test_verbosewould be the best of both worlds.If there was TAP output then yes, patches 4, 5, 6 would probably break it.
How/when is TAP output enabled? I don't see any TAP output by default.
With "--tap", but with glib 2.62 it will be enabled by default. For example on Fedora 32:
$ ./test-mul64 # random seed: R02S3efb20d48a41e1897cb761e02393c11b 1..2 # Start of host-utils tests ok 1 /host-utils/mulu64 ok 2 /host-utils/muls64 # End of host-utils tests
I'm okay I guess with using g_test_message on 2.62 or newer, and assuming people don't use --tap --verbose on older versions.
Paolo
Quoted 11 lines
which is inappropriate for multi-line messages as these proposed patches do.
Is that actually a real-life problem? I mean these patches only output anything if --verbose CL switch is used, and I don't see any TAP output enabled by default. And the --verbose CL switch is usually just used by developers for debugging test case issues, isn't it?
Best regards,
Christian Schoenebeck
Re: [PATCH v3 05/11] tests/qtest/qos-test: dump environment variables if verbose
Quoted 19 lines · On Donnerstag, 8. Oktober 2020 15:21:54 CEST Paolo Bonzini wrote:
Quoted 6 lines · Christian Schoenebeck
Quoted 2 lines
But doesn't this (and patch 6 as well) break TAP output? Using
g_test_message+g_test_verbosewould be the best of both worlds.If there was TAP output then yes, patches 4, 5, 6 would probably break it.
How/when is TAP output enabled? I don't see any TAP output by default.
With "--tap", but with glib 2.62 it will be enabled by default. For example on Fedora 32:
$ ./test-mul64 # random seed: R02S3efb20d48a41e1897cb761e02393c11b 1..2 # Start of host-utils tests ok 1 /host-utils/mulu64 ok 2 /host-utils/muls64 # End of host-utils tests
Quoted 2 lines
I'm okay I guess with using
g_test_messageon 2.62 or newer, and assuming people don't use --tap --verbose on older versions.
Simpler solution: just appending '#' character in front of each printf() line, that would be both fine for TAP and regular output:
http://testanything.org/tap-specification.html#diagnostics
Unfortunately 'test_tap_log' is a private variable in glib (gtestutils.c), otherwise I could have made that conditionally. There is no getter function in the glib API for this (TAP on/off) variable.
I could check the CL for --verbose somewhere, but I think that's probably overkill.
Best regards,
Christian Schoenebeck
Re: [PATCH v3 05/11] tests/qtest/qos-test: dump environment variables if verbose
Quoted 6 lines · Christian Schoenebeck
Quoted 3 lines
I'm okay I guess with using
g_test_messageon 2.62 or newer, and assuming people don't use --tap --verbose on older versions.Simpler solution: just appending '#' character in front of each
printf()line, that would be both fine for TAP and regular output:
http://testanything.org/tap-specification.html#diagnostics
I'm not sure how it would be simpler than a
#if !GLIB_CHECK_VERSION(2, 62, 0)
#define qemu_test_message printf
#else
#define qemu_test_message g_test_message
#endif
but you choose.
Paolo
Re: [PATCH v3 05/11] tests/qtest/qos-test: dump environment variables if verbose
Quoted 16 lines · On Donnerstag, 8. Oktober 2020 15:52:08 CEST Paolo Bonzini wrote:
Quoted 6 lines · Christian Schoenebeck
Quoted 2 lines
I'm okay I guess with using
g_test_messageon 2.62 or newer, and assuming people don't use --tap --verbose on older versions.Simpler solution: just appending '#' character in front of each
printf()line, that would be both fine for TAP and regular output:
http://testanything.org/tap-specification.html#diagnosticsI'm not sure how it would be simpler than a
#if !GLIB_CHECK_VERSION(2, 62, 0)
#defineqemu_test_messageprintf
#else
#defineqemu_test_messageg_test_message
#endif
Quoted 3 lines
but you choose.
Paolo
Simple yes, but it would not fix the cluttered output problem of g_test_message().
So I'll go with prepending '#' for now, and if one day there will be a public glib function to check for TAP mode, it can easily be adjusted.
Best regards,
Christian Schoenebeck
PATCH v3 6/11 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.
Instead of using g_test_message() rather use printf() in combination with g_test_verbose(), to avoid g_test_message() 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 ()) { +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
Re: [PATCH v3 06/11] tests/qtest/qos-test: dump QEMU command if verbose
Quoted 19 lines · Christian Schoenebeck
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.
Instead of using
g_test_message()rather useprintf()in combination withg_test_verbose(), to avoidg_test_message()cluttering the output.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 static void qos_set_machines_devices_available(void) · line 97
Quoted 9 lines
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 ()) { +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
This need not even be made verbose I think.
Paolo
Re: [PATCH v3 06/11] tests/qtest/qos-test: dump QEMU command if verbose
Quoted 28 lines · On Donnerstag, 8. Oktober 2020 14:36:11 CEST Paolo Bonzini wrote:
Quoted 27 lines · Christian Schoenebeck
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.
Instead of using
g_test_message()rather useprintf()in combination withg_test_verbose(), to avoidg_test_message()cluttering the output.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@@ -89,6 +89,9 @@ static void qos_set_machines_devices_available(void)static void restart_qemu_or_continue (char *path) { +if (g_test_verbose ()) { +printf ("Run QEMU with: '%s'\n" , path); + }
Quoted 6 lines
Quoted 4 lines
tests/qtest/qos-test.c +0
-0/* compares the current command line with the * one previously executed: if they are the same,
* don't restart QEMU, if they differ, stop previousThis need not even be made verbose I think.
I actually find that handy in this way. By default I prefer the current output where I just see the name of the test currently running. I only need to see the actual QEMU command if there is some kind of problem to fix.
Best regards,
Christian Schoenebeck
PATCH v3 7/11 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 v3 8/11 tests/9pfs: introduce local tests
In reply to Christian SchoenebeckThis 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 | 71 ++++++++++++++++++++++++++++++++++ tests/qtest/libqos/virtio-9p.h | 5 +++ tests/qtest/virtio-9p-test.c | 44 ++++++++++++++------- 3 files changed, 106 insertions(+), 14 deletions(-)
tests/qtest/libqos/virtio-9p.c +71 -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,54 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc,return obj; } +void virtio_9p_assign_local_driver (GString *cmd_line,const char *args) +{ +GRegex *regex; +char *s, *arg_repl; + +g_assert_nonnull (local_test_path); + +/* replace 'synth' driver by 'local' driver */ + regex =g_regex_new ("-fsdev synth," ,0 ,0 ,NULL ); + s =g_regex_replace_literal ( + regex, cmd_line->str,-1 ,0 ,"-fsdev local," ,0 ,NULL + ); +g_string_assign (cmd_line, s); +g_free (s); +g_regex_unref (regex); + +/* add 'path=...' to '-fsdev ...' group */ + regex =g_regex_new ("(-fsdev \\w+)(\\s*)" ,0 ,0 ,NULL ); + arg_repl =g_strdup_printf ("\\1\\2,path='%s'" , local_test_path); + s =g_regex_replace ( + regex, cmd_line->str,-1 ,0 , arg_repl,0 ,NULL + ); +g_string_assign (cmd_line, s); +g_free (arg_repl); +g_free (s); +g_regex_unref (regex); + +/* add passed args to '-fsdev ...' group */ + regex =g_regex_new ("(-fsdev \\w+)(\\s*)" ,0 ,0 ,NULL ); + arg_repl =g_strdup_printf ("\\1\\2,%s" , args); + s =g_regex_replace ( + regex, cmd_line->str,-1 ,0 , arg_repl,0 ,NULL + ); +g_string_assign (cmd_line, s); +g_free (arg_repl); +g_free (s); +g_regex_unref (regex); +} +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 v3 9/11 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.
--- 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);
@@ -220,6 +232,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 v3 09/11] tests/9pfs: wipe local 9pfs test directory
Quoted 65 lines · On Freitag, 2. Oktober 2020 18:15:05 CEST Christian Schoenebeck wrote:
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.
Signed-off-by Christian Schoenebeck <[email protected]>--- 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);@@ -220,6 +232,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 = {.devfn = QPCI_DEVFN(4, 0), }; QOSGraphEdgeOptions opts = { .before_cmd_line = "-fsdev synth,id=fsdev0", }; /* virtio-9p-device */ opts.extra_device_opts = str_simple, qos_node_create_driver("virtio-9p-device", virtio_9p_device_create); qos_node_consumes("virtio-9p-device", "virtio-bus", &opts); qos_node_produces("virtio-9p-device", "virtio"); qos_node_produces("virtio-9p-device", "virtio-9p"); /* virtio-9p-pci */ opts.extra_device_opts = str_addr; add_qpci_address(&opts, &addr); qos_node_create_driver("virtio-9p-pci", virtio_9p_pci_create); qos_node_consumes("virtio-9p-pci", "pci-bus", &opts); qos_node_produces("virtio-9p-pci", "pci-device"); qos_node_produces("virtio-9p-pci", "virtio"); qos_node_produces("virtio-9p-pci", "virtio-9p"); }
Quoted 1 line
libqos_init(virtio_9p_register_nodes);
I wonder why libqos is calling virtio_9p_register_nodes() again after all qtests ended.
That's somewhat suboptimal here, as it causes remove_local_test_dir() to be called again after all qtests completed. My intention was actually only to wipe the "qtest-9p-local" test directory at the *start* of the test suite run. Not at the end of the test suite. Because it would allow developers to look at the actual dirs/files created after the tests completed.
I could of course misuse and add a dedicated "wipedir" test as workaround, but that OTOH would break the option of running individual tests with the -p CL switch.
Best regards,
Christian Schoenebeck
Re: [PATCH v3 09/11] tests/9pfs: wipe local 9pfs test directory
Quoted 90 lines · On Donnerstag, 8. Oktober 2020 14:26:28 CEST Christian Schoenebeck wrote:
Quoted 76 lines · On Freitag, 2. Oktober 2020 18:15:05 CEST Christian Schoenebeck wrote:
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.
Signed-off-by Christian Schoenebeck <[email protected]>---
tests/qtest/libqos/virtio-9p.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)(quoted diff) +0
-0
b/tests/qtest/libqos/virtio-9p.cindex1bada47af1..41a7c2baaa100644tests/qtest/libqos/virtio-9p.c +12
-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);tests/qtest/libqos/virtio-9p.c +1
-0@@ -220,6 +232,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 = { .devfn = QPCI_DEVFN(4, 0), }; QOSGraphEdgeOptions opts = { .before_cmd_line = "-fsdev synth,id=fsdev0", }; /* virtio-9p-device */ opts.extra_device_opts = str_simple, qos_node_create_driver("virtio-9p-device", virtio_9p_device_create); qos_node_consumes("virtio-9p-device", "virtio-bus", &opts); qos_node_produces("virtio-9p-device", "virtio"); qos_node_produces("virtio-9p-device", "virtio-9p"); /* virtio-9p-pci */ opts.extra_device_opts = str_addr; add_qpci_address(&opts, &addr); qos_node_create_driver("virtio-9p-pci", virtio_9p_pci_create); qos_node_consumes("virtio-9p-pci", "pci-bus", &opts); qos_node_produces("virtio-9p-pci", "pci-device"); qos_node_produces("virtio-9p-pci", "virtio"); qos_node_produces("virtio-9p-pci", "virtio-9p");Quoted 3 lines
}
libqos_init(virtio_9p_register_nodes);I wonder why libqos is calling
virtio_9p_register_nodes()again after all qtests ended.That's somewhat suboptimal here, as it causes
remove_local_test_dir()to be called again after all qtests completed. My intention was actually only to wipe the "qtest-9p-local" test directory at the *start* of the test suite run. Not at the end of the test suite. Because it would allow developers to look at the actual dirs/files created after the tests completed.
Quoted 3 lines
I could of course misuse and add a dedicated "wipedir" test as workaround, but that OTOH would break the option of running individual tests with the -p CL switch.
I probably leave that issue unfixed for now.
There seems to be no easy way to fix this, as libqos does not having something like "run this function once per test suite run", and due to the multi process approach a static variable hack would not be viable either.
Fortunately though, if a test case fails virtio_9p_register_nodes() would not be called again, so at least in case of failures the test dir is note wiped.
So I don't think it's worth to drill another hole into libqos just for this.
Best regards,
Christian Schoenebeck
PATCH v3 10/11 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 v3 11/11 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