diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.include | 8 | ||||
-rw-r--r-- | tests/check-qdict.c | 20 | ||||
-rw-r--r-- | tests/check-qjson.c | 41 | ||||
-rw-r--r-- | tests/check-qlist.c | 4 | ||||
-rw-r--r-- | tests/check-qlit.c | 30 | ||||
-rw-r--r-- | tests/check-qnum.c | 4 | ||||
-rw-r--r-- | tests/check-qobject.c | 2 | ||||
-rw-r--r-- | tests/check-qstring.c | 2 | ||||
-rw-r--r-- | tests/device-introspect-test.c | 14 | ||||
-rw-r--r-- | tests/libqtest.c | 6 | ||||
-rw-r--r-- | tests/numa-test.c | 8 | ||||
-rw-r--r-- | tests/qapi-schema/test-qapi.py | 2 | ||||
-rwxr-xr-x | tests/qemu-iotests/089 | 20 | ||||
-rw-r--r-- | tests/qemu-iotests/089.out | 8 | ||||
-rw-r--r-- | tests/qmp-test.c | 97 | ||||
-rw-r--r-- | tests/qom-test.c | 4 | ||||
-rw-r--r-- | tests/test-char.c | 2 | ||||
-rw-r--r-- | tests/test-keyval.c | 8 | ||||
-rw-r--r-- | tests/test-qga.c | 19 | ||||
-rw-r--r-- | tests/test-qmp-cmds.c | 12 | ||||
-rw-r--r-- | tests/test-qmp-event.c | 16 | ||||
-rw-r--r-- | tests/test-qobject-input-visitor.c | 21 | ||||
-rw-r--r-- | tests/test-qobject-output-visitor.c | 54 | ||||
-rw-r--r-- | tests/test-x86-cpuid-compat.c | 17 |
24 files changed, 288 insertions, 131 deletions
diff --git a/tests/Makefile.include b/tests/Makefile.include index 42fd426..412aed1 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -929,14 +929,14 @@ $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json $^ >$*.test.out 2>$*.test.err; \ echo $$? >$*.test.exit, \ "TEST","$*.out") - @diff $(SRC_PATH)/$*.out $*.test.out @# Sanitize error messages (make them independent of build directory) - @perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff $(SRC_PATH)/$*.err - - @diff $(SRC_PATH)/$*.exit $*.test.exit + @perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff -u $(SRC_PATH)/$*.err - + @diff -u $(SRC_PATH)/$*.out $*.test.out + @diff -u $(SRC_PATH)/$*.exit $*.test.exit .PHONY: check-tests/qapi-schema/doc-good.texi check-tests/qapi-schema/doc-good.texi: tests/qapi-schema/doc-good.test.texi - @diff -q $(SRC_PATH)/tests/qapi-schema/doc-good.texi $< + @diff -u $(SRC_PATH)/tests/qapi-schema/doc-good.texi $< .PHONY: check-decodetree check-decodetree: diff --git a/tests/check-qdict.c b/tests/check-qdict.c index a3faea8..2e73c2f 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -51,7 +51,7 @@ static void qdict_put_obj_test(void) g_assert(qdict_size(qdict) == 1); ent = QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]); - qn = qobject_to_qnum(ent->value); + qn = qobject_to(QNum, ent->value); g_assert_cmpint(qnum_get_int(qn), ==, num); QDECREF(qdict); @@ -81,7 +81,7 @@ static void qdict_get_test(void) obj = qdict_get(tests_dict, key); g_assert(obj != NULL); - qn = qobject_to_qnum(obj); + qn = qobject_to(QNum, obj); g_assert_cmpint(qnum_get_int(qn), ==, value); QDECREF(tests_dict); @@ -216,7 +216,7 @@ static void qdict_del_test(void) static void qobject_to_qdict_test(void) { QDict *tests_dict = qdict_new(); - g_assert(qobject_to_qdict(QOBJECT(tests_dict)) == tests_dict); + g_assert(qobject_to(QDict, QOBJECT(tests_dict)) == tests_dict); QDECREF(tests_dict); } @@ -381,9 +381,9 @@ static void qdict_array_split_test(void) qdict_array_split(test_dict, &test_list); - dict1 = qobject_to_qdict(qlist_pop(test_list)); - dict2 = qobject_to_qdict(qlist_pop(test_list)); - int1 = qobject_to_qnum(qlist_pop(test_list)); + dict1 = qobject_to(QDict, qlist_pop(test_list)); + dict2 = qobject_to(QDict, qlist_pop(test_list)); + int1 = qobject_to(QNum, qlist_pop(test_list)); g_assert(dict1); g_assert(dict2); @@ -450,7 +450,7 @@ static void qdict_array_split_test(void) qdict_array_split(test_dict, &test_list); - int1 = qobject_to_qnum(qlist_pop(test_list)); + int1 = qobject_to(QNum, qlist_pop(test_list)); g_assert(int1); g_assert(qlist_empty(test_list)); @@ -607,7 +607,7 @@ static void qdict_crumple_test_recursive(void) qdict_put_str(src, "vnc.acl..name", "acl0"); qdict_put_str(src, "vnc.acl.rule..name", "acl0"); - dst = qobject_to_qdict(qdict_crumple(src, &error_abort)); + dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); g_assert(dst); g_assert_cmpint(qdict_size(dst), ==, 1); @@ -629,14 +629,14 @@ static void qdict_crumple_test_recursive(void) g_assert(rules); g_assert_cmpint(qlist_size(rules), ==, 2); - rule = qobject_to_qdict(qlist_pop(rules)); + 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)); + 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")); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index a18ea47..997f4d3 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -60,7 +60,7 @@ static void escaped_string(void) QString *str; obj = qobject_from_json(test_cases[i].encoded, &error_abort); - str = qobject_to_qstring(obj); + str = qobject_to(QString, obj); g_assert(str); g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded); @@ -92,7 +92,7 @@ static void simple_string(void) QString *str; obj = qobject_from_json(test_cases[i].encoded, &error_abort); - str = qobject_to_qstring(obj); + str = qobject_to(QString, obj); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0); @@ -123,7 +123,7 @@ static void single_quote_string(void) QString *str; obj = qobject_from_json(test_cases[i].encoded, &error_abort); - str = qobject_to_qstring(obj); + str = qobject_to(QString, obj); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0); @@ -817,7 +817,7 @@ static void utf8_string(void) obj = qobject_from_json(json_in, utf8_out ? &error_abort : NULL); if (utf8_out) { - str = qobject_to_qstring(obj); + str = qobject_to(QString, obj); g_assert(str); g_assert_cmpstr(qstring_get_str(str), ==, utf8_out); } else { @@ -843,7 +843,7 @@ static void utf8_string(void) */ if (0 && json_out != json_in) { obj = qobject_from_json(json_out, &error_abort); - str = qobject_to_qstring(obj); + str = qobject_to(QString, obj); g_assert(str); g_assert_cmpstr(qstring_get_str(str), ==, utf8_out); } @@ -864,8 +864,8 @@ static void vararg_string(void) for (i = 0; test_cases[i].decoded; i++) { QString *str; - str = qobject_to_qstring(qobject_from_jsonf("%s", - test_cases[i].decoded)); + 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); @@ -893,8 +893,9 @@ static void simple_number(void) QNum *qnum; int64_t val; - qnum = qobject_to_qnum(qobject_from_json(test_cases[i].encoded, - &error_abort)); + qnum = qobject_to(QNum, + qobject_from_json(test_cases[i].encoded, + &error_abort)); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, test_cases[i].decoded); @@ -920,7 +921,7 @@ static void large_number(void) uint64_t val; int64_t ival; - qnum = qobject_to_qnum(qobject_from_json(maxu64, &error_abort)); + qnum = qobject_to(QNum, qobject_from_json(maxu64, &error_abort)); g_assert(qnum); g_assert_cmpuint(qnum_get_uint(qnum), ==, 18446744073709551615U); g_assert(!qnum_get_try_int(qnum, &ival)); @@ -930,7 +931,7 @@ static void large_number(void) QDECREF(str); QDECREF(qnum); - qnum = qobject_to_qnum(qobject_from_json(gtu64, &error_abort)); + qnum = qobject_to(QNum, qobject_from_json(gtu64, &error_abort)); g_assert(qnum); g_assert_cmpfloat(qnum_get_double(qnum), ==, 18446744073709552e3); g_assert(!qnum_get_try_uint(qnum, &val)); @@ -941,7 +942,7 @@ static void large_number(void) QDECREF(str); QDECREF(qnum); - qnum = qobject_to_qnum(qobject_from_json(lti64, &error_abort)); + qnum = qobject_to(QNum, qobject_from_json(lti64, &error_abort)); g_assert(qnum); g_assert_cmpfloat(qnum_get_double(qnum), ==, -92233720368547758e2); g_assert(!qnum_get_try_uint(qnum, &val)); @@ -973,7 +974,7 @@ static void float_number(void) QNum *qnum; obj = qobject_from_json(test_cases[i].encoded, &error_abort); - qnum = qobject_to_qnum(obj); + qnum = qobject_to(QNum, obj); g_assert(qnum); g_assert(qnum_get_double(qnum) == test_cases[i].decoded); @@ -997,17 +998,17 @@ static void vararg_number(void) double valuef = 2.323423423; int64_t val; - qnum = qobject_to_qnum(qobject_from_jsonf("%d", value)); + qnum = qobject_to(QNum, qobject_from_jsonf("%d", value)); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, value); QDECREF(qnum); - qnum = qobject_to_qnum(qobject_from_jsonf("%lld", value_ll)); + qnum = qobject_to(QNum, qobject_from_jsonf("%lld", value_ll)); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, value_ll); QDECREF(qnum); - qnum = qobject_to_qnum(qobject_from_jsonf("%f", valuef)); + qnum = qobject_to(QNum, qobject_from_jsonf("%f", valuef)); g_assert(qnum_get_double(qnum) == valuef); QDECREF(qnum); } @@ -1020,7 +1021,7 @@ static void keyword_literal(void) QString *str; obj = qobject_from_json("true", &error_abort); - qbool = qobject_to_qbool(obj); + qbool = qobject_to(QBool, obj); g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); @@ -1031,7 +1032,7 @@ static void keyword_literal(void) QDECREF(qbool); obj = qobject_from_json("false", &error_abort); - qbool = qobject_to_qbool(obj); + qbool = qobject_to(QBool, obj); g_assert(qbool); g_assert(qbool_get_bool(qbool) == false); @@ -1041,13 +1042,13 @@ static void keyword_literal(void) QDECREF(qbool); - qbool = qobject_to_qbool(qobject_from_jsonf("%i", false)); + 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 */ - qbool = qobject_to_qbool(qobject_from_jsonf("%i", 2)); + qbool = qobject_to(QBool, qobject_from_jsonf("%i", 2)); g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); QDECREF(qbool); diff --git a/tests/check-qlist.c b/tests/check-qlist.c index 259980d..a1c69ed 100644 --- a/tests/check-qlist.c +++ b/tests/check-qlist.c @@ -56,7 +56,7 @@ static void qobject_to_qlist_test(void) qlist = qlist_new(); - g_assert(qobject_to_qlist(QOBJECT(qlist)) == qlist); + g_assert(qobject_to(QList, QOBJECT(qlist)) == qlist); QDECREF(qlist); } @@ -71,7 +71,7 @@ static void iter_func(QObject *obj, void *opaque) g_assert(opaque == NULL); - qi = qobject_to_qnum(obj); + qi = qobject_to(QNum, obj); g_assert(qi != NULL); g_assert(qnum_get_try_int(qi, &val)); diff --git a/tests/check-qlit.c b/tests/check-qlit.c index 5d0f65b..96bbb06 100644 --- a/tests/check-qlit.c +++ b/tests/check-qlit.c @@ -9,9 +9,11 @@ #include "qemu/osdep.h" +#include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qapi/qmp/qlit.h" +#include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) { @@ -57,17 +59,43 @@ static void qlit_equal_qobject_test(void) g_assert(!qlit_equal_qobject(&qlit_foo, qobj)); - qdict_put(qobject_to_qdict(qobj), "bee", qlist_new()); + qdict_put(qobject_to(QDict, qobj), "bee", qlist_new()); g_assert(!qlit_equal_qobject(&qlit, qobj)); qobject_decref(qobj); } +static void qobject_from_qlit_test(void) +{ + QObject *obj, *qobj = qobject_from_qlit(&qlit); + QDict *qdict; + QList *bee; + + qdict = qobject_to(QDict, qobj); + g_assert_cmpint(qdict_get_int(qdict, "foo"), ==, 42); + g_assert_cmpstr(qdict_get_str(qdict, "bar"), ==, "hello world"); + g_assert(qobject_type(qdict_get(qdict, "baz")) == QTYPE_QNULL); + + bee = qdict_get_qlist(qdict, "bee"); + obj = qlist_pop(bee); + g_assert_cmpint(qnum_get_int(qobject_to(QNum, obj)), ==, 43); + qobject_decref(obj); + obj = qlist_pop(bee); + g_assert_cmpint(qnum_get_int(qobject_to(QNum, obj)), ==, 44); + qobject_decref(obj); + obj = qlist_pop(bee); + g_assert(qbool_get_bool(qobject_to(QBool, obj))); + qobject_decref(obj); + + qobject_decref(qobj); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test); + g_test_add_func("/qlit/qobject_from_qlit", qobject_from_qlit_test); return g_test_run(); } diff --git a/tests/check-qnum.c b/tests/check-qnum.c index 2b667f7..9187da7 100644 --- a/tests/check-qnum.c +++ b/tests/check-qnum.c @@ -126,11 +126,11 @@ static void qobject_to_qnum_test(void) QNum *qn; qn = qnum_from_int(0); - g_assert(qobject_to_qnum(QOBJECT(qn)) == qn); + g_assert(qobject_to(QNum, QOBJECT(qn)) == qn); QDECREF(qn); qn = qnum_from_double(0); - g_assert(qobject_to_qnum(QOBJECT(qn)) == qn); + g_assert(qobject_to(QNum, QOBJECT(qn)) == qn); QDECREF(qn); } diff --git a/tests/check-qobject.c b/tests/check-qobject.c index 7a36706..7629b80 100644 --- a/tests/check-qobject.c +++ b/tests/check-qobject.c @@ -275,7 +275,7 @@ static void qobject_is_equal_dict_test(void) dict_different_null_key, dict_longer, dict_shorter, dict_nested); - dict_crumpled = qobject_to_qdict(qdict_crumple(dict_1, &local_err)); + dict_crumpled = qobject_to(QDict, qdict_crumple(dict_1, &local_err)); g_assert(!local_err); check_equal(dict_crumpled, dict_nested); diff --git a/tests/check-qstring.c b/tests/check-qstring.c index 112ec08..9c4dd3f 100644 --- a/tests/check-qstring.c +++ b/tests/check-qstring.c @@ -79,7 +79,7 @@ static void qobject_to_qstring_test(void) QString *qstring; qstring = qstring_from_str("foo"); - g_assert(qobject_to_qstring(QOBJECT(qstring)) == qstring); + g_assert(qobject_to(QString, QOBJECT(qstring)) == qstring); QDECREF(qstring); } diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c index b80058f..a01321a 100644 --- a/tests/device-introspect-test.c +++ b/tests/device-introspect-test.c @@ -52,7 +52,7 @@ static QDict *qom_type_index(QList *types) QListEntry *e; QLIST_FOREACH_ENTRY(types, e) { - QDict *d = qobject_to_qdict(qlist_entry_obj(e)); + QDict *d = qobject_to(QDict, qlist_entry_obj(e)); const char *name = qdict_get_str(d, "name"); QINCREF(d); qdict_put(index, name, d); @@ -85,7 +85,7 @@ static QDict *type_list_find(QList *types, const char *name) QListEntry *e; QLIST_FOREACH_ENTRY(types, e) { - QDict *d = qobject_to_qdict(qlist_entry_obj(e)); + QDict *d = qobject_to(QDict, qlist_entry_obj(e)); const char *ename = qdict_get_str(d, "name"); if (!strcmp(ename, name)) { return d; @@ -151,7 +151,7 @@ static void test_qom_list_parents(const char *parent) index = qom_type_index(types); QLIST_FOREACH_ENTRY(types, e) { - QDict *d = qobject_to_qdict(qlist_entry_obj(e)); + QDict *d = qobject_to(QDict, qlist_entry_obj(e)); const char *name = qdict_get_str(d, "name"); g_assert(qom_has_parent(index, name, parent)); @@ -173,7 +173,7 @@ static void test_qom_list_fields(void) non_abstract = qom_list_types(NULL, false); QLIST_FOREACH_ENTRY(all_types, e) { - QDict *d = qobject_to_qdict(qlist_entry_obj(e)); + QDict *d = qobject_to(QDict, qlist_entry_obj(e)); const char *name = qdict_get_str(d, "name"); bool abstract = qdict_haskey(d, "abstract") ? qdict_get_bool(d, "abstract") : @@ -216,8 +216,8 @@ static void test_device_intro_concrete(void) types = device_type_list(false); QLIST_FOREACH_ENTRY(types, entry) { - type = qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)), - "name"); + type = qdict_get_try_str(qobject_to(QDict, qlist_entry_obj(entry)), + "name"); g_assert(type); test_one_device(type); } @@ -238,7 +238,7 @@ static void test_abstract_interfaces(void) index = qom_type_index(all_types); QLIST_FOREACH_ENTRY(all_types, e) { - QDict *d = qobject_to_qdict(qlist_entry_obj(e)); + QDict *d = qobject_to(QDict, qlist_entry_obj(e)); const char *name = qdict_get_str(d, "name"); /* diff --git a/tests/libqtest.c b/tests/libqtest.c index 13c9100..200b2b9 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -430,7 +430,7 @@ static void qmp_response(JSONMessageParser *parser, GQueue *tokens) } g_assert(!qmp->response); - qmp->response = qobject_to_qdict(obj); + qmp->response = qobject_to(QDict, obj); g_assert(qmp->response); } @@ -1008,11 +1008,11 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine)) g_assert(list); for (p = qlist_first(list); p; p = qlist_next(p)) { - minfo = qobject_to_qdict(qlist_entry_obj(p)); + minfo = qobject_to(QDict, qlist_entry_obj(p)); g_assert(minfo); qobj = qdict_get(minfo, "name"); g_assert(qobj); - qstr = qobject_to_qstring(qobj); + qstr = qobject_to(QString, qobj); g_assert(qstr); mname = qstring_get_str(qstr); cb(mname); diff --git a/tests/numa-test.c b/tests/numa-test.c index 68aca9c..0f861d8 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -98,7 +98,7 @@ static void test_query_cpus(const void *data) QDict *cpu, *props; int64_t cpu_idx, node; - cpu = qobject_to_qdict(e); + cpu = qobject_to(QDict, e); g_assert(qdict_haskey(cpu, "CPU")); g_assert(qdict_haskey(cpu, "props")); @@ -140,7 +140,7 @@ static void pc_numa_cpu(const void *data) QDict *cpu, *props; int64_t socket, core, thread, node; - cpu = qobject_to_qdict(e); + cpu = qobject_to(QDict, e); g_assert(qdict_haskey(cpu, "props")); props = qdict_get_qdict(cpu, "props"); @@ -193,7 +193,7 @@ static void spapr_numa_cpu(const void *data) QDict *cpu, *props; int64_t core, node; - cpu = qobject_to_qdict(e); + cpu = qobject_to(QDict, e); g_assert(qdict_haskey(cpu, "props")); props = qdict_get_qdict(cpu, "props"); @@ -236,7 +236,7 @@ static void aarch64_numa_cpu(const void *data) QDict *cpu, *props; int64_t thread, node; - cpu = qobject_to_qdict(e); + cpu = qobject_to(QDict, e); g_assert(qdict_haskey(cpu, "props")); props = qdict_get_qdict(cpu, "props"); diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 67e417e..10e68b0 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -42,7 +42,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_variants(variants) def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): print('command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.name)) print(' gen=%s success_response=%s boxed=%s' % \ diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089 index 0b059ab..aa1ba4a 100755 --- a/tests/qemu-iotests/089 +++ b/tests/qemu-iotests/089 @@ -82,6 +82,26 @@ $QEMU_IO_PROG --cache $CACHEMODE \ $QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io +echo +echo "=== Testing correct handling of 'backing':null ===" +echo + +_make_test_img -b "$TEST_IMG.base" $IMG_SIZE + +# This should read 42 +$QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io + +# This should read 0 +$QEMU_IO -c 'read -P 0 0 512' "json:{\ + 'driver': '$IMGFMT', + 'file': { + 'driver': 'file', + 'filename': '$TEST_IMG' + }, + 'backing': null +}" | _filter_qemu_io + + # Taken from test 071 echo echo "=== Testing blkdebug ===" diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out index 0bf5a13..89e3e43 100644 --- a/tests/qemu-iotests/089.out +++ b/tests/qemu-iotests/089.out @@ -19,6 +19,14 @@ Pattern verification failed at offset 0, 512 bytes read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +=== Testing correct handling of 'backing':null === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + === Testing blkdebug === Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 7470c6b..07c0b87 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -20,6 +20,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/util.h" #include "qapi/visitor.h" +#include "qapi/qmp/qstring.h" const char common_args[] = "-nodefaults -machine none"; @@ -79,6 +80,9 @@ static void test_qmp_protocol(void) QDict *resp, *q, *ret; QList *capabilities; QTestState *qts; + const QListEntry *entry; + QString *qstr; + int i; qts = qtest_init_without_qmp_handshake(common_args); @@ -88,7 +92,12 @@ static void test_qmp_protocol(void) g_assert(q); test_version(qdict_get(q, "version")); capabilities = qdict_get_qlist(q, "capabilities"); - g_assert(capabilities && qlist_empty(capabilities)); + g_assert(capabilities); + entry = qlist_first(capabilities); + g_assert(entry); + qstr = qobject_to(QString, entry->value); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), ==, "oob"); QDECREF(resp); /* Test valid command before handshake */ @@ -131,9 +140,94 @@ static void test_qmp_protocol(void) g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2); QDECREF(resp); + /* + * Test command batching. In current test OOB is not enabled, we + * should be able to run as many commands in batch as we like. + * Using 16 (>8, which is OOB queue length) to make sure OOB won't + * break existing clients. Note: this test does not control the + * scheduling of QEMU's QMP command processing threads so it may + * not really trigger batching inside QEMU. This is just a + * best-effort test. + */ + for (i = 0; i < 16; i++) { + qtest_async_qmp(qts, "{ 'execute': 'query-version' }"); + } + /* Verify the replies to make sure no command is dropped. */ + for (i = 0; i < 16; i++) { + resp = qtest_qmp_receive(qts); + /* It should never be dropped. Each of them should be a reply. */ + g_assert(qdict_haskey(resp, "return")); + g_assert(!qdict_haskey(resp, "event")); + QDECREF(resp); + } + qtest_quit(qts); } +/* Tests for Out-Of-Band support. */ +static void test_qmp_oob(void) +{ + QDict *resp; + int acks = 0; + const char *cmd_id; + + global_qtest = qtest_init_without_qmp_handshake(common_args); + + /* Ignore the greeting message. */ + resp = qmp_receive(); + g_assert(qdict_get_qdict(resp, "QMP")); + QDECREF(resp); + + /* Try a fake capability, it should fail. */ + resp = qmp("{ 'execute': 'qmp_capabilities', " + " 'arguments': { 'enable': [ 'cap-does-not-exist' ] } }"); + g_assert(qdict_haskey(resp, "error")); + QDECREF(resp); + + /* Now, enable OOB in current QMP session, it should succeed. */ + resp = qmp("{ 'execute': 'qmp_capabilities', " + " 'arguments': { 'enable': [ 'oob' ] } }"); + g_assert(qdict_haskey(resp, "return")); + QDECREF(resp); + + /* + * Try any command that does not support OOB but with OOB flag. We + * should get failure. + */ + resp = qmp("{ 'execute': 'query-cpus'," + " 'control': { 'run-oob': true } }"); + g_assert(qdict_haskey(resp, "error")); + QDECREF(resp); + + /* + * First send the "x-oob-test" command with lock=true and + * oob=false, it should hang the dispatcher and main thread; + * later, we send another lock=false with oob=true to continue + * that thread processing. Finally we should receive replies from + * both commands. + */ + qmp_async("{ 'execute': 'x-oob-test'," + " 'arguments': { 'lock': true }, " + " 'id': 'lock-cmd'}"); + qmp_async("{ 'execute': 'x-oob-test', " + " 'arguments': { 'lock': false }, " + " 'control': { 'run-oob': true }, " + " 'id': 'unlock-cmd' }"); + + /* Ignore all events. Wait for 2 acks */ + while (acks < 2) { + resp = qmp_receive(); + cmd_id = qdict_get_str(resp, "id"); + if (!g_strcmp0(cmd_id, "lock-cmd") || + !g_strcmp0(cmd_id, "unlock-cmd")) { + acks++; + } + QDECREF(resp); + } + + qtest_end(); +} + static int query_error_class(const char *cmd) { static struct { @@ -318,6 +412,7 @@ int main(int argc, char *argv[]) g_test_init(&argc, &argv, NULL); qtest_add_func("qmp/protocol", test_qmp_protocol); + qtest_add_func("qmp/oob", test_qmp_oob); qmp_schema_init(&schema); add_query_tests(&schema); diff --git a/tests/qom-test.c b/tests/qom-test.c index 9dab7ac..a34ff6b 100644 --- a/tests/qom-test.c +++ b/tests/qom-test.c @@ -62,9 +62,9 @@ static void test_properties(const char *path, bool recurse) } g_assert(qdict_haskey(response, "return")); - list = qobject_to_qlist(qdict_get(response, "return")); + list = qobject_to(QList, qdict_get(response, "return")); QLIST_FOREACH_ENTRY(list, entry) { - tuple = qobject_to_qdict(qlist_entry_obj(entry)); + tuple = qobject_to(QDict, qlist_entry_obj(entry)); bool is_child = strstart(qdict_get_str(tuple, "type"), "child<", NULL); bool is_link = strstart(qdict_get_str(tuple, "type"), "link<", NULL); diff --git a/tests/test-char.c b/tests/test-char.c index df939cc..306c728 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -319,7 +319,7 @@ static void char_socket_test_common(Chardev *chr) g_assert(!object_property_get_bool(OBJECT(chr), "connected", &error_abort)); addr = object_property_get_qobject(OBJECT(chr), "addr", &error_abort); - qdict = qobject_to_qdict(addr); + qdict = qobject_to(QDict, addr); port = qdict_get_str(qdict, "port"); tmp = g_strdup_printf("tcp:127.0.0.1:%s", port); QDECREF(qdict); diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 94eb4df..029f052 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -195,7 +195,7 @@ static void check_list012(QList *qlist) g_assert(qlist); for (i = 0; i < ARRAY_SIZE(expected); i++) { - qstr = qobject_to_qstring(qlist_pop(qlist)); + qstr = qobject_to(QString, qlist_pop(qlist)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), ==, expected[i]); QDECREF(qstr); @@ -654,12 +654,12 @@ static void test_keyval_visit_any(void) QDECREF(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_any(v, "a", &any, &error_abort); - qlist = qobject_to_qlist(any); + qlist = qobject_to(QList, any); g_assert(qlist); - qstr = qobject_to_qstring(qlist_pop(qlist)); + qstr = qobject_to(QString, qlist_pop(qlist)); g_assert_cmpstr(qstring_get_str(qstr), ==, "null"); QDECREF(qstr); - qstr = qobject_to_qstring(qlist_pop(qlist)); + qstr = qobject_to(QString, qlist_pop(qlist)); g_assert_cmpstr(qstring_get_str(qstr), ==, "1"); g_assert(qlist_empty(qlist)); QDECREF(qstr); diff --git a/tests/test-qga.c b/tests/test-qga.c index 5c5b661..e6ab788 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -297,8 +297,8 @@ static void test_qga_get_vcpus(gconstpointer fix) /* check there is at least a cpu */ list = qdict_get_qlist(ret, "return"); entry = qlist_first(list); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "online")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "logical-id")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id")); QDECREF(ret); } @@ -318,10 +318,10 @@ static void test_qga_get_fsinfo(gconstpointer fix) list = qdict_get_qlist(ret, "return"); entry = qlist_first(list); if (entry) { - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "name")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "mountpoint")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "type")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "disk")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "mountpoint")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "type")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "disk")); } QDECREF(ret); @@ -363,8 +363,9 @@ static void test_qga_get_memory_blocks(gconstpointer fix) entry = qlist_first(list); /* newer versions of qga may return empty list without error */ if (entry) { - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "phys-index")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "online")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), + "phys-index")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); } } @@ -385,7 +386,7 @@ static void test_qga_network_get_interfaces(gconstpointer fix) /* check there is at least an interface */ list = qdict_get_qlist(ret, "return"); entry = qlist_first(list); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "name")); + g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); QDECREF(ret); } diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 5b1cee6..93fbbb1 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -100,7 +100,7 @@ static void test_dispatch_cmd(void) resp = qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp != NULL); - assert(!qdict_haskey(qobject_to_qdict(resp), "error")); + assert(!qdict_haskey(qobject_to(QDict, resp), "error")); qobject_decref(resp); QDECREF(req); @@ -117,7 +117,7 @@ static void test_dispatch_cmd_failure(void) resp = qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp != NULL); - assert(qdict_haskey(qobject_to_qdict(resp), "error")); + assert(qdict_haskey(qobject_to(QDict, resp), "error")); qobject_decref(resp); QDECREF(req); @@ -131,7 +131,7 @@ static void test_dispatch_cmd_failure(void) resp = qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp != NULL); - assert(qdict_haskey(qobject_to_qdict(resp), "error")); + assert(qdict_haskey(qobject_to(QDict, resp), "error")); qobject_decref(resp); QDECREF(req); @@ -145,7 +145,7 @@ static QObject *test_qmp_dispatch(QDict *req) resp_obj = qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp_obj); - resp = qobject_to_qdict(resp_obj); + resp = qobject_to(QDict, resp_obj); assert(resp && !qdict_haskey(resp, "error")); ret = qdict_get(resp, "return"); assert(ret); @@ -176,7 +176,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args); qdict_put_str(req, "execute", "user_def_cmd2"); - ret = qobject_to_qdict(test_qmp_dispatch(req)); + ret = qobject_to(QDict, test_qmp_dispatch(req)); assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict = qdict_get_qdict(ret, "dict1"); @@ -197,7 +197,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args3); qdict_put_str(req, "execute", "guest-get-time"); - ret3 = qobject_to_qnum(test_qmp_dispatch(req)); + ret3 = qobject_to(QNum, test_qmp_dispatch(req)); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, ==, 66); QDECREF(ret3); diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 31f35b3..bb10366 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -60,22 +60,22 @@ void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque) switch (qobject_type(obj1)) { case QTYPE_QBOOL: - d->result = (qbool_get_bool(qobject_to_qbool(obj1)) == - qbool_get_bool(qobject_to_qbool(obj2))); + d->result = (qbool_get_bool(qobject_to(QBool, obj1)) == + qbool_get_bool(qobject_to(QBool, obj2))); return; case QTYPE_QNUM: - g_assert(qnum_get_try_int(qobject_to_qnum(obj1), &val1)); - g_assert(qnum_get_try_int(qobject_to_qnum(obj2), &val2)); + g_assert(qnum_get_try_int(qobject_to(QNum, obj1), &val1)); + g_assert(qnum_get_try_int(qobject_to(QNum, obj2), &val2)); d->result = val1 == val2; return; case QTYPE_QSTRING: - d->result = g_strcmp0(qstring_get_str(qobject_to_qstring(obj1)), - qstring_get_str(qobject_to_qstring(obj2))) == 0; + d->result = g_strcmp0(qstring_get_str(qobject_to(QString, obj1)), + qstring_get_str(qobject_to(QString, obj2))) == 0; return; case QTYPE_QDICT: - d_new.expect = qobject_to_qdict(obj2); + d_new.expect = qobject_to(QDict, obj2); d_new.result = true; - qdict_iter(qobject_to_qdict(obj1), qdict_cmp_do_simple, &d_new); + qdict_iter(qobject_to(QDict, obj1), qdict_cmp_do_simple, &d_new); d->result = d_new.result; return; default: diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c index 79b1a8c..6dc59c6 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -479,7 +479,7 @@ static void test_visitor_in_any(TestInputVisitorData *data, v = visitor_input_test_init(data, "-42"); visit_type_any(v, NULL, &res, &error_abort); - qnum = qobject_to_qnum(res); + qnum = qobject_to(QNum, res); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, -42); @@ -487,22 +487,22 @@ static void test_visitor_in_any(TestInputVisitorData *data, v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }"); visit_type_any(v, NULL, &res, &error_abort); - qdict = qobject_to_qdict(res); + qdict = qobject_to(QDict, res); g_assert(qdict && qdict_size(qdict) == 3); qobj = qdict_get(qdict, "integer"); g_assert(qobj); - qnum = qobject_to_qnum(qobj); + qnum = qobject_to(QNum, qobj); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, -42); qobj = qdict_get(qdict, "boolean"); g_assert(qobj); - qbool = qobject_to_qbool(qobj); + 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, qobj); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo"); qobject_decref(res); @@ -1250,24 +1250,27 @@ static void test_visitor_in_fail_alternate(TestInputVisitorData *data, } static void do_test_visitor_in_qmp_introspect(TestInputVisitorData *data, - const char *schema_json) + const QLitObject *qlit) { SchemaInfoList *schema = NULL; + QObject *obj = qobject_from_qlit(qlit); Visitor *v; - v = visitor_input_test_init_raw(data, schema_json); + v = qobject_input_visitor_new(obj); visit_type_SchemaInfoList(v, NULL, &schema, &error_abort); g_assert(schema); qapi_free_SchemaInfoList(schema); + qobject_decref(obj); + visit_free(v); } static void test_visitor_in_qmp_introspect(TestInputVisitorData *data, const void *unused) { - do_test_visitor_in_qmp_introspect(data, test_qmp_schema_json); - do_test_visitor_in_qmp_introspect(data, qmp_schema_json); + do_test_visitor_in_qmp_introspect(data, &test_qmp_schema_qlit); + do_test_visitor_in_qmp_introspect(data, &qmp_schema_qlit); } int main(int argc, char **argv) diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c index 11e8c5a..ecf21c0 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -66,7 +66,7 @@ static void test_visitor_out_int(TestOutputVisitorData *data, visit_type_int(data->ov, NULL, &value, &error_abort); - qnum = qobject_to_qnum(visitor_get(data)); + qnum = qobject_to(QNum, visitor_get(data)); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, value); @@ -80,7 +80,7 @@ static void test_visitor_out_bool(TestOutputVisitorData *data, visit_type_bool(data->ov, NULL, &value, &error_abort); - qbool = qobject_to_qbool(visitor_get(data)); + qbool = qobject_to(QBool, visitor_get(data)); g_assert(qbool); g_assert(qbool_get_bool(qbool) == value); } @@ -93,7 +93,7 @@ static void test_visitor_out_number(TestOutputVisitorData *data, visit_type_number(data->ov, NULL, &value, &error_abort); - qnum = qobject_to_qnum(visitor_get(data)); + qnum = qobject_to(QNum, visitor_get(data)); g_assert(qnum); g_assert(qnum_get_double(qnum) == value); } @@ -106,7 +106,7 @@ static void test_visitor_out_string(TestOutputVisitorData *data, visit_type_str(data->ov, NULL, &string, &error_abort); - qstr = qobject_to_qstring(visitor_get(data)); + qstr = qobject_to(QString, visitor_get(data)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), ==, string); } @@ -120,7 +120,7 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data, /* A null string should return "" */ visit_type_str(data->ov, NULL, &string, &error_abort); - qstr = qobject_to_qstring(visitor_get(data)); + qstr = qobject_to(QString, visitor_get(data)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), ==, ""); } @@ -134,7 +134,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data, for (i = 0; i < ENUM_ONE__MAX; i++) { visit_type_EnumOne(data->ov, "unused", &i, &error_abort); - qstr = qobject_to_qstring(visitor_get(data)); + qstr = qobject_to(QString, visitor_get(data)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_str(i)); visitor_reset(data); @@ -167,7 +167,7 @@ static void test_visitor_out_struct(TestOutputVisitorData *data, visit_type_TestStruct(data->ov, NULL, &p, &error_abort); - qdict = qobject_to_qdict(visitor_get(data)); + qdict = qobject_to(QDict, visitor_get(data)); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42); @@ -206,7 +206,7 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort); - qdict = qobject_to_qdict(visitor_get(data)); + qdict = qobject_to(QDict, visitor_get(data)); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 2); g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]); @@ -280,7 +280,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, visit_type_TestStructList(data->ov, NULL, &head, &error_abort); - qlist = qobject_to_qlist(visitor_get(data)); + qlist = qobject_to(QList, visitor_get(data)); g_assert(qlist); g_assert(!qlist_empty(qlist)); @@ -289,7 +289,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, QLIST_FOREACH_ENTRY(qlist, entry) { QDict *qdict; - qdict = qobject_to_qdict(entry->value); + qdict = qobject_to(QDict, entry->value); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i); @@ -342,7 +342,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobj = QOBJECT(qnum_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); - qnum = qobject_to_qnum(visitor_get(data)); + qnum = qobject_to(QNum, visitor_get(data)); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, -42); @@ -356,16 +356,16 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qobj = QOBJECT(qdict); visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); - qdict = qobject_to_qdict(visitor_get(data)); + qdict = qobject_to(QDict, visitor_get(data)); g_assert(qdict); - qnum = qobject_to_qnum(qdict_get(qdict, "integer")); + qnum = qobject_to(QNum, qdict_get(qdict, "integer")); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, -42); - qbool = qobject_to_qbool(qdict_get(qdict, "boolean")); + 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")); + qstring = qobject_to(QString, qdict_get(qdict, "string")); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo"); } @@ -382,7 +382,7 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data, tmp->u.value1.boolean = true; visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort); - qdict = qobject_to_qdict(visitor_get(data)); + qdict = qobject_to(QDict, visitor_get(data)); g_assert(qdict); g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1"); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str"); @@ -406,7 +406,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.i = 42; visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qnum = qobject_to_qnum(visitor_get(data)); + qnum = qobject_to(QNum, visitor_get(data)); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, ==, 42); @@ -419,7 +419,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.e = ENUM_ONE_VALUE1; visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qstr = qobject_to_qstring(visitor_get(data)); + qstr = qobject_to(QString, visitor_get(data)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), ==, "value1"); @@ -444,7 +444,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->u.udfu.u.value1.boolean = true; visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qdict = qobject_to_qdict(visitor_get(data)); + qdict = qobject_to(QDict, visitor_get(data)); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 4); g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 1); @@ -466,7 +466,7 @@ static void test_visitor_out_null(TestOutputVisitorData *data, visit_type_null(data->ov, "a", &null, &error_abort); visit_check_struct(data->ov, &error_abort); visit_end_struct(data->ov, NULL); - qdict = qobject_to_qdict(visitor_get(data)); + qdict = qobject_to(QDict, visitor_get(data)); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), ==, 1); nil = qdict_get(qdict, "a"); @@ -610,10 +610,10 @@ static void check_native_list(QObject *qobj, QList *qlist; int i; - qdict = qobject_to_qdict(qobj); + qdict = qobject_to(QDict, qobj); g_assert(qdict); g_assert(qdict_haskey(qdict, "data")); - qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data"))); + qlist = qlist_copy(qobject_to(QList, qdict_get(qdict, "data"))); switch (kind) { case USER_DEF_NATIVE_LIST_UNION_KIND_U8: @@ -627,7 +627,7 @@ static void check_native_list(QObject *qobj, tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qnum(tmp); + qvalue = qobject_to(QNum, tmp); g_assert(qnum_get_try_uint(qvalue, &val)); g_assert_cmpint(val, ==, i); qobject_decref(qlist_pop(qlist)); @@ -651,7 +651,7 @@ static void check_native_list(QObject *qobj, tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qnum(tmp); + qvalue = qobject_to(QNum, tmp); g_assert(qnum_get_try_int(qvalue, &val)); g_assert_cmpint(val, ==, i); qobject_decref(qlist_pop(qlist)); @@ -663,7 +663,7 @@ static void check_native_list(QObject *qobj, QBool *qvalue; tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qbool(tmp); + qvalue = qobject_to(QBool, tmp); g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0); qobject_decref(qlist_pop(qlist)); } @@ -675,7 +675,7 @@ static void check_native_list(QObject *qobj, gchar str[8]; tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qstring(tmp); + qvalue = qobject_to(QString, tmp); sprintf(str, "%d", i); g_assert_cmpstr(qstring_get_str(qvalue), ==, str); qobject_decref(qlist_pop(qlist)); @@ -690,7 +690,7 @@ static void check_native_list(QObject *qobj, tmp = qlist_peek(qlist); g_assert(tmp); - qvalue = qobject_to_qnum(tmp); + qvalue = qobject_to(QNum, tmp); g_string_printf(double_expected, "%.6f", (double)i / 3); g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue)); g_assert_cmpstr(double_actual->str, ==, double_expected->str); diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c index 495dd1e..02e4184 100644 --- a/tests/test-x86-cpuid-compat.c +++ b/tests/test-x86-cpuid-compat.c @@ -17,7 +17,7 @@ static char *get_cpu0_qom_path(void) g_assert(qdict_haskey(resp, "return")); ret = qdict_get_qlist(resp, "return"); - cpu0 = qobject_to_qdict(qlist_peek(ret)); + cpu0 = qobject_to(QDict, qlist_peek(ret)); path = g_strdup(qdict_get_str(cpu0, "qom_path")); QDECREF(resp); return path; @@ -38,7 +38,7 @@ static QObject *qom_get(const char *path, const char *prop) #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS static bool qom_get_bool(const char *path, const char *prop) { - QBool *value = qobject_to_qbool(qom_get(path, prop)); + QBool *value = qobject_to(QBool, qom_get(path, prop)); bool b = qbool_get_bool(value); QDECREF(value); @@ -61,7 +61,7 @@ static void test_cpuid_prop(const void *data) qtest_start(args->cmdline); path = get_cpu0_qom_path(); - value = qobject_to_qnum(qom_get(path, args->property)); + value = qobject_to(QNum, qom_get(path, args->property)); g_assert(qnum_get_try_int(value, &val)); g_assert_cmpint(val, ==, args->expected_value); qtest_end(); @@ -105,7 +105,7 @@ static uint32_t get_feature_word(QList *features, uint32_t eax, uint32_t ecx, const QListEntry *e; for (e = qlist_first(features); e; e = qlist_next(e)) { - QDict *w = qobject_to_qdict(qlist_entry_obj(e)); + QDict *w = qobject_to(QDict, qlist_entry_obj(e)); const char *rreg = qdict_get_str(w, "cpuid-register"); uint32_t reax = qdict_get_int(w, "cpuid-input-eax"); bool has_ecx = qdict_haskey(w, "cpuid-input-ecx"); @@ -116,8 +116,9 @@ static uint32_t get_feature_word(QList *features, uint32_t eax, uint32_t ecx, recx = qdict_get_int(w, "cpuid-input-ecx"); } if (eax == reax && (!has_ecx || ecx == recx) && !strcmp(rreg, reg)) { - g_assert(qnum_get_try_int(qobject_to_qnum(qdict_get(w, "features")), - &val)); + g_assert(qnum_get_try_int(qobject_to(QNum, + qdict_get(w, "features")), + &val)); return val; } } @@ -133,8 +134,8 @@ static void test_feature_flag(const void *data) qtest_start(args->cmdline); path = get_cpu0_qom_path(); - present = qobject_to_qlist(qom_get(path, "feature-words")); - filtered = qobject_to_qlist(qom_get(path, "filtered-features")); + present = qobject_to(QList, qom_get(path, "feature-words")); + filtered = qobject_to(QList, qom_get(path, "filtered-features")); value = get_feature_word(present, args->in_eax, args->in_ecx, args->reg); value |= get_feature_word(filtered, args->in_eax, args->in_ecx, args->reg); qtest_end(); |