Mini-OS: move xenbus test code into test.c
PATCH 1/1 Mini-OS: move xenbus test code into test.c
The test code in xenbus.c can easily be moved into test.c.
Signed-off-by Juergen Gross <[email protected]>
--- test.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++- xenbus.c | 113 ------------------------------------------------------- 2 files changed, 106 insertions(+), 115 deletions(-)
test.c +106 -2
@@ -44,6 +44,7 @@#include <fcntl.h> #include <xen/features.h> #include <xen/version.h> +#include <xen/io/xs_wire.h> #ifdef CONFIG_XENBUS static unsigned int do_shutdown =0 ;
@@ -52,11 +53,114 @@ static DECLARE_WAIT_QUEUE_HEAD(shutdown_queue);#endif #ifdef CONFIG_XENBUS -void test_xenbus (void ); +/* Send a debug message to xenbus. Can block. */ +static void xenbus_debug_msg (const char *msg) +{ +int len =strlen (msg); +struct write_req req[] = { + {"print" ,sizeof ("print" ) }, + { msg, len }, + {"" ,1 }}; +struct xsd_sockmsg *reply; + + reply =xenbus_msg_reply (XS_DEBUG ,0 , req,ARRAY_SIZE (req)); +printk ("Got a reply, type %d, id %d, len %d.\n" , + reply->type, reply->req_id, reply->len); +} + +static void do_ls_test (const char *pre) +{ +char **dirs, *msg; +int x; + +printk ("ls %s...\n" , pre); + msg =xenbus_ls (XBT_NIL , pre, &dirs); +if ( msg ) + { +printk ("Error in xenbus ls: %s\n" , msg); +free (msg); +return ; + } + +for ( x =0 ; dirs[x]; x++ ) + { +printk ("ls %s[%d] -> %s\n" , pre, x, dirs[x]); +free (dirs[x]); + } + +free (dirs); +} + +static void do_read_test (const char *path) +{ +char *res, *msg; + +printk ("Read %s...\n" , path); + msg =xenbus_read (XBT_NIL , path, &res); +if ( msg ) + { +printk ("Error in xenbus read: %s\n" , msg); +free (msg); +return ; + } +printk ("Read %s -> %s.\n" , path, res); +free (res); +} + +static void do_write_test (const char *path,const char *val) +{ +char *msg; + +printk ("Write %s to %s...\n" , val, path); + msg =xenbus_write (XBT_NIL , path, val); +if ( msg ) + { +printk ("Result %s\n" , msg); +free (msg); + } +else +printk ("Success.\n" ); +} + +static void do_rm_test (const char *path) +{ +char *msg; + +printk ("rm %s...\n" , path); + msg =xenbus_rm (XBT_NIL , path); +if ( msg ) + { +printk ("Result %s\n" , msg); +free (msg); + } +else +printk ("Success.\n" ); +}static void xenbus_tester (void *p) { -test_xenbus (); +printk ("Doing xenbus test.\n" ); +xenbus_debug_msg ("Testing xenbus...\n" ); + +printk ("Doing ls test.\n" ); +do_ls_test ("device" ); +do_ls_test ("device/vif" ); +do_ls_test ("device/vif/0" ); + +printk ("Doing read test.\n" ); +do_read_test ("device/vif/0/mac" ); +do_read_test ("device/vif/0/backend" ); + +printk ("Doing write test.\n" ); +do_write_test ("device/vif/0/flibble" ,"flobble" ); +do_read_test ("device/vif/0/flibble" ); +do_write_test ("device/vif/0/flibble" ,"widget" ); +do_read_test ("device/vif/0/flibble" ); + +printk ("Doing rm test.\n" ); +do_rm_test ("device/vif/0/flibble" ); +do_read_test ("device/vif/0/flibble" ); +printk ("(Should have said ENOENT)\n" ); }#endif
xenbus.c +0 -113
119 lines not on this page · raw message
Signature · 1 line
2.35.3
Juergen Gross, le ven. 27 janv. 2023 08:33:46 +0100, a ecrit:
Quoted 3 lines
The test code in
xenbus.ccan easily be moved intotest.c.Signed-off-by Juergen Gross <[email protected]>
Reviewed-by Samuel Thibault <[email protected]>
Quoted 261 lines
--- test.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++- xenbus.c | 113 ------------------------------------------------------- 2 files changed, 106 insertions(+), 115 deletions(-)test.c +106
-2@@ -44,6 +44,7 @@#include <fcntl.h> #include <xen/features.h> #include <xen/version.h> +#include <xen/io/xs_wire.h> #ifdef CONFIG_XENBUS static unsigned int do_shutdown =0 ;@@ -52,11 +53,114 @@ static DECLARE_WAIT_QUEUE_HEAD(shutdown_queue);#endif #ifdef CONFIG_XENBUS -void test_xenbus (void ); +/* Send a debug message to xenbus. Can block. */ +static void xenbus_debug_msg (const char *msg) +{ +int len =strlen (msg); +struct write_req req[] = { + {"print" ,sizeof ("print" ) }, + { msg, len }, + {"" ,1 }}; +struct xsd_sockmsg *reply; + + reply =xenbus_msg_reply (XS_DEBUG ,0 , req,ARRAY_SIZE (req)); +printk ("Got a reply, type %d, id %d, len %d.\n" , + reply->type, reply->req_id, reply->len); +} + +static void do_ls_test (const char *pre) +{ +char **dirs, *msg; +int x; + +printk ("ls %s...\n" , pre); + msg =xenbus_ls (XBT_NIL , pre, &dirs); +if ( msg ) + { +printk ("Error in xenbus ls: %s\n" , msg); +free (msg); +return ; + } + +for ( x =0 ; dirs[x]; x++ ) + { +printk ("ls %s[%d] -> %s\n" , pre, x, dirs[x]); +free (dirs[x]); + } + +free (dirs); +} + +static void do_read_test (const char *path) +{ +char *res, *msg; + +printk ("Read %s...\n" , path); + msg =xenbus_read (XBT_NIL , path, &res); +if ( msg ) + { +printk ("Error in xenbus read: %s\n" , msg); +free (msg); +return ; + } +printk ("Read %s -> %s.\n" , path, res); +free (res); +} + +static void do_write_test (const char *path,const char *val) +{ +char *msg; + +printk ("Write %s to %s...\n" , val, path); + msg =xenbus_write (XBT_NIL , path, val); +if ( msg ) + { +printk ("Result %s\n" , msg); +free (msg); + } +else +printk ("Success.\n" ); +} + +static void do_rm_test (const char *path) +{ +char *msg; + +printk ("rm %s...\n" , path); + msg =xenbus_rm (XBT_NIL , path); +if ( msg ) + { +printk ("Result %s\n" , msg); +free (msg); + } +else +printk ("Success.\n" ); +}static void xenbus_tester (void *p) { -test_xenbus (); +printk ("Doing xenbus test.\n" ); +xenbus_debug_msg ("Testing xenbus...\n" ); + +printk ("Doing ls test.\n" ); +do_ls_test ("device" ); +do_ls_test ("device/vif" ); +do_ls_test ("device/vif/0" ); + +printk ("Doing read test.\n" ); +do_read_test ("device/vif/0/mac" ); +do_read_test ("device/vif/0/backend" ); + +printk ("Doing write test.\n" ); +do_write_test ("device/vif/0/flibble" ,"flobble" ); +do_read_test ("device/vif/0/flibble" ); +do_write_test ("device/vif/0/flibble" ,"widget" ); +do_read_test ("device/vif/0/flibble" ); + +printk ("Doing rm test.\n" ); +do_rm_test ("device/vif/0/flibble" ); +do_read_test ("device/vif/0/flibble" ); +printk ("(Should have said ENOENT)\n" ); }#endif xenbus.c +0
-113@@ -964,119 +964,6 @@ domid_t xenbus_get_self_id(void)return ret; } -#ifdef CONFIG_TEST -/* Send a debug message to xenbus. Can block. */ -static void xenbus_debug_msg (const char *msg) -{ -int len =strlen (msg); -struct write_req req[] = { - {"print" ,sizeof ("print" ) }, - { msg, len }, - {"" ,1 }}; -struct xsd_sockmsg *reply; - - reply =xenbus_msg_reply (XS_DEBUG ,0 , req,ARRAY_SIZE (req)); -printk ("Got a reply, type %d, id %d, len %d.\n" , - reply->type, reply->req_id, reply->len); -} - -static void do_ls_test (const char *pre) -{ -char **dirs, *msg; -int x; - -printk ("ls %s...\n" , pre); - msg =xenbus_ls (XBT_NIL , pre, &dirs); -if ( msg ) - { -printk ("Error in xenbus ls: %s\n" , msg); -free (msg); -return ; - } - -for ( x =0 ; dirs[x]; x++ ) - { -printk ("ls %s[%d] -> %s\n" , pre, x, dirs[x]); -free (dirs[x]); - } - -free (dirs); -} - -static void do_read_test (const char *path) -{ -char *res, *msg; - -printk ("Read %s...\n" , path); - msg =xenbus_read (XBT_NIL , path, &res); -if ( msg ) - { -printk ("Error in xenbus read: %s\n" , msg); -free (msg); -return ; - } -printk ("Read %s -> %s.\n" , path, res); -free (res); -} - -static void do_write_test (const char *path,const char *val) -{ -char *msg; - -printk ("Write %s to %s...\n" , val, path); - msg =xenbus_write (XBT_NIL , path, val); -if ( msg ) - { -printk ("Result %s\n" , msg); -free (msg); - } -else -printk ("Success.\n" ); -} - -static void do_rm_test (const char *path) -{ -char *msg; - -printk ("rm %s...\n" , path); - msg =xenbus_rm (XBT_NIL , path); -if ( msg ) - { -printk ("Result %s\n" , msg); -free (msg); - } -else -printk ("Success.\n" ); -} - -/* Simple testing thing */ -void test_xenbus (void ) -{ -printk ("Doing xenbus test.\n" ); -xenbus_debug_msg ("Testing xenbus...\n" ); - -printk ("Doing ls test.\n" ); -do_ls_test ("device" ); -do_ls_test ("device/vif" ); -do_ls_test ("device/vif/0" ); - -printk ("Doing read test.\n" ); -do_read_test ("device/vif/0/mac" ); -do_read_test ("device/vif/0/backend" ); - -printk ("Doing write test.\n" ); -do_write_test ("device/vif/0/flibble" ,"flobble" ); -do_read_test ("device/vif/0/flibble" ); -do_write_test ("device/vif/0/flibble" ,"widget" ); -do_read_test ("device/vif/0/flibble" ); - -printk ("Doing rm test.\n" ); -do_rm_test ("device/vif/0/flibble" ); -do_read_test ("device/vif/0/flibble" ); -printk ("(Should have said ENOENT)\n" ); -} -#endif /* CONFIG_TEST */ -/* * Local variables: * mode: C Signature · 1 line
2.35.3
Signature · 4 lines
Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.