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
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
|
|
|
enum cpuTestBoolWithError {
|
|
|
|
FAIL = -1,
|
|
|
|
NO = 0,
|
|
|
|
YES = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum api {
|
|
|
|
API_COMPARE,
|
|
|
|
API_GUEST_DATA,
|
|
|
|
API_BASELINE,
|
|
|
|
API_UPDATE,
|
|
|
|
API_HAS_FEATURE
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *apis[] = {
|
|
|
|
"compare",
|
|
|
|
"guest data",
|
|
|
|
"baseline",
|
|
|
|
"update",
|
|
|
|
"has feature"
|
|
|
|
};
|
|
|
|
|
|
|
|
struct data {
|
|
|
|
const char *arch;
|
|
|
|
enum api api;
|
|
|
|
const char *host;
|
|
|
|
const char *name;
|
|
|
|
const char **models;
|
|
|
|
const char *modelsName;
|
|
|
|
unsigned int nmodels;
|
|
|
|
const char *preferred;
|
2013-08-02 19:08:19 +00:00
|
|
|
unsigned int flags;
|
2010-10-07 14:35:17 +00:00
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static virCPUDefPtr
|
|
|
|
cpuTestLoadXML(const char *arch, const char *name)
|
|
|
|
{
|
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;
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
|
|
|
|
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;
|
|
|
|
|
|
|
|
cpu = virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_AUTO);
|
|
|
|
|
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 *
|
|
|
|
cpuTestLoadMultiXML(const char *arch,
|
|
|
|
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
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
|
|
|
|
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];
|
|
|
|
cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
|
|
|
|
if (!cpus[i])
|
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
|
|
|
|
cpuTestCompareXML(const char *arch,
|
2013-10-05 01:40:19 +00:00
|
|
|
virCPUDef *cpu,
|
2011-12-19 14:41:16 +00:00
|
|
|
const char *name,
|
2015-01-06 11:54:32 +00:00
|
|
|
bool updateCPU)
|
2010-10-07 14:35:17 +00:00
|
|
|
{
|
2011-04-24 22:25:10 +00:00
|
|
|
char *xml = NULL;
|
|
|
|
char *expected = 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",
|
|
|
|
abs_srcdir, arch, name) < 0)
|
|
|
|
goto cleanup;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virtTestLoadFile(xml, &expected) < 0)
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU)))
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (STRNEQ(expected, actual)) {
|
2012-01-04 13:23:20 +00:00
|
|
|
if (virTestGetVerbose())
|
|
|
|
fprintf(stderr, "\nCompared to %s-%s.xml", arch, name);
|
2010-10-07 14:35:17 +00:00
|
|
|
virtTestDifference(stderr, expected, actual);
|
|
|
|
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(expected);
|
|
|
|
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;
|
|
|
|
|
2014-05-28 13:11:57 +00:00
|
|
|
result = cpuCompare(host, cpu, false);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->result == VIR_CPU_COMPARE_ERROR)
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (data->result != result) {
|
|
|
|
if (virTestGetVerbose()) {
|
|
|
|
fprintf(stderr, "\nExpected result %s, got %s\n",
|
|
|
|
cpuTestCompResStr(data->result),
|
|
|
|
cpuTestCompResStr(result));
|
|
|
|
/* Pad to line up with test name ... in virTestRun */
|
|
|
|
fprintf(stderr, "%74s", "... ");
|
|
|
|
}
|
|
|
|
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
|
|
|
|
cpuTestGuestData(const void *arg)
|
|
|
|
{
|
|
|
|
const struct data *data = arg;
|
|
|
|
int ret = -1;
|
|
|
|
virCPUDefPtr host = NULL;
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
virCPUDefPtr guest = NULL;
|
2012-12-18 18:44:23 +00:00
|
|
|
virCPUDataPtr guestData = NULL;
|
2010-10-07 14:35:17 +00:00
|
|
|
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;
|
|
|
|
|
2012-04-17 13:24:47 +00:00
|
|
|
cmpResult = cpuGuestData(host, cpu, &guestData, NULL);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (cmpResult == VIR_CPU_COMPARE_ERROR ||
|
|
|
|
cmpResult == VIR_CPU_COMPARE_INCOMPATIBLE)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-12-18 19:32:23 +00:00
|
|
|
if (VIR_ALLOC(guest) < 0)
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-12-18 19:32:23 +00:00
|
|
|
guest->arch = host->arch;
|
2010-10-07 14:35:17 +00:00
|
|
|
guest->type = VIR_CPU_TYPE_GUEST;
|
|
|
|
guest->match = VIR_CPU_MATCH_EXACT;
|
2011-12-21 13:27:16 +00:00
|
|
|
guest->fallback = cpu->fallback;
|
2010-10-07 14:35:17 +00:00
|
|
|
if (cpuDecode(guest, guestData, data->models,
|
|
|
|
data->nmodels, data->preferred) < 0) {
|
|
|
|
if (data->result < 0) {
|
|
|
|
virResetLastError();
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "%s+%s", data->host, data->name);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->nmodels)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s", data->modelsName);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->preferred)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, ",%s", data->preferred);
|
2010-10-07 14:35:17 +00:00
|
|
|
virBufferAddLit(&buf, "-result");
|
|
|
|
|
|
|
|
if (virBufferError(&buf)) {
|
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
result = virBufferContentAndReset(&buf);
|
|
|
|
|
2015-01-06 11:54:32 +00:00
|
|
|
ret = cpuTestCompareXML(data->arch, guest, result, false);
|
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);
|
2013-07-16 12:39:40 +00:00
|
|
|
cpuDataFree(guestData);
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefFree(host);
|
|
|
|
virCPUDefFree(cpu);
|
|
|
|
virCPUDefFree(guest);
|
|
|
|
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;
|
|
|
|
|
2013-08-02 19:08:19 +00:00
|
|
|
baseline = cpuBaseline(cpus, ncpus, NULL, 0, data->flags);
|
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;
|
2014-09-03 19:39:21 +00:00
|
|
|
} else if (virTestGetVerbose()) {
|
2010-10-07 14:35:17 +00:00
|
|
|
fprintf(stderr, "\n%-70s... ",
|
|
|
|
"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";
|
|
|
|
else
|
|
|
|
suffix = "result";
|
|
|
|
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
|
2011-04-24 22:25:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-01-06 11:54:32 +00:00
|
|
|
if (cpuTestCompareXML(data->arch, baseline, result, false) < 0)
|
2010-10-07 14:35:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < ncpus; i++) {
|
|
|
|
virCPUCompareResult cmp;
|
|
|
|
|
2014-05-28 13:11:57 +00:00
|
|
|
cmp = cpuCompare(cpus[i], baseline, false);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (cmp != VIR_CPU_COMPARE_SUPERSET &&
|
|
|
|
cmp != VIR_CPU_COMPARE_IDENTICAL) {
|
|
|
|
if (virTestGetVerbose()) {
|
|
|
|
fprintf(stderr,
|
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
|
|
|
"\nbaseline CPU is incompatible with CPU %zu\n", i);
|
2010-10-07 14:35:17 +00:00
|
|
|
fprintf(stderr, "%74s", "... ");
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (cpuUpdate(cpu, host) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-01-06 11:54:32 +00:00
|
|
|
ret = cpuTestCompareXML(data->arch, cpu, result, true);
|
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);
|
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;
|
|
|
|
|
2013-07-16 12:39:40 +00:00
|
|
|
result = cpuHasFeature(hostData, data->name);
|
2010-10-07 14:35:17 +00:00
|
|
|
if (data->result == -1)
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (data->result != result) {
|
|
|
|
if (virTestGetVerbose()) {
|
|
|
|
fprintf(stderr, "\nExpected result %s, got %s\n",
|
|
|
|
cpuTestBoolWithErrorStr(data->result),
|
|
|
|
cpuTestBoolWithErrorStr(result));
|
|
|
|
/* Pad to line up with test name ... in virTestRun */
|
|
|
|
fprintf(stderr, "%74s", "... ");
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-07-16 12:39:40 +00:00
|
|
|
cpuDataFree(hostData);
|
2010-10-07 14:35:17 +00:00
|
|
|
virCPUDefFree(host);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int (*cpuTest[])(const void *) = {
|
|
|
|
cpuTestCompare,
|
|
|
|
cpuTestGuestData,
|
|
|
|
cpuTestBaseline,
|
|
|
|
cpuTestUpdate,
|
|
|
|
cpuTestHasFeature
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuTestRun(const char *name, const struct data *data)
|
|
|
|
{
|
2011-04-24 22:25:10 +00:00
|
|
|
char *label = NULL;
|
2012-02-02 23:16:43 +00:00
|
|
|
char *tmp;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virAsprintf(&label, "CPU %s(%s): %s", apis[data->api], data->arch, name) < 0)
|
|
|
|
return -1;
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2012-02-02 23:16:43 +00:00
|
|
|
tmp = virtTestLogContentAndReset();
|
|
|
|
VIR_FREE(tmp);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun(label, cpuTest[data->api], data) < 0) {
|
2010-10-07 14:35:17 +00:00
|
|
|
if (virTestGetDebug()) {
|
|
|
|
char *log;
|
|
|
|
if ((log = virtTestLogContentAndReset()) &&
|
|
|
|
strlen(log) > 0)
|
|
|
|
fprintf(stderr, "\n%s\n", log);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(log);
|
2010-10-07 14:35:17 +00:00
|
|
|
}
|
2011-04-24 22:25:10 +00:00
|
|
|
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(label);
|
2010-10-07 14:35:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(label);
|
2010-10-07 14:35:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *model486[] = { "486" };
|
|
|
|
static const char *nomodel[] = { "nomodel" };
|
|
|
|
static const char *models[] = { "qemu64", "core2duo", "Nehalem" };
|
2015-03-23 16:19:28 +00:00
|
|
|
static const char *haswell[] = { "SandyBridge", "Haswell" };
|
2013-09-03 06:28:25 +00:00
|
|
|
static const char *ppc_models[] = { "POWER7", "POWER7_v2.1", "POWER8_v1.0"};
|
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
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
#define DO_TEST(arch, api, name, host, cpu, \
|
2013-08-02 19:08:19 +00:00
|
|
|
models, nmodels, preferred, flags, result) \
|
2010-10-07 14:35:17 +00:00
|
|
|
do { \
|
test: fix build errors with gcc 4.7.0 and -O0
When building on Fedora 17 (which uses gcc 4.7.0) with -O0 in CFLAGS,
three of the tests failed to compile.
cputest.c and qemuxml2argvtest.c had non-static structs defined
inside the macro that was being repeatedly invoked. Due to some so-far
unidentified change in gcc, the stack space used by variables defined
inside { } is not recovered/re-used when the block ends, so all these
structs have become additive (this is the same problem worked around
in commit cf57d345b). Fortunately, these two files could be fixed with
a single line addition of "static" to the struct definition in the
macro.
virnettlscontexttest.c was a bit different, though. The problem structs
in the do/while loop of macros had non-constant initializers, so it
took a bit more work and piecemeal initialization instead of member
initialization to get things to be happy.
In an ideal world, none of these changes should be necessary, but not
knowing how long it will be until the gcc regressions are fixed, and
since the code is just as correct after this patch as before, it makes
sense to fix libvirt's build for -O0 while also reporting the gcc
problem.
2012-04-05 20:31:36 +00:00
|
|
|
static struct data data = { \
|
2010-10-07 14:35:17 +00:00
|
|
|
arch, api, host, cpu, models, \
|
|
|
|
models == NULL ? NULL : #models, \
|
2013-08-02 19:08:19 +00:00
|
|
|
nmodels, preferred, flags, result \
|
2010-10-07 14:35:17 +00:00
|
|
|
}; \
|
|
|
|
if (cpuTestRun(name, &data) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DO_TEST_COMPARE(arch, host, cpu, result) \
|
|
|
|
DO_TEST(arch, API_COMPARE, \
|
|
|
|
host "/" cpu " (" #result ")", \
|
2013-08-02 19:08:19 +00:00
|
|
|
host, cpu, NULL, 0, NULL, 0, result)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
#define DO_TEST_UPDATE(arch, host, cpu, result) \
|
|
|
|
do { \
|
|
|
|
DO_TEST(arch, API_UPDATE, \
|
|
|
|
cpu " on " host, \
|
2013-08-02 19:08:19 +00:00
|
|
|
host, cpu, NULL, 0, NULL, 0, 0); \
|
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)"; \
|
|
|
|
if (virAsprintf(&label, "%s%s", name, suffix) < 0) { \
|
|
|
|
ret = -1; \
|
|
|
|
} else { \
|
|
|
|
DO_TEST(arch, API_BASELINE, label, NULL, "baseline-" name, \
|
|
|
|
NULL, 0, NULL, flags, result); \
|
|
|
|
} \
|
|
|
|
VIR_FREE(label); \
|
|
|
|
} while (0)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
#define DO_TEST_HASFEATURE(arch, host, feature, result) \
|
|
|
|
DO_TEST(arch, API_HAS_FEATURE, \
|
|
|
|
host "/" feature " (" #result ")", \
|
2013-08-02 19:08:19 +00:00
|
|
|
host, feature, NULL, 0, NULL, 0, result)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
#define DO_TEST_GUESTDATA(arch, host, cpu, models, preferred, result) \
|
|
|
|
DO_TEST(arch, API_GUEST_DATA, \
|
|
|
|
host "/" cpu " (" #models ", pref=" #preferred ")", \
|
|
|
|
host, cpu, models, \
|
|
|
|
models == NULL ? 0 : sizeof(models) / sizeof(char *), \
|
2013-08-02 19:08:19 +00:00
|
|
|
preferred, 0, result)
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
/* host to host comparison */
|
2012-03-29 09:47:07 +00:00
|
|
|
DO_TEST_COMPARE("x86", "host", "host", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "host-better", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "host-worse", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "host-amd-fake", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "host-incomp-arch", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "host-no-vendor", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE("x86", "host-no-vendor", "host", VIR_CPU_COMPARE_INCOMPATIBLE);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
/* guest to host comparison */
|
2012-03-29 09:47:07 +00:00
|
|
|
DO_TEST_COMPARE("x86", "host", "bogus-model", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "bogus-feature", VIR_CPU_COMPARE_ERROR);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "min", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "pentium3", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-forbid", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-forbid-extra", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-disable", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-disable2", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-disable-extra", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-require", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-require-extra", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "exact-force", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "strict", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "strict-full", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "strict-disable", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "strict-force-extra", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "guest", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host", "pentium3-amd", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
DO_TEST_COMPARE("x86", "host-amd", "pentium3-amd", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_COMPARE("x86", "host-worse", "nehalem-force", VIR_CPU_COMPARE_IDENTICAL);
|
2013-07-20 22:27:40 +00:00
|
|
|
DO_TEST_COMPARE("x86", "host-SandyBridge", "exact-force-Haswell", VIR_CPU_COMPARE_IDENTICAL);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2013-09-03 06:28:25 +00:00
|
|
|
DO_TEST_COMPARE("ppc64", "host", "strict", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_COMPARE("ppc64", "host", "exact", VIR_CPU_COMPARE_INCOMPATIBLE);
|
|
|
|
|
2010-10-07 14:35:17 +00:00
|
|
|
/* guest updates for migration
|
|
|
|
* automatically compares host CPU with the result */
|
2012-03-29 09:47:07 +00:00
|
|
|
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE("x86", "host", "guest", VIR_CPU_COMPARE_SUPERSET);
|
|
|
|
DO_TEST_UPDATE("x86", "host", "host-model", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE("x86", "host", "host-model-nofallback", VIR_CPU_COMPARE_IDENTICAL);
|
|
|
|
DO_TEST_UPDATE("x86", "host", "host-passthrough", VIR_CPU_COMPARE_IDENTICAL);
|
2014-09-05 07:50:36 +00:00
|
|
|
DO_TEST_UPDATE("x86", "host-invtsc", "host-model", VIR_CPU_COMPARE_SUPERSET);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
|
|
|
/* computing baseline CPUs */
|
2013-08-02 19:08:19 +00:00
|
|
|
DO_TEST_BASELINE("x86", "incompatible-vendors", 0, -1);
|
|
|
|
DO_TEST_BASELINE("x86", "no-vendor", 0, 0);
|
|
|
|
DO_TEST_BASELINE("x86", "some-vendors", 0, 0);
|
|
|
|
DO_TEST_BASELINE("x86", "1", 0, 0);
|
|
|
|
DO_TEST_BASELINE("x86", "2", 0, 0);
|
2014-01-27 20:53:51 +00:00
|
|
|
DO_TEST_BASELINE("x86", "3", 0, 0);
|
2013-08-02 19:08:19 +00:00
|
|
|
DO_TEST_BASELINE("x86", "3", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0);
|
2014-01-27 20:53:51 +00:00
|
|
|
DO_TEST_BASELINE("x86", "4", 0, 0);
|
|
|
|
DO_TEST_BASELINE("x86", "4", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0);
|
|
|
|
DO_TEST_BASELINE("x86", "5", 0, 0);
|
|
|
|
DO_TEST_BASELINE("x86", "5", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2013-09-03 06:28:25 +00:00
|
|
|
DO_TEST_BASELINE("ppc64", "incompatible-vendors", 0, -1);
|
|
|
|
DO_TEST_BASELINE("ppc64", "no-vendor", 0, 0);
|
2010-10-07 14:35:17 +00:00
|
|
|
/* CPU features */
|
|
|
|
DO_TEST_HASFEATURE("x86", "host", "vmx", YES);
|
|
|
|
DO_TEST_HASFEATURE("x86", "host", "lm", YES);
|
|
|
|
DO_TEST_HASFEATURE("x86", "host", "sse4.1", YES);
|
|
|
|
DO_TEST_HASFEATURE("x86", "host", "3dnowext", NO);
|
|
|
|
DO_TEST_HASFEATURE("x86", "host", "skinit", NO);
|
|
|
|
DO_TEST_HASFEATURE("x86", "host", "foo", FAIL);
|
|
|
|
|
|
|
|
/* computing guest data and decoding the data into a guest CPU XML */
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest", NULL, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-better", "pentium3", NULL, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-better", "pentium3", NULL, "pentium3", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-better", "pentium3", NULL, "core2duo", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-worse", "guest", NULL, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "strict-force-extra", NULL, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "nehalem-force", NULL, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest", model486, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest", models, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest", models, "Penryn", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1);
|
2011-12-21 13:27:16 +00:00
|
|
|
DO_TEST_GUESTDATA("x86", "host", "guest-nofallback", models, "Penryn", -1);
|
2011-12-19 14:41:16 +00:00
|
|
|
DO_TEST_GUESTDATA("x86", "host", "host+host-model", models, "Penryn", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host", "host+host-model-nofallback",
|
|
|
|
models, "Penryn", -1);
|
2015-03-23 16:19:28 +00:00
|
|
|
DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell",
|
|
|
|
haswell, "Haswell", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell-noTSX",
|
|
|
|
haswell, "Haswell-noTSX", 0);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell-noTSX-nofallback",
|
|
|
|
haswell, "Haswell-noTSX", -1);
|
|
|
|
DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell-noTSX",
|
|
|
|
NULL, "Haswell-noTSX", 0);
|
2010-10-07 14:35:17 +00:00
|
|
|
|
2013-09-03 06:28:25 +00:00
|
|
|
DO_TEST_GUESTDATA("ppc64", "host", "guest", ppc_models, NULL, 0);
|
|
|
|
DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", -1);
|
|
|
|
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2010-10-07 14:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|