From patchwork Sat Jan 9 00:13:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 59424 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp861036lbb; Fri, 8 Jan 2016 16:16:50 -0800 (PST) X-Received: by 10.194.6.196 with SMTP id d4mr122057710wja.120.1452298610117; Fri, 08 Jan 2016 16:16:50 -0800 (PST) Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id ay10si178399538wjc.212.2016.01.08.16.16.49 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 08 Jan 2016 16:16:50 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u090EGN0009284; Fri, 8 Jan 2016 19:14:17 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u090DVwQ002868 for ; Fri, 8 Jan 2016 19:13:31 -0500 Received: from colepc.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u090DSuC014481; Fri, 8 Jan 2016 19:13:30 -0500 From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 8 Jan 2016 19:13:22 -0500 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/6] tests: Share domain XML2XML compare helper X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com This creates a shared function in testutils.c that consolidates all the slightly different implementations. --- tests/bhyvexml2xmltest.c | 30 +++----------------------- tests/lxcxml2xmltest.c | 50 +++---------------------------------------- tests/qemuxml2xmltest.c | 55 ++++-------------------------------------------- tests/testutils.c | 34 ++++++++++++++++++++++++++++++ tests/testutils.h | 6 ++++++ 5 files changed, 50 insertions(+), 125 deletions(-) -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 826baea..d860a41 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -11,31 +11,6 @@ static bhyveConn driver; -static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml) -{ - char *actual = NULL; - virDomainDefPtr def = NULL; - int ret = -1; - - if (!(def = virDomainDefParseFile(inxml, driver.caps, driver.xmlopt, - VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; - - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE))) - goto fail; - - if (virtTestCompareToFile(actual, outxml) < 0) - goto fail; - - ret = 0; - - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - struct testInfo { const char *name; bool different; @@ -55,8 +30,9 @@ testCompareXMLToXMLHelper(const void *data) abs_srcdir, info->name) < 0) goto cleanup; - ret = testCompareXMLToXMLFiles(xml_in, - info->different ? xml_out : xml_in); + ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in, + info->different ? xml_out : xml_in, + false); cleanup: VIR_FREE(xml_in); diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 8d824b9..e460d0a 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -22,35 +22,6 @@ static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; -static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) -{ - char *actual = NULL; - int ret = -1; - virDomainDefPtr def = NULL; - - if (!(def = virDomainDefParseFile(inxml, caps, xmlopt, - live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; - - if (!virDomainDefCheckABIStability(def, def)) { - fprintf(stderr, "ABI stability check failed on %s", inxml); - goto fail; - } - - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) - goto fail; - - if (virtTestCompareToFile(actual, outxml) < 0) - goto fail; - - ret = 0; - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - struct testInfo { const char *name; int different; @@ -71,24 +42,9 @@ testCompareXMLToXMLHelper(const void *data) abs_srcdir, info->name) < 0) goto cleanup; - if (info->different) { - if (testCompareXMLToXMLFiles(xml_in, xml_out, false) < 0) - goto cleanup; - } else { - if (testCompareXMLToXMLFiles(xml_in, xml_in, false) < 0) - goto cleanup; - } - if (!info->inactive_only) { - if (info->different) { - if (testCompareXMLToXMLFiles(xml_in, xml_out, true) < 0) - goto cleanup; - } else { - if (testCompareXMLToXMLFiles(xml_in, xml_in, true) < 0) - goto cleanup; - } - } - - ret = 0; + ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, + info->different ? xml_out : xml_in, + !info->inactive_only); cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d654182..312bb53 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -40,56 +40,12 @@ struct testInfo { }; static int -testXML2XMLHelper(const char *inxml, - const char *inXmlData, - const char *outxml, - const char *outXmlData, - bool live) -{ - char *actual = NULL; - int ret = -1; - virDomainDefPtr def = NULL; - unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; - unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; - if (!live) - format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; - - if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt, - parse_flags))) - goto fail; - - if (!virDomainDefCheckABIStability(def, def)) { - VIR_TEST_DEBUG("ABI stability check failed on %s", inxml); - goto fail; - } - - if (!(actual = virDomainDefFormat(def, format_flags))) - goto fail; - - if (STRNEQ(outXmlData, actual)) { - virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); - goto fail; - } - - ret = 0; - - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - - -static int testXML2XMLActive(const void *opaque) { const struct testInfo *info = opaque; - return testXML2XMLHelper(info->inName, - info->inFile, - info->outActiveName, - info->outActiveFile, - true); + return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, + info->inName, info->outActiveName, true); } @@ -98,11 +54,8 @@ testXML2XMLInactive(const void *opaque) { const struct testInfo *info = opaque; - return testXML2XMLHelper(info->inName, - info->inFile, - info->outInactiveName, - info->outInactiveFile, - false); + return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName, + info->outInactiveName, false); } diff --git a/tests/testutils.c b/tests/testutils.c index 0091fcd..4ffea0c 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1072,6 +1072,40 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void) } +int +testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, + const char *infile, const char *outfile, bool live) +{ + char *actual = NULL; + int ret = -1; + virDomainDefPtr def = NULL; + unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; + if (!live) + format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; + + if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags))) + goto fail; + + if (!virDomainDefCheckABIStability(def, def)) { + VIR_TEST_DEBUG("ABI stability check failed on %s", infile); + goto fail; + } + + if (!(actual = virDomainDefFormat(def, format_flags))) + goto fail; + + if (virtTestCompareToFile(actual, outfile) < 0) + goto fail; + + ret = 0; + fail: + VIR_FREE(actual); + virDomainDefFree(def); + return ret; +} + + static int virtTestCounter; static char virtTestCounterStr[128]; static char *virtTestCounterPrefixEndOffset; diff --git a/tests/testutils.h b/tests/testutils.h index 3bd9004..b1d7397 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -137,4 +137,10 @@ int virtTestMain(int argc, virCapsPtr virTestGenericCapsInit(void); virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void); +int testCompareDomXML2XMLFiles(virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *inxml, + const char *outfile, + bool live); + #endif /* __VIT_TEST_UTILS_H__ */