Patchwork [RfC,0/9] chardev hotplug

login
register
mail settings
Submitter Paolo Bonzini
Date Dec. 21, 2012, 12:40 p.m.
Message ID <50D458A9.2060705@redhat.com>
Download mbox | patch
Permalink /patch/207798/
State New
Headers show

Comments

Paolo Bonzini - Dec. 21, 2012, 12:40 p.m.
Il 21/12/2012 13:17, Gerd Hoffmann ha scritto:
> { 'type': 'ChardevDummy', 'data': { } }
> 
> { 'union': 'ChardevBackend', 'data': { 'file'   : 'ChardevFile',
>                                        'port'   : 'ChardevPort',
>                                        'socket' : 'ChardevSocket',
>                                        'pty'    : 'ChardevDummy',
>                                        'null'   : 'ChardevDummy' } }
> 
> { 'command': 'chardev-add', 'data': {'id'      : 'str',
>                                      'backend' : 'ChardevBackend' },
> 
> ... should accept ...
> 
> {'id': 'test-null', 'backend': {'data': {}, 'type': 'null'}}
> 
> ... as parameters for chardev-add, no?  But I get back ...
> 
>  {u'error': {u'class': u'GenericError', u'desc': u"Invalid parameter
> 'backend'"}}
> 
> ... and can't see what is wrong there ...

Me neither, but this quick test seems to work here:

$ tests/test-qmp-commands
/gerd: test-null 1
OK


Paolo
Gerd Hoffmann - Dec. 21, 2012, 2:21 p.m.
Hi,

>> ... and can't see what is wrong there ...
> 
> Me neither, but this quick test seems to work here:

Test works for me too.

Bug turned out to be elsewhere: args_type in qmp-commands.hx not set
correctly ...

cheers,
  Gerd

Patch

diff --git a/qapi-schema-test.json b/qapi-schema-test.json
index 9eae350..c2e9316 100644
--- a/qapi-schema-test.json
+++ b/qapi-schema-test.json
@@ -36,3 +36,12 @@ 
 { 'command': 'user_def_cmd', 'data': {} }
 { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
 { 'command': 'user_def_cmd2', 'data': {'ud1a': 'UserDefOne', 'ud1b': 'UserDefOne'}, 'returns': 'UserDefTwo' }
+
+
+{ 'type': 'ChardevDummy', 'data': { } }
+
+{ 'union': 'ChardevBackend', 'data': { 'pty'    : 'ChardevDummy',
+                                       'null'   : 'ChardevDummy' } }
+
+{ 'command': 'chardev-add', 'data': {'id'      : 'str',
+                                     'backend' : 'ChardevBackend' } }
diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c
index 5a3e82a..96396db 100644
--- a/tests/test-qmp-commands.c
+++ b/tests/test-qmp-commands.c
@@ -55,6 +55,11 @@  static void test_dispatch_cmd(void)
     QDECREF(req);
 }
 
+void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp)
+{
+	printf("%s %d\n", id, backend->kind);
+}
+
 /* test commands that return an error due to invalid parameters */
 static void test_dispatch_cmd_error(void)
 {
@@ -71,6 +76,20 @@  static void test_dispatch_cmd_error(void)
     QDECREF(req);
 }
 
+static void test_dispatch_gerd(void)
+{
+    QObject *req = qobject_from_json(
+	    "{'execute': 'chardev-add', "
+	    " 'arguments': {'id': 'test-null', "
+	    "               'backend': {'data': {}, 'type': 'null'}}} ");
+    QObject *resp = qmp_dispatch(req);
+    assert(resp != NULL);
+    assert(!qdict_haskey(qobject_to_qdict(resp), "error"));
+
+    qobject_decref(resp);
+    qobject_decref(req);
+}
+
 /* test commands that involve both input parameters and return values */
 static void test_dispatch_cmd_io(void)
 {
@@ -174,6 +193,7 @@  int main(int argc, char **argv)
     g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io);
     g_test_add_func("/0.15/dealloc_types", test_dealloc_types);
     g_test_add_func("/0.15/dealloc_partial", test_dealloc_partial);
+    g_test_add_func("/gerd", test_dispatch_gerd);
 
     module_call_init(MODULE_INIT_QAPI);
     g_test_run();