qobject: Cleanups, mostly in tests
cover qobject: Cleanups, mostly in tests
Markus Armbruster (14):
qdict: Make qdict_get_qlist() safe like qdict_get_qdict()
check-qdict: Simplify qdict_crumple_test_recursive()
check-qdict: Tighten qdict_crumple_test_recursive() some
check-qjson: Simplify around compare_litqobj_to_qobj()
libqtest: Clean up qmp_response() a bit
test-qmp-event: Simplify and tighten event_test_emit() Don't check qobject_type() before qobject_to_qdict()
tests: Don't check qobject_type() before qobject_to_qlist()
tests: Don't check qobject_type() before qobject_to_qstring()
tests: Don't check qobject_type() before qobject_to_qint()
tests: Don't check qobject_type() before qobject_to_qfloat()
tests: Don't check qobject_type() before qobject_to_qbool()
monitor: Clean up handle_hmp_command() a bit
block: Don't bother asserting type of output visitor's output
block.c | 4 +- block/nbd.c | 2 - block/nfs.c | 2 - block/qapi.c | 1 - hw/pci/pcie_aer.c | 2 +- monitor.c | 19 +++--- qapi/qmp-dispatch.c | 5 +- qobject/qdict.c | 30 +------- tests/check-qdict.c | 37 ++++------ tests/check-qjson.c | 113 ++++++------------------------ tests/libqtest.c | 4 +- tests/test-qmp-event.c | 14 ++-- tests/test-qobject-output-visitor.c | 133 ++++++++++++++---------------------- 13 files changed, 113 insertions(+), 253 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/14 qdict: Make qdict_get_qlist() safe like qdict_get_qdict()
Commit 89cad9f changed qdict_get_qdict() to return NULL instead of crash when the key doesn't exist or its value isn't a QDict. Commit 2d6421a neglected to do the same for qdict_get_qlist(). Correct that, and update the function comments.
qdict_get_obj() is now unused, remove.
--- qobject/qdict.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-)
qobject/qdict.c +3 -27
@@ -178,20 +178,6 @@ size_t qdict_size(const QDict *qdict) }/** -* qdict_get_obj(): Get a QObject of a specific type -*/ -static QObject *qdict_get_obj (const QDict *qdict,const char *key,QType type) -{ -QObject *obj; - - obj =qdict_get (qdict, key); -assert (obj !=NULL ); -assert (qobject_type (obj) == type); - -return obj; -} - -/** * qdict_get_double(): Get an number mapped by 'key' * * This function assumes that 'key' exists and it stores a
@@ -241,25 +227,15 @@ bool qdict_get_bool(const QDict *qdict, const char *key) }/** -* qdict_get_qlist(): Get the QList mapped by 'key' -* -* This function assumes that 'key' exists and it stores a -* QList object. -* -* Return QList mapped by 'key'. +* qdict_get_qlist(): If @qdict maps @key to a QList, return it, else NULL. */ QList *qdict_get_qlist (const QDict *qdict,const char *key) { -return qobject_to_qlist (qdict_get_obj (qdict, key,QTYPE_QLIST )); +return qobject_to_qlist (qdict_get (qdict, key)); }/** -* qdict_get_qdict(): Get the QDict mapped by 'key' -* -* This function assumes that 'key' exists and it stores a -* QDict object. -* -* Return QDict mapped by 'key'. +* qdict_get_qdict(): If @qdict maps @key to a QDict, return it, else NULL. */ QDict *qdict_get_qdict (const QDict *qdict,const char *key) {
Signature · 1 line
2.7.4
PATCH 2/14 check-qdict: Simplify qdict_crumple_test_recursive()
In reply to Markus ArmbrusterUse qdict_get_qdict(), qdict_get_qlist() instead of qdict_get() followed by qobject_to_qdict(), qobject_to_qlist().
While there, drop some redundant code.
--- tests/check-qdict.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
tests/check-qdict.c +9 -16
@@ -591,7 +591,7 @@ static void qdict_join_test(void)static void qdict_crumple_test_recursive (void ) {QDict *src, *dst, *rule, *vnc, *acl, *listen; -QObject *child, *res; +QObject *res;QList *rules; src =qdict_new ();
@@ -613,23 +613,19 @@ static void qdict_crumple_test_recursive(void) g_assert_cmpint(qdict_size(dst), ==, 1); - child =qdict_get (dst,"vnc" ); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - vnc =qobject_to_qdict (child); + vnc =qdict_get_qdict (dst,"vnc" ); +g_assert (vnc); - child =qdict_get (vnc,"listen" ); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - listen =qobject_to_qdict (child); + listen =qdict_get_qdict (vnc,"listen" ); +g_assert (listen); g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); - child =qdict_get (vnc,"acl" ); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - acl =qobject_to_qdict (child); + acl =qdict_get_qdict (vnc,"acl" ); +g_assert (acl); - child =qdict_get (acl,"rules" ); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QLIST); - rules =qobject_to_qlist (child); + rules =qdict_get_qlist (acl,"rules" ); +g_assert (rules); g_assert_cmpint(qlist_size(rules), ==, 2); rule =qobject_to_qdict (qlist_pop (rules));
@@ -646,9 +642,6 @@ static void qdict_crumple_test_recursive(void)/* With recursive crumpling, we should see all names unescaped */ g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); - child =qdict_get (vnc,"acl" ); - g_assert_cmpint(qobject_type(child), ==, QTYPE_QDICT); - acl =qdict_get_qdict (vnc,"acl" ); g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name"));QDECREF (src);
Signature · 1 line
2.7.4
PATCH 3/14 check-qdict: Tighten qdict_crumple_test_recursive() some
In reply to Markus ArmbrusterConsistently check for unexpected QDict entries, and qdict_get_qdict() success. The latter doesn't tighten the test, it only makes it fail more nicely.
--- tests/check-qdict.c | 5 +++++ 1 file changed, 5 insertions(+)
tests/check-qdict.c +5 -0
@@ -615,26 +615,31 @@ static void qdict_crumple_test_recursive(void) vnc =qdict_get_qdict (dst,"vnc" );g_assert (vnc); + g_assert_cmpint(qdict_size(vnc), ==, 3); listen =qdict_get_qdict (vnc,"listen" );g_assert (listen); + g_assert_cmpint(qdict_size(listen), ==, 2); g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); acl =qdict_get_qdict (vnc,"acl" );g_assert (acl); + g_assert_cmpint(qdict_size(acl), ==, 3); rules =qdict_get_qlist (acl,"rules" );g_assert (rules); g_assert_cmpint(qlist_size(rules), ==, 2); rule =qobject_to_qdict (qlist_pop (rules)); +g_assert (rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy"));QDECREF (rule); rule =qobject_to_qdict (qlist_pop (rules)); +g_assert (rule); g_assert_cmpint(qdict_size(rule), ==, 2); g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match")); g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy"));
Signature · 1 line
2.7.4
PATCH 5/14 libqtest: Clean up qmp_response() a bit
In reply to Markus ArmbrusterUse qobject_to_qdict() instead of a type cast.
--- tests/libqtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/libqtest.c +2 -2
@@ -379,9 +379,9 @@ static void qmp_response(JSONMessageParser *parser, GQueue *tokens)exit (1 ); } -g_assert (qobject_type (obj) ==QTYPE_QDICT );g_assert (!qmp->response); - qmp->response = (QDict *)obj; + qmp->response =qobject_to_qdict (obj); +g_assert (qmp->response); }QDict *qmp_fd_receive (int fd)
Signature · 1 line
2.7.4
PATCH 6/14 test-qmp-event: Simplify and tighten event_test_emit()
In reply to Markus ArmbrusterUse qdict_get_qdict() and qdict_get_try_int() to simplify.
While there, add a sanity check for seconds.
--- tests/test-qmp-event.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
tests/test-qmp-event.c +4 -10
@@ -95,24 +95,18 @@ static bool qdict_cmp_simple(QDict *a, QDict *b)correctness. */ static void event_test_emit (test_QAPIEvent event,QDict *d,Error **errp) { -QObject *obj;QDict *t;int64_t s, ms;/* Verify that we have timestamp, then remove it to compare other fields */ - obj =qdict_get (d,"timestamp" ); -g_assert (obj); - t =qobject_to_qdict (obj); + t =qdict_get_qdict (d,"timestamp" );g_assert (t); - obj =qdict_get (t,"seconds" ); -g_assert (obj &&qobject_type (obj) ==QTYPE_QINT ); - s =qint_get_int (qobject_to_qint (obj)); - obj =qdict_get (t,"microseconds" ); -g_assert (obj &&qobject_type (obj) ==QTYPE_QINT ); - ms =qint_get_int (qobject_to_qint (obj)); + s =qdict_get_try_int (t,"seconds" ,-2 ); + ms =qdict_get_try_int (t,"microseconds" ,-2 );if (s ==-1 ) {g_assert (ms ==-1 ); }else { +g_assert (s >=0 );g_assert (ms >=0 && ms <=999999 ); }g_assert (qdict_size (t) ==2 );
Signature · 1 line
2.7.4
PATCH 8/14 tests: Don't check qobject_type() before qobject_to_qlist()
In reply to Markus Armbrusterqobject_to_qlist(obj) returns NULL when obj isn't a QList. Check that instead of qobject_type(obj) == QTYPE_QLIST.
--- tests/test-qobject-output-visitor.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tests/test-qobject-output-visitor.c +2 -5
@@ -261,7 +261,6 @@ static void test_visitor_out_list(TestOutputVisitorData *data,bool value_bool = true;int value_int =10 ;QListEntry *entry; -QObject *obj;QList *qlist;int i;
@@ -279,10 +278,8 @@ static void test_visitor_out_list(TestOutputVisitorData *data,visit_type_TestStructList (data->ov,NULL , &head, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QLIST ); - - qlist =qobject_to_qlist (obj); + qlist =qobject_to_qlist (visitor_get (data)); +g_assert (qlist);g_assert (!qlist_empty (qlist));/* ...and ensure that the visitor sees it in order */
Signature · 1 line
2.7.4
PATCH 11/14 tests: Don't check qobject_type() before qobject_to_qfloat()
In reply to Markus Armbrusterqobject_to_qfloat(obj) returns NULL when obj isn't a QFloat. Check that instead of qobject_type(obj) == QTYPE_QFLOAT.
--- tests/check-qjson.c | 12 ++---------- tests/test-qobject-output-visitor.c | 8 ++++---- 2 files changed, 6 insertions(+), 14 deletions(-)
tests/check-qjson.c +2 -10
@@ -921,10 +921,8 @@ static void float_number(void)QFloat *qfloat; obj =qobject_from_json (test_cases[i].encoded); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QFLOAT ); - qfloat =qobject_to_qfloat (obj); +g_assert (qfloat);g_assert (qfloat_get_double (qfloat) == test_cases[i].decoded);if (test_cases[i].skip ==0 ) {
@@ -941,7 +939,6 @@ static void float_number(void)static void vararg_number (void ) { -QObject *obj;QInt *qint;QFloat *qfloat;int value =0x2342 ;
@@ -956,13 +953,8 @@ static void vararg_number(void)g_assert (qint_get_int (qint) == value_ll);QDECREF (qint); - obj =qobject_from_jsonf ("%f" , valuef); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QFLOAT ); - - qfloat =qobject_to_qfloat (obj); + qfloat =qobject_to_qfloat (qobject_from_jsonf ("%f" , valuef));g_assert (qfloat_get_double (qfloat) == valuef); -QDECREF (qfloat); }
tests/test-qobject-output-visitor.c +4 -4
@@ -84,13 +84,13 @@ static void test_visitor_out_number(TestOutputVisitorData *data, const void *unused) {double value =3.14 ; -QObject *obj; +QFloat *qfloat;visit_type_number (data->ov,NULL , &value, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QFLOAT ); -g_assert (qfloat_get_double (qobject_to_qfloat (obj)) == value); + qfloat =qobject_to_qfloat (visitor_get (data)); +g_assert (qfloat); +g_assert (qfloat_get_double (qfloat) == value); } static void test_visitor_out_string(TestOutputVisitorData *data,
Signature · 1 line
2.7.4
PATCH 13/14 monitor: Clean up handle_hmp_command() a bit
In reply to Markus ArmbrusterLeave checking qobject_type(req) to qmp_check_input_obj(). Rework handling of json_parser_parse_err() failing without setting an error.
--- monitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
monitor.c +5 -4
@@ -3735,10 +3735,11 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)Error *err =NULL ; req =json_parser_parse_err (tokens,NULL , &err); -if (err || !req ||qobject_type (req) !=QTYPE_QDICT ) { -if (!err) { -error_setg (&err,QERR_JSON_PARSING ); - } +if (!req && !err) { +/* json_parser_parse_err() sucks: can fail without setting @err */ +error_setg (&err,QERR_JSON_PARSING ); + } +if (err) { goto err_out; }
Signature · 1 line
2.7.4
PATCH 14/14 block: Don't bother asserting type of output visitor's output
In reply to Markus ArmbrusterAfter a visit of a complex QAPI type FOO
ov = qobject_output_visitor_new(&foo);
visit_type_FOO(ov, NULL, expr, &error_abort);
visit_complete(ov, &foo);we can safely assume qobject_type(foo) is QTYPE_QDICT. We do in many places, but occasionally assert qobject_type(obj) == QTYPE_QDICT. Don't. The appropriate place to check such fundamental properties of QAPI visitors is the test suite.
--- block/nbd.c | 2 -- block/nfs.c | 2 -- block/qapi.c | 1 - 3 files changed, 5 deletions(-)
block/nbd.c +0 -2
@@ -537,8 +537,6 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)visit_type_SocketAddress (ov,NULL , &s->saddr, &error_abort);visit_complete (ov, &saddr_qdict);visit_free (ov); -assert (qobject_type (saddr_qdict) ==QTYPE_QDICT ); -qdict_put_obj (opts,"server" , saddr_qdict);if (s->export) {
block/nfs.c +0 -2
@@ -798,8 +798,6 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options) ov =qobject_output_visitor_new (&server_qdict);visit_type_NFSServer (ov,NULL , &client->server, &error_abort);visit_complete (ov, &server_qdict); -assert (qobject_type (server_qdict) ==QTYPE_QDICT ); -qdict_put_obj (opts,"server" , server_qdict);qdict_put (opts,"path" ,qstring_from_str (client->path));
block/qapi.c +0 -1
@@ -682,7 +682,6 @@ void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,visit_type_ImageInfoSpecific (v,NULL , &info_spec, &error_abort);visit_complete (v, &obj); -assert (qobject_type (obj) ==QTYPE_QDICT ); data =qdict_get (qobject_to_qdict (obj),"data" );dump_qobject (func_fprintf, f,1 , data);qobject_decref (obj);
Signature · 1 line
2.7.4
PATCH 4/14 check-qjson: Simplify around compare_litqobj_to_qobj()
In reply to Markus ArmbrusterMake compare_litqobj_to_qobj() cope with null, and drop non-null assertions from callers.
compare_litqobj_to_qobj() already checks the QType matches; drop the redundant assertions from callers.
--- tests/check-qjson.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)
tests/check-qjson.c +1 -21
@@ -1110,7 +1110,7 @@ static void compare_helper(QObject *obj, void *opaque)static int compare_litqobj_to_qobj (LiteralQObject *lhs,QObject *rhs) { -if (lhs->type !=qobject_type (rhs)) { +if (!rhs || lhs->type !=qobject_type (rhs)) {return 0 ; }
@@ -1184,18 +1184,12 @@ static void simple_dict(void)QString *str; obj =qobject_from_json (test_cases[i].encoded); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QDICT ); -g_assert (compare_litqobj_to_qobj (&test_cases[i].decoded, obj) ==1 ); str =qobject_to_json (obj);qobject_decref (obj); obj =qobject_from_json (qstring_get_str (str)); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QDICT ); -g_assert (compare_litqobj_to_qobj (&test_cases[i].decoded, obj) ==1 );qobject_decref (obj);QDECREF (str);
@@ -1299,18 +1293,12 @@ static void simple_list(void)QString *str; obj =qobject_from_json (test_cases[i].encoded); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QLIST ); -g_assert (compare_litqobj_to_qobj (&test_cases[i].decoded, obj) ==1 ); str =qobject_to_json (obj);qobject_decref (obj); obj =qobject_from_json (qstring_get_str (str)); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QLIST ); -g_assert (compare_litqobj_to_qobj (&test_cases[i].decoded, obj) ==1 );qobject_decref (obj);QDECREF (str);
@@ -1367,18 +1355,12 @@ static void simple_whitespace(void)QString *str; obj =qobject_from_json (test_cases[i].encoded); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QLIST ); -g_assert (compare_litqobj_to_qobj (&test_cases[i].decoded, obj) ==1 ); str =qobject_to_json (obj);qobject_decref (obj); obj =qobject_from_json (qstring_get_str (str)); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QLIST ); -g_assert (compare_litqobj_to_qobj (&test_cases[i].decoded, obj) ==1 );qobject_decref (obj);
@@ -1403,8 +1385,6 @@ static void simple_varargs(void)g_assert (embedded_obj !=NULL ); obj =qobject_from_jsonf ("[%d, 2, %p]" ,1 , embedded_obj); -g_assert (obj !=NULL ); -g_assert (compare_litqobj_to_qobj (&decoded, obj) ==1 );qobject_decref (obj);
Signature · 1 line
2.7.4
PATCH 12/14 tests: Don't check qobject_type() before qobject_to_qbool()
In reply to Markus Armbrusterqobject_to_qbool(obj) returns NULL when obj isn't a QBool. Check that instead of qobject_type(obj) == QTYPE_QBOOL.
--- tests/check-qjson.c | 24 ++++++------------------ tests/test-qobject-output-visitor.c | 12 +++++------- 2 files changed, 11 insertions(+), 25 deletions(-)
tests/check-qjson.c +6 -18
@@ -966,10 +966,8 @@ static void keyword_literal(void)QString *str; obj =qobject_from_json ("true" ); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QBOOL ); - qbool =qobject_to_qbool (obj); +g_assert (qbool);g_assert (qbool_get_bool (qbool) == true); str =qobject_to_json (obj);
@@ -979,10 +977,8 @@ static void keyword_literal(void)QDECREF (qbool); obj =qobject_from_json ("false" ); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QBOOL ); - qbool =qobject_to_qbool (obj); +g_assert (qbool);g_assert (qbool_get_bool (qbool) == false); str =qobject_to_json (obj);
@@ -991,23 +987,15 @@ static void keyword_literal(void)QDECREF (qbool); - obj =qobject_from_jsonf ("%i" , false); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QBOOL ); - - qbool =qobject_to_qbool (obj); + qbool =qobject_to_qbool (qobject_from_jsonf ("%i" , false)); +g_assert (qbool);g_assert (qbool_get_bool (qbool) == false); -QDECREF (qbool);/* Test that non-zero values other than 1 get collapsed to true */ - obj =qobject_from_jsonf ("%i" ,2 ); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QBOOL ); - - qbool =qobject_to_qbool (obj); + qbool =qobject_to_qbool (qobject_from_jsonf ("%i" ,2 )); +g_assert (qbool);g_assert (qbool_get_bool (qbool) == true); -QDECREF (qbool); obj =qobject_from_json ("null" );
tests/test-qobject-output-visitor.c +5 -7
@@ -71,13 +71,13 @@ static void test_visitor_out_bool(TestOutputVisitorData *data, const void *unused) {bool value = true; -QObject *obj; +QBool *qbool;visit_type_bool (data->ov,NULL , &value, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QBOOL ); -g_assert (qbool_get_bool (qobject_to_qbool (obj)) == value); + qbool =qobject_to_qbool (visitor_get (data)); +g_assert (qbool); +g_assert (qbool_get_bool (qbool) == value); } static void test_visitor_out_number(TestOutputVisitorData *data,
@@ -356,9 +356,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qint =qobject_to_qint (qdict_get (qdict,"integer" ));g_assert (qint); g_assert_cmpint(qint_get_int(qint), ==, -42); - qobj =qdict_get (qdict,"boolean" ); -g_assert (qobj); - qbool =qobject_to_qbool (qobj); + qbool =qobject_to_qbool (qdict_get (qdict,"boolean" ));g_assert (qbool);g_assert (qbool_get_bool (qbool) == true); qstring =qobject_to_qstring (qdict_get (qdict,"string" ));
Signature · 1 line
2.7.4
PATCH 7/14 Don't check qobject_type() before qobject_to_qdict()
In reply to Markus Armbrusterqobject_to_qdict(obj) returns NULL when obj isn't a QDict. Check that instead of qobject_type(obj) == QTYPE_QDICT.
--- block.c | 4 ++-- hw/pci/pcie_aer.c | 2 +- monitor.c | 10 ++++----- qapi/qmp-dispatch.c | 5 ++--- tests/check-qdict.c | 9 ++------ tests/test-qobject-output-visitor.c | 41 +++++++++++-------------------------- 6 files changed, 24 insertions(+), 47 deletions(-)
block.c +2 -2
@@ -1169,13 +1169,13 @@ static QDict *parse_json_filename(const char *filename, Error **errp)return NULL ; } -if (qobject_type (options_obj) !=QTYPE_QDICT ) { + options =qobject_to_qdict (options_obj); +if (!options) {qobject_decref (options_obj);error_setg (errp,"Invalid JSON object given" );return NULL ; } - options =qobject_to_qdict (options_obj);qdict_flatten (options);return options;
hw/pci/pcie_aer.c +1 -1
@@ -1025,8 +1025,8 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict)return ; } -assert (qobject_type (data) ==QTYPE_QDICT ); qdict =qobject_to_qdict (data); +assert (qdict); devfn = (int )qdict_get_int (qdict,"devfn" ); monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n",
monitor.c +5 -5
@@ -3686,12 +3686,12 @@ static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp)int has_exec_key =0 ;QDict *input_dict; -if (qobject_type (input_obj) !=QTYPE_QDICT ) { -error_setg (errp,QERR_QMP_BAD_INPUT_OBJECT ,"object" ); -return NULL ; - } - input_dict =qobject_to_qdict (input_obj); +if (!input_dict) { +error_setg (errp,QERR_QMP_BAD_INPUT_OBJECT ,"object" ); +return NULL ; + } +for (ent =qdict_first (input_dict); ent; ent =qdict_next (input_dict, ent)){const char *arg_name =qdict_entry_key (ent);
qapi/qmp-dispatch.c +2 -3
@@ -28,14 +28,13 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)bool has_exec_key = false;QDict *dict =NULL ; -if (qobject_type (request) !=QTYPE_QDICT ) { + dict =qobject_to_qdict (request); +if (!dict) {error_setg (errp,QERR_QMP_BAD_INPUT_OBJECT ,"request is not a dictionary" );return NULL ; } - dict =qobject_to_qdict (request); -for (ent =qdict_first (dict); ent; ent =qdict_next (dict, ent)) { arg_name =qdict_entry_key (ent);
tests/check-qdict.c +2 -7
@@ -591,7 +591,6 @@ static void qdict_join_test(void)static void qdict_crumple_test_recursive (void ) {QDict *src, *dst, *rule, *vnc, *acl, *listen; -QObject *res;QList *rules; src =qdict_new ();
@@ -605,12 +604,8 @@ static void qdict_crumple_test_recursive(void)qdict_put (src,"vnc.acl..name" ,qstring_from_str ("acl0" ));qdict_put (src,"vnc.acl.rule..name" ,qstring_from_str ("acl0" )); - res =qdict_crumple (src, &error_abort); - - g_assert_cmpint(qobject_type(res), ==, QTYPE_QDICT); - - dst =qobject_to_qdict (res); - + dst =qobject_to_qdict (qdict_crumple (src, &error_abort)); +g_assert (dst); g_assert_cmpint(qdict_size(dst), ==, 1); vnc =qdict_get_qdict (dst,"vnc" );
tests/test-qobject-output-visitor.c +12 -29
112 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 9/14 tests: Don't check qobject_type() before qobject_to_qstring()
In reply to Markus Armbrusterqobject_to_qstring(obj) returns NULL when obj isn't a QString. Check that instead of qobject_type(obj) == QTYPE_QSTRING.
--- tests/check-qjson.c | 31 ++++++++----------------------- tests/test-qobject-output-visitor.c | 37 +++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 43 deletions(-)
tests/check-qjson.c +8 -23
@@ -54,11 +54,8 @@ static void escaped_string(void)QString *str; obj =qobject_from_json (test_cases[i].encoded); - -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - str =qobject_to_qstring (obj); +g_assert (str); g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded);if (test_cases[i].skip ==0 ) {
@@ -89,11 +86,8 @@ static void simple_string(void)QString *str; obj =qobject_from_json (test_cases[i].encoded); - -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - str =qobject_to_qstring (obj); +g_assert (str);g_assert (strcmp (qstring_get_str (str), test_cases[i].decoded) ==0 ); str =qobject_to_json (obj);
@@ -123,11 +117,8 @@ static void single_quote_string(void)QString *str; obj =qobject_from_json (test_cases[i].encoded); - -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - str =qobject_to_qstring (obj); +g_assert (str);g_assert (strcmp (qstring_get_str (str), test_cases[i].decoded) ==0 );QDECREF (str);
@@ -820,9 +811,8 @@ static void utf8_string(void) obj =qobject_from_json (json_in);if (utf8_out) { -g_assert (obj); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); str =qobject_to_qstring (obj); +g_assert (str); g_assert_cmpstr(qstring_get_str(str), ==, utf8_out); }else {g_assert (!obj);
@@ -847,9 +837,8 @@ static void utf8_string(void)*/ if (0 && json_out != json_in) { obj =qobject_from_json (json_out); -g_assert (obj); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); str =qobject_to_qstring (obj); +g_assert (str); g_assert_cmpstr(qstring_get_str(str), ==, utf8_out); } }
@@ -867,15 +856,11 @@ static void vararg_string(void) };for (i =0 ; test_cases[i].decoded; i++) { -QObject *obj;QString *str; - obj =qobject_from_jsonf ("%s" , test_cases[i].decoded); - -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - - str =qobject_to_qstring (obj); + str =qobject_to_qstring (qobject_from_jsonf ("%s" , + test_cases[i].decoded)); +g_assert (str);g_assert (strcmp (qstring_get_str (str), test_cases[i].decoded) ==0 );QDECREF (str);
tests/test-qobject-output-visitor.c +17 -20
@@ -97,42 +97,41 @@ static void test_visitor_out_string(TestOutputVisitorData *data, const void *unused) {char *string = (char *)"Q E M U" ; -QObject *obj; +QString *qstr;visit_type_str (data->ov,NULL , &string, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string); + qstr =qobject_to_qstring (visitor_get (data)); +g_assert (qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, string); }static void test_visitor_out_no_string (TestOutputVisitorData *data,const void *unused) {char *string =NULL ; -QObject *obj; +QString *qstr;/* A null string should return "" */ visit_type_str (data->ov,NULL , &string, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, ""); + qstr =qobject_to_qstring (visitor_get (data)); +g_assert (qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, ""); }static void test_visitor_out_enum (TestOutputVisitorData *data,const void *unused) { -QObject *obj;EnumOne i; +QString *qstr;for (i =0 ; i <ENUM_ONE__MAX ; i++) {visit_type_EnumOne (data->ov,"unused" , &i, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QSTRING ); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, - EnumOne_lookup[i]); + qstr =qobject_to_qstring (visitor_get (data)); +g_assert (qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_lookup[i]);visitor_reset (data); } }
@@ -365,9 +364,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qbool =qobject_to_qbool (qobj);g_assert (qbool);g_assert (qbool_get_bool (qbool) == true); - qobj =qdict_get (qdict,"string" ); -g_assert (qobj); - qstring =qobject_to_qstring (qobj); + qstring =qobject_to_qstring (qdict_get (qdict,"string" ));g_assert (qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo"); }
@@ -399,6 +396,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, {QObject *arg;UserDefAlternate *tmp; +QString *qstr;QDict *qdict; tmp =g_new0 (UserDefAlternate,1 );
@@ -419,10 +417,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.s =g_strdup ("hello" );visit_type_UserDefAlternate (data->ov,NULL , &tmp, &error_abort); - arg =visitor_get (data); - -g_assert (qobject_type (arg) ==QTYPE_QSTRING ); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello"); + qstr =qobject_to_qstring (visitor_get (data)); +g_assert (qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, "hello");qapi_free_UserDefAlternate (tmp);
Signature · 1 line
2.7.4
PATCH 10/14 tests: Don't check qobject_type() before qobject_to_qint()
In reply to Markus Armbrusterqobject_to_qint(obj) returns NULL when obj isn't a QInt. Check that instead of qobject_type(obj) == QTYPE_QINT.
--- tests/check-qjson.c | 24 +++++------------------- tests/test-qobject-output-visitor.c | 28 ++++++++++++---------------- 2 files changed, 17 insertions(+), 35 deletions(-)
tests/check-qjson.c +5 -19
@@ -884,19 +884,15 @@ static void simple_number(void) };for (i =0 ; test_cases[i].encoded; i++) { -QObject *obj;QInt *qint; - obj =qobject_from_json (test_cases[i].encoded); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QINT ); - - qint =qobject_to_qint (obj); + qint =qobject_to_qint (qobject_from_json (test_cases[i].encoded)); +g_assert (qint);g_assert (qint_get_int (qint) == test_cases[i].decoded);if (test_cases[i].skip ==0 ) {QString *str; - str =qobject_to_json (obj); + str =qobject_to_json (QOBJECT (qint));g_assert (strcmp (qstring_get_str (str), test_cases[i].encoded) ==0 );QDECREF (str); }
@@ -952,22 +948,12 @@ static void vararg_number(void)long long value_ll =0x2342342343LL ;double valuef =2.323423423 ; - obj =qobject_from_jsonf ("%d" , value); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QINT ); - - qint =qobject_to_qint (obj); + qint =qobject_to_qint (qobject_from_jsonf ("%d" , value));g_assert (qint_get_int (qint) == value); -QDECREF (qint); - obj =qobject_from_jsonf ("%lld" , value_ll); -g_assert (obj !=NULL ); -g_assert (qobject_type (obj) ==QTYPE_QINT ); - - qint =qobject_to_qint (obj); + qint =qobject_to_qint (qobject_from_jsonf ("%lld" , value_ll));g_assert (qint_get_int (qint) == value_ll); -QDECREF (qint); obj =qobject_from_jsonf ("%f" , valuef);
tests/test-qobject-output-visitor.c +12 -16
@@ -58,13 +58,13 @@ static void test_visitor_out_int(TestOutputVisitorData *data, const void *unused) {int64_t value =-42 ; -QObject *obj; +QInt *qint;visit_type_int (data->ov,NULL , &value, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QINT ); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value); + qint =qobject_to_qint (visitor_get (data)); +g_assert (qint); + g_assert_cmpint(qint_get_int(qint), ==, value); } static void test_visitor_out_bool(TestOutputVisitorData *data,
@@ -335,13 +335,12 @@ static void test_visitor_out_any(TestOutputVisitorData *data,QBool *qbool;QString *qstring;QDict *qdict; -QObject *obj; qobj =QOBJECT (qint_from_int (-42 ));visit_type_any (data->ov,NULL , &qobj, &error_abort); - obj =visitor_get (data); -g_assert (qobject_type (obj) ==QTYPE_QINT ); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42); + qint =qobject_to_qint (visitor_get (data)); +g_assert (qint); + g_assert_cmpint(qint_get_int(qint), ==, -42);qobject_decref (qobj);visitor_reset (data);
@@ -354,9 +353,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data,qobject_decref (qobj); qdict =qobject_to_qdict (visitor_get (data));g_assert (qdict); - qobj =qdict_get (qdict,"integer" ); -g_assert (qobj); - qint =qobject_to_qint (qobj); + qint =qobject_to_qint (qdict_get (qdict,"integer" ));g_assert (qint); g_assert_cmpint(qint_get_int(qint), ==, -42); qobj =qdict_get (qdict,"boolean" );
@@ -394,8 +391,8 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,static void test_visitor_out_alternate (TestOutputVisitorData *data,const void *unused) { -QObject *arg;UserDefAlternate *tmp; +QInt *qint;QString *qstr;QDict *qdict;
@@ -404,10 +401,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.i =42 ;visit_type_UserDefAlternate (data->ov,NULL , &tmp, &error_abort); - arg =visitor_get (data); - -g_assert (qobject_type (arg) ==QTYPE_QINT ); - g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42); + qint =qobject_to_qint (visitor_get (data)); +g_assert (qint); + g_assert_cmpint(qint_get_int(qint), ==, 42);qapi_free_UserDefAlternate (tmp);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 01/14] qdict: Make qdict_get_qlist() safe like qdict_get_qdict()
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
Commit 89cad9f changed
qdict_get_qdict()to return NULL instead of crash when the key doesn't exist or its value isn't a QDict. Commit 2d6421a neglected to do the same forqdict_get_qlist(). Correct that, and update the function comments.
Quoted 7 lines
qdict_get_obj()is now unused, remove.Signed-off-by Markus Armbruster <[email protected]>--- qobject/qdict.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 02/14] check-qdict: Simplify qdict_crumple_test_recursive()
In reply to Markus ArmbrusterQuoted 2 lines · Markus Armbruster
Use
qdict_get_qdict(),qdict_get_qlist()instead ofqdict_get()followed byqobject_to_qdict(),qobject_to_qlist().
Worth a Coccinelle script to make sure we catch it all?
Quoted 8 lines
While there, drop some redundant code.
Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qdict.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 02/14] check-qdict: Simplify qdict_crumple_test_recursive()
Quoted 5 lines · Eric Blake
Quoted 2 lines · Markus Armbruster
Use
qdict_get_qdict(),qdict_get_qlist()instead ofqdict_get()followed byqobject_to_qdict(),qobject_to_qlist().Worth a Coccinelle script to make sure we catch it all?
I'm pretty sure I got them all: I examined all uses of the QType enumeration constants for this series.
Quoted 10 lines
Quoted 8 lines
While there, drop some redundant code.
Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qdict.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 03/14] check-qdict: Tighten qdict_crumple_test_recursive() some
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
Consistently check for unexpected QDict entries, and
qdict_get_qdict()success. The latter doesn't tighten the test, it only makes it fail more nicely.Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qdict.c | 5 +++++ 1 file changed, 5 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 04/14] check-qjson: Simplify around compare_litqobj_to_qobj()
In reply to Markus ArmbrusterQuoted 10 lines · Markus Armbruster
Make
compare_litqobj_to_qobj()cope with null, and drop non-null assertions from callers.
compare_litqobj_to_qobj()already checks the QType matches; drop the redundant assertions from callers.Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qjson.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-)
Wow - impressive diffstat.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 05/14] libqtest: Clean up qmp_response() a bit
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
Use
qobject_to_qdict()instead of a type cast.Signed-off-by Markus Armbruster <[email protected]>--- tests/libqtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Happens to be the same (because of our struct layout), but agree that the conversion function is safer if we ever change struct layout.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 06/14] test-qmp-event: Simplify and tighten event_test_emit()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
Use
qdict_get_qdict()andqdict_get_try_int()to simplify.While there, add a sanity check for seconds.
Signed-off-by Markus Armbruster <[email protected]>--- tests/test-qmp-event.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 07/14] Don't check qobject_type() before qobject_to_qdict()
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
qobject_to_qdict(obj)returns NULL when obj isn't a QDict. Check that instead ofqobject_type(obj)==QTYPE_QDICT.Signed-off-by Markus Armbruster <[email protected]>---
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 08/14] tests: Don't check qobject_type() before qobject_to_qlist()
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
qobject_to_qlist(obj)returns NULL when obj isn't a QList. Check that instead ofqobject_type(obj)==QTYPE_QLIST.Signed-off-by Markus Armbruster <[email protected]>--- tests/test-qobject-output-visitor.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 09/14] tests: Don't check qobject_type() before qobject_to_qstring()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
qobject_to_qstring(obj)returns NULL when obj isn't a QString. Check that instead ofqobject_type(obj)==QTYPE_QSTRING.Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qjson.c | 31 ++++++++----------------------- tests/test-qobject-output-visitor.c | 37 +++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 43 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 10/14] tests: Don't check qobject_type() before qobject_to_qint()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
qobject_to_qint(obj)returns NULL when obj isn't a QInt. Check that instead ofqobject_type(obj)==QTYPE_QINT.Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qjson.c | 24 +++++------------------- tests/test-qobject-output-visitor.c | 28 ++++++++++++---------------- 2 files changed, 17 insertions(+), 35 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 11/14] tests: Don't check qobject_type() before qobject_to_qfloat()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
qobject_to_qfloat(obj)returns NULL when obj isn't a QFloat. Check that instead ofqobject_type(obj)==QTYPE_QFLOAT.Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qjson.c | 12 ++---------- tests/test-qobject-output-visitor.c | 8 ++++---- 2 files changed, 6 insertions(+), 14 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 12/14] tests: Don't check qobject_type() before qobject_to_qbool()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
qobject_to_qbool(obj)returns NULL when obj isn't a QBool. Check that instead ofqobject_type(obj)==QTYPE_QBOOL.Signed-off-by Markus Armbruster <[email protected]>--- tests/check-qjson.c | 24 ++++++------------------ tests/test-qobject-output-visitor.c | 12 +++++------- 2 files changed, 11 insertions(+), 25 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 13/14] monitor: Clean up handle_hmp_command() a bit
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
Leave checking
qobject_type(req)toqmp_check_input_obj(). Rework handling ofjson_parser_parse_err()failing without setting an error.Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 14/14] block: Don't bother asserting type of output visitor's output
In reply to Markus ArmbrusterQuoted 11 lines · Markus Armbruster
After a visit of a complex QAPI type FOO
ov = qobject_output_visitor_new(&foo); visit_type_FOO(ov, NULL, expr, &error_abort); visit_complete(ov, &foo);we can safely assume
qobject_type(foo)isQTYPE_QDICT. We do in many places, but occasionally assertqobject_type(obj)==QTYPE_QDICT. Don't. The appropriate place to check such fundamental properties of QAPI visitors is the test suite.
Quoted 6 lines
Signed-off-by Markus Armbruster <[email protected]>--- block/nbd.c | 2 -- block/nfs.c | 2 -- block/qapi.c | 1 - 3 files changed, 5 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org