From nobody Sun Feb 8 15:08:43 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 1489768635622172.26744574717702; Fri, 17 Mar 2017 09:37:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A1ED624C6; Fri, 17 Mar 2017 16:37:15 +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 548B951DF2; Fri, 17 Mar 2017 16:37:14 +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 02EB41853D14; Fri, 17 Mar 2017 16:37:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2HGb2OS007160 for ; Fri, 17 Mar 2017 12:37:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9AF71187A8; Fri, 17 Mar 2017 16:37:02 +0000 (UTC) Received: from mamuti.net (ovpn-204-109.brq.redhat.com [10.40.204.109]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FABD5C6C3 for ; Fri, 17 Mar 2017 16:37:02 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 5344F1061D0; Fri, 17 Mar 2017 17:36:55 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1A1ED624C6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 1A1ED624C6 From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 17 Mar 2017 17:36:52 +0100 Message-Id: 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.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/14] cputest: Add tests for virCPUUpdateLive API 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 17 Mar 2017 16:37:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The test takes x86-cpuid-Something-guest.xml CPU (the CPU libvirt would use for host-model on a CPU described by x86_64-cpuid-Something.xml without talking to QEMU about what it supports on the host) and updates it according to CPUID data from QEMU: x86_64-cpuid-Something-enabled.xml (reported as "feature-words" property of the CPU device) and x86_64-cpuid-Something-disabled.xml (reported as "filtered-features" property of the CPU device). The result is compared to x86_64-cpuid-Something-json.xml (the CPU libvirt would use as host-model based on the reply from query-cpu-model-expansion). The comparison is a bit tricky because the *-json.xml CPU contains fewer disabled features. Only the features which are included in the base CPU model, but listed as disabled in *.json will be disabled in *-json.xml. The CPU computed by virCPUUpdateLive from the test data will list all features present in the host's CPUID data and not enabled in *.json as disabled. The cpuTestUpdateLiveCompare function checks that the computed and expected sets of enabled features match. Signed-off-by: Jiri Denemark --- tests/cputest.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 149 insertions(+) diff --git a/tests/cputest.c b/tests/cputest.c index 4a4d427e1..2c64c2cd0 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -523,6 +523,151 @@ cpuTestGuestCPUID(const void *arg) } =20 =20 +static int +cpuTestUpdateLiveCompare(virArch arch, + virCPUDefPtr actual, + virCPUDefPtr expected) +{ + size_t i, j; + int ret =3D 0; + + if (virCPUExpandFeatures(arch, actual) < 0 || + virCPUExpandFeatures(arch, expected) < 0) + return -1; + + if (STRNEQ(actual->model, expected->model)) { + VIR_TEST_VERBOSE("Actual CPU model '%s', expected '%s'\n", + actual->model, expected->model); + return -1; + } + + i =3D j =3D 0; + while (i < actual->nfeatures || j < expected->nfeatures) { + virCPUFeatureDefPtr featAct =3D NULL; + virCPUFeatureDefPtr featExp =3D NULL; + int cmp; + + if (i < actual->nfeatures) + featAct =3D actual->features + i; + + if (j < expected->nfeatures) + featExp =3D expected->features + j; + + /* + * Act < Exp =3D> cmp < 0 (missing entry in Exp) + * Act =3D Exp =3D> cmp =3D 0 + * Act > Exp =3D> cmp > 0 (missing entry in Act) + * + * NULL > name for any name !=3D NULL + */ + if (featAct && featExp) + cmp =3D strcmp(featAct->name, featExp->name); + else + cmp =3D featExp ? 1 : -1; + + if (cmp <=3D 0) + i++; + if (cmp >=3D 0) + j++; + + /* Possible combinations of cmp, featAct->policy, and featExp->pol= icy: + * cmp Act Exp result + * --------------------------------- + * 0 dis dis ok + * 0 dis req missing + * 0 req dis extra + * 0 req req ok + * --------------------------------- + * - dis X ok # ignoring extra disabled feat= ures + * - req X extra + * --------------------------------- + * + X dis extra + * + X req missing + */ + if ((cmp =3D=3D 0 && + featAct->policy =3D=3D VIR_CPU_FEATURE_DISABLE && + featExp->policy =3D=3D VIR_CPU_FEATURE_REQUIRE) || + (cmp > 0 && + featExp->policy =3D=3D VIR_CPU_FEATURE_REQUIRE)) { + VIR_TEST_VERBOSE("Actual CPU lacks feature '%s'\n", + featExp->name); + ret =3D -1; + continue; + } + + if ((cmp =3D=3D 0 && + featAct->policy =3D=3D VIR_CPU_FEATURE_REQUIRE && + featExp->policy =3D=3D VIR_CPU_FEATURE_DISABLE) || + (cmp < 0 && + featAct->policy =3D=3D VIR_CPU_FEATURE_REQUIRE) || + (cmp > 0 && + featExp->policy =3D=3D VIR_CPU_FEATURE_DISABLE)) { + VIR_TEST_VERBOSE("Actual CPU has extra feature '%s'\n", + featAct->name); + ret =3D -1; + } + } + + return ret; +} + + +static int +cpuTestUpdateLive(const void *arg) +{ + const struct data *data =3D arg; + char *cpuFile =3D NULL; + virCPUDefPtr cpu =3D NULL; + char *enabledFile =3D NULL; + char *enabled =3D NULL; + virCPUDataPtr enabledData =3D NULL; + char *disabledFile =3D NULL; + char *disabled =3D NULL; + virCPUDataPtr disabledData =3D NULL; + char *expectedFile =3D NULL; + virCPUDefPtr expected =3D NULL; + int ret =3D -1; + + if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 || + !(cpu =3D cpuTestLoadXML(data->arch, cpuFile))) + goto cleanup; + + if (virAsprintf(&enabledFile, "%s/cputestdata/%s-cpuid-%s-enabled.xml", + abs_srcdir, virArchToString(data->arch), data->host) <= 0 || + virTestLoadFile(enabledFile, &enabled) < 0 || + !(enabledData =3D virCPUDataParse(enabled))) + goto cleanup; + + if (virAsprintf(&disabledFile, "%s/cputestdata/%s-cpuid-%s-disabled.xm= l", + abs_srcdir, virArchToString(data->arch), data->host) <= 0 || + virTestLoadFile(disabledFile, &disabled) < 0 || + !(disabledData =3D virCPUDataParse(disabled))) + goto cleanup; + + 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; + + ret =3D cpuTestUpdateLiveCompare(data->arch, cpu, expected); + + cleanup: + VIR_FREE(cpuFile); + virCPUDefFree(cpu); + VIR_FREE(enabledFile); + VIR_FREE(enabled); + virCPUDataFree(enabledData); + VIR_FREE(disabledFile); + VIR_FREE(disabled); + virCPUDataFree(disabledData); + VIR_FREE(expectedFile); + virCPUDefFree(expected); + return ret; +} + + #if WITH_QEMU && WITH_YAJL static int cpuTestJSONCPUID(const void *arg) @@ -697,6 +842,10 @@ mymain(void) DO_TEST(arch, cpuTestGuestCPUID, host, host, \ NULL, NULL, 0, 0, 0); \ DO_TEST_CPUID_JSON(arch, host, json); \ + if (json) { \ + DO_TEST(arch, cpuTestUpdateLive, host, host, \ + NULL, NULL, 0, 0, 0); \ + } \ } while (0) =20 /* host to host comparison */ --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list