From patchwork Fri Apr 8 17:48:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 65421 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp206067lbl; Fri, 8 Apr 2016 10:51:56 -0700 (PDT) X-Received: by 10.55.78.207 with SMTP id c198mr12823805qkb.34.1460137915807; Fri, 08 Apr 2016 10:51:55 -0700 (PDT) Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com. [209.132.183.37]) by mx.google.com with ESMTPS id 68si10718371qgi.22.2016.04.08.10.51.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 10:51:55 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 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 mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u38Hn9xi050021; Fri, 8 Apr 2016 13:49:09 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u38Hn4Ml013478 for ; Fri, 8 Apr 2016 13:49:04 -0400 Received: from colepc.redhat.com (ovpn-113-53.phx2.redhat.com [10.3.113.53]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u38Hn3Gh017562; Fri, 8 Apr 2016 13:49:04 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 8 Apr 2016 13:48:59 -0400 Message-Id: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] tests: Enable failure testing with CompareDomXML2XML 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 allows tests to check for specific failure scenarios --- tests/bhyvexml2xmltest.c | 4 ++-- tests/genericxml2xmltest.c | 4 ++-- tests/lxcxml2xmltest.c | 3 ++- tests/qemuxml2xmltest.c | 6 ++++-- tests/testutils.c | 47 ++++++++++++++++++++++++++++++++++------------ tests/testutils.h | 12 +++++++++++- 6 files changed, 56 insertions(+), 20 deletions(-) -- 2.5.5 -- 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 8f556ee..c8c6c6e 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -32,8 +32,8 @@ testCompareXMLToXMLHelper(const void *data) ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in, info->different ? xml_out : xml_in, - false, - NULL, NULL, 0); + false, NULL, NULL, 0, + TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); cleanup: VIR_FREE(xml_in); diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index bf9b11d..7d504db 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -39,8 +39,8 @@ testCompareXMLToXMLHelper(const void *data) ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, info->different ? xml_out : xml_in, - !info->inactive_only, - NULL, NULL, 0); + !info->inactive_only, NULL, NULL, 0, + TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 0b51340..fec0142 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -46,7 +46,8 @@ testCompareXMLToXMLHelper(const void *data) ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, info->different ? xml_out : xml_in, !info->inactive_only, - NULL, NULL, info->parse_flags); + NULL, NULL, info->parse_flags, + TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 0735677..b0f298c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -54,7 +54,8 @@ testXML2XMLActive(const void *opaque) return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName, info->outActiveName, true, - qemuXML2XMLPreFormatCallback, opaque, 0); + qemuXML2XMLPreFormatCallback, opaque, 0, + TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); } @@ -65,7 +66,8 @@ testXML2XMLInactive(const void *opaque) return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName, info->outInactiveName, false, - qemuXML2XMLPreFormatCallback, opaque, 0); + qemuXML2XMLPreFormatCallback, opaque, 0, + TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); } diff --git a/tests/testutils.c b/tests/testutils.c index fc4c339..a0ce4b6 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1079,10 +1079,12 @@ int testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, const char *infile, const char *outfile, bool live, testCompareDomXML2XMLPreFormatCallback cb, - const void *opaque, unsigned int parseFlags) + const void *opaque, unsigned int parseFlags, + testCompareDomXML2XMLResult expectResult) { char *actual = NULL; int ret = -1; + testCompareDomXML2XMLResult result; virDomainDefPtr def = NULL; unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; @@ -1092,25 +1094,46 @@ testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, if (!live) format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; - if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags))) - goto fail; + if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags))) { + result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE; + goto out; + } if (!virDomainDefCheckABIStability(def, def)) { VIR_TEST_DEBUG("ABI stability check failed on %s", infile); - goto fail; + result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_STABILITY; + goto out; } - if (cb && cb(def, opaque) < 0) - goto fail; + if (cb && cb(def, opaque) < 0) { + result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_CB; + goto out; + } - if (!(actual = virDomainDefFormat(def, caps, format_flags))) - goto fail; + if (!(actual = virDomainDefFormat(def, caps, format_flags))) { + result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT; + goto out; + } - if (virtTestCompareToFile(actual, outfile) < 0) - goto fail; + if (virtTestCompareToFile(actual, outfile) < 0) { + result = TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_COMPARE; + goto out; + } + + result = TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS; + out: + if (result == expectResult) { + ret = 0; + if (expectResult != TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS) { + VIR_TEST_DEBUG("Got expected failure code=%d msg=%s", + result, virGetLastErrorMessage()); + } + } else { + ret = -1; + VIR_TEST_DEBUG("Expected failure code=%d but received code=%d", + expectResult, result); + } - ret = 0; - fail: VIR_FREE(actual); virDomainDefFree(def); return ret; diff --git a/tests/testutils.h b/tests/testutils.h index 058be55..0417a0b 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -134,6 +134,15 @@ int virtTestMain(int argc, virCapsPtr virTestGenericCapsInit(void); virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void); +typedef enum { + TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_STABILITY, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_CB, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_COMPARE, +} testCompareDomXML2XMLResult; + typedef int (*testCompareDomXML2XMLPreFormatCallback)(virDomainDefPtr def, const void *opaque); int testCompareDomXML2XMLFiles(virCapsPtr caps, @@ -143,6 +152,7 @@ int testCompareDomXML2XMLFiles(virCapsPtr caps, bool live, testCompareDomXML2XMLPreFormatCallback cb, const void *opaque, - unsigned int parseFlags); + unsigned int parseFlags, + testCompareDomXML2XMLResult expectResult); #endif /* __VIR_TEST_UTILS_H__ */