From nobody Sat Apr 27 16:45:12 2024 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 1515420959445933.6319003777697; Mon, 8 Jan 2018 06:15:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68CA01F583; Mon, 8 Jan 2018 14:15:57 +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 5EBE75D964; Mon, 8 Jan 2018 14:15:56 +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 12A573FB1A; Mon, 8 Jan 2018 14:15:54 +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 w08EAZcw008697 for ; Mon, 8 Jan 2018 09:10:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id C59AE5D6A2; Mon, 8 Jan 2018 14:10:35 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.40.205.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A6F25D760 for ; Mon, 8 Jan 2018 14:10:32 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Mon, 8 Jan 2018 15:10:29 +0100 Message-Id: <20180108141029.3864-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] tests: Only format the CPU frequency if it's known 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 08 Jan 2018 14:15:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Instead of formatting 'MHz: 0', which can be confusing, skip the field altogether. This behavior is consistent with that of 'virsh nodeinfo'. Suggested-by: John Ferlan Signed-off-by: Andrea Bolognani --- .../linux-aarch64-f21-mustang.expected | 2 +- .../linux-aarch64-rhel74-moonshot.expected | 2 +- .../linux-aarch64-rhelsa-3.19.0-mustang.expected | 2 +- .../linux-armv6l-raspberrypi.expected | 2 +- tests/virhostcputest.c | 28 +++++++++++++++++-= ---- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/virhostcpudata/linux-aarch64-f21-mustang.expected b/test= s/virhostcpudata/linux-aarch64-f21-mustang.expected index ac950dc15..1ee3cf737 100644 --- a/tests/virhostcpudata/linux-aarch64-f21-mustang.expected +++ b/tests/virhostcpudata/linux-aarch64-f21-mustang.expected @@ -1 +1 @@ -CPUs: 8/8, MHz: 0, Nodes: 1, Sockets: 4, Cores: 2, Threads: 1 +CPUs: 8/8, Nodes: 1, Sockets: 4, Cores: 2, Threads: 1 diff --git a/tests/virhostcpudata/linux-aarch64-rhel74-moonshot.expected b/= tests/virhostcpudata/linux-aarch64-rhel74-moonshot.expected index 6776aa6c2..1926af836 100644 --- a/tests/virhostcpudata/linux-aarch64-rhel74-moonshot.expected +++ b/tests/virhostcpudata/linux-aarch64-rhel74-moonshot.expected @@ -1 +1 @@ -CPUs: 8/8, MHz: 0, Nodes: 1, Sockets: 1, Cores: 8, Threads: 1 +CPUs: 8/8, Nodes: 1, Sockets: 1, Cores: 8, Threads: 1 diff --git a/tests/virhostcpudata/linux-aarch64-rhelsa-3.19.0-mustang.expec= ted b/tests/virhostcpudata/linux-aarch64-rhelsa-3.19.0-mustang.expected index 6776aa6c2..1926af836 100644 --- a/tests/virhostcpudata/linux-aarch64-rhelsa-3.19.0-mustang.expected +++ b/tests/virhostcpudata/linux-aarch64-rhelsa-3.19.0-mustang.expected @@ -1 +1 @@ -CPUs: 8/8, MHz: 0, Nodes: 1, Sockets: 1, Cores: 8, Threads: 1 +CPUs: 8/8, Nodes: 1, Sockets: 1, Cores: 8, Threads: 1 diff --git a/tests/virhostcpudata/linux-armv6l-raspberrypi.expected b/tests= /virhostcpudata/linux-armv6l-raspberrypi.expected index 1c4c713d5..4961316fb 100644 --- a/tests/virhostcpudata/linux-armv6l-raspberrypi.expected +++ b/tests/virhostcpudata/linux-armv6l-raspberrypi.expected @@ -1 +1 @@ -CPUs: 1/1, MHz: 0, Nodes: 1, Sockets: 1, Cores: 1, Threads: 1 +CPUs: 1/1, Nodes: 1, Sockets: 1, Cores: 1, Threads: 1 diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index d3ee18461..9a1a48098 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -32,6 +32,7 @@ linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { int ret =3D -1; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *actualData =3D NULL; virNodeInfo nodeinfo; FILE *cpuinfo; @@ -57,20 +58,35 @@ linuxTestCompareFiles(const char *cpuinfofile, } VIR_FORCE_FCLOSE(cpuinfo); =20 - if (virAsprintf(&actualData, - "CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " - "Cores: %u, Threads: %u\n", - nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo), - nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets, - nodeinfo.cores, nodeinfo.threads) < 0) + virBufferAsprintf(&buf, + "CPUs: %u/%u, ", + nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo)); + + /* Only format the CPU frequency if it's known. This behavior is + * consistent with that of 'virsh nodeinfo' */ + if (nodeinfo.mhz) { + virBufferAsprintf(&buf, + "MHz: %u, ", + nodeinfo.mhz); + } + + virBufferAsprintf(&buf, + "Nodes: %u, Sockets: %u, Cores: %u, Threads: %u\n", + nodeinfo.nodes, nodeinfo.sockets, + nodeinfo.cores, nodeinfo.threads); + + if (virBufferError(&buf)) goto fail; =20 + actualData =3D virBufferContentAndReset(&buf); + if (virTestCompareToFile(actualData, outputfile) < 0) goto fail; =20 ret =3D 0; =20 fail: + virBufferFreeAndReset(&buf); VIR_FREE(actualData); return ret; } --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list