From 0274e1b452666094c5a2475938056cd8a23b3f6d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 23 Apr 2020 16:52:12 +0200 Subject: [PATCH] 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 Reviewed-by: Michal Privoznik --- tests/qemuagenttest.c | 17 ++++++++++++----- tests/qemumonitortestutils.c | 10 ++++++++++ tests/qemumonitortestutils.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 943251df77..2c3a1efb09 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -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; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 3f827452fc..74b9cb5454 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -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); diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h index c693b626fc..384002d086 100644 --- a/tests/qemumonitortestutils.h +++ b/tests/qemumonitortestutils.h @@ -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); -- 2.47.2