From nobody Wed Feb 11 10:38:19 2026 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 14915726901691021.7405460128174; Fri, 7 Apr 2017 06:44:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC74B6AAD0; Fri, 7 Apr 2017 13:44:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FEEAB145A; Fri, 7 Apr 2017 13:44:47 +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 4768A4BB74; Fri, 7 Apr 2017 13:44:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v37DiddC027170 for ; Fri, 7 Apr 2017 09:44:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2AEB1B11F3; Fri, 7 Apr 2017 13:44:39 +0000 (UTC) Received: from antique-work.brq.redhat.com (dhcp129-230.brq.redhat.com [10.34.129.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52B4B1218 for ; Fri, 7 Apr 2017 13:44:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BC74B6AAD0 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 BC74B6AAD0 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 7 Apr 2017 15:44:23 +0200 Message-Id: <2396148e9ea708c7dc6e7160adeffaed7473cae9.1491572622.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] tests/testutilsqemu: properly initialize qemu caps for tests 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Apr 2017 13:44:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This removes the hacky extern global variable and modifies the test code to properly create QEMU capabilities cache for QEMU binaries used in our tests. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_capabilities.c | 6 ------ tests/qemuhotplugtest.c | 11 ++++------- tests/qemuxml2argvtest.c | 7 +++---- tests/qemuxml2xmltest.c | 30 ++++++++++++++++-------------- tests/testutilsqemu.c | 36 +++++++++++++++++++----------------- tests/testutilsqemu.h | 5 +---- 6 files changed, 43 insertions(+), 52 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 11fe3e2d9d..2648d46619 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5209,8 +5209,6 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, } =20 =20 -const char *qemuTestCapsName; - virQEMUCapsPtr virQEMUCapsCacheLookup(virCapsPtr caps, virQEMUCapsCachePtr cache, @@ -5218,10 +5216,6 @@ virQEMUCapsCacheLookup(virCapsPtr caps, { virQEMUCapsPtr ret =3D NULL; =20 - /* This is used only by test suite!!! */ - if (qemuTestCapsName) - binary =3D qemuTestCapsName; - virMutexLock(&cache->lock); =20 ret =3D virHashLookup(cache->binaries, binary); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index e835999c72..fe97fd0dc3 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -58,7 +58,7 @@ static int qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virDomainObjPtr *vm, const char *domxml, - bool event, const char *testname) + bool event) { int ret =3D -1; qemuDomainObjPrivatePtr priv =3D NULL; @@ -79,8 +79,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, if (event) virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT); =20 - if (qemuTestCapsCacheInsert(driver.qemuCapsCache, testname, - priv->qemuCaps) < 0) + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0) goto cleanup; =20 if (!((*vm)->def =3D virDomainDefParseString(domxml, @@ -262,8 +261,7 @@ testQemuHotplug(const void *data) vm =3D test->vm; } else { if (qemuHotplugCreateObjects(driver.xmlopt, &vm, domain_xml, - test->deviceDeletedEvent, - test->domain_filename) < 0) + test->deviceDeletedEvent) < 0) goto cleanup; } =20 @@ -415,8 +413,7 @@ testQemuHotplugCpuPrepare(const char *test, if (virTestLoadFile(data->file_xml_dom, &data->xml_dom) < 0) goto error; =20 - if (qemuHotplugCreateObjects(driver.xmlopt, &data->vm, data->xml_dom, = true, - "cpu-hotplug-test-domain") < 0) + if (qemuHotplugCreateObjects(driver.xmlopt, &data->vm, data->xml_dom, = true) < 0) goto error; =20 if (!(caps =3D virQEMUDriverGetCapabilities(&driver, false))) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 18ff5ad147..525aa67e02 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -434,16 +434,15 @@ testCompareXMLToArgv(const void *data) if (virQEMUCapsGet(info->qemuCaps, QEMU_CAPS_ENABLE_FIPS)) flags |=3D FLAG_FIPS; =20 - if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->name, - info->qemuCaps) < 0) - goto cleanup; - if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml", abs_srcdir, info->name) < 0 || virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args", abs_srcdir, info->name) < 0) goto cleanup; =20 + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) + goto cleanup; + if (info->migrateFrom && !(migrateURI =3D qemuMigrationIncomingURI(info->migrateFrom, info->migrateFd))) diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 579328912a..e1ef9e5b86 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -251,25 +251,26 @@ testInfoSet(struct testInfo *info, int when, int gic) { + int ret =3D -1; + if (!(info->qemuCaps =3D virQEMUCapsNew())) - goto error; + goto cleanup; =20 if (testQemuCapsSetGIC(info->qemuCaps, gic) < 0) - goto error; + goto cleanup; =20 - if (qemuTestCapsCacheInsert(driver.qemuCapsCache, name, - info->qemuCaps) < 0) - goto error; + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) + goto cleanup; =20 if (virAsprintf(&info->inName, "%s/qemuxml2argvdata/qemuxml2argv-%s.xm= l", abs_srcdir, name) < 0) - goto error; + goto cleanup; =20 if (when & WHEN_INACTIVE) { if (virAsprintf(&info->outInactiveName, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s-inactive.= xml", abs_srcdir, name) < 0) - goto error; + goto cleanup; =20 if (!virFileExists(info->outInactiveName)) { VIR_FREE(info->outInactiveName); @@ -277,7 +278,7 @@ testInfoSet(struct testInfo *info, if (virAsprintf(&info->outInactiveName, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml", abs_srcdir, name) < 0) - goto error; + goto cleanup; } } =20 @@ -285,7 +286,7 @@ testInfoSet(struct testInfo *info, if (virAsprintf(&info->outActiveName, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s-active.xm= l", abs_srcdir, name) < 0) - goto error; + goto cleanup; =20 if (!virFileExists(info->outActiveName)) { VIR_FREE(info->outActiveName); @@ -293,15 +294,16 @@ testInfoSet(struct testInfo *info, if (virAsprintf(&info->outActiveName, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml", abs_srcdir, name) < 0) - goto error; + goto cleanup; } } =20 - return 0; + ret =3D 0; =20 - error: - testInfoFree(info); - return -1; + cleanup: + if (ret < 0) + testInfoFree(info); + return ret; } =20 =20 diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index d3d62df9d1..709e291bd4 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -586,34 +586,36 @@ void qemuTestDriverFree(virQEMUDriver *driver) virObjectUnref(driver->securityManager); } =20 -int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, const char *binary, +int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, virQEMUCapsPtr caps) { - int ret; + size_t i; + virQEMUCapsPtr tmpCaps; =20 if (caps) { - /* Our caps were created artificially, so we don't want - * virQEMUCapsCacheFree() to attempt to deallocate them */ - virObjectRef(caps); + tmpCaps =3D caps; } else { - caps =3D virQEMUCapsNew(); - if (!caps) + if (!(tmpCaps =3D virQEMUCapsNew())) return -ENOMEM; } =20 - /* We can have repeating names for our test data sets, - * so make sure there's no old copy */ - virHashRemoveEntry(cache->binaries, binary); + for (i =3D 0; i < ARRAY_CARDINALITY(QEMUBinList); i++) { + virObjectRef(tmpCaps); + if (virHashUpdateEntry(cache->binaries, + QEMUBinList[i], + tmpCaps) < 0) { + virObjectUnref(tmpCaps); + return -1; + } + } =20 - ret =3D virHashAddEntry(cache->binaries, binary, caps); - if (ret < 0) - virObjectUnref(caps); - else - qemuTestCapsName =3D binary; + if (!caps) + virObjectUnref(tmpCaps); =20 - return ret; + return 0; } =20 + # define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX" # define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX" =20 @@ -678,7 +680,7 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (!driver->xmlopt) goto error; =20 - if (qemuTestCapsCacheInsert(driver->qemuCapsCache, "empty", NULL) < 0) + if (qemuTestCapsCacheInsert(driver->qemuCapsCache, NULL) < 0) goto error; =20 if (!(mgr =3D virSecurityManagerNew("none", "qemu", diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 047a64d1ac..3393f5eb71 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -29,12 +29,9 @@ void qemuTestSetHostCPU(virCapsPtr caps, =20 int qemuTestDriverInit(virQEMUDriver *driver); void qemuTestDriverFree(virQEMUDriver *driver); -int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, const char *binary, +int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, virQEMUCapsPtr caps); =20 int testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps, int gic); - -/* This variable is actually defined in src/qemu/qemu_capabilities.c */ -extern const char *qemuTestCapsName; #endif --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list