@samitouri / QOSamiQemu / commits / f166b69598

tests/qtest/cdrom-test: replace HMP "info block" with QMP query-block

The test_cdrom_param() function uses qtest_hmp() to run "info block", which depends on the human-monitor-command QMP endpoint. Replace it with the QMP query-block command so the test works when HMP is disabled (-Dhmp=disabled). Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Denis V. Lunev <den@openvz.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-15-9227de146347@redhat.com>

Marc-André Lureau committed Aug 28, 2026 at 16:04 UTC f166b69598863cbe70599ea4fa36ced7d55ece58
1 file changed +24 -5
tests/qtest/cdrom-test.c
+24 -5
@@ -14,6 +14,7 @@
14 #include "libqtest.h"
15 #include "boot-sector.h"
16 #include "qobject/qdict.h"
17 +#include "qobject/qlist.h"
18
19 static char isoimage[] = "cdrom-boot-iso-XXXXXX";
20
@@ -92,17 +93,35 @@ cleanup:
93
94 /**
95 * Check that at least the -cdrom parameter is basically working, i.e. we can
95 - * see the filename of the ISO image in the output of "info block" afterwards
96 + * see the filename of the ISO image in the output of "query-block" afterwards
97 */
98 static void test_cdrom_param(gconstpointer data)
99 {
100 QTestState *qts;
100 - char *resp;
101 + QDict *response;
102 + QList *ret;
103 + QListEntry *entry;
104 + bool found = false;
105
106 qts = qtest_initf("-M %s -cdrom %s", (const char *)data, isoimage);
103 - resp = qtest_hmp(qts, "info block");
104 - g_assert(strstr(resp, isoimage) != 0);
105 - g_free(resp);
107 + response = qtest_qmp(qts, "{'execute': 'query-block'}");
108 + g_assert(response && qdict_haskey(response, "return"));
109 + ret = qdict_get_qlist(response, "return");
110 +
111 + QLIST_FOREACH_ENTRY(ret, entry) {
112 + QDict *entry_dict = qobject_to(QDict, entry->value);
113 + QDict *inserted = qdict_get_qdict(entry_dict, "inserted");
114 + if (inserted) {
115 + const char *file = qdict_get_str(inserted, "file");
116 + if (file && strstr(file, isoimage)) {
117 + found = true;
118 + break;
119 + }
120 + }
121 + }
122 +
123 + g_assert(found);
124 + qobject_unref(response);
125 qtest_quit(qts);
126 }
127