Some tests need the monitor to operate on an already existing VM object rather than on a new mock-up the monitor test normally creates. --- tests/qemuhotplugtest.c | 2 +- tests/qemumonitorjsontest.c | 26 +++++++++++++------------- tests/qemumonitortestutils.c | 19 ++++++++++++++----- tests/qemumonitortestutils.h | 6 +++++- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index bb047fe..088a0f1 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -237,7 +237,7 @@ testQemuHotplug(const void *data) /* Now is the best time to feed the spoofed monitor with predefined * replies. */ - if (!(test_mon = qemuMonitorTestNew(true, driver.xmlopt))) + if (!(test_mon = qemuMonitorTestNew(true, driver.xmlopt, vm))) goto cleanup; tmp = test->mon; diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 9e66059..b287747 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -35,7 +35,7 @@ static int testQemuMonitorJSONGetStatus(const void *data) { virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; bool running = false; virDomainPausedReason reason = 0; @@ -129,7 +129,7 @@ static int testQemuMonitorJSONGetVersion(const void *data) { virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; int major; int minor; @@ -232,7 +232,7 @@ static int testQemuMonitorJSONGetMachines(const void *data) { virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; qemuMonitorMachineInfoPtr *info; int ninfo = 0; @@ -314,7 +314,7 @@ static int testQemuMonitorJSONGetCPUDefinitions(const void *data) { virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; char **cpus = NULL; int ncpus = 0; @@ -380,7 +380,7 @@ static int testQemuMonitorJSONGetCommands(const void *data) { virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; char **commands = NULL; int ncommands = 0; @@ -445,7 +445,7 @@ static int testQemuMonitorJSONGetTPMModels(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; char **tpmmodels = NULL; int ntpmmodels = 0; @@ -498,7 +498,7 @@ static int testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; char **params = NULL; int nparams = 0; @@ -599,7 +599,7 @@ static int testQemuMonitorJSONAttachChardev(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); virDomainChrSourceDef chr; int ret = 0; @@ -680,7 +680,7 @@ static int testQemuMonitorJSONDetachChardev(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; if (!test) @@ -713,7 +713,7 @@ static int testQemuMonitorJSONGetListPaths(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; qemuMonitorJSONListPathPtr *paths; int npaths = 0; @@ -791,7 +791,7 @@ static int testQemuMonitorJSONGetObjectProperty(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; qemuMonitorJSONObjectProperty prop; @@ -834,7 +834,7 @@ static int testQemuMonitorJSONSetObjectProperty(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; qemuMonitorJSONObjectProperty prop; @@ -886,7 +886,7 @@ static int testQemuMonitorJSONGetDeviceAliases(const void *data) { const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); int ret = -1; char **aliases = NULL; char **alias; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 93fb342..95c1b3d 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -743,6 +743,7 @@ static qemuAgentCallbacks qemuMonitorTestAgentCallbacks = { static qemuMonitorTestPtr qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, + virDomainObjPtr vm, virDomainChrSourceDefPtr src) { qemuMonitorTestPtr test = NULL; @@ -773,8 +774,14 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) goto error; - if (!(test->vm = virDomainObjNew(xmlopt))) - goto error; + if (vm) { + virObjectRef(vm); + test->vm = vm; + } else { + test->vm = virDomainObjNew(xmlopt); + if (!test->vm) + goto error; + } if (virNetSocketNewListenUNIX(path, 0700, getuid(), getgid(), &test->server) < 0) @@ -860,12 +867,14 @@ error: #define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information" qemuMonitorTestPtr -qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) +qemuMonitorTestNew(bool json, + virDomainXMLOptionPtr xmlopt, + virDomainObjPtr vm) { qemuMonitorTestPtr test = NULL; virDomainChrSourceDef src; - if (!(test = qemuMonitorCommonTestNew(xmlopt, &src))) + if (!(test = qemuMonitorCommonTestNew(xmlopt, vm, &src))) goto error; test->json = json; @@ -902,7 +911,7 @@ qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt) qemuMonitorTestPtr test = NULL; virDomainChrSourceDef src; - if (!(test = qemuMonitorCommonTestNew(xmlopt, &src))) + if (!(test = qemuMonitorCommonTestNew(xmlopt, NULL, &src))) goto error; if (!(test->agent = qemuAgentOpen(test->vm, diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h index 1122409..ccb5457 100644 --- a/tests/qemumonitortestutils.h +++ b/tests/qemumonitortestutils.h @@ -59,8 +59,12 @@ int qemuMonitorTestAddItemParams(qemuMonitorTestPtr test, ...) ATTRIBUTE_SENTINEL; +# define qemuMonitorTestNewSimple(json, xmlopt) \ + qemuMonitorTestNew(json, xmlopt, NULL) + qemuMonitorTestPtr qemuMonitorTestNew(bool json, - virDomainXMLOptionPtr xmlopt); + virDomainXMLOptionPtr xmlopt, + virDomainObjPtr vm); qemuMonitorTestPtr qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt); -- 1.8.3.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list