From nobody Fri May 16 13:05:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 14986987502591.5003142919716765; Wed, 28 Jun 2017 18:12:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3457B81127; Thu, 29 Jun 2017 01:12:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD4D5757AF; Thu, 29 Jun 2017 01:12:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 06CD71853E2F; Thu, 29 Jun 2017 01:12:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T1CHjd014881 for ; Wed, 28 Jun 2017 21:12:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id F28CE8189A; Thu, 29 Jun 2017 01:12:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E78788138B for ; Thu, 29 Jun 2017 01:12:15 +0000 (UTC) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B60140F1B for ; Thu, 29 Jun 2017 01:12:08 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 137FE20B20; Wed, 28 Jun 2017 21:12:07 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Wed, 28 Jun 2017 21:12:07 -0400 Received: from devel-3rdparty.localdomain (89-70-103-23.dynamic.chello.pl [89.70.103.23]) by mail.messagingengine.com (Postfix) with ESMTPA id 5E5D72424E; Wed, 28 Jun 2017 21:12:06 -0400 (EDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3457B81127 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3457B81127 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RT5wUea/" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B60140F1B Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=marmarek@invisiblethingslab.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0B60140F1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:in-reply-to:message-id:mime-version :references:references:subject:to:x-me-sender:x-me-sender :x-sasl-enc:x-sasl-enc; s=fm1; bh=gvSyzLkXCdgVVBPeW+vDrNoxaNaqHf SIvc+4JZUWjz8=; b=RT5wUea/o7xqlZeUgA6gDrjn9BUj9v+AEg5AU984YLcJTh NV34J7MMh0hVl469/5xeS7cmmNg6XGRTLy8m9rShTytcRSC/AGJhbIERCkkIxDk0 4nhEAeQrqhvILBfOD97QoT28ox/C6o8DBq2gpFjUkMP2aWK/931BTshx7YCojv3N uQq4F8WYIzQ/geE+5ozYOidsNwCbhgTAiKZ3TgUr6tmWFbxrBIpOQ2fPRW0WSDOH CPBtKlv3frhKVOF2r3n6G2nKb/JYS4fBi1Lw9OjdrAEhVVaX8K/d2EpDXfj4DCjP 7gtIyUciObNJ40fDXMgCn9ie4rJukfvbKjY7Tlkg== X-ME-Sender: X-Sasl-enc: //36ZNv00y1WoOmADJUalj311WTlc8geaokxlLYHB8bW 1498698726 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: libvir-list@redhat.com Date: Thu, 29 Jun 2017 03:11:43 +0200 Message-Id: <867ed30d1527ee7b07da9ec2f181399f1f28466e.1498698613.git-series.marmarek@invisiblethingslab.com> In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 01:12:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 01:12:08 +0000 (UTC) for IP:'66.111.4.29' DOMAIN:'out5-smtp.messagingengine.com' HELO:'out5-smtp.messagingengine.com' FROM:'marmarek@invisiblethingslab.com' RCPT:'' X-RedHat-Spam-Score: -0.3 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW) 66.111.4.29 out5-smtp.messagingengine.com 66.111.4.29 out5-smtp.messagingengine.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] tests: check domain XML to libxl structures conversion 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 29 Jun 2017 01:12:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 libxl contains a method to dump libxl_domain_config in json format, which is really convenient for tests. Unfortunately it require libxl_ctx, which can be only created when running on Xen (wither in dom0 or domU). Because of this, skip the test in other cases. For now, have just two tests, including just-introduced CPUID handling, but this commit introduces a framework for further tests of src/libxl/libxl_conf.c file. --- tests/Makefile.am | 8 +- tests/libxlxmltest.c | 232 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 tests/libxlxmltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 19986dc..06c5c73 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -274,7 +274,7 @@ test_programs +=3D xml2sexprtest sexpr2xmltest \ endif WITH_XEN =20 if WITH_LIBXL -test_programs +=3D xlconfigtest +test_programs +=3D xlconfigtest libxlxmltest endif WITH_LIBXL =20 if WITH_QEMU @@ -528,9 +528,13 @@ libxl_LDADDS +=3D $(LDADDS) xlconfigtest_SOURCES =3D \ xlconfigtest.c testutilsxen.c testutilsxen.h \ testutils.c testutils.h +libxlxmltest_SOURCES =3D \ + libxlxmltest.c testutilsxen.c testutilsxen.h \ + testutils.c testutils.h xlconfigtest_LDADD =3D$(libxl_LDADDS) +libxlxmltest_LDADD =3D$(libxl_LDADDS) else ! WITH_LIBXL -EXTRA_DIST +=3D xlconfigtest.c +EXTRA_DIST +=3D xlconfigtest.c libxlxmltest.c endif ! WITH_LIBXL =20 QEMUMONITORTESTUTILS_SOURCES =3D \ diff --git a/tests/libxlxmltest.c b/tests/libxlxmltest.c new file mode 100644 index 0000000..7e11af4 --- /dev/null +++ b/tests/libxlxmltest.c @@ -0,0 +1,232 @@ +/* + * libxlxmltest.c: Test xl.cfg(5) <-> libxl_domain_config conversion + * + * Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc. + * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Author: Daniel P. Berrange + * Author: Kiarie Kahurani + * Author: Marek Marczykowski-G=C3=B3recki + * + */ + +#include + +#include +#include +#include +#ifdef WITH_YAJL2 +# define HAVE_YAJL_V2 1 +#endif +#include +#include + +#include "internal.h" +#include "datatypes.h" +#include "viralloc.h" +#include "virstring.h" +#include "testutils.h" +#include "testutilsxen.h" +#include "libxl/libxl_conf.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +static virCapsPtr caps; +static virDomainXMLOptionPtr xmlopt; +xentoollog_logger_stdiostream *logger; +libxl_ctx *ctx; + + +/* + * This function provides a mechanism to replace variables in test + * data files whose values are discovered at built time. + */ +static char * +testReplaceVarsXML(const char *xml) +{ + char *xmlcfgData; + char *replacedXML; + + if (virTestLoadFile(xml, &xmlcfgData) < 0) + return NULL; + + replacedXML =3D virStringReplace(xmlcfgData, "/LIBXL_FIRMWARE_DIR", + LIBXL_FIRMWARE_DIR); + + /* libxl driver checks for emulator existence */ + replacedXML =3D virStringReplace(xmlcfgData, "/usr/lib/xen/bin/qemu-sy= stem-i386", + "/bin/true"); + + VIR_FREE(xmlcfgData); + return replacedXML; +} + +/* + * Parses domXML to virDomainDef object, which is then converted to json + * config and compared with expected config. + */ +static int +testCompareParseXML(const char *json, const char *xml, bool replaceVars) +{ + char *gotjsonData =3D NULL; + virConfPtr conf =3D NULL; + virConnectPtr conn =3D NULL; + size_t wrote =3D 0; + int ret =3D -1; + virDomainDefPtr def =3D NULL; + char *replacedXML =3D NULL; + virPortAllocatorPtr reservedGraphicsPorts =3D NULL; + libxl_domain_config d_config; + yajl_gen gen =3D NULL; + + conn =3D virGetConnect(); + if (!conn) goto fail; + + if (replaceVars) { + if (!(replacedXML =3D testReplaceVarsXML(xml))) + goto fail; + if (!(def =3D virDomainDefParseString(replacedXML, caps, xmlopt, + NULL, VIR_DOMAIN_XML_INACTIVE)= )) + goto fail; + } else { + if (!(def =3D virDomainDefParseFile(xml, caps, xmlopt, + NULL, VIR_DOMAIN_XML_INACTIVE))) + goto fail; + } + + if (!(reservedGraphicsPorts =3D virPortAllocatorNew("VNC", + LIBXL_VNC_PORT_MIN, + LIBXL_VNC_PORT_MAX, + 0))) + goto fail; + + if (libxlBuildDomainConfig(reservedGraphicsPorts, + def, + NULL, /* channelDir, unused in current version */ + ctx, + caps, + &d_config)) + goto fail; + + if (!(gen =3D libxl_yajl_gen_alloc(NULL))) + goto fail; + + if (libxl_domain_config_gen_json(gen, &d_config) !=3D yajl_gen_status_= ok) + goto fail; + + if (yajl_gen_get_buf(gen, + (const unsigned char **)&gotjsonData, + &wrote) !=3D yajl_gen_status_ok) + goto fail; + + if (virTestCompareToFile(gotjsonData, json) < 0) + goto fail; + + ret =3D 0; + + fail: + VIR_FREE(replacedXML); + // yajl_gen_free handle also gotjsonData + if (gen) + yajl_gen_free(gen); + if (conf) + virConfFree(conf); + virObjectUnref(reservedGraphicsPorts); + virDomainDefFree(def); + virObjectUnref(conn); + + return ret; +} + +struct testInfo { + const char *name; + bool replaceVars; +}; + +static int +testCompareHelper(const void *data) +{ + int result =3D -1; + const struct testInfo *info =3D data; + char *xml =3D NULL; + char *json =3D NULL; + + if (virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml", + abs_srcdir, info->name) < 0 || + virAsprintf(&json, "%s/xlconfigdata/test-%s.json", + abs_srcdir, info->name) < 0) + goto cleanup; + + result =3D testCompareParseXML(json, xml, info->replaceVars); + + cleanup: + VIR_FREE(xml); + VIR_FREE(json); + + return result; +} + + +static int +mymain(void) +{ + int ret =3D 0; + + logger =3D xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); + if (!logger) + return EXIT_FAILURE; + + if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, (xentoollog_logger*)logger= )) + return EXIT_AM_SKIP; + + if (!(caps =3D testXLInitCaps())) + return EXIT_FAILURE; + + if (!(xmlopt =3D libxlCreateXMLConf())) + return EXIT_FAILURE; + +#define DO_TEST_PARSE(name, replace) \ + do { \ + struct testInfo info0 =3D { name, replace }; \ + if (virTestRun("Xen XML-2-json Parse " name, \ + testCompareHelper, &info0) < 0) \ + ret =3D -1; \ + } while (0) + +#define DO_TEST(name) \ + do { \ + DO_TEST_PARSE(name, false); \ + } while (0) + +#define DO_TEST_REPLACE_VARS(name) \ + do { \ + DO_TEST_PARSE(name, true); \ + } while (0) + + DO_TEST_REPLACE_VARS("fullvirt-ovmf"); + + DO_TEST("fullvirt-cpuid"); + + virObjectUnref(caps); + virObjectUnref(xmlopt); + libxl_ctx_free(ctx); + xtl_logger_destroy((xentoollog_logger*)logger); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) --=20 git-series 0.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list