qemumonitortestutils: Store a string identifying test monitor entry

For each test monitor entry store an optional string which will allow to
identify it. This will be used later when checking that all registered
monitor commands were used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-04-23 16:52:12 +02:00
parent 0bb29de6ba
commit 0274e1b452
3 changed files with 23 additions and 5 deletions

View File

@ -471,7 +471,8 @@ testQemuAgentShutdown(const void *data)
priv.event = QEMU_AGENT_EVENT_SHUTDOWN;
priv.mode = "halt";
if (qemuMonitorTestAddHandler(test, qemuAgentShutdownTestMonitorHandler,
if (qemuMonitorTestAddHandler(test, "guest-shutdown",
qemuAgentShutdownTestMonitorHandler,
&priv, NULL) < 0)
goto cleanup;
@ -485,7 +486,8 @@ testQemuAgentShutdown(const void *data)
priv.event = QEMU_AGENT_EVENT_SHUTDOWN;
priv.mode = "powerdown";
if (qemuMonitorTestAddHandler(test, qemuAgentShutdownTestMonitorHandler,
if (qemuMonitorTestAddHandler(test, "guest-shutdown",
qemuAgentShutdownTestMonitorHandler,
&priv, NULL) < 0)
goto cleanup;
@ -499,7 +501,9 @@ testQemuAgentShutdown(const void *data)
priv.event = QEMU_AGENT_EVENT_RESET;
priv.mode = "reboot";
if (qemuMonitorTestAddHandler(test, qemuAgentShutdownTestMonitorHandler,
if (qemuMonitorTestAddHandler(test,
"guest-shutdown",
qemuAgentShutdownTestMonitorHandler,
&priv, NULL) < 0)
goto cleanup;
@ -720,7 +724,8 @@ testQemuAgentTimeout(const void *data)
goto cleanup;
}
if (qemuMonitorTestAddHandler(test, qemuAgentTimeoutTestMonitorHandler,
if (qemuMonitorTestAddHandler(test, NULL,
qemuAgentTimeoutTestMonitorHandler,
NULL, NULL) < 0)
goto cleanup;
@ -734,7 +739,9 @@ testQemuAgentTimeout(const void *data)
if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
goto cleanup;
if (qemuMonitorTestAddHandler(test, qemuAgentTimeoutTestMonitorHandler,
if (qemuMonitorTestAddHandler(test,
NULL,
qemuAgentTimeoutTestMonitorHandler,
NULL, NULL) < 0)
goto cleanup;

View File

@ -43,6 +43,7 @@
VIR_LOG_INIT("tests.qemumonitortestutils");
struct _qemuMonitorTestItem {
char *identifier;
qemuMonitorTestResponseCallback cb;
void *opaque;
virFreeCallback freecb;
@ -88,6 +89,8 @@ qemuMonitorTestItemFree(qemuMonitorTestItemPtr item)
if (!item)
return;
g_free(item->identifier);
if (item->freecb)
(item->freecb)(item->opaque);
@ -434,6 +437,7 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
int
qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
const char *identifier,
qemuMonitorTestResponseCallback cb,
void *opaque,
virFreeCallback freecb)
@ -443,6 +447,7 @@ qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
if (VIR_ALLOC(item) < 0)
goto error;
item->identifier = g_strdup(identifier);
item->cb = cb;
item->freecb = freecb;
item->opaque = opaque;
@ -615,6 +620,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
data->response = g_strdup(response);
return qemuMonitorTestAddHandler(test,
command_name,
qemuMonitorTestProcessCommandDefault,
data, qemuMonitorTestHandlerDataFree);
}
@ -698,6 +704,7 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test,
goto error;
return qemuMonitorTestAddHandler(test,
command,
qemuMonitorTestProcessCommandVerbatim,
data, qemuMonitorTestHandlerDataFree);
@ -764,6 +771,7 @@ qemuMonitorTestAddAgentSyncResponse(qemuMonitorTestPtr test)
}
return qemuMonitorTestAddHandler(test,
"agent-sync",
qemuMonitorTestProcessGuestAgentSync,
NULL, NULL);
}
@ -882,6 +890,7 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
va_end(args);
return qemuMonitorTestAddHandler(test,
cmdname,
qemuMonitorTestProcessCommandWithArgs,
data, qemuMonitorTestHandlerDataFree);
@ -986,6 +995,7 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
}
return qemuMonitorTestAddHandler(test,
cmdname,
qemuMonitorTestProcessCommandWithArgStr,
data, qemuMonitorTestHandlerDataFree);

View File

@ -34,6 +34,7 @@ typedef int (*qemuMonitorTestResponseCallback)(qemuMonitorTestPtr test,
const char *message);
int qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
const char *identifier,
qemuMonitorTestResponseCallback cb,
void *opaque,
virFreeCallback freecb);