The instrumentation for the monitor test can be hacked for qemu agent testing. Split out the monitor specific stuff to allow using the code in guest agent tests in the future. --- tests/qemumonitortestutils.c | 96 ++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 5ca569f..1785293 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -440,16 +440,11 @@ static qemuMonitorCallbacks qemuCallbacks = { }; -#define QEMU_JSON_GREETING "{\"QMP\": {\"version\": {\"qemu\": {\"micro\": 1, \"minor\": 0, \"major\": 1}, \"package\": \" (qemu-kvm-1.0.1)\"}, \"capabilities\": []}}" -/* We skip the normal handshake reply of "{\"execute\":\"qmp_capabilities\"}" */ - -#define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information" - -qemuMonitorTestPtr -qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) +static qemuMonitorTestPtr +qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, + virDomainChrSourceDefPtr src) { qemuMonitorTestPtr test = NULL; - virDomainChrSourceDef src; char *path = NULL; char *tmpdir_template = NULL; @@ -477,7 +472,6 @@ qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) goto error; - test->json = json; if (!(test->vm = virDomainObjNew(xmlopt))) goto error; @@ -485,29 +479,36 @@ qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) &test->server) < 0) goto error; - memset(&src, 0, sizeof(src)); - src.type = VIR_DOMAIN_CHR_TYPE_UNIX; - src.data.nix.path = (char *)path; - src.data.nix.listen = false; + memset(src, 0, sizeof(*src)); + src->type = VIR_DOMAIN_CHR_TYPE_UNIX; + src->data.nix.path = (char *)path; + src->data.nix.listen = false; if (virNetSocketListen(test->server, 1) < 0) goto error; - if (!(test->mon = qemuMonitorOpen(test->vm, - &src, - json, - &qemuCallbacks))) - goto error; - virObjectLock(test->mon); +cleanup: + return test; + +error: + VIR_FREE(tmpdir_template); + qemuMonitorTestFree(test); + test = NULL; + goto cleanup; + +} + + +static int +qemuMonitorCommonTestInit(qemuMonitorTestPtr test) +{ + if (!test) + return -1; if (virNetSocketAccept(test->server, &test->client) < 0) goto error; - if (!test->client) - goto error; - if (qemuMonitorTestAddReponse(test, json ? - QEMU_JSON_GREETING : - QEMU_TEXT_GREETING) < 0) + if (!test->client) goto error; if (virNetSocketAddIOCallback(test->client, @@ -528,17 +529,52 @@ qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) test->running = true; virMutexUnlock(&test->lock); -cleanup: - VIR_FREE(path); - return test; + return 0; error: - VIR_FREE(tmpdir_template); qemuMonitorTestFree(test); - test = NULL; - goto cleanup; + return -1; } +#define QEMU_JSON_GREETING "{\"QMP\": {\"version\": {\"qemu\": {\"micro\": 1, \"minor\": 0, \"major\": 1}, \"package\": \" (qemu-kvm-1.0.1)\"}, \"capabilities\": []}}" +/* We skip the normal handshake reply of "{\"execute\":\"qmp_capabilities\"}" */ + +#define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information" + +qemuMonitorTestPtr +qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) +{ + qemuMonitorTestPtr test = NULL; + virDomainChrSourceDef src; + + if (!(test = qemuMonitorCommonTestNew(xmlopt, &src))) + goto error; + + test->json = json; + if (!(test->mon = qemuMonitorOpen(test->vm, + &src, + json, + &qemuCallbacks))) + goto error; + + virObjectLock(test->mon); + + if (qemuMonitorTestAddReponse(test, json ? + QEMU_JSON_GREETING : + QEMU_TEXT_GREETING) < 0) + goto error; + + if (qemuMonitorCommonTestInit(test) < 0) + goto error; + + virDomainChrSourceDefClear(&src); + + return test; + +error: + qemuMonitorTestFree(test); + return NULL; +} qemuMonitorPtr qemuMonitorTestGetMonitor(qemuMonitorTestPtr test) -- 1.8.3.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list