mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
qemu: monitor: Add test validating that 'eventHandlers' are properly sorted
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#include "cpu/cpu.h"
|
||||
#include "util/virgic.h"
|
||||
|
||||
char *
|
||||
qemuMonitorJSONValidateEventHandlers(void);
|
||||
|
||||
int
|
||||
qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
|
||||
const char *line,
|
||||
|
||||
@@ -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 }; \
|
||||
|
||||
Reference in New Issue
Block a user