From: Paolo Bonzini Date: Wed, 7 Oct 2020 09:50:22 +0000 (-0400) Subject: qtest: check that drives are really appearing and disappearing X-Git-Tag: upstream/4.2.1~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab5f5176b549c19953f5c8c359af6894880ad46c;p=tools%2Fqemu-arm-static.git qtest: check that drives are really appearing and disappearing Git-commit: 9a613ddccce125e4cc3a4a23c294837c906440d6 References: bsc#1184574 Do not just trust the HMP commands to create and delete the drive, use query-block to check that this is actually the case. Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini Signed-off-by: Lin Ma --- diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c index 64c0fe242..de0dc6f5b 100644 --- a/tests/drive_del-test.c +++ b/tests/drive_del-test.c @@ -14,20 +14,49 @@ #include "libqtest.h" #include "libqos/virtio.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" + +static bool has_drive(QTestState *qts) +{ + QDict *response; + QList *ret; + QListEntry *entry; + bool found; + + response = qtest_qmp(qts, "{'execute': 'query-block'}"); + g_assert(response && qdict_haskey(response, "return")); + ret = qdict_get_qlist(response, "return"); + + found = false; + QLIST_FOREACH_ENTRY(ret, entry) { + QDict *entry_dict = qobject_to(QDict, entry->value); + if (!strcmp(qdict_get_str(entry_dict, "device"), "drive0")) { + found = true; + break; + } + } + + qobject_unref(response); + return found; +} static void drive_add(QTestState *qts) { char *resp = qtest_hmp(qts, "drive_add 0 if=none,id=drive0"); g_assert_cmpstr(resp, ==, "OK\r\n"); + g_assert(has_drive(qts)); g_free(resp); } static void drive_del(QTestState *qts) { - char *resp = qtest_hmp(qts, "drive_del drive0"); + char *resp; + g_assert(has_drive(qts)); + resp = qtest_hmp(qts, "drive_del drive0"); g_assert_cmpstr(resp, ==, ""); + g_assert(!has_drive(qts)); g_free(resp); } @@ -130,6 +159,7 @@ static void test_drive_del_device_del(void) */ drive_del(qts); device_del(qts); + g_assert(!has_drive(qts)); qtest_quit(qts); }