tests: Add support for passing vm to qemu monitor

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.
This commit is contained in:
Jiri Denemark 2013-07-25 19:17:44 +02:00
parent 2074574821
commit a950b4f91d
4 changed files with 33 additions and 20 deletions

View File

@ -242,7 +242,7 @@ testQemuHotplug(const void *data)
/* Now is the best time to feed the spoofed monitor with predefined /* Now is the best time to feed the spoofed monitor with predefined
* replies. */ * replies. */
if (!(test_mon = qemuMonitorTestNew(true, driver.xmlopt))) if (!(test_mon = qemuMonitorTestNew(true, driver.xmlopt, vm)))
goto cleanup; goto cleanup;
tmp = test->mon; tmp = test->mon;

View File

@ -35,7 +35,7 @@ static int
testQemuMonitorJSONGetStatus(const void *data) testQemuMonitorJSONGetStatus(const void *data)
{ {
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
bool running = false; bool running = false;
virDomainPausedReason reason = 0; virDomainPausedReason reason = 0;
@ -129,7 +129,7 @@ static int
testQemuMonitorJSONGetVersion(const void *data) testQemuMonitorJSONGetVersion(const void *data)
{ {
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
int major; int major;
int minor; int minor;
@ -232,7 +232,7 @@ static int
testQemuMonitorJSONGetMachines(const void *data) testQemuMonitorJSONGetMachines(const void *data)
{ {
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
qemuMonitorMachineInfoPtr *info; qemuMonitorMachineInfoPtr *info;
int ninfo = 0; int ninfo = 0;
@ -314,7 +314,7 @@ static int
testQemuMonitorJSONGetCPUDefinitions(const void *data) testQemuMonitorJSONGetCPUDefinitions(const void *data)
{ {
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
char **cpus = NULL; char **cpus = NULL;
int ncpus = 0; int ncpus = 0;
@ -380,7 +380,7 @@ static int
testQemuMonitorJSONGetCommands(const void *data) testQemuMonitorJSONGetCommands(const void *data)
{ {
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
char **commands = NULL; char **commands = NULL;
int ncommands = 0; int ncommands = 0;
@ -445,7 +445,7 @@ static int
testQemuMonitorJSONGetTPMModels(const void *data) testQemuMonitorJSONGetTPMModels(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
char **tpmmodels = NULL; char **tpmmodels = NULL;
int ntpmmodels = 0; int ntpmmodels = 0;
@ -498,7 +498,7 @@ static int
testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) testQemuMonitorJSONGetCommandLineOptionParameters(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
char **params = NULL; char **params = NULL;
int nparams = 0; int nparams = 0;
@ -599,7 +599,7 @@ static int
testQemuMonitorJSONAttachChardev(const void *data) testQemuMonitorJSONAttachChardev(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
virDomainChrSourceDef chr; virDomainChrSourceDef chr;
int ret = 0; int ret = 0;
@ -680,7 +680,7 @@ static int
testQemuMonitorJSONDetachChardev(const void *data) testQemuMonitorJSONDetachChardev(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
if (!test) if (!test)
@ -713,7 +713,7 @@ static int
testQemuMonitorJSONGetListPaths(const void *data) testQemuMonitorJSONGetListPaths(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
qemuMonitorJSONListPathPtr *paths; qemuMonitorJSONListPathPtr *paths;
int npaths = 0; int npaths = 0;
@ -791,7 +791,7 @@ static int
testQemuMonitorJSONGetObjectProperty(const void *data) testQemuMonitorJSONGetObjectProperty(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
qemuMonitorJSONObjectProperty prop; qemuMonitorJSONObjectProperty prop;
@ -834,7 +834,7 @@ static int
testQemuMonitorJSONSetObjectProperty(const void *data) testQemuMonitorJSONSetObjectProperty(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
qemuMonitorJSONObjectProperty prop; qemuMonitorJSONObjectProperty prop;
@ -886,7 +886,7 @@ static int
testQemuMonitorJSONGetDeviceAliases(const void *data) testQemuMonitorJSONGetDeviceAliases(const void *data)
{ {
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1; int ret = -1;
char **aliases = NULL; char **aliases = NULL;
char **alias; char **alias;

View File

@ -743,6 +743,7 @@ static qemuAgentCallbacks qemuMonitorTestAgentCallbacks = {
static qemuMonitorTestPtr static qemuMonitorTestPtr
qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
virDomainObjPtr vm,
virDomainChrSourceDefPtr src) virDomainChrSourceDefPtr src)
{ {
qemuMonitorTestPtr test = NULL; qemuMonitorTestPtr test = NULL;
@ -773,8 +774,14 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
goto error; goto error;
if (!(test->vm = virDomainObjNew(xmlopt))) if (vm) {
virObjectRef(vm);
test->vm = vm;
} else {
test->vm = virDomainObjNew(xmlopt);
if (!test->vm)
goto error; goto error;
}
if (virNetSocketNewListenUNIX(path, 0700, getuid(), getgid(), if (virNetSocketNewListenUNIX(path, 0700, getuid(), getgid(),
&test->server) < 0) &test->server) < 0)
@ -860,12 +867,14 @@ error:
#define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information" #define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information"
qemuMonitorTestPtr qemuMonitorTestPtr
qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) qemuMonitorTestNew(bool json,
virDomainXMLOptionPtr xmlopt,
virDomainObjPtr vm)
{ {
qemuMonitorTestPtr test = NULL; qemuMonitorTestPtr test = NULL;
virDomainChrSourceDef src; virDomainChrSourceDef src;
if (!(test = qemuMonitorCommonTestNew(xmlopt, &src))) if (!(test = qemuMonitorCommonTestNew(xmlopt, vm, &src)))
goto error; goto error;
test->json = json; test->json = json;
@ -902,7 +911,7 @@ qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt)
qemuMonitorTestPtr test = NULL; qemuMonitorTestPtr test = NULL;
virDomainChrSourceDef src; virDomainChrSourceDef src;
if (!(test = qemuMonitorCommonTestNew(xmlopt, &src))) if (!(test = qemuMonitorCommonTestNew(xmlopt, NULL, &src)))
goto error; goto error;
if (!(test->agent = qemuAgentOpen(test->vm, if (!(test->agent = qemuAgentOpen(test->vm,

View File

@ -59,8 +59,12 @@ int qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
...) ...)
ATTRIBUTE_SENTINEL; ATTRIBUTE_SENTINEL;
# define qemuMonitorTestNewSimple(json, xmlopt) \
qemuMonitorTestNew(json, xmlopt, NULL)
qemuMonitorTestPtr qemuMonitorTestNew(bool json, qemuMonitorTestPtr qemuMonitorTestNew(bool json,
virDomainXMLOptionPtr xmlopt); virDomainXMLOptionPtr xmlopt,
virDomainObjPtr vm);
qemuMonitorTestPtr qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt); qemuMonitorTestPtr qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt);