cputest.c 35.8 KB
Newer Older
1 2 3
/*
 * cputest.c: Test the libvirtd internal CPU APIs
 *
4
 * Copyright (C) 2010-2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 * 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"
34
#include "virxml.h"
35
#include "viralloc.h"
36
#include "virbuffer.h"
37 38 39 40
#include "testutils.h"
#include "cpu_conf.h"
#include "cpu/cpu.h"
#include "cpu/cpu_map.h"
41
#include "virstring.h"
42

J
Jiri Denemark 已提交
43 44 45
#if WITH_QEMU && WITH_YAJL
# include "testutilsqemu.h"
# include "qemumonitortestutils.h"
46
# define __QEMU_CAPSPRIV_H_ALLOW__
47
# include "qemu/qemu_capspriv.h"
48
# undef __QEMU_CAPSPRIV_H_ALLOW__
J
Jiri Denemark 已提交
49 50
#endif

51 52 53 54 55 56 57 58 59 60
#define VIR_FROM_THIS VIR_FROM_CPU

enum cpuTestBoolWithError {
    FAIL    = -1,
    NO      = 0,
    YES     = 1
};


struct data {
61
    virArch arch;
62 63 64 65 66
    const char *host;
    const char *name;
    const char **models;
    const char *modelsName;
    unsigned int nmodels;
67
    unsigned int flags;
68 69 70
    int result;
};

J
Jiri Denemark 已提交
71 72 73 74
#if WITH_QEMU && WITH_YAJL
static virQEMUDriver driver;
#endif

75 76

static virCPUDefPtr
77
cpuTestLoadXML(virArch arch, const char *name)
78
{
79
    char *xml = NULL;
80 81 82 83
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    virCPUDefPtr cpu = NULL;

84 85
    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
                    abs_srcdir, virArchToString(arch), name) < 0)
86
        goto cleanup;
87

88
    if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
89 90 91 92
        goto cleanup;

    cpu = virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_AUTO);

93
 cleanup:
94 95
    xmlXPathFreeContext(ctxt);
    xmlFreeDoc(doc);
96
    VIR_FREE(xml);
97 98 99 100 101
    return cpu;
}


static virCPUDefPtr *
102
cpuTestLoadMultiXML(virArch arch,
103 104 105
                    const char *name,
                    unsigned int *count)
{
106
    char *xml = NULL;
107 108 109 110 111
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    xmlNodePtr *nodes = NULL;
    virCPUDefPtr *cpus = NULL;
    int n;
112
    size_t i;
113

114 115
    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
                    abs_srcdir, virArchToString(arch), name) < 0)
116
        goto cleanup;
117

118
    if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
J
Jiri Denemark 已提交
119
        goto cleanup;
120 121

    n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
122 123
    if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) {
        fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml);
J
Jiri Denemark 已提交
124
        goto cleanup;
125
    }
126 127 128 129 130

    for (i = 0; i < n; i++) {
        ctxt->node = nodes[i];
        cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
        if (!cpus[i])
J
Jiri Denemark 已提交
131
            goto cleanup_cpus;
132 133 134 135
    }

    *count = n;

136
 cleanup:
137 138
    VIR_FREE(xml);
    VIR_FREE(nodes);
139 140 141 142
    xmlXPathFreeContext(ctxt);
    xmlFreeDoc(doc);
    return cpus;

143
 cleanup_cpus:
J
Jiri Denemark 已提交
144 145 146
    for (i = 0; i < n; i++)
        virCPUDefFree(cpus[i]);
    VIR_FREE(cpus);
147 148 149 150 151
    goto cleanup;
}


static int
152
cpuTestCompareXML(virArch arch,
E
Eric Blake 已提交
153
                  virCPUDef *cpu,
154
                  const char *name,
155
                  bool updateCPU)
156
{
157
    char *xml = NULL;
158 159 160
    char *actual = NULL;
    int ret = -1;

161
    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
162
                    abs_srcdir, virArchToString(arch), name) < 0)
163
        goto cleanup;
164

165
    if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU)))
166 167
        goto cleanup;

168
    if (virTestCompareToFile(actual, xml) < 0)
169 170 171 172
        goto cleanup;

    ret = 0;

173
 cleanup:
174 175
    VIR_FREE(xml);
    VIR_FREE(actual);
176 177 178 179 180 181 182 183 184 185 186 187
    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";
188
    case VIR_CPU_COMPARE_LAST:          break;
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
    }

    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;

J
Jiri Denemark 已提交
221
    result = virCPUCompare(host->arch, host, cpu, false);
222 223 224 225
    if (data->result == VIR_CPU_COMPARE_ERROR)
        virResetLastError();

    if (data->result != result) {
226
        VIR_TEST_VERBOSE("\nExpected result %s, got %s\n",
227 228
                    cpuTestCompResStr(data->result),
                    cpuTestCompResStr(result));
229 230
        /* Pad to line up with test name ... in virTestRun */
        VIR_TEST_VERBOSE("%74s", "... ");
231 232 233 234 235
        goto cleanup;
    }

    ret = 0;

236
 cleanup:
237 238 239 240 241 242 243
    virCPUDefFree(host);
    virCPUDefFree(cpu);
    return ret;
}


static int
J
Jiri Denemark 已提交
244
cpuTestGuestCPU(const void *arg)
245 246
{
    const struct data *data = arg;
247
    int ret = -2;
248 249 250 251 252 253 254 255 256 257
    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;

258 259 260
    if (virCPUConvertLegacy(host->arch, cpu) < 0)
        goto cleanup;

J
Jiri Denemark 已提交
261
    cmpResult = virCPUCompare(host->arch, host, cpu, false);
262
    if (cmpResult == VIR_CPU_COMPARE_ERROR ||
263 264
        cmpResult == VIR_CPU_COMPARE_INCOMPATIBLE) {
        ret = -1;
265
        goto cleanup;
266
    }
267

J
Jiri Denemark 已提交
268 269
    if (virCPUUpdate(host->arch, cpu, host) < 0 ||
        virCPUTranslate(host->arch, cpu, data->models, data->nmodels) < 0) {
270
        ret = -1;
271 272 273
        goto cleanup;
    }

274
    virBufferAsprintf(&buf, "%s+%s", data->host, data->name);
275
    if (data->nmodels)
276
        virBufferAsprintf(&buf, ",%s", data->modelsName);
277 278 279 280 281 282 283 284
    virBufferAddLit(&buf, "-result");

    if (virBufferError(&buf)) {
        virBufferFreeAndReset(&buf);
        goto cleanup;
    }
    result = virBufferContentAndReset(&buf);

J
Jiri Denemark 已提交
285
    if (cpuTestCompareXML(data->arch, cpu, result, false) < 0)
286 287 288
        goto cleanup;

    ret = 0;
289

290
 cleanup:
291 292 293
    VIR_FREE(result);
    virCPUDefFree(host);
    virCPUDefFree(cpu);
294 295 296 297 298 299 300 301 302 303 304 305 306 307

    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;
    }

308 309 310 311 312 313 314 315 316 317 318 319
    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;
320
    char *result = NULL;
321
    const char *suffix;
322
    size_t i;
323 324 325 326

    if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
        goto cleanup;

327 328
    baseline = cpuBaseline(cpus, ncpus, NULL, 0,
                           !!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
329 330 331 332 333 334 335 336

    if (baseline &&
        (data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
        virCPUExpandFeatures(data->arch, baseline) < 0) {
        virCPUDefFree(baseline);
        baseline = NULL;
    }

337 338
    if (data->result < 0) {
        virResetLastError();
339
        if (!baseline) {
340
            ret = 0;
341 342
        } else {
            VIR_TEST_VERBOSE("\n%-70s... ",
343 344 345 346 347 348 349
                    "cpuBaseline was expected to fail but it succeeded");
        }
        goto cleanup;
    }
    if (!baseline)
        goto cleanup;

350 351
    if (data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES)
        suffix = "expanded";
352 353
    else if (data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)
        suffix = "migratable";
354 355 356
    else
        suffix = "result";
    if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
357 358
        goto cleanup;

359
    if (cpuTestCompareXML(data->arch, baseline, result, false) < 0)
360 361 362 363 364
        goto cleanup;

    for (i = 0; i < ncpus; i++) {
        virCPUCompareResult cmp;

J
Jiri Denemark 已提交
365
        cmp = virCPUCompare(cpus[i]->arch, cpus[i], baseline, false);
366 367
        if (cmp != VIR_CPU_COMPARE_SUPERSET &&
            cmp != VIR_CPU_COMPARE_IDENTICAL) {
368 369 370
            VIR_TEST_VERBOSE("\nbaseline CPU is incompatible with CPU %zu\n",
                             i);
            VIR_TEST_VERBOSE("%74s", "... ");
371 372 373 374 375 376 377
            ret = -1;
            goto cleanup;
        }
    }

    ret = 0;

378
 cleanup:
379 380 381
    if (cpus) {
        for (i = 0; i < ncpus; i++)
            virCPUDefFree(cpus[i]);
382
        VIR_FREE(cpus);
383 384
    }
    virCPUDefFree(baseline);
385
    VIR_FREE(result);
386 387 388 389 390 391 392 393 394 395 396
    return ret;
}


static int
cpuTestUpdate(const void *arg)
{
    const struct data *data = arg;
    int ret = -1;
    virCPUDefPtr host = NULL;
    virCPUDefPtr cpu = NULL;
397
    char *result = NULL;
398 399 400 401 402

    if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
        !(cpu = cpuTestLoadXML(data->arch, data->name)))
        goto cleanup;

403
    if (virCPUUpdate(host->arch, cpu, host) < 0)
404 405
        goto cleanup;

406 407 408
    if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
        goto cleanup;

409
    ret = cpuTestCompareXML(data->arch, cpu, result, true);
410

411
 cleanup:
412 413
    virCPUDefFree(host);
    virCPUDefFree(cpu);
414
    VIR_FREE(result);
415 416 417 418 419 420 421 422 423 424
    return ret;
}


static int
cpuTestHasFeature(const void *arg)
{
    const struct data *data = arg;
    int ret = -1;
    virCPUDefPtr host = NULL;
425
    virCPUDataPtr hostData = NULL;
426 427 428 429 430 431 432 433 434
    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;

435 436 437 438 439
    result = virCPUCheckFeature(host->arch, host, data->name);

    if (data->result == result)
        result = virCPUDataCheckFeature(hostData, data->name);

440 441 442 443
    if (data->result == -1)
        virResetLastError();

    if (data->result != result) {
444 445 446 447 448
        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", "... ");
449 450 451 452 453
        goto cleanup;
    }

    ret = 0;

454
 cleanup:
J
Jiri Denemark 已提交
455
    virCPUDataFree(hostData);
456 457 458 459 460
    virCPUDefFree(host);
    return ret;
}


J
Jiri Denemark 已提交
461
static int
462
cpuTestCPUID(bool guest, const void *arg)
J
Jiri Denemark 已提交
463 464 465 466 467 468 469 470 471 472
{
    const struct data *data = arg;
    int ret = -1;
    virCPUDataPtr hostData = NULL;
    char *hostFile = NULL;
    char *host = NULL;
    virCPUDefPtr cpu = NULL;
    char *result = NULL;

    if (virAsprintf(&hostFile, "%s/cputestdata/%s-cpuid-%s.xml",
473
                    abs_srcdir, virArchToString(data->arch), data->host) < 0)
J
Jiri Denemark 已提交
474 475 476
        goto cleanup;

    if (virTestLoadFile(hostFile, &host) < 0 ||
J
Jiri Denemark 已提交
477
        !(hostData = virCPUDataParse(host)))
J
Jiri Denemark 已提交
478 479 480 481 482 483
        goto cleanup;

    if (VIR_ALLOC(cpu) < 0)
        goto cleanup;

    cpu->arch = hostData->arch;
484
    if (guest) {
J
Jiri Denemark 已提交
485 486 487 488 489 490 491 492 493 494 495 496
        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;
    }

    if (cpuDecode(cpu, hostData, NULL, 0, NULL) < 0)
        goto cleanup;

    if (virAsprintf(&result, "cpuid-%s-%s",
                    data->host,
497
                    guest ? "guest" : "host") < 0)
J
Jiri Denemark 已提交
498 499 500 501 502 503 504
        goto cleanup;

    ret = cpuTestCompareXML(data->arch, cpu, result, false);

 cleanup:
    VIR_FREE(hostFile);
    VIR_FREE(host);
J
Jiri Denemark 已提交
505
    virCPUDataFree(hostData);
J
Jiri Denemark 已提交
506 507 508 509 510 511
    virCPUDefFree(cpu);
    VIR_FREE(result);
    return ret;
}


512 513 514 515 516 517 518 519 520 521 522 523 524 525
static int
cpuTestHostCPUID(const void *arg)
{
    return cpuTestCPUID(false, arg);
}


static int
cpuTestGuestCPUID(const void *arg)
{
    return cpuTestCPUID(true, arg);
}


526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
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",
                             featAct->name);
            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;
    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 (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0)
        goto cleanup;

    if (virAsprintf(&expectedFile, "cpuid-%s-json", data->host) < 0 ||
        !(expected = cpuTestLoadXML(data->arch, expectedFile)))
        goto cleanup;

    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);
    return ret;
}


J
Jiri Denemark 已提交
671 672 673 674 675
#if WITH_QEMU && WITH_YAJL
static int
cpuTestJSONCPUID(const void *arg)
{
    const struct data *data = arg;
676 677
    qemuMonitorCPUModelInfoPtr model = NULL;
    virQEMUCapsPtr qemuCaps = NULL;
J
Jiri Denemark 已提交
678 679 680 681 682 683
    virCPUDefPtr cpu = NULL;
    qemuMonitorTestPtr testMon = NULL;
    char *json = NULL;
    char *result = NULL;
    int ret = -1;

684
    if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json",
685
                    abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
J
Jiri Denemark 已提交
686 687 688 689 690 691
        virAsprintf(&result, "cpuid-%s-json", data->host) < 0)
        goto cleanup;

    if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
        goto cleanup;

692 693
    if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
                                        QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
694
                                        "host", true, &model) < 0)
J
Jiri Denemark 已提交
695 696
        goto cleanup;

697 698 699 700 701 702 703
    if (!(qemuCaps = virQEMUCapsNew()))
        goto cleanup;

    virQEMUCapsSetArch(qemuCaps, data->arch);
    virQEMUCapsSetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM, model);
    model = NULL;

J
Jiri Denemark 已提交
704 705 706
    if (VIR_ALLOC(cpu) < 0)
        goto cleanup;

707
    cpu->arch = data->arch;
J
Jiri Denemark 已提交
708 709 710 711
    cpu->type = VIR_CPU_TYPE_GUEST;
    cpu->match = VIR_CPU_MATCH_EXACT;
    cpu->fallback = VIR_CPU_FALLBACK_FORBID;

712
    if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu, false) != 0)
J
Jiri Denemark 已提交
713 714 715 716 717
        goto cleanup;

    ret = cpuTestCompareXML(data->arch, cpu, result, false);

 cleanup:
718 719
    qemuMonitorCPUModelInfoFree(model);
    virObjectUnref(qemuCaps);
J
Jiri Denemark 已提交
720 721 722 723 724 725 726 727 728
    qemuMonitorTestFree(testMon);
    virCPUDefFree(cpu);
    VIR_FREE(result);
    VIR_FREE(json);
    return ret;
}
#endif


729 730 731
static const char *model486[]   = { "486" };
static const char *nomodel[]    = { "nomodel" };
static const char *models[]     = { "qemu64", "core2duo", "Nehalem" };
732
static const char *haswell[]    = { "SandyBridge", "Haswell" };
733
static const char *ppc_models[] = { "POWER6", "POWER7", "POWER8" };
734 735

static int
E
Eric Blake 已提交
736
mymain(void)
737 738 739
{
    int ret = 0;

J
Jiri Denemark 已提交
740 741 742 743 744 745 746
#if WITH_QEMU && WITH_YAJL
    if (qemuTestDriverInit(&driver) < 0)
        return EXIT_FAILURE;

    virEventRegisterDefaultImpl();
#endif

747
#define DO_TEST(arch, api, name, host, cpu,                             \
748
                models, nmodels, flags, result)                         \
749
    do {                                                                \
750 751
        struct data data = {                                            \
            arch, host, cpu, models,                                    \
752
            models == NULL ? NULL : #models,                            \
753
            nmodels, flags, result                                      \
754
        };                                                              \
755 756 757 758 759 760 761
        char *testLabel;                                                \
        char *tmp;                                                      \
                                                                        \
        tmp = virTestLogContentAndReset();                              \
        VIR_FREE(tmp);                                                  \
                                                                        \
        if (virAsprintf(&testLabel, "%s(%s): %s",                       \
762
                        #api, virArchToString(arch), name) < 0) {       \
763
            ret = -1;                                                   \
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
            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);                                            \
779 780 781
    } while (0)

#define DO_TEST_COMPARE(arch, host, cpu, result)                        \
782
    DO_TEST(arch, cpuTestCompare,                                       \
783
            host "/" cpu " (" #result ")",                              \
784
            host, cpu, NULL, 0, 0, result)
785

J
Jiri Denemark 已提交
786 787 788
#define DO_TEST_UPDATE_ONLY(arch, host, cpu)                            \
    DO_TEST(arch, cpuTestUpdate,                                        \
            cpu " on " host,                                            \
789
            host, cpu, NULL, 0, 0, 0)
J
Jiri Denemark 已提交
790

791 792
#define DO_TEST_UPDATE(arch, host, cpu, result)                         \
    do {                                                                \
J
Jiri Denemark 已提交
793
        DO_TEST_UPDATE_ONLY(arch, host, cpu);                           \
794 795 796
        DO_TEST_COMPARE(arch, host, host "+" cpu, result);              \
    } while (0)

797
#define DO_TEST_BASELINE(arch, name, flags, result)                     \
798 799 800 801 802
    do {                                                                \
        const char *suffix = "";                                        \
        char *label;                                                    \
        if ((flags) & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES)         \
            suffix = " (expanded)";                                     \
803 804
        if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)              \
            suffix = " (migratable)";                                   \
805 806 807
        if (virAsprintf(&label, "%s%s", name, suffix) < 0) {            \
            ret = -1;                                                   \
        } else {                                                        \
808
            DO_TEST(arch, cpuTestBaseline, label, NULL,                 \
809
                    "baseline-" name, NULL, 0, flags, result);          \
810 811 812
        }                                                               \
        VIR_FREE(label);                                                \
    } while (0)
813 814

#define DO_TEST_HASFEATURE(arch, host, feature, result)                 \
815
    DO_TEST(arch, cpuTestHasFeature,                                    \
816
            host "/" feature " (" #result ")",                          \
817
            host, feature, NULL, 0, 0, result)
818

J
Jiri Denemark 已提交
819 820
#define DO_TEST_GUESTCPU(arch, host, cpu, models, result)               \
    DO_TEST(arch, cpuTestGuestCPU,                                      \
821
            host "/" cpu " (" #models ")",                              \
822 823
            host, cpu, models,                                          \
            models == NULL ? 0 : sizeof(models) / sizeof(char *),       \
824
            0, result)
825

J
Jiri Denemark 已提交
826 827 828 829
#if WITH_QEMU && WITH_YAJL
# define DO_TEST_CPUID_JSON(arch, host, json)                           \
    do {                                                                \
        if (json) {                                                     \
830
            DO_TEST(arch, cpuTestJSONCPUID, host, host,                 \
831
                    NULL, NULL, 0, 0, 0);                               \
J
Jiri Denemark 已提交
832 833 834
        }                                                               \
    } while (0)
#else
835
# define DO_TEST_CPUID_JSON(arch, host, json)
J
Jiri Denemark 已提交
836 837 838 839
#endif

#define DO_TEST_CPUID(arch, host, json)                                 \
    do {                                                                \
840
        DO_TEST(arch, cpuTestHostCPUID, host, host,                     \
841
                NULL, NULL, 0, 0, 0);                                   \
842
        DO_TEST(arch, cpuTestGuestCPUID, host, host,                    \
843
                NULL, NULL, 0, 0, 0);                                   \
J
Jiri Denemark 已提交
844
        DO_TEST_CPUID_JSON(arch, host, json);                           \
845 846 847 848
        if (json) {                                                     \
            DO_TEST(arch, cpuTestUpdateLive, host, host,                \
                    NULL, NULL, 0, 0, 0);                               \
        }                                                               \
J
Jiri Denemark 已提交
849 850
    } while (0)

851
    /* host to host comparison */
852 853 854 855 856 857 858 859 860 861 862 863 864 865
    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);
866

867
    /* guest to host comparison */
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
    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);
900

901 902
    /* guest updates for migration
     * automatically compares host CPU with the result */
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
    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);
921

922
    /* computing baseline CPUs */
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
    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);
944

945
    /* CPU features */
946 947 948 949 950 951
    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);
952 953

    /* computing guest data and decoding the data into a guest CPU XML */
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
    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);

    DO_TEST_CPUID(VIR_ARCH_X86_64, "A10-5800K", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Atom-D510", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Atom-N450", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-2500", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-2540M", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-4670T", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i5-6600", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-2600", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-3520M", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-3740QM", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-3770", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-4600U", true);
988
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-4510U", true);
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core-i7-5600U", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core2-E6850", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Core2-Q9500", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "FX-8150", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-1352", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-2350", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-6234", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Opteron-6282", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Pentium-P6100", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Phenom-B95", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-5110", false);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E3-1245", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E5-2630", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E5-2650", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E7-4820", true);
1004
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-E7-8890", false);
1005 1006
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-W3520", true);
    DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-X5460", false);
1007

J
Jiri Denemark 已提交
1008 1009 1010 1011
#if WITH_QEMU && WITH_YAJL
    qemuTestDriverFree(&driver);
#endif

1012
    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
1013 1014
}

1015
VIR_TEST_MAIN(mymain)