qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

tests/test-qmp-event: Use qobject_is_equal()

Locally defined helper qdict_cmp_simple() implements just enough of a
comparison to serve here. Replace it by qobject_is_equal(), which
implements all of it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20200317115459.31821-10-armbru@redhat.com>

+1 -65
+1 -65
tests/test-qmp-event.c
··· 28 28 QDict *expect; 29 29 } TestEventData; 30 30 31 - typedef struct QDictCmpData { 32 - QDict *expect; 33 - bool result; 34 - } QDictCmpData; 35 - 36 31 TestEventData *test_event_data; 37 32 static GMutex test_event_lock; 38 33 39 - /* Only compares bool, int, string */ 40 - static 41 - void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque) 42 - 43 - { 44 - QObject *obj2; 45 - QDictCmpData d_new, *d = opaque; 46 - int64_t val1, val2; 47 - 48 - if (!d->result) { 49 - return; 50 - } 51 - 52 - obj2 = qdict_get(d->expect, key); 53 - if (!obj2) { 54 - d->result = false; 55 - return; 56 - } 57 - 58 - if (qobject_type(obj1) != qobject_type(obj2)) { 59 - d->result = false; 60 - return; 61 - } 62 - 63 - switch (qobject_type(obj1)) { 64 - case QTYPE_QBOOL: 65 - d->result = (qbool_get_bool(qobject_to(QBool, obj1)) == 66 - qbool_get_bool(qobject_to(QBool, obj2))); 67 - return; 68 - case QTYPE_QNUM: 69 - g_assert(qnum_get_try_int(qobject_to(QNum, obj1), &val1)); 70 - g_assert(qnum_get_try_int(qobject_to(QNum, obj2), &val2)); 71 - d->result = val1 == val2; 72 - return; 73 - case QTYPE_QSTRING: 74 - d->result = g_strcmp0(qstring_get_str(qobject_to(QString, obj1)), 75 - qstring_get_str(qobject_to(QString, obj2))) == 0; 76 - return; 77 - case QTYPE_QDICT: 78 - d_new.expect = qobject_to(QDict, obj2); 79 - d_new.result = true; 80 - qdict_iter(qobject_to(QDict, obj1), qdict_cmp_do_simple, &d_new); 81 - d->result = d_new.result; 82 - return; 83 - default: 84 - abort(); 85 - } 86 - } 87 - 88 - static bool qdict_cmp_simple(QDict *a, QDict *b) 89 - { 90 - QDictCmpData d; 91 - 92 - d.expect = b; 93 - d.result = true; 94 - qdict_iter(a, qdict_cmp_do_simple, &d); 95 - return d.result; 96 - } 97 - 98 34 void test_qapi_event_emit(test_QAPIEvent event, QDict *d) 99 35 { 100 36 QDict *t; ··· 115 51 116 52 qdict_del(d, "timestamp"); 117 53 118 - g_assert(qdict_cmp_simple(d, test_event_data->expect)); 54 + g_assert(qobject_is_equal(QOBJECT(d), QOBJECT(test_event_data->expect))); 119 55 120 56 } 121 57