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 <jferlan@xxxxxxxxxx> Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- .../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/tests/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.expected 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 = -1; + virBuffer buf = VIR_BUFFER_INITIALIZER; char *actualData = NULL; virNodeInfo nodeinfo; FILE *cpuinfo; @@ -57,20 +58,35 @@ linuxTestCompareFiles(const char *cpuinfofile, } VIR_FORCE_FCLOSE(cpuinfo); - 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; + actualData = virBufferContentAndReset(&buf); + if (virTestCompareToFile(actualData, outputfile) < 0) goto fail; ret = 0; fail: + virBufferFreeAndReset(&buf); VIR_FREE(actualData); return ret; } -- 2.14.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list