From nobody Mon Dec 15 01:52:59 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 150792041648575.52029365466387; Fri, 13 Oct 2017 11:46:56 -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 742884A702; Fri, 13 Oct 2017 18:46:55 +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 50DCA5C462; Fri, 13 Oct 2017 18:46:55 +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 162F718355DB; Fri, 13 Oct 2017 18:46:55 +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 v9DIF5Oj014116 for ; Fri, 13 Oct 2017 14:15:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7AF15D6A6; Fri, 13 Oct 2017 18:15:05 +0000 (UTC) Received: from mamuti.net (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F1C35D6A8 for ; Fri, 13 Oct 2017 18:15:05 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 3CC4B1006F7; Fri, 13 Oct 2017 20:14:56 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 742884A702 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 13 Oct 2017 20:14:47 +0200 Message-Id: <86c355cf049e344cbacfaea762d151065a63092b.1507918308.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 15/22] cputest: Use CPU models from QEMU when available 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.38]); Fri, 13 Oct 2017 18:46:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When testing cpuDecode for computing guest CPU definition from CPUID data (the CPU definition reported by domain capabilities), we need to use CPU models (and their usability blockers) from QEMU if they are available to cpuDecode in the same way it is actually used in the qemu driver. Signed-off-by: Jiri Denemark Reviewed-by: John Ferlan --- Notes: Version 2: - dropped if (models) before virObjectRef() - virDomainCapsCPUModelsGet is used instead of virCPUModelIsAllowed, which means [PATCH 15/23] build: Export virCPUModelIsAllowed private = API from v1 can be dropped tests/cputest.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/tests/cputest.c b/tests/cputest.c index b72c17a168..9e1e20f83f 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -515,6 +515,36 @@ cpuTestMakeQEMUCaps(const struct data *data) qemuCaps =3D NULL; goto cleanup; } + + +static virDomainCapsCPUModelsPtr +cpuTestGetCPUModels(const struct data *data) +{ + virDomainCapsCPUModelsPtr models =3D NULL; + virQEMUCapsPtr qemuCaps; + + if (data->flags !=3D JSON_MODELS) + return NULL; + + if (!(qemuCaps =3D cpuTestMakeQEMUCaps(data))) + return NULL; + + models =3D virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM); + virObjectRef(models); + + virObjectUnref(qemuCaps); + + return models; +} + +#else /* if WITH_QEMU && WITH_YAJL */ + +static virDomainCapsCPUModelsPtr +cpuTestGetCPUModels(const struct data *data ATTRIBUTE_UNUSED) +{ + return NULL; +} + #endif =20 =20 @@ -528,6 +558,7 @@ cpuTestCPUID(bool guest, const void *arg) char *host =3D NULL; virCPUDefPtr cpu =3D NULL; char *result =3D NULL; + virDomainCapsCPUModelsPtr models =3D NULL; =20 if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir, virArchToString(data->arch), data->host) <= 0) @@ -549,7 +580,10 @@ cpuTestCPUID(bool guest, const void *arg) cpu->type =3D VIR_CPU_TYPE_HOST; } =20 - if (cpuDecode(cpu, hostData, NULL) < 0) + if (guest) + models =3D cpuTestGetCPUModels(data); + + if (cpuDecode(cpu, hostData, models) < 0) goto cleanup; =20 if (virAsprintf(&result, "cpuid-%s-%s", @@ -565,6 +599,7 @@ cpuTestCPUID(bool guest, const void *arg) virCPUDataFree(hostData); virCPUDefFree(cpu); VIR_FREE(result); + virObjectUnref(models); return ret; } =20 @@ -686,6 +721,8 @@ cpuTestUpdateLive(const void *arg) virCPUDataPtr disabledData =3D NULL; char *expectedFile =3D NULL; virCPUDefPtr expected =3D NULL; + virDomainCapsCPUModelsPtr hvModels =3D NULL; + virDomainCapsCPUModelsPtr models =3D NULL; int ret =3D -1; =20 if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 || @@ -704,13 +741,44 @@ cpuTestUpdateLive(const void *arg) !(disabledData =3D virCPUDataParse(disabled))) goto cleanup; =20 - if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0) - goto cleanup; - if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 || !(expected =3D cpuTestLoadXML(data->arch, expectedFile))) goto cleanup; =20 + /* In case the host CPU signature does not exactly match any CPU model= from + * cpu_map.xml, the CPU model we detect from CPUID may differ from the= one + * we compute by asking QEMU. Since this test expands both CPU models = and + * compares their features, we can try to translate the 'actual' CPU to + * use the CPU model from 'expected'. + */ + if (STRNEQ(cpu->model, expected->model)) { + virDomainCapsCPUModelPtr hvModel; + char **blockers =3D NULL; + virDomainCapsCPUUsable usable =3D VIR_DOMCAPS_CPU_USABLE_UNKNOWN; + + if (!(models =3D virDomainCapsCPUModelsNew(0))) + goto cleanup; + + hvModels =3D cpuTestGetCPUModels(data); + hvModel =3D virDomainCapsCPUModelsGet(hvModels, expected->model); + + if (hvModel) { + blockers =3D hvModel->blockers; + usable =3D hvModel->usable; + } + + if (virDomainCapsCPUModelsAdd(models, expected->model, -1, + usable, blockers) < 0) + goto cleanup; + + cpu->fallback =3D VIR_CPU_FALLBACK_ALLOW; + ignore_value(virCPUTranslate(data->arch, cpu, models)); + cpu->fallback =3D VIR_CPU_FALLBACK_FORBID; + } + + if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0) + goto cleanup; + ret =3D cpuTestUpdateLiveCompare(data->arch, cpu, expected); =20 cleanup: @@ -724,6 +792,8 @@ cpuTestUpdateLive(const void *arg) virCPUDataFree(disabledData); VIR_FREE(expectedFile); virCPUDefFree(expected); + virObjectUnref(hvModels); + virObjectUnref(models); return ret; } =20 @@ -915,11 +985,11 @@ mymain(void) DO_TEST(arch, cpuTestHostCPUID, host, host, \ NULL, NULL, 0, 0); \ DO_TEST(arch, cpuTestGuestCPUID, host, host, \ - NULL, NULL, 0, 0); \ + NULL, NULL, json, 0); \ DO_TEST_CPUID_JSON(arch, host, json); \ if (json !=3D JSON_NONE) { \ DO_TEST(arch, cpuTestUpdateLive, host, host, \ - NULL, NULL, 0, 0); \ + NULL, NULL, json, 0); \ } \ } while (0) =20 --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list