From nobody Wed May 14 17:16:43 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15234578224681004.0737861474594; Wed, 11 Apr 2018 07:43:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C08C7D4EA; Wed, 11 Apr 2018 14:43:41 +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 F185A78BB0; Wed, 11 Apr 2018 14:43:40 +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 B7B13181BA1E; Wed, 11 Apr 2018 14:43:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3BEgHeZ008925 for ; Wed, 11 Apr 2018 10:42:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 54C0D10B0F38; Wed, 11 Apr 2018 14:42:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18C7710B0F39 for ; Wed, 11 Apr 2018 14:42:17 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 27030100B98; Wed, 11 Apr 2018 16:42:11 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Apr 2018 16:41:54 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 64/73] tests: Add tests for QEMU migration parameters 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 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 11 Apr 2018 14:43:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is an enhanced replacement for the original test from qemumonitorjsontest which was dropped earlier in this series. More data files with some real data will be added in the following patches. Signed-off-by: Jiri Denemark Reviewed-by: J=EF=BF=BDn Tomko --- tests/Makefile.am | 12 ++ tests/qemumigparamsdata/unsupported.json | 3 + tests/qemumigparamsdata/unsupported.reply | 7 + tests/qemumigparamsdata/unsupported.xml | 4 + tests/qemumigparamstest.c | 237 ++++++++++++++++++++++ 5 files changed, 263 insertions(+) create mode 100644 tests/qemumigparamsdata/unsupported.json create mode 100644 tests/qemumigparamsdata/unsupported.reply create mode 100644 tests/qemumigparamsdata/unsupported.xml create mode 100644 tests/qemumigparamstest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index a4f231d2a7..2c0d1311c2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -124,6 +124,7 @@ EXTRA_DIST =3D \ qemuhotplugtestcpus \ qemuhotplugtestdevices \ qemuhotplugtestdomains \ + qemumigparamsdata \ qemumonitorjsondata \ qemuxml2argvdata \ qemuxml2startupxmloutdata \ @@ -284,6 +285,7 @@ test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ qemumemlocktest \ qemucommandutiltest \ qemublocktest \ + qemumigparamstest \ $(NULL) test_helpers +=3D qemucapsprobe test_libraries +=3D libqemumonitortestutils.la \ @@ -670,6 +672,15 @@ qemumemlocktest_SOURCES =3D \ testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h qemumemlocktest_LDADD =3D $(qemu_LDADDS) $(LDADDS) + +qemumigparamstest_SOURCES =3D \ + qemumigparamstest.c \ + testutils.c testutils.h \ + testutilsqemu.c testutilsqemu.h \ + $(NULL) +qemumigparamstest_LDADD =3D libqemumonitortestutils.la \ + $(qemu_LDADDS) $(LDADDS) + else ! WITH_QEMU EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \ domainsnapshotxml2xmltest.c \ @@ -680,6 +691,7 @@ EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c qe= muargv2xmltest.c \ qemucaps2xmltest.c qemucommandutiltest.c \ qemumemlocktest.c qemucpumock.c testutilshostcpus.h \ qemublocktest.c \ + qemumigparamstest.c \ $(QEMUMONITORTESTUTILS_SOURCES) endif ! WITH_QEMU =20 diff --git a/tests/qemumigparamsdata/unsupported.json b/tests/qemumigparams= data/unsupported.json new file mode 100644 index 0000000000..0db3279e44 --- /dev/null +++ b/tests/qemumigparamsdata/unsupported.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/tests/qemumigparamsdata/unsupported.reply b/tests/qemumigparam= sdata/unsupported.reply new file mode 100644 index 0000000000..2b88ba10c3 --- /dev/null +++ b/tests/qemumigparamsdata/unsupported.reply @@ -0,0 +1,7 @@ +{ + "id": "libvirt-1", + "error": { + "class": "CommandNotFound", + "desc": "The command query-migrate-parameters has not been found" + } +} diff --git a/tests/qemumigparamsdata/unsupported.xml b/tests/qemumigparamsd= ata/unsupported.xml new file mode 100644 index 0000000000..8aa3abefc0 --- /dev/null +++ b/tests/qemumigparamsdata/unsupported.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c new file mode 100644 index 0000000000..4cc27bcf52 --- /dev/null +++ b/tests/qemumigparamstest.c @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2011-2013 Red Hat, Inc. + * + * 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 + * . + * + */ + +#include + +#include "virjson.h" +#include "virbuffer.h" +#include "virxml.h" +#include "testutils.h" +#include "testutilsqemu.h" +#include "qemumonitortestutils.h" +#include "qemu/qemu_migration_params.h" +#include "qemu/qemu_migration_paramspriv.h" +#include "qemu/qemu_monitor.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +typedef struct _qemuMigParamsData qemuMigParamsData; +struct _qemuMigParamsData { + virDomainXMLOptionPtr xmlopt; + const char *name; +}; + + +static void +qemuMigParamsTestFormatXML(virBufferPtr buf, + qemuMigrationParamsPtr migParams) +{ + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + if (migParams) + qemuMigrationParamsFormat(buf, migParams); + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); +} + + +static int +qemuMigParamsTestXML2XML(const void *opaque) +{ + const qemuMigParamsData *data =3D opaque; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *xmlFile =3D NULL; + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + qemuMigrationParamsPtr migParams =3D NULL; + char *actualXML =3D NULL; + int ret =3D -1; + + if (virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml", + abs_srcdir, data->name) < 0) + goto cleanup; + + if (!(doc =3D virXMLParseFileCtxt(xmlFile, &ctxt))) + goto cleanup; + + if (qemuMigrationParamsParse(ctxt, &migParams) < 0) + goto cleanup; + + qemuMigParamsTestFormatXML(&buf, migParams); + + if (!(actualXML =3D virBufferContentAndReset(&buf))) + goto cleanup; + + if (virTestCompareToFile(actualXML, xmlFile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(xmlFile); + VIR_FREE(actualXML); + qemuMigrationParamsFree(migParams); + virBufferFreeAndReset(&buf); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); + return ret; +} + + +static int +qemuMigParamsTestXML(const void *opaque) +{ + const qemuMigParamsData *data =3D opaque; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *replyFile =3D NULL; + char *xmlFile =3D NULL; + qemuMonitorTestPtr mon =3D NULL; + virJSONValuePtr params =3D NULL; + qemuMigrationParamsPtr migParams =3D NULL; + char *actualXML =3D NULL; + int ret =3D -1; + + if (virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply", + abs_srcdir, data->name) < 0 || + virAsprintf(&xmlFile, "%s/qemumigparamsdata/%s.xml", + abs_srcdir, data->name) < 0) + goto cleanup; + + if (!(mon =3D qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true= ))) + goto cleanup; + + if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon), + ¶ms) < 0) + goto cleanup; + + if (!(migParams =3D qemuMigrationParamsFromJSON(params))) + goto cleanup; + + qemuMigParamsTestFormatXML(&buf, migParams); + + if (!(actualXML =3D virBufferContentAndReset(&buf))) + goto cleanup; + + if (virTestCompareToFile(actualXML, xmlFile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(replyFile); + VIR_FREE(xmlFile); + VIR_FREE(actualXML); + virJSONValueFree(params); + qemuMigrationParamsFree(migParams); + virBufferFreeAndReset(&buf); + qemuMonitorTestFree(mon); + return ret; +} + + +static int +qemuMigParamsTestJSON(const void *opaque) +{ + const qemuMigParamsData *data =3D opaque; + char *replyFile =3D NULL; + char *jsonFile =3D NULL; + qemuMonitorTestPtr mon =3D NULL; + virJSONValuePtr paramsIn =3D NULL; + virJSONValuePtr paramsOut =3D NULL; + qemuMigrationParamsPtr migParams =3D NULL; + char *actualJSON =3D NULL; + int ret =3D -1; + + if (virAsprintf(&replyFile, "%s/qemumigparamsdata/%s.reply", + abs_srcdir, data->name) < 0 || + virAsprintf(&jsonFile, "%s/qemumigparamsdata/%s.json", + abs_srcdir, data->name) < 0) + goto cleanup; + + if (!(mon =3D qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true= ))) + goto cleanup; + + if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon), + ¶msIn) < 0) + goto cleanup; + + if (!(migParams =3D qemuMigrationParamsFromJSON(paramsIn))) + goto cleanup; + + if (!(paramsOut =3D qemuMigrationParamsToJSON(migParams)) || + !(actualJSON =3D virJSONValueToString(paramsOut, true))) + goto cleanup; + + if (virTestCompareToFile(actualJSON, jsonFile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(replyFile); + VIR_FREE(jsonFile); + VIR_FREE(actualJSON); + virJSONValueFree(paramsIn); + virJSONValueFree(paramsOut); + qemuMigrationParamsFree(migParams); + qemuMonitorTestFree(mon); + return ret; +} + + +static int +mymain(void) +{ + virQEMUDriver driver; + int ret =3D 0; + +#if !WITH_YAJL + fputs("libvirt not compiled with yajl, skipping this test\n", stderr); + return EXIT_AM_SKIP; +#endif + + if (virThreadInitialize() < 0 || + qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + virEventRegisterDefaultImpl(); + +#define DO_TEST(name) \ + do { \ + qemuMigParamsData data =3D { \ + driver.xmlopt, name \ + }; \ + if (virTestRun(name " (xml)", qemuMigParamsTestXML, &data) < 0) \ + ret =3D -1; \ + if (virTestRun(name " (json)", qemuMigParamsTestJSON, &data) < 0) \ + ret =3D -1; \ + if (virTestRun(name " (xml2xml)", qemuMigParamsTestXML2XML, &data)= < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST("unsupported"); + + qemuTestDriverFree(&driver); + + return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list