2010-10-07 14:35:17 +00:00
|
|
|
/*
|
|
|
|
* cputest.c: Test the libvirtd internal CPU APIs
|
|
|
|
*
|
2014-09-03 19:39:21 +00:00
|
|
|
* Copyright (C) 2010-2014 Red Hat, Inc.
|
2010-10-07 14:35:17 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-10-07 14:35:17 +00:00
|
|
|
*
|
|
|
|
* Author: Jiri Denemark <jdenemar@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2010-10-07 14:35:17 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
#include "cpu_conf.h"
|
|
|
|
#include "cpu/cpu.h"
|
|
|
|
#include "cpu/cpu_map.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
# include "testutilsqemu.h"
|
|
|
|
# include "qemumonitortestutils.h"
|
2017-03-22 15:22:15 +00:00
|
|
|
# define __QEMU_CAPSPRIV_H_ALLOW__
|
2017-02-13 09:33:52 +00:00
|
|
|
# include "qemu/qemu_capspriv.h"
|
2017-03-22 15:22:15 +00:00
|
|
|
# undef __QEMU_CAPSPRIV_H_ALLOW__
|
2016-06-01 13:57:00 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
|
|
|
enum cpuTestBoolWithError {
|
|
|
|
FAIL = -1,
|
|
|
|
NO = 0,
|
|
|
|
YES = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct data {
|
2017-02-13 13:18:55 +00:00
|
|
|
virArch arch;
|
2010-10-07 14:35:17 +00:00
|
|
|
const char *host;
|
|
|
|
const char *name;
|
2017-09-22 13:51:33 +00:00
|
|
|
virDomainCapsCPUModelsPtr models;
|
2010-10-07 14:35:17 +00:00
|
|
|
const char *modelsName;
|
2013-08-02 19:08:19 +00:00
|
|
|
unsigned int flags;
|
2010-10-07 14:35:17 +00:00
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
static virQEMUDriver driver;
|
|
|
|
#endif
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
static virCPUDefPtr
|
2017-02-13 13:18:55 +00:00
|
|
|
cpuTestLoadXML(virArch arch, const char *name)
|
2010-10-07 14:35:17 +00:00
|
|
|
{
|
2011-04-24 22:25:10 +00:00
|
|
|
char *xml = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
|
2017-02-13 13:18:55 +00:00
|
|
|
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
|
|
|
|
abs_srcdir, virArchToString(arch), name) < 0)
|
2011-04-24 22:25:10 +00:00
|
|
|
goto cleanup;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2011-08-18 21:37:14 +00:00
|
|
|
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2010-10-07 14:35:17 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(xml);
|
2010-10-07 14:35:17 +00:00
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virCPUDefPtr *
|
2017-02-13 13:18:55 +00:00
|
|
|
cpuTestLoadMultiXML(virArch arch,
|
2010-10-07 14:35:17 +00:00
|
|
|
const char *name,
|
|
|
|
unsigned int *count)
|
|
|
|
{
|
2011-04-24 22:25:10 +00:00
|
|
|
char *xml = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
xmlDocPtr doc = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
virCPUDefPtr *cpus = NULL;
|
|
|
|
int n;
|
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2017-02-13 13:18:55 +00:00
|
|
|
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
|
|
|
|
abs_srcdir, virArchToString(arch), name) < 0)
|
2011-04-24 22:25:10 +00:00
|
|
|
goto cleanup;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2011-08-18 21:37:14 +00:00
|
|
|
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
|
2012-02-06 08:35:47 +00:00
|
|
|
goto cleanup;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
|
2015-03-23 16:19:28 +00:00
|
|
|
if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) {
|
|
|
|
fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml);
|
2012-02-06 08:35:47 +00:00
|
|
|
goto cleanup;
|
2015-03-23 16:19:28 +00:00
|
|
|
}
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
ctxt->node = nodes[i];
|
2017-05-23 07:29:36 +00:00
|
|
|
if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_HOST, &cpus[i]) < 0)
|
2012-02-06 08:35:47 +00:00
|
|
|
goto cleanup_cpus;
|
2010-10-07 14:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*count = n;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(nodes);
|
2010-10-07 14:35:17 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return cpus;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup_cpus:
|
2012-02-06 08:35:47 +00:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
virCPUDefFree(cpus[i]);
|
|
|
|
VIR_FREE(cpus);
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2017-02-13 13:18:55 +00:00
|
|
|
cpuTestCompareXML(virArch arch,
|
2013-10-05 01:40:19 +00:00
|
|
|
virCPUDef *cpu,
|
2017-06-30 13:47:23 +00:00
|
|
|
const char *name)
|
2010-10-07 14:35:17 +00:00
|
|
|
{
|
2011-04-24 22:25:10 +00:00
|
|
|
char *xml = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
char *actual = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
|
2017-02-13 13:18:55 +00:00
|
|
|
abs_srcdir, virArchToString(arch), name) < 0)
|
2011-04-24 22:25:10 +00:00
|
|
|
goto cleanup;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
if (!(actual = virCPUDefFormat(cpu, NULL)))
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actual, xml) < 0)
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(actual);
|
2010-10-07 14:35:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
cpuTestCompResStr(virCPUCompareResult result)
|
|
|
|
{
|
|
|
|
switch (result) {
|
|
|
|
case VIR_CPU_COMPARE_ERROR: return "ERROR";
|
|
|
|
case VIR_CPU_COMPARE_INCOMPATIBLE: return "INCOMPATIBLE";
|
|
|
|
case VIR_CPU_COMPARE_IDENTICAL: return "IDENTICAL";
|
|
|
|
case VIR_CPU_COMPARE_SUPERSET: return "SUPERSET";
|
2012-01-20 18:43:28 +00:00
|
|
|
case VIR_CPU_COMPARE_LAST: break;
|
2010-10-07 14:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
cpuTestBoolWithErrorStr(enum cpuTestBoolWithError result)
|
|
|
|
{
|
|
|
|
switch (result) {
|
|
|
|
case FAIL: return "FAIL";
|
|
|
|
case NO: return "NO";
|
|
|
|
case YES: return "YES";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestCompare(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
int ret = -1;
|
|
|
|
virCPUDefPtr host = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
virCPUCompareResult result;
|
|
|
|
|
|
|
|
if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
|
|
|
|
!(cpu = cpuTestLoadXML(data->arch, data->name)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-08-09 11:26:53 +00:00
|
|
|
result = virCPUCompare(host->arch, host, cpu, false);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->result == VIR_CPU_COMPARE_ERROR)
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (data->result != result) {
|
2015-04-23 17:38:00 +00:00
|
|
|
VIR_TEST_VERBOSE("\nExpected result %s, got %s\n",
|
2010-10-07 14:35:17 +00:00
|
|
|
cpuTestCompResStr(data->result),
|
|
|
|
cpuTestCompResStr(result));
|
2015-04-23 17:38:00 +00:00
|
|
|
/* Pad to line up with test name ... in virTestRun */
|
|
|
|
VIR_TEST_VERBOSE("%74s", "... ");
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefFree(host);
|
|
|
|
virCPUDefFree(cpu);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 08:41:17 +00:00
|
|
|
cpuTestGuestCPU(const void *arg)
|
2010-10-07 14:35:17 +00:00
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
2015-08-07 15:39:08 +00:00
|
|
|
int ret = -2;
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefPtr host = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
virCPUCompareResult cmpResult;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *result = NULL;
|
|
|
|
|
|
|
|
if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
|
|
|
|
!(cpu = cpuTestLoadXML(data->arch, data->name)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-09 16:09:48 +00:00
|
|
|
if (virCPUConvertLegacy(host->arch, cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 08:41:17 +00:00
|
|
|
cmpResult = virCPUCompare(host->arch, host, cpu, false);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (cmpResult == VIR_CPU_COMPARE_ERROR ||
|
2015-08-07 15:39:08 +00:00
|
|
|
cmpResult == VIR_CPU_COMPARE_INCOMPATIBLE) {
|
|
|
|
ret = -1;
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
2015-08-07 15:39:08 +00:00
|
|
|
}
|
2010-10-07 14:35:17 +00:00
|
|
|
|
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 08:41:17 +00:00
|
|
|
if (virCPUUpdate(host->arch, cpu, host) < 0 ||
|
2017-09-22 13:51:33 +00:00
|
|
|
virCPUTranslate(host->arch, cpu, data->models) < 0) {
|
2015-08-07 15:39:08 +00:00
|
|
|
ret = -1;
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "%s+%s", data->host, data->name);
|
2017-09-22 13:51:33 +00:00
|
|
|
if (data->modelsName)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s", data->modelsName);
|
2010-10-07 14:35:17 +00:00
|
|
|
virBufferAddLit(&buf, "-result");
|
|
|
|
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
result = virBufferContentAndReset(&buf);
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
if (cpuTestCompareXML(data->arch, cpu, result) < 0)
|
2015-08-07 15:39:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2010-10-07 14:35:17 +00:00
|
|
|
VIR_FREE(result);
|
|
|
|
virCPUDefFree(host);
|
|
|
|
virCPUDefFree(cpu);
|
2015-08-07 15:39:08 +00:00
|
|
|
|
|
|
|
if (ret == data->result) {
|
|
|
|
/* We got the result we expected, whether it was
|
|
|
|
* a success or a failure */
|
|
|
|
virResetLastError();
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
VIR_TEST_VERBOSE("\nExpected result %d, got %d\n",
|
|
|
|
data->result, ret);
|
|
|
|
/* Pad to line up with test name ... in virTestRun */
|
|
|
|
VIR_TEST_VERBOSE("%74s", "... ");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestBaseline(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
int ret = -1;
|
|
|
|
virCPUDefPtr *cpus = NULL;
|
|
|
|
virCPUDefPtr baseline = NULL;
|
|
|
|
unsigned int ncpus = 0;
|
2011-04-24 22:25:10 +00:00
|
|
|
char *result = NULL;
|
2014-01-27 23:00:44 +00:00
|
|
|
const char *suffix;
|
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-09-22 13:51:33 +00:00
|
|
|
baseline = cpuBaseline(cpus, ncpus, NULL,
|
2017-03-17 14:58:07 +00:00
|
|
|
!!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
|
2017-03-17 14:57:47 +00:00
|
|
|
|
|
|
|
if (baseline &&
|
|
|
|
(data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
|
|
|
|
virCPUExpandFeatures(data->arch, baseline) < 0) {
|
|
|
|
virCPUDefFree(baseline);
|
|
|
|
baseline = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->result < 0) {
|
|
|
|
virResetLastError();
|
2014-09-03 19:39:21 +00:00
|
|
|
if (!baseline) {
|
2010-10-07 14:35:17 +00:00
|
|
|
ret = 0;
|
2015-04-23 17:38:00 +00:00
|
|
|
} else {
|
|
|
|
VIR_TEST_VERBOSE("\n%-70s... ",
|
2010-10-07 14:35:17 +00:00
|
|
|
"cpuBaseline was expected to fail but it succeeded");
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (!baseline)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-01-27 23:00:44 +00:00
|
|
|
if (data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES)
|
|
|
|
suffix = "expanded";
|
2015-02-05 14:28:09 +00:00
|
|
|
else if (data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)
|
|
|
|
suffix = "migratable";
|
2014-01-27 23:00:44 +00:00
|
|
|
else
|
|
|
|
suffix = "result";
|
|
|
|
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
|
2011-04-24 22:25:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
if (cpuTestCompareXML(data->arch, baseline, result) < 0)
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < ncpus; i++) {
|
|
|
|
virCPUCompareResult cmp;
|
|
|
|
|
2016-08-09 11:26:53 +00:00
|
|
|
cmp = virCPUCompare(cpus[i]->arch, cpus[i], baseline, false);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (cmp != VIR_CPU_COMPARE_SUPERSET &&
|
|
|
|
cmp != VIR_CPU_COMPARE_IDENTICAL) {
|
2015-04-23 17:38:00 +00:00
|
|
|
VIR_TEST_VERBOSE("\nbaseline CPU is incompatible with CPU %zu\n",
|
|
|
|
i);
|
|
|
|
VIR_TEST_VERBOSE("%74s", "... ");
|
2010-10-07 14:35:17 +00:00
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2010-10-07 14:35:17 +00:00
|
|
|
if (cpus) {
|
|
|
|
for (i = 0; i < ncpus; i++)
|
|
|
|
virCPUDefFree(cpus[i]);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(cpus);
|
2010-10-07 14:35:17 +00:00
|
|
|
}
|
|
|
|
virCPUDefFree(baseline);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(result);
|
2010-10-07 14:35:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestUpdate(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
int ret = -1;
|
|
|
|
virCPUDefPtr host = NULL;
|
2017-03-29 13:31:17 +00:00
|
|
|
virCPUDefPtr migHost = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefPtr cpu = NULL;
|
2011-04-24 22:25:10 +00:00
|
|
|
char *result = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
|
|
|
|
!(cpu = cpuTestLoadXML(data->arch, data->name)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-29 13:31:17 +00:00
|
|
|
if (!(migHost = virCPUCopyMigratable(data->arch, host)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virCPUUpdate(host->arch, cpu, migHost) < 0)
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
ret = cpuTestCompareXML(data->arch, cpu, result);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefFree(host);
|
|
|
|
virCPUDefFree(cpu);
|
2017-03-29 13:31:17 +00:00
|
|
|
virCPUDefFree(migHost);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(result);
|
2010-10-07 14:35:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestHasFeature(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
int ret = -1;
|
|
|
|
virCPUDefPtr host = NULL;
|
2012-12-18 18:44:23 +00:00
|
|
|
virCPUDataPtr hostData = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
if (!(host = cpuTestLoadXML(data->arch, data->host)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (cpuEncode(host->arch, host, NULL, &hostData,
|
|
|
|
NULL, NULL, NULL, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-09-16 12:13:09 +00:00
|
|
|
result = virCPUCheckFeature(host->arch, host, data->name);
|
|
|
|
|
|
|
|
if (data->result == result)
|
|
|
|
result = virCPUDataCheckFeature(hostData, data->name);
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->result == -1)
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (data->result != result) {
|
2015-04-23 17:38:00 +00:00
|
|
|
VIR_TEST_VERBOSE("\nExpected result %s, got %s\n",
|
|
|
|
cpuTestBoolWithErrorStr(data->result),
|
|
|
|
cpuTestBoolWithErrorStr(result));
|
|
|
|
/* Pad to line up with test name ... in virTestRun */
|
|
|
|
VIR_TEST_VERBOSE("%74s", "... ");
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2017-02-02 14:37:40 +00:00
|
|
|
virCPUDataFree(hostData);
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefFree(host);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-27 09:58:23 +00:00
|
|
|
typedef enum {
|
|
|
|
JSON_NONE,
|
|
|
|
JSON_HOST,
|
|
|
|
JSON_MODELS,
|
|
|
|
} cpuTestCPUIDJson;
|
|
|
|
|
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
static virQEMUCapsPtr
|
|
|
|
cpuTestMakeQEMUCaps(const struct data *data)
|
|
|
|
{
|
|
|
|
virQEMUCapsPtr qemuCaps = NULL;
|
|
|
|
qemuMonitorTestPtr testMon = NULL;
|
|
|
|
qemuMonitorCPUModelInfoPtr model = NULL;
|
|
|
|
char *json = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json",
|
|
|
|
abs_srcdir, virArchToString(data->arch), data->host) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
|
|
|
|
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
|
|
|
|
"host", true, &model) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(qemuCaps = virQEMUCapsNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
|
|
|
|
if (data->flags == JSON_MODELS)
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS);
|
|
|
|
|
|
|
|
virQEMUCapsSetArch(qemuCaps, data->arch);
|
|
|
|
virQEMUCapsSetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM, model);
|
|
|
|
model = NULL;
|
|
|
|
|
|
|
|
if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps,
|
|
|
|
qemuMonitorTestGetMonitor(testMon),
|
|
|
|
false) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qemuMonitorCPUModelInfoFree(model);
|
|
|
|
qemuMonitorTestFree(testMon);
|
|
|
|
VIR_FREE(json);
|
|
|
|
|
|
|
|
return qemuCaps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(qemuCaps);
|
|
|
|
qemuCaps = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-09-27 07:29:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
static virDomainCapsCPUModelsPtr
|
|
|
|
cpuTestGetCPUModels(const struct data *data)
|
|
|
|
{
|
|
|
|
virDomainCapsCPUModelsPtr models = NULL;
|
|
|
|
virQEMUCapsPtr qemuCaps;
|
|
|
|
|
|
|
|
if (data->flags != JSON_MODELS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
models = 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;
|
|
|
|
}
|
|
|
|
|
2017-09-27 09:58:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
static int
|
2016-06-08 14:57:28 +00:00
|
|
|
cpuTestCPUID(bool guest, const void *arg)
|
2016-06-01 13:57:00 +00:00
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
int ret = -1;
|
|
|
|
virCPUDataPtr hostData = NULL;
|
|
|
|
char *hostFile = NULL;
|
|
|
|
char *host = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
char *result = NULL;
|
2017-09-27 07:29:28 +00:00
|
|
|
virDomainCapsCPUModelsPtr models = NULL;
|
2016-06-01 13:57:00 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml",
|
2017-02-13 13:18:55 +00:00
|
|
|
abs_srcdir, virArchToString(data->arch), data->host) < 0)
|
2016-06-01 13:57:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTestLoadFile(hostFile, &host) < 0 ||
|
2016-11-04 14:02:26 +00:00
|
|
|
!(hostData = virCPUDataParse(host)))
|
2016-06-01 13:57:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
cpu->arch = hostData->arch;
|
2016-06-08 14:57:28 +00:00
|
|
|
if (guest) {
|
2016-06-01 13:57:00 +00:00
|
|
|
cpu->type = VIR_CPU_TYPE_GUEST;
|
|
|
|
cpu->match = VIR_CPU_MATCH_EXACT;
|
|
|
|
cpu->fallback = VIR_CPU_FALLBACK_FORBID;
|
|
|
|
} else {
|
|
|
|
cpu->type = VIR_CPU_TYPE_HOST;
|
|
|
|
}
|
|
|
|
|
2017-09-27 07:29:28 +00:00
|
|
|
if (guest)
|
|
|
|
models = cpuTestGetCPUModels(data);
|
|
|
|
|
|
|
|
if (cpuDecode(cpu, hostData, models) < 0)
|
2016-06-01 13:57:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&result, "cpuid-%s-%s",
|
|
|
|
data->host,
|
2016-06-08 14:57:28 +00:00
|
|
|
guest ? "guest" : "host") < 0)
|
2016-06-01 13:57:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
ret = cpuTestCompareXML(data->arch, cpu, result);
|
2016-06-01 13:57:00 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(hostFile);
|
|
|
|
VIR_FREE(host);
|
2017-02-02 14:37:40 +00:00
|
|
|
virCPUDataFree(hostData);
|
2016-06-01 13:57:00 +00:00
|
|
|
virCPUDefFree(cpu);
|
|
|
|
VIR_FREE(result);
|
2017-09-27 07:29:28 +00:00
|
|
|
virObjectUnref(models);
|
2016-06-01 13:57:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-08 14:57:28 +00:00
|
|
|
static int
|
|
|
|
cpuTestHostCPUID(const void *arg)
|
|
|
|
{
|
|
|
|
return cpuTestCPUID(false, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestGuestCPUID(const void *arg)
|
|
|
|
{
|
|
|
|
return cpuTestCPUID(true, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-16 11:26:30 +00:00
|
|
|
static int
|
|
|
|
cpuTestUpdateLiveCompare(virArch arch,
|
|
|
|
virCPUDefPtr actual,
|
|
|
|
virCPUDefPtr expected)
|
|
|
|
{
|
|
|
|
size_t i, j;
|
|
|
|
int ret = 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 = j = 0;
|
|
|
|
while (i < actual->nfeatures || j < expected->nfeatures) {
|
|
|
|
virCPUFeatureDefPtr featAct = NULL;
|
|
|
|
virCPUFeatureDefPtr featExp = NULL;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
if (i < actual->nfeatures)
|
|
|
|
featAct = actual->features + i;
|
|
|
|
|
|
|
|
if (j < expected->nfeatures)
|
|
|
|
featExp = expected->features + j;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Act < Exp => cmp < 0 (missing entry in Exp)
|
|
|
|
* Act = Exp => cmp = 0
|
|
|
|
* Act > Exp => cmp > 0 (missing entry in Act)
|
|
|
|
*
|
|
|
|
* NULL > name for any name != NULL
|
|
|
|
*/
|
|
|
|
if (featAct && featExp)
|
|
|
|
cmp = strcmp(featAct->name, featExp->name);
|
|
|
|
else
|
|
|
|
cmp = featExp ? 1 : -1;
|
|
|
|
|
|
|
|
if (cmp <= 0)
|
|
|
|
i++;
|
|
|
|
if (cmp >= 0)
|
|
|
|
j++;
|
|
|
|
|
|
|
|
/* Possible combinations of cmp, featAct->policy, and featExp->policy:
|
|
|
|
* 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 features
|
|
|
|
* - req X extra
|
|
|
|
* ---------------------------------
|
|
|
|
* + X dis extra
|
|
|
|
* + X req missing
|
|
|
|
*/
|
|
|
|
if ((cmp == 0 &&
|
|
|
|
featAct->policy == VIR_CPU_FEATURE_DISABLE &&
|
|
|
|
featExp->policy == VIR_CPU_FEATURE_REQUIRE) ||
|
|
|
|
(cmp > 0 &&
|
|
|
|
featExp->policy == VIR_CPU_FEATURE_REQUIRE)) {
|
|
|
|
VIR_TEST_VERBOSE("Actual CPU lacks feature '%s'\n",
|
|
|
|
featExp->name);
|
|
|
|
ret = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmp == 0 &&
|
|
|
|
featAct->policy == VIR_CPU_FEATURE_REQUIRE &&
|
|
|
|
featExp->policy == VIR_CPU_FEATURE_DISABLE) ||
|
|
|
|
(cmp < 0 &&
|
|
|
|
featAct->policy == VIR_CPU_FEATURE_REQUIRE) ||
|
|
|
|
(cmp > 0 &&
|
|
|
|
featExp->policy == VIR_CPU_FEATURE_DISABLE)) {
|
|
|
|
VIR_TEST_VERBOSE("Actual CPU has extra feature '%s'\n",
|
2017-09-27 09:21:36 +00:00
|
|
|
cmp <= 0 ? featAct->name : featExp->name);
|
2017-03-16 11:26:30 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestUpdateLive(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
char *cpuFile = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
char *enabledFile = NULL;
|
|
|
|
char *enabled = NULL;
|
|
|
|
virCPUDataPtr enabledData = NULL;
|
|
|
|
char *disabledFile = NULL;
|
|
|
|
char *disabled = NULL;
|
|
|
|
virCPUDataPtr disabledData = NULL;
|
|
|
|
char *expectedFile = NULL;
|
|
|
|
virCPUDefPtr expected = NULL;
|
2017-09-27 07:29:28 +00:00
|
|
|
virDomainCapsCPUModelsPtr hvModels = NULL;
|
|
|
|
virDomainCapsCPUModelsPtr models = NULL;
|
2017-03-16 11:26:30 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (virAsprintf(&cpuFile, "cpuid-%s-guest", data->host) < 0 ||
|
|
|
|
!(cpu = 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 = virCPUDataParse(enabled)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&disabledFile, "%s/cputestdata/%s-cpuid-%s-disabled.xml",
|
|
|
|
abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
|
|
|
|
virTestLoadFile(disabledFile, &disabled) < 0 ||
|
|
|
|
!(disabledData = virCPUDataParse(disabled)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 ||
|
|
|
|
!(expected = cpuTestLoadXML(data->arch, expectedFile)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-09-27 07:29:28 +00:00
|
|
|
/* 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 = NULL;
|
|
|
|
virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
|
|
|
|
|
|
|
|
if (!(models = virDomainCapsCPUModelsNew(0)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
hvModels = cpuTestGetCPUModels(data);
|
|
|
|
hvModel = virDomainCapsCPUModelsGet(hvModels, expected->model);
|
|
|
|
|
|
|
|
if (hvModel) {
|
|
|
|
blockers = hvModel->blockers;
|
|
|
|
usable = hvModel->usable;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainCapsCPUModelsAdd(models, expected->model, -1,
|
|
|
|
usable, blockers) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
|
|
|
|
ignore_value(virCPUTranslate(data->arch, cpu, models));
|
|
|
|
cpu->fallback = VIR_CPU_FALLBACK_FORBID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-16 11:26:30 +00:00
|
|
|
ret = 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);
|
2017-09-27 07:29:28 +00:00
|
|
|
virObjectUnref(hvModels);
|
|
|
|
virObjectUnref(models);
|
2017-03-16 11:26:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
static int
|
|
|
|
cpuTestJSONCPUID(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
2017-02-13 09:33:52 +00:00
|
|
|
virQEMUCapsPtr qemuCaps = NULL;
|
2016-06-01 13:57:00 +00:00
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
char *result = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2017-09-27 09:58:23 +00:00
|
|
|
if (virAsprintf(&result, "cpuid-%s-json", data->host) < 0)
|
2016-06-01 13:57:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-09-27 09:58:23 +00:00
|
|
|
if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
|
2017-09-26 19:08:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
if (VIR_ALLOC(cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-02-13 09:33:52 +00:00
|
|
|
cpu->arch = data->arch;
|
2016-06-01 13:57:00 +00:00
|
|
|
cpu->type = VIR_CPU_TYPE_GUEST;
|
|
|
|
cpu->match = VIR_CPU_MATCH_EXACT;
|
|
|
|
cpu->fallback = VIR_CPU_FALLBACK_FORBID;
|
|
|
|
|
2017-03-29 11:33:50 +00:00
|
|
|
if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu, false) != 0)
|
2016-06-01 13:57:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
ret = cpuTestCompareXML(data->arch, cpu, result);
|
2016-06-01 13:57:00 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-02-13 09:33:52 +00:00
|
|
|
virObjectUnref(qemuCaps);
|
2016-06-01 13:57:00 +00:00
|
|
|
virCPUDefFree(cpu);
|
|
|
|
VIR_FREE(result);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-09-22 13:51:33 +00:00
|
|
|
static const char *model486_list[] = { "486", NULL };
|
|
|
|
static const char *nomodel_list[] = { "nomodel", NULL };
|
|
|
|
static const char *models_list[] = { "qemu64", "core2duo", "Nehalem", NULL };
|
|
|
|
static const char *haswell_list[] = { "SandyBridge", "Haswell", NULL };
|
|
|
|
static const char *ppc_models_list[] = { "POWER6", "POWER7", "POWER8", NULL };
|
|
|
|
|
|
|
|
static virDomainCapsCPUModelsPtr
|
|
|
|
cpuTestInitModels(const char **list)
|
|
|
|
{
|
|
|
|
virDomainCapsCPUModelsPtr cpus;
|
|
|
|
const char **model;
|
|
|
|
|
|
|
|
if (!(cpus = virDomainCapsCPUModelsNew(0)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (model = list; *model; model++) {
|
|
|
|
if (virDomainCapsCPUModelsAdd(cpus, *model, -1,
|
|
|
|
VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpus;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(cpus);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
static int
|
2011-04-29 16:21:20 +00:00
|
|
|
mymain(void)
|
2010-10-07 14:35:17 +00:00
|
|
|
{
|
2017-09-22 13:51:33 +00:00
|
|
|
virDomainCapsCPUModelsPtr model486 = NULL;
|
|
|
|
virDomainCapsCPUModelsPtr nomodel = NULL;
|
|
|
|
virDomainCapsCPUModelsPtr models = NULL;
|
|
|
|
virDomainCapsCPUModelsPtr haswell = NULL;
|
|
|
|
virDomainCapsCPUModelsPtr ppc_models = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
if (qemuTestDriverInit(&driver) < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
virEventRegisterDefaultImpl();
|
|
|
|
#endif
|
|
|
|
|
2017-09-22 13:51:33 +00:00
|
|
|
if (!(model486 = cpuTestInitModels(model486_list)) ||
|
|
|
|
!(nomodel = cpuTestInitModels(nomodel_list)) ||
|
|
|
|
!(models = cpuTestInitModels(models_list)) ||
|
|
|
|
!(haswell = cpuTestInitModels(haswell_list)) ||
|
|
|
|
!(ppc_models = cpuTestInitModels(ppc_models_list))) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
#define DO_TEST(arch, api, name, host, cpu, \
|
2017-09-22 13:51:33 +00:00
|
|
|
models, flags, result) \
|
2010-10-07 14:35:17 +00:00
|
|
|
do { \
|
2016-06-08 14:57:28 +00:00
|
|
|
struct data data = { \
|
|
|
|
arch, host, cpu, models, \
|
2010-10-07 14:35:17 +00:00
|
|
|
models == NULL ? NULL : #models, \
|
2017-09-22 13:51:33 +00:00
|
|
|
flags, result \
|
2010-10-07 14:35:17 +00:00
|
|
|
}; \
|
2016-06-08 14:57:28 +00:00
|
|
|
char *testLabel; \
|
|
|
|
char *tmp; \
|
|
|
|
\
|
|
|
|
tmp = virTestLogContentAndReset(); \
|
|
|
|
VIR_FREE(tmp); \
|
|
|
|
\
|
|
|
|
if (virAsprintf(&testLabel, "%s(%s): %s", \
|
2017-02-13 13:18:55 +00:00
|
|
|
#api, virArchToString(arch), name) < 0) { \
|
2010-10-07 14:35:17 +00:00
|
|
|
ret = -1; \
|
2016-06-08 14:57:28 +00:00
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (virTestRun(testLabel, api, &data) < 0) { \
|
|
|
|
if (virTestGetDebug()) { \
|
|
|
|
char *log; \
|
|
|
|
if ((log = virTestLogContentAndReset()) && \
|
|
|
|
strlen(log) > 0) \
|
|
|
|
VIR_TEST_DEBUG("\n%s\n", log); \
|
|
|
|
VIR_FREE(log); \
|
|
|
|
} \
|
|
|
|
ret = -1; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
VIR_FREE(testLabel); \
|
2010-10-07 14:35:17 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DO_TEST_COMPARE(arch, host, cpu, result) \
|
2016-06-08 14:57:28 +00:00
|
|
|
DO_TEST(arch, cpuTestCompare, \
|
2010-10-07 14:35:17 +00:00
|
|
|
host "/" cpu " (" #result ")", \
|
2017-09-22 13:51:33 +00:00
|
|
|
host, cpu, NULL, 0, result)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2016-06-23 13:27:07 +00:00
|
|
|
#define DO_TEST_UPDATE_ONLY(arch, host, cpu) \
|
|
|
|
DO_TEST(arch, cpuTestUpdate, \
|
|
|
|
cpu " on " host, \
|
2017-09-22 13:51:33 +00:00
|
|
|
host, cpu, NULL, 0, 0)
|
2016-06-23 13:27:07 +00:00
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
#define DO_TEST_UPDATE(arch, host, cpu, result) \
|
|
|
|
do { \
|
2016-06-23 13:27:07 +00:00
|
|
|
DO_TEST_UPDATE_ONLY(arch, host, cpu); \
|
2010-10-07 14:35:17 +00:00
|
|
|
DO_TEST_COMPARE(arch, host, host "+" cpu, result); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-08-02 19:08:19 +00:00
|
|
|
#define DO_TEST_BASELINE(arch, name, flags, result) \
|
2014-01-27 23:00:44 +00:00
|
|
|
do { \
|
|
|
|
const char *suffix = ""; \
|
|
|
|
char *label; \
|
|
|
|
if ((flags) & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) \
|
|
|
|
suffix = " (expanded)"; \
|
2015-02-05 14:28:09 +00:00
|
|
|
if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) \
|
|
|
|
suffix = " (migratable)"; \
|
2014-01-27 23:00:44 +00:00
|
|
|
if (virAsprintf(&label, "%s%s", name, suffix) < 0) { \
|
|
|
|
ret = -1; \
|
|
|
|
} else { \
|
2016-06-08 14:57:28 +00:00
|
|
|
DO_TEST(arch, cpuTestBaseline, label, NULL, \
|
2017-09-22 13:51:33 +00:00
|
|
|
"baseline-" name, NULL, flags, result); \
|
2014-01-27 23:00:44 +00:00
|
|
|
} \
|
|
|
|
VIR_FREE(label); \
|
|
|
|
} while (0)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
#define DO_TEST_HASFEATURE(arch, host, feature, result) \
|
2016-06-08 14:57:28 +00:00
|
|
|
DO_TEST(arch, cpuTestHasFeature, \
|
2010-10-07 14:35:17 +00:00
|
|
|
host "/" feature " (" #result ")", \
|
2017-09-22 13:51:33 +00:00
|
|
|
host, feature, NULL, 0, result)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 08:41:17 +00:00
|
|
|
#define DO_TEST_GUESTCPU(arch, host, cpu, models, result) \
|
|
|
|
DO_TEST(arch, cpuTestGuestCPU, \
|
2016-11-08 19:55:48 +00:00
|
|
|
host "/" cpu " (" #models ")", \
|
2017-09-22 13:51:33 +00:00
|
|
|
host, cpu, models, 0, result)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2016-06-01 13:57:00 +00:00
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
# define DO_TEST_CPUID_JSON(arch, host, json) \
|
|
|
|
do { \
|
2017-09-26 19:01:56 +00:00
|
|
|
if (json != JSON_NONE) { \
|
2016-06-08 14:57:28 +00:00
|
|
|
DO_TEST(arch, cpuTestJSONCPUID, host, host, \
|
2017-09-26 19:08:37 +00:00
|
|
|
NULL, NULL, json, 0); \
|
2016-06-01 13:57:00 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#else
|
2016-06-13 09:11:41 +00:00
|
|
|
# define DO_TEST_CPUID_JSON(arch, host, json)
|
2016-06-01 13:57:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DO_TEST_CPUID(arch, host, json) \
|
|
|
|
do { \
|
2016-06-08 14:57:28 +00:00
|
|
|
DO_TEST(arch, cpuTestHostCPUID, host, host, \
|
2017-09-22 13:51:33 +00:00
|
|
|
NULL, NULL, 0, 0); \
|
2016-06-08 14:57:28 +00:00
|
|
|
DO_TEST(arch, cpuTestGuestCPUID, host, host, \
|
2017-09-27 07:29:28 +00:00
|
|
|
NULL, NULL, json, 0); \
|
2016-06-01 13:57:00 +00:00
|
|
|
DO_TEST_CPUID_JSON(arch, host, json); \
|
2017-09-26 19:01:56 +00:00
|
|
|
if (json != JSON_NONE) { \
|
2017-03-16 11:26:30 +00:00
|
|
|
DO_TEST(arch, cpuTestUpdateLive, host, host, \
|
2017-09-27 07:29:28 +00:00
|
|
|
NULL, NULL, json, 0); \
|
2017-03-16 11:26:30 +00:00
|
|
|
} \
|
2016-06-01 13:57:00 +00:00
|
|
|
} while (0)
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
/* host to host comparison */
|
2017-02-13 13:18:55 +00:00
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-better", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-worse", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-amd-fake", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-incomp-arch", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-no-vendor", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host-no-vendor", "host", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "host", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "host-better", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "host-worse", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "host-incomp-arch", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "host-no-vendor", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host-no-vendor", "host", VIR_CPU_COMPARE_INCOMPATIBLE);
|
2015-08-07 15:39:21 +00:00
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
/* guest to host comparison */
|
2017-02-13 13:18:55 +00:00
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "bogus-model", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "bogus-feature", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "min", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "pentium3", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-forbid", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-forbid-extra", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-disable", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-disable2", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-disable-extra", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-require", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-require-extra", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "exact-force", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "strict", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "strict-full", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "strict-disable", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "strict-force-extra", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "guest", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "pentium3-amd", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host-amd", "pentium3-amd", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host-worse", "penryn-force", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_X86_64, "host-SandyBridge", "exact-force-Haswell", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-strict", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-exact", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-legacy", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-legacy-incompatible", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-legacy-invalid", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-compat-none", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-compat-valid", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-compat-invalid", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_COMPARE(VIR_ARCH_PPC64, "host", "guest-compat-incompatible", VIR_CPU_COMPARE_INCOMPATIBLE);
|
2013-09-03 06:28:25 +00:00
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
/* guest updates for migration
|
|
|
|
* automatically compares host CPU with the result */
|
2017-02-13 13:18:55 +00:00
|
|
|
DO_TEST_UPDATE(VIR_ARCH_X86_64, "host", "min", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_X86_64, "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_X86_64, "host", "guest", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_X86_64, "host", "host-model", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_X86_64, "host", "host-model-nofallback", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_X86_64, "host-invtsc", "host-model", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_UPDATE_ONLY(VIR_ARCH_X86_64, "host", "host-passthrough");
|
|
|
|
DO_TEST_UPDATE_ONLY(VIR_ARCH_X86_64, "host", "host-passthrough-features");
|
|
|
|
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-nofallback", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-legacy", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-legacy-incompatible", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-legacy-invalid", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-compat-none", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-compat-valid", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-compat-invalid", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_UPDATE(VIR_ARCH_PPC64, "host", "guest-compat-incompatible", VIR_CPU_COMPARE_INCOMPATIBLE);
|
2015-08-14 14:45:18 +00:00
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
/* computing baseline CPUs */
|
2017-02-13 13:18:55 +00:00
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "incompatible-vendors", 0, -1);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "no-vendor", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "some-vendors", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "1", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "2", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "3", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "3", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "4", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "4", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "5", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "5", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "6", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "6", VIR_CONNECT_BASELINE_CPU_MIGRATABLE, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "7", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_X86_64, "8", 0, 0);
|
|
|
|
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_PPC64, "incompatible-vendors", 0, -1);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_PPC64, "no-vendor", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_PPC64, "incompatible-models", 0, -1);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_PPC64, "same-model", 0, 0);
|
|
|
|
DO_TEST_BASELINE(VIR_ARCH_PPC64, "legacy", 0, -1);
|
2015-08-07 15:39:12 +00:00
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
/* CPU features */
|
2017-02-13 13:18:55 +00:00
|
|
|
DO_TEST_HASFEATURE(VIR_ARCH_X86_64, "host", "vmx", YES);
|
|
|
|
DO_TEST_HASFEATURE(VIR_ARCH_X86_64, "host", "lm", YES);
|
|
|
|
DO_TEST_HASFEATURE(VIR_ARCH_X86_64, "host", "sse4.1", YES);
|
|
|
|
DO_TEST_HASFEATURE(VIR_ARCH_X86_64, "host", "3dnowext", NO);
|
|
|
|
DO_TEST_HASFEATURE(VIR_ARCH_X86_64, "host", "skinit", NO);
|
|
|
|
DO_TEST_HASFEATURE(VIR_ARCH_X86_64, "host", "foo", FAIL);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
/* computing guest data and decoding the data into a guest CPU XML */
|
2017-02-13 13:18:55 +00:00
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "guest", NULL, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host-better", "pentium3", NULL, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host-worse", "guest", NULL, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "strict-force-extra", NULL, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "penryn-force", NULL, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "guest", model486, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "guest", models, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "guest", nomodel, -1);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "guest-nofallback", models, -1);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "host+host-model", models, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host", "host+host-model-nofallback", models, -1);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host-Haswell-noTSX", "Haswell", haswell, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host-Haswell-noTSX", "Haswell-noTSX", haswell, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host-Haswell-noTSX", "Haswell-noTSX-nofallback", haswell, -1);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_X86_64, "host-Haswell-noTSX", "Haswell-noTSX", NULL, 0);
|
|
|
|
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_PPC64, "host", "guest", ppc_models, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_PPC64, "host", "guest-nofallback", ppc_models, -1);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_PPC64, "host", "guest-legacy", ppc_models, 0);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_PPC64, "host", "guest-legacy-incompatible", ppc_models, -1);
|
|
|
|
DO_TEST_GUESTCPU(VIR_ARCH_PPC64, "host", "guest-legacy-invalid", ppc_models, -1);
|
|
|
|
|
2017-09-26 19:01:56 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "A10-5800K", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Atom-D510", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Atom-N450", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-2500", JSON_HOST);
|
2017-09-26 21:07:47 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-2540M", JSON_MODELS);
|
2017-09-26 19:01:56 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-4670T", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-6600", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-2600", JSON_HOST);
|
2017-10-03 22:55:46 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-2600-xsaveopt", JSON_MODELS);
|
2017-09-26 19:01:56 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-3520M", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-3740QM", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-3770", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-4600U", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-4510U", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-5600U", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-5600U-arat", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core2-E6850", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Core2-Q9500", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "EPYC-7601-32-Core", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "FX-8150", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-1352", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-2350", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-6234", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-6282", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Pentium-P6100", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Phenom-B95", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Ryzen-7-1800X-Eight-Core", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-5110", JSON_NONE);
|
2017-09-26 19:08:58 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E3-1245", JSON_MODELS);
|
2017-09-26 19:01:56 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E5-2630", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E5-2650", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E7-4820", JSON_HOST);
|
2017-09-26 20:14:25 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E7-4830", JSON_MODELS);
|
2017-09-26 19:01:56 +00:00
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E7-8890", JSON_NONE);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-Gold-6148", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-W3520", JSON_HOST);
|
|
|
|
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-X5460", JSON_NONE);
|
2016-06-06 12:43:07 +00:00
|
|
|
|
2017-09-22 13:51:33 +00:00
|
|
|
cleanup:
|
2016-06-01 13:57:00 +00:00
|
|
|
#if WITH_QEMU && WITH_YAJL
|
|
|
|
qemuTestDriverFree(&driver);
|
|
|
|
#endif
|
|
|
|
|
2017-09-22 13:51:33 +00:00
|
|
|
virObjectUnref(model486);
|
|
|
|
virObjectUnref(nomodel);
|
|
|
|
virObjectUnref(models);
|
|
|
|
virObjectUnref(haswell);
|
|
|
|
virObjectUnref(ppc_models);
|
|
|
|
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2010-10-07 14:35:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|