---
src/test/test_driver.c | 96 +++++++++++++++++++++-----------------------------
1 file changed, 41 insertions(+), 55 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 732dde9..c68b3d6 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -309,24 +309,6 @@ testDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED,
return -1;
}
-static virDomainXMLOptionPtr
-testBuildXMLConfig(void)
-{
- virDomainXMLPrivateDataCallbacks priv = {
- .alloc = testDomainObjPrivateAlloc,
- .free = testDomainObjPrivateFree
- };
-
- /* All our XML extensions are input only, so we only need to parse */
- virDomainXMLNamespace ns = {
- .parse = testDomainDefNamespaceParse,
- .free = testDomainDefNamespaceFree,
- };
-
- return virDomainXMLOptionNew(NULL, &priv, &ns);
-}
-
-
static virCapsPtr
testBuildCapabilities(virConnectPtr conn)
{
@@ -402,6 +384,45 @@ testBuildCapabilities(virConnectPtr conn)
}
+static testDriverPtr
+testDriverNew(void)
+{
+ virDomainXMLPrivateDataCallbacks priv = {
+ .alloc = testDomainObjPrivateAlloc,
+ .free = testDomainObjPrivateFree
+ };
+
+ virDomainXMLNamespace ns = {
+ .parse = testDomainDefNamespaceParse,
+ .free = testDomainDefNamespaceFree,
+ };
+ testDriverPtr ret;
+
+ if (VIR_ALLOC(ret) < 0)
+ return NULL;
+
+ if (virMutexInit(&ret->lock) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("cannot initialize mutex"));
+ goto error;
+ }
+
+ if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, &priv, &ns)) ||
+ !(ret->eventState = virObjectEventStateNew()) ||
+ !(ret->domains = virDomainObjListNew()) ||
+ !(ret->networks = virNetworkObjListNew()))
+ goto error;
+
+ ret->nextDomID = 1;
+
+ return ret;
+
+ error:
+ testDriverFree(ret);
+ return NULL;
+}
+
+
static const char *defaultDomainXML =
"<domain type='test'>"
" <name>test</name>"
@@ -730,24 +751,11 @@ testOpenDefault(virConnectPtr conn)
return VIR_DRV_OPEN_SUCCESS;
}
- if (VIR_ALLOC(privconn) < 0)
- goto error;
-
- if (virMutexInit(&privconn->lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot initialize mutex"));
+ if (!(privconn = testDriverNew()))
goto error;
- }
conn->privateData = privconn;
- if (!(privconn->eventState = virObjectEventStateNew()))
- goto error;
-
- if (!(privconn->domains = virDomainObjListNew()) ||
- !(privconn->networks = virNetworkObjListNew()))
- goto error;
-
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
/* Numa setup */
@@ -770,11 +778,6 @@ testOpenDefault(virConnectPtr conn)
if (!(privconn->caps = testBuildCapabilities(conn)))
goto error;
- if (!(privconn->xmlopt = testBuildXMLConfig()))
- goto error;
-
- privconn->nextDomID = 1;
-
if (!(domdef = virDomainDefParseString(defaultDomainXML,
privconn->caps,
privconn->xmlopt,
@@ -1412,31 +1415,15 @@ testOpenFromFile(virConnectPtr conn, const char *file)
xmlXPathContextPtr ctxt = NULL;
testDriverPtr privconn;
- if (VIR_ALLOC(privconn) < 0)
- return VIR_DRV_OPEN_ERROR;
- if (virMutexInit(&privconn->lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot initialize mutex"));
- VIR_FREE(privconn);
+ if (!(privconn = testDriverNew()))
return VIR_DRV_OPEN_ERROR;
- }
testDriverLock(privconn);
conn->privateData = privconn;
- if (!(privconn->domains = virDomainObjListNew()) ||
- !(privconn->networks = virNetworkObjListNew()))
- goto error;
-
if (!(privconn->caps = testBuildCapabilities(conn)))
goto error;
- if (!(privconn->xmlopt = testBuildXMLConfig()))
- goto error;
-
- if (!(privconn->eventState = virObjectEventStateNew()))
- goto error;
-
if (!(doc = virXMLParseFileCtxt(file, &ctxt)))
goto error;
@@ -1446,7 +1433,6 @@ testOpenFromFile(virConnectPtr conn, const char *file)
goto error;
}
- privconn->nextDomID = 1;
privconn->numCells = 0;
if (VIR_STRDUP(privconn->path, file) < 0)
goto error;
--
2.4.1