[libvirt] [PATCH 17/26] cputest: Test CPU signatures

Ján Tomko jtomko at redhat.com
Thu Feb 28 16:29:15 UTC 2019


On Wed, Feb 27, 2019 at 02:29:07PM +0100, Jiri Denemark wrote:
>The signature computation code is not too complicated and it will likely
>never change so testing it is not very important. We do it mostly for a
>nice side effect of easily accessible signature numbers for all CPU
>data files.
>
>Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
>---
> tests/cputest.c                               | 92 +++++++++++++++++++
> tests/cputestdata/x86_64-cpuid-A10-5800K.sig  |  4 +

[ many diffstat, such files ]

> create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-W3520.sig
> create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-X5460.sig
>
>diff --git a/tests/cputest.c b/tests/cputest.c
>index 19caf41bf3..5b1bdc11c6 100644
>--- a/tests/cputest.c
>+++ b/tests/cputest.c
>@@ -32,6 +32,7 @@
> #include "testutils.h"
> #include "cpu_conf.h"
> #include "cpu/cpu.h"
>+#include "cpu/cpu_x86.h"
> #include "cpu/cpu_map.h"
> #include "virstring.h"
>
>@@ -642,6 +643,68 @@ cpuTestGuestCPUID(const void *arg)
> }
>
>
>+static int
>+cpuTestCompareSignature(const struct data *data,
>+                        virCPUDataPtr hostData)
>+{
>+    unsigned long signature;
>+    unsigned int family;
>+    unsigned int model;
>+    unsigned int stepping;
>+    char *result = NULL;
>+    char *sigStr = NULL;

Could have used VIR_AUTOFREE

>+    int ret = -1;
>+
>+    signature = virCPUx86DataGetSignature(hostData, &family, &model, &stepping);
>+
>+    if (virAsprintf(&result, "%s/cputestdata/%s-cpuid-%s.sig",
>+                    abs_srcdir, virArchToString(data->arch), data->host) < 0)
>+        goto cleanup;
>+
>+    if (virAsprintf(&sigStr,
>+                    "%1$06lx\n"
>+                    "family:   %2$2u (0x%2$02x)\n"
>+                    "model:    %3$2u (0x%3$02x)\n"
>+                    "stepping: %4$2u (0x%4$02x)\n",

$3u to nicely align numbers greater than 0x63

>+                    signature, family, model, stepping) < 0)
>+        goto cleanup;
>+
>+    ret = virTestCompareToFile(sigStr, result);
>+
>+ cleanup:
>+    VIR_FREE(result);
>+    VIR_FREE(sigStr);
>+    return ret;
>+}
>+
>+

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190228/427244a3/attachment-0001.sig>


More information about the libvir-list mailing list