From nobody Sun Feb 8 23:06:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1641462425; cv=none; d=zohomail.com; s=zohoarc; b=A1z9eFuJ5eLMjVUyTwVIPPopqtQitTiv1U397l8YLD32Rq+oaj44afO4bomZqjjgRqzAZaoYWUBh2t6k+d730AxFLdSNwqY+FoH/WPytHqqADiDuLcu7EvJvlagd3NgYpTOP2c+3N7tWX09ak6Bc9EQ8ogwiuqW6IANUXZn/+1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641462425; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vFaMtMtzZRLWJBLleUE2/xjgmHpIx6bzFzWNZBS0th4=; b=TE4bCGVhAXcuemf/6Rs9QHmrwOk7Y7As5F6xoVsP8/qARsWDebYfAUhQ75qWjAszv1e/XPqX1rUkkr8RH/CwxcAgQvLjzfdLT6Sf+QQjix/Pck5uEMc3Ymk7aaScORn6tvZyR2wM7ZrsCBvETX/OUPtcLi96qByuYjSVqfB3A68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1641462425392682.013091032995; Thu, 6 Jan 2022 01:47:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-AoV8pPE4OYONvBqK_uZO5A-1; Thu, 06 Jan 2022 04:46:15 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB73A85EE86; Thu, 6 Jan 2022 09:46:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98A44106A026; Thu, 6 Jan 2022 09:46:10 +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 448044A7C9; Thu, 6 Jan 2022 09:46:10 +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 2069k73r005907 for ; Thu, 6 Jan 2022 04:46:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F1DD7CAD2; Thu, 6 Jan 2022 09:46:07 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3A1F7D474 for ; Thu, 6 Jan 2022 09:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641462424; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vFaMtMtzZRLWJBLleUE2/xjgmHpIx6bzFzWNZBS0th4=; b=hOAkgUlG0gii3c9CzE8ENV7e7FAhsvt3+pyOfvK/qzE54e+crq/hQ4EZ7XIWtF+D6A+vos UcHon6UDCVJArKnGigmx5bwYw1sIl5fZprj4sdsuZbEFBObswD2b9uqCFh8P3gs3I5GLze aaV/nQyGgxMCNUIa5oA1nZKDZz3OSCE= X-MC-Unique: AoV8pPE4OYONvBqK_uZO5A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 21/21] qemuTestCapsCacheInsert: Rewrite caps cache insertion Date: Thu, 6 Jan 2022 10:44:20 +0100 Message-Id: <2f3811b7039646992a4a7996fee99f395cd54546.1641461748.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1641462426673100003 Content-Type: text/plain; charset="utf-8" Until now we did 2 weird things when inserting the qemuCaps used for individual test cases into the capability cache: 1) we inserted the same caps for all emulators 2) we always (expensively) copied them Now when real capabilities are used we don't touch them at all just simply inser them. This allows us one big optimization, by trading a copy for just a virObjectRef as we can borrow the caps object to the cache. For fake caps we still copy them as we insert the fake machine types into them, but second big optimization is to insert the capabilities only for the architecture they belong to. Additionally this commit also ensures that all other entries in the cache for the binary are poisoned by empty caps so that it's obvious that the test is doing the right thing. Apart from this making actually more sense this shaves off more than 40% of runtime from qemuxml2argvtest. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/testutilsqemu.c | 85 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 15 deletions(-) diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 94ff538382..cb665e501b 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -385,30 +385,85 @@ qemuTestCapsPopulateFakeMachines(virQEMUCaps *caps, } +static int +qemuTestCapsCacheInsertData(virFileCache *cache, + const char *binary, + virQEMUCaps *caps) +{ + if (virFileCacheInsertData(cache, binary, virObjectRef(caps)) < 0) { + virObjectUnref(caps); + return -1; + } + + return 0; +} + + int qemuTestCapsCacheInsert(virFileCache *cache, virQEMUCaps *caps) { size_t i; - for (i =3D 0; i < G_N_ELEMENTS(qemu_emulators); i++) { - virQEMUCaps *tmpCaps; - if (qemu_emulators[i] =3D=3D NULL) - continue; - if (caps) { - tmpCaps =3D virQEMUCapsNewCopy(caps); - } else { - tmpCaps =3D virQEMUCapsNew(); - } + if (caps && virQEMUCapsGetArch(caps) !=3D VIR_ARCH_NONE) { + /* for capabilities which have architecture set we populate only t= he + * given architecture and poison all other so that the test doesn't + * accidentally test a weird combination */ + virArch arch =3D virQEMUCapsGetArch(caps); + g_autoptr(virQEMUCaps) emptyCaps =3D virQEMUCapsNew(); + g_autoptr(virQEMUCaps) copyCaps =3D NULL; + virQEMUCaps *effCaps =3D caps; - if (!tmpCaps) + if (!emptyCaps) return -1; - if (!virQEMUCapsHasMachines(tmpCaps)) - qemuTestCapsPopulateFakeMachines(tmpCaps, i); + if (arch_alias[arch] !=3D VIR_ARCH_NONE) + arch =3D arch_alias[arch]; - if (virFileCacheInsertData(cache, qemu_emulators[i], tmpCaps) < 0)= { - virObjectUnref(tmpCaps); - return -1; + if (qemu_emulators[arch]) { + /* if we are dealing with fake caps we need to populate machin= e types */ + if (!virQEMUCapsHasMachines(caps)) { + if (!(copyCaps =3D effCaps =3D virQEMUCapsNewCopy(caps))) + return -1; + + qemuTestCapsPopulateFakeMachines(copyCaps, arch); + } + + if (qemuTestCapsCacheInsertData(cache, qemu_emulators[arch], e= ffCaps) < 0) + return -1; + } + + + for (i =3D 0; i < G_N_ELEMENTS(qemu_emulators); i++) { + if (!qemu_emulators[i]) + continue; + + if (i =3D=3D arch) + continue; + + if (qemuTestCapsCacheInsertData(cache, qemu_emulators[i], empt= yCaps) < 0) + return -1; + } + } else { + /* in case when caps are missing or are missing architecture, we p= opulate + * everything */ + for (i =3D 0; i < G_N_ELEMENTS(qemu_emulators); i++) { + g_autoptr(virQEMUCaps) tmp =3D NULL; + + if (qemu_emulators[i] =3D=3D NULL) + continue; + + if (caps) + tmp =3D virQEMUCapsNewCopy(caps); + else + tmp =3D virQEMUCapsNew(); + + if (!tmp) + return -1; + + qemuTestCapsPopulateFakeMachines(tmp, i); + + if (qemuTestCapsCacheInsertData(cache, qemu_emulators[i], tmp)= < 0) + return -1; } } --=20 2.31.1