From: Peter Krempa Date: Wed, 31 Mar 2021 14:11:42 +0000 (+0200) Subject: qemuxml2argvtest: Rewrite parsing of XMLs to provide earlier parsing X-Git-Tag: v7.3.0-rc1~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75d18dbd032bff31456a5302f6c47faacebd9b8b;p=thirdparty%2Flibvirt.git qemuxml2argvtest: Rewrite parsing of XMLs to provide earlier parsing In upcoming patches we'll need to parse a certain bit of XML before calling the full XML parser. This effectively open-codes what virDomainDefParseFile to reach virDomainDefParseNode. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 15a14be1bb..60f833d1ac 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -645,6 +645,9 @@ testCompareXMLToArgv(const void *data) char *log = NULL; g_autoptr(virCommand) cmd = NULL; qemuDomainObjPrivatePtr priv = NULL; + g_autoptr(xmlDoc) xml = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; + xmlNodePtr root; if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64) qemuTestSetHostArch(&driver, info->arch); @@ -668,6 +671,21 @@ testCompareXMLToArgv(const void *data) if (testCheckExclusiveFlags(info->flags) < 0) goto cleanup; + if (!(xml = virXMLParse(info->infile, NULL, "(domain_definition)"))) + goto cleanup; + + root = xmlDocGetRootElement(xml); + if (!virXMLNodeNameEqual(root, "domain")) { + VIR_TEST_VERBOSE("unexpected root element <%s>, expecting ", + root->name); + goto cleanup; + } + + if (!(ctxt = virXMLXPathContextNew(xml))) + goto cleanup; + + ctxt->node = root; + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) goto cleanup; @@ -686,9 +704,9 @@ testCompareXMLToArgv(const void *data) } parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE; - if (!(vm->def = virDomainDefParseFile(info->infile, - driver.xmlopt, - NULL, parseFlags))) { + + if (!(vm->def = virDomainDefParseNode(xml, root, driver.xmlopt, NULL, + parseFlags))) { err = virGetLastError(); if (!err) { VIR_TEST_DEBUG("no error was reported for expected parse error");