libvirt/libvirt-qemuagenttest-Introduce-GetGuestDeviceInfo-test-case.patch
Jiri Denemark 0f2ee777b8 libvirt-11.10.0-18.el9
- qemu: Always assume support for 'QEMU_CAPS_SET_ACTION' (RHEL-242546)
- qemu: Remove unused 'qemuProcessRebootAllowed' (RHEL-242546)
- qemu: monitor: Remove support for 'watchdog-set-action' (RHEL-242546)
- qemu: Remove 'allowReboot' field (RHEL-242546)
- qemu: capabilities: Retire QEMU_CAPS_SET_ACTION (RHEL-242546)
- qemuProcessSetupLifecycleActions: Prepare to handle other actions (RHEL-242546)
- qemuDomainModifyLifecycleActionLive: Prepare to handle other actions (RHEL-242546)
- processGuestPanicEvent: Don't pass panic action via parameter (RHEL-242546)
- conf: Use proper enum types for 'onReboot', 'onPoweroff', 'onCrash', and 'onLockFailure' (RHEL-242546)
- qemuMonitorGuestPanicEventInfoFormatMsg: Directly return message (RHEL-242546)
- qemuProcessGuestPanicEventInfo: Fold into only caller (RHEL-242546)
- qemu: processGuestPanicEvent: Split individual steps under separate conditions (RHEL-242546)
- Add support for keeping VM running when panic notifier is used (RHEL-242546)
- qemu: Fix proper ordering of 'virtlockd' shutdown (RHEL-180876)
- Add guest device info to virDomainGetGuestInfo (RHEL-243300)
- qemu_agent: Introduce guest-get-devices (RHEL-243300)
- qemuagenttest: Introduce GetGuestDeviceInfo test case (RHEL-243300)
- qemu: Implement device info for virDomainGetGuestInfo() API (RHEL-243300)
- virsh: Add support for VIR_DOMAIN_GUEST_INFO_DEVICES (RHEL-243300)

Resolves: RHEL-180876, RHEL-242546, RHEL-243300
2026-08-19 15:04:03 +02:00

165 lines
5.2 KiB
Diff

From bab073ee5a84722b4f49b5f66d5a5bef0eee4858 Mon Sep 17 00:00:00 2001
Message-ID: <bab073ee5a84722b4f49b5f66d5a5bef0eee4858.1787144643.git.jdenemar@redhat.com>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Wed, 12 Aug 2026 14:08:37 +0200
Subject: [PATCH] qemuagenttest: Introduce GetGuestDeviceInfo test case
Introduce a test case for newly introduced
qemuAgentGetGuestDeviceInfo(). The expected data started as a
genuine reply from a qemu-ga running inside a Windows VM. But
then was modified to cover more cases (like an optional key
missing).
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit c56a2479ab59167af6cc9094981ef6e1c0a83a01)
Resolves: https://redhat.atlassian.net/browse/RHEL-243300
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
tests/qemuagenttest.c | 123 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 123 insertions(+)
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index 9c64ed3c5f..612ecb976b 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -1394,6 +1394,128 @@ testQemuAgentGetLoadAvg(const void *data)
}
+static const char *testQemuAgentGetGuestDeviceInfoResponse =
+"{"
+" \"return\": ["
+" {"
+" \"driver-date\": 1736726400000000000,"
+" \"driver-name\": \"Red Hat VirtIO Ethernet Adapter\","
+" \"driver-version\": \"100.100.104.27100\","
+" \"id\": {"
+" \"device-id\": 4161,"
+" \"vendor-id\": 6900,"
+" \"type\": \"pci\""
+" }"
+" },"
+" {"
+" \"driver-name\": \"VirtIO Serial Driver\","
+" \"driver-version\": \"100.100.104.27100\","
+" \"id\": {"
+" \"device-id\": 4163,"
+" \"vendor-id\": 6900,"
+" \"type\": \"pci\""
+" }"
+" },"
+" {"
+" \"driver-date\": 1736726400000000000,"
+" \"driver-name\": \"VirtIO Balloon Driver\","
+" \"id\": {"
+" \"device-id\": 4165,"
+" \"vendor-id\": 6900,"
+" \"type\": \"pci\""
+" }"
+" },"
+" {"
+" \"driver-date\": 1736726400000000000,"
+" \"driver-name\": \"Red Hat VirtIO GPU DOD controller\","
+" \"driver-version\": \"100.100.104.27100\""
+" }"
+" ]"
+"}";
+
+
+static int
+testQemuAgentGetGuestDeviceInfo(const void *data)
+{
+ virDomainXMLOption *xmlopt = (virDomainXMLOption *)data;
+ g_autoptr(qemuMonitorTest) test = qemuMonitorTestNewAgent(xmlopt);
+ qemuAgentGuestDeviceInfo **devices = NULL;
+ int ret = -1;
+ size_t i;
+ int ndevices;
+
+ if (!test)
+ return -1;
+
+ if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+ return -1;
+
+ if (qemuMonitorTestAddItem(test, "guest-get-devices",
+ testQemuAgentGetGuestDeviceInfoResponse) < 0)
+ return -1;
+
+ ndevices = qemuAgentGetGuestDeviceInfo(qemuMonitorTestGetAgent(test),
+ &devices, true);
+
+ if (ndevices < 0)
+ return -1;
+
+ if (ndevices != 4) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "unexpected number of guest devices returned (%d), expected 4",
+ ndevices);
+ goto cleanup;
+ }
+
+ if (STRNEQ(devices[0]->driverName, "Red Hat VirtIO Ethernet Adapter") ||
+ STRNEQ(devices[0]->driverVersion, "100.100.104.27100") ||
+ devices[0]->driverDate != 1736726400000000000LL ||
+ devices[0]->pci->vendorID != 6900 ||
+ devices[0]->pci->deviceID != 4161) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "unexpected device info returned for device #0");
+ goto cleanup;
+ }
+
+ if (STRNEQ(devices[1]->driverName, "VirtIO Serial Driver") ||
+ STRNEQ(devices[1]->driverVersion, "100.100.104.27100") ||
+ devices[1]->driverDate != -1LL ||
+ devices[1]->pci->vendorID != 6900 ||
+ devices[1]->pci->deviceID != 4163) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "unexpected device info returned for device #1");
+ goto cleanup;
+ }
+
+ if (STRNEQ(devices[2]->driverName, "VirtIO Balloon Driver") ||
+ devices[2]->driverVersion ||
+ devices[2]->driverDate != 1736726400000000000LL ||
+ devices[2]->pci->vendorID != 6900 ||
+ devices[2]->pci->deviceID != 4165) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "unexpected device info returned for device #2");
+ goto cleanup;
+ }
+
+ if (STRNEQ(devices[3]->driverName, "Red Hat VirtIO GPU DOD controller") ||
+ STRNEQ(devices[3]->driverVersion, "100.100.104.27100") ||
+ devices[3]->driverDate != 1736726400000000000LL ||
+ devices[3]->pci) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ "unexpected device info returned for device #3");
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ for (i = 0; i < ndevices; i++) {
+ qemuAgentGuestDeviceInfoFree(devices[i]);
+ }
+ g_free(devices);
+ return ret;
+}
+
+
static int
mymain(void)
{
@@ -1431,6 +1553,7 @@ mymain(void)
DO_TEST(SSHKeys);
DO_TEST(GetDisks);
DO_TEST(GetLoadAvg);
+ DO_TEST(GetGuestDeviceInfo);
DO_TEST(Timeout); /* Timeout should always be called last */
--
2.55.0