]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Add test validating that 'eventHandlers' are properly sorted
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Feb 2026 10:35:57 +0000 (11:35 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 12 Feb 2026 15:45:34 +0000 (16:45 +0100)
The monitor code uses 'bsearch' to look up the event handler so the
event names must be properly listed. Until now only a comment reminded
us to do it. Add a test to verify that it is actually sorted properly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 021995f5ccc8381b9cd343e96c3f7db14061675d..825508e8f5a211751474403f150448c46ffa5188 100644 (file)
@@ -143,6 +143,27 @@ qemuMonitorEventCompare(const void *key, const void *elt)
 }
 
 
+/**
+ * qemuMonitorJSONValidateEventHandlers:
+ *
+ * Used by 'qemumonitorjsontest' to validate that the 'eventHandlers' array
+ * is properly sorted to use 'bsearch'.
+ */
+char *
+qemuMonitorJSONValidateEventHandlers(void)
+{
+    size_t i;
+
+    for (i = 1; i < G_N_ELEMENTS(eventHandlers); i++) {
+        if (strcmp(eventHandlers[i-1].type, eventHandlers[i].type) > -1)
+            return g_strdup_printf("mis-ordered 'eventHandlers': '%s', '%s'",
+                                   eventHandlers[i-1].type, eventHandlers[i].type);
+    }
+
+    return NULL;
+}
+
+
 static int
 qemuMonitorJSONIOProcessEvent(qemuMonitor *mon,
                               virJSONValue *obj)
index db9160eb68ac3b7835ac02b0762e5c8db2e52634..8f5434d0dfa0b94cea25e6e3c8a87106fd71a695 100644 (file)
@@ -27,6 +27,9 @@
 #include "cpu/cpu.h"
 #include "util/virgic.h"
 
+char *
+qemuMonitorJSONValidateEventHandlers(void);
+
 int
 qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
                              const char *line,
index b3aca6a6c38147a348ae82a31c0503835a801abe..9c9b3397add1cce6e4f1fd2e8135dd53ba0e939f 100644 (file)
@@ -2825,6 +2825,20 @@ testQemuMonitorJSONGetGuestCPU(const void *opaque)
 }
 
 
+static int
+testEventHandlersOrdering(const void *opaque G_GNUC_UNUSED)
+{
+    g_autofree char *errmsg = NULL;
+
+    if ((errmsg = qemuMonitorJSONValidateEventHandlers())) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", errmsg);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 mymain(void)
 {
@@ -2848,6 +2862,10 @@ mymain(void)
 
     qapiData.schema = qapischema_x86_64;
 
+    if (virTestRun("'eventHandlers' ordering check", testEventHandlersOrdering,
+                   NULL) < 0)
+        ret = -1;
+
 #define DO_TEST(name) \
     do { \
         testGenericData data = { driver.xmlopt, qapiData.schema }; \