testutilsqemu.c 20.2 KB
Newer Older
1
#include <config.h>
A
Atsushi SAKAI 已提交
2
#ifdef WITH_QEMU
3
# include <stdlib.h>
4

5 6
# include "testutilsqemu.h"
# include "testutils.h"
7
# include "viralloc.h"
J
Jiri Denemark 已提交
8
# include "cpu_conf.h"
9
# include "qemu/qemu_driver.h"
10
# include "qemu/qemu_domain.h"
11
# define __QEMU_CAPSPRIV_H_ALLOW__
12
# include "qemu/qemu_capspriv.h"
13 14 15
# include "virstring.h"

# define VIR_FROM_THIS VIR_FROM_QEMU
16

17 18
virCPUDefPtr cpuDefault;
virCPUDefPtr cpuHaswell;
19
virCPUDefPtr cpuPower8;
20
virCPUDefPtr cpuPower9;
21 22

static virCPUFeatureDef cpuDefaultFeatures[] = {
23
    { (char *) "ds",        -1 },
24
    { (char *) "acpi",      -1 },
25 26 27 28 29 30 31 32 33 34 35
    { (char *) "ss",        -1 },
    { (char *) "ht",        -1 },
    { (char *) "tm",        -1 },
    { (char *) "pbe",       -1 },
    { (char *) "ds_cpl",    -1 },
    { (char *) "vmx",       -1 },
    { (char *) "est",       -1 },
    { (char *) "tm2",       -1 },
    { (char *) "cx16",      -1 },
    { (char *) "xtpr",      -1 },
    { (char *) "lahf_lm",   -1 },
36 37
};
static virCPUDef cpuDefaultData = {
38 39 40 41 42 43 44 45 46 47
    .type = VIR_CPU_TYPE_HOST,
    .arch = VIR_ARCH_X86_64,
    .model = (char *) "core2duo",
    .vendor = (char *) "Intel",
    .sockets = 1,
    .cores = 2,
    .threads = 1,
    .nfeatures = ARRAY_CARDINALITY(cpuDefaultFeatures),
    .nfeatures_max = ARRAY_CARDINALITY(cpuDefaultFeatures),
    .features = cpuDefaultFeatures,
48 49 50 51
};

static virCPUFeatureDef cpuHaswellFeatures[] = {
    { (char *) "vme",       -1 },
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    { (char *) "ds",        -1 },
    { (char *) "acpi",      -1 },
    { (char *) "ss",        -1 },
    { (char *) "ht",        -1 },
    { (char *) "tm",        -1 },
    { (char *) "pbe",       -1 },
    { (char *) "dtes64",    -1 },
    { (char *) "monitor",   -1 },
    { (char *) "ds_cpl",    -1 },
    { (char *) "vmx",       -1 },
    { (char *) "smx",       -1 },
    { (char *) "est",       -1 },
    { (char *) "tm2",       -1 },
    { (char *) "xtpr",      -1 },
    { (char *) "pdcm",      -1 },
    { (char *) "osxsave",   -1 },
    { (char *) "f16c",      -1 },
    { (char *) "rdrand",    -1 },
    { (char *) "cmt",       -1 },
    { (char *) "pdpe1gb",   -1 },
    { (char *) "abm",       -1 },
    { (char *) "invtsc",    -1 },
    { (char *) "lahf_lm",   -1 },
75 76
};
static virCPUDef cpuHaswellData = {
77 78 79 80 81 82 83 84 85 86
    .type = VIR_CPU_TYPE_HOST,
    .arch = VIR_ARCH_X86_64,
    .model = (char *) "Haswell",
    .vendor = (char *) "Intel",
    .sockets = 1,
    .cores = 2,
    .threads = 2,
    .nfeatures = ARRAY_CARDINALITY(cpuHaswellFeatures),
    .nfeatures_max = ARRAY_CARDINALITY(cpuHaswellFeatures),
    .features = cpuHaswellFeatures,
87 88
};

89 90 91 92 93 94 95 96 97
static virCPUDef cpuPower8Data = {
    .type = VIR_CPU_TYPE_HOST,
    .arch = VIR_ARCH_PPC64,
    .model = (char *) "POWER8",
    .sockets = 1,
    .cores = 8,
    .threads = 8,
};

98 99 100 101 102 103 104 105 106
static virCPUDef cpuPower9Data = {
    .type = VIR_CPU_TYPE_HOST,
    .arch = VIR_ARCH_PPC64,
    .model = (char *) "POWER9",
    .sockets = 1,
    .cores = 16,
    .threads = 1,
};

107
typedef enum {
108 109 110 111 112 113 114
    TEST_UTILS_QEMU_BIN_I686,
    TEST_UTILS_QEMU_BIN_X86_64,
    TEST_UTILS_QEMU_BIN_AARCH64,
    TEST_UTILS_QEMU_BIN_ARM,
    TEST_UTILS_QEMU_BIN_PPC64,
    TEST_UTILS_QEMU_BIN_PPC,
    TEST_UTILS_QEMU_BIN_S390X
115 116 117
} QEMUBinType;

static const char *QEMUBinList[] = {
118
    "/usr/bin/qemu-system-i686",
119 120 121 122 123 124 125 126 127
    "/usr/bin/qemu-system-x86_64",
    "/usr/bin/qemu-system-aarch64",
    "/usr/bin/qemu-system-arm",
    "/usr/bin/qemu-system-ppc64",
    "/usr/bin/qemu-system-ppc",
    "/usr/bin/qemu-system-s390x"
};


128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
    virCapsGuestMachinePtr *machines;
    static const char *const x86_machines[] = {
        "pc", "isapc"
    };

    machines = virCapabilitiesAllocMachines(x86_machines,
                                            ARRAY_CARDINALITY(x86_machines));
    if (machines == NULL)
        return NULL;

    *nmachines = ARRAY_CARDINALITY(x86_machines);

    return machines;
}

M
Mark McLoughlin 已提交
145 146 147 148 149 150 151 152 153 154 155 156
/* Newer versions of qemu have versioned machine types to allow
 * compatibility with older releases.
 * The 'pc' machine type is an alias of the newest machine type.
 */
static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines)
{
    virCapsGuestMachinePtr *machines;
    char *canonical;
    static const char *const x86_machines[] = {
        "pc-0.11", "pc", "pc-0.10", "isapc"
    };

157
    if (VIR_STRDUP(canonical, x86_machines[0]) < 0)
M
Mark McLoughlin 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
        return NULL;

    machines = virCapabilitiesAllocMachines(x86_machines,
                                            ARRAY_CARDINALITY(x86_machines));
    if (machines == NULL) {
        VIR_FREE(canonical);
        return NULL;
    }

    machines[1]->canonical = canonical;

    *nmachines = ARRAY_CARDINALITY(x86_machines);

    return machines;
}

174

175 176 177 178 179 180 181 182 183 184 185 186 187
static int
testQemuAddI686Guest(virCapsPtr caps)
{
    int nmachines = 0;
    virCapsGuestMachinePtr *machines = NULL;
    virCapsGuestPtr guest;

    if (!(machines = testQemuAllocMachines(&nmachines)))
        goto error;

    if (!(guest = virCapabilitiesAddGuest(caps,
                                          VIR_DOMAIN_OSTYPE_HVM,
                                          VIR_ARCH_I686,
188
                                          QEMUBinList[TEST_UTILS_QEMU_BIN_I686],
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
                                          NULL,
                                          nmachines,
                                          machines)))
        goto error;

    if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false))
        goto error;

    machines = NULL;

    if (!virCapabilitiesAddGuestDomain(guest,
                                       VIR_DOMAIN_VIRT_QEMU,
                                       NULL,
                                       NULL,
                                       0,
                                       NULL))
        goto error;

    if (!(machines = testQemuAllocMachines(&nmachines)))
        goto error;

    if (!virCapabilitiesAddGuestDomain(guest,
                                       VIR_DOMAIN_VIRT_KVM,
212
                                       QEMUBinList[TEST_UTILS_QEMU_BIN_I686],
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                                       NULL,
                                       nmachines,
                                       machines))
        goto error;

    return 0;

 error:
    virCapabilitiesFreeMachines(machines, nmachines);
    return -1;
}


static int
testQemuAddX86_64Guest(virCapsPtr caps)
{
    int nmachines = 0;
    virCapsGuestMachinePtr *machines = NULL;
    virCapsGuestPtr guest;

    if (!(machines = testQemuAllocNewerMachines(&nmachines)))
        goto error;

    if (!(guest = virCapabilitiesAddGuest(caps,
                                          VIR_DOMAIN_OSTYPE_HVM,
                                          VIR_ARCH_X86_64,
239
                                          QEMUBinList[TEST_UTILS_QEMU_BIN_X86_64],
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
                                          NULL,
                                          nmachines,
                                          machines)))
        goto error;

    if (!virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false))
        goto error;

    machines = NULL;

    if (!virCapabilitiesAddGuestDomain(guest,
                                       VIR_DOMAIN_VIRT_QEMU,
                                       NULL,
                                       NULL,
                                       0,
                                       NULL))
        goto error;

    if (!(machines = testQemuAllocMachines(&nmachines)))
        goto error;

    if (!virCapabilitiesAddGuestDomain(guest,
                                       VIR_DOMAIN_VIRT_KVM,
263
                                       QEMUBinList[TEST_UTILS_QEMU_BIN_X86_64],
264 265 266 267 268 269 270 271 272
                                       NULL,
                                       nmachines,
                                       machines))
        goto error;

    machines = NULL;

    if (!virCapabilitiesAddGuestDomain(guest,
                                       VIR_DOMAIN_VIRT_KVM,
273
                                       QEMUBinList[TEST_UTILS_QEMU_BIN_X86_64],
274 275 276 277 278 279 280 281 282 283 284 285 286
                                       NULL,
                                       0,
                                       NULL))
        goto error;

    return 0;

 error:
    virCapabilitiesFreeMachines(machines, nmachines);
    return -1;
}


287 288 289 290 291 292 293 294 295 296
static int testQemuAddPPC64Guest(virCapsPtr caps)
{
    static const char *machine[] = { "pseries" };
    virCapsGuestMachinePtr *machines = NULL;
    virCapsGuestPtr guest;

    machines = virCapabilitiesAllocMachines(machine, 1);
    if (!machines)
        goto error;

297
    guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64,
298
                                    QEMUBinList[TEST_UTILS_QEMU_BIN_PPC64],
299
                                    NULL, 1, machines);
300 301 302
    if (!guest)
        goto error;

303
    if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
304 305 306 307
        goto error;

    return 0;

308
 error:
309 310 311 312 313
    /* No way to free a guest? */
    virCapabilitiesFreeMachines(machines, 1);
    return -1;
}

314 315 316 317 318 319 320 321 322 323
static int testQemuAddPPC64LEGuest(virCapsPtr caps)
{
    static const char *machine[] = { "pseries" };
    virCapsGuestMachinePtr *machines = NULL;
    virCapsGuestPtr guest;

    machines = virCapabilitiesAllocMachines(machine, 1);
    if (!machines)
        goto error;

324
    guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64LE,
325
                                    QEMUBinList[TEST_UTILS_QEMU_BIN_PPC64],
326
                                    NULL, 1, machines);
327 328 329
    if (!guest)
        goto error;

330
    if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
331 332 333 334 335 336 337 338 339 340
        goto error;

    return 0;

 error:
    /* No way to free a guest? */
    virCapabilitiesFreeMachines(machines, 1);
    return -1;
}

O
Olivia Yin 已提交
341 342 343 344 345
static int testQemuAddPPCGuest(virCapsPtr caps)
{
    static const char *machine[] = { "g3beige",
                                     "mac99",
                                     "prep",
346
                                     "ppce500" };
O
Olivia Yin 已提交
347 348 349 350 351 352 353
    virCapsGuestMachinePtr *machines = NULL;
    virCapsGuestPtr guest;

    machines = virCapabilitiesAllocMachines(machine, 1);
    if (!machines)
        goto error;

354
    guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC,
355
                                    QEMUBinList[TEST_UTILS_QEMU_BIN_PPC],
356
                                    NULL, 1, machines);
O
Olivia Yin 已提交
357 358 359
    if (!guest)
        goto error;

360
    if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
O
Olivia Yin 已提交
361 362 363 364
        goto error;

    return 0;

365
 error:
O
Olivia Yin 已提交
366 367 368 369 370
    /* No way to free a guest? */
    virCapabilitiesFreeMachines(machines, 1);
    return -1;
}

371 372
static int testQemuAddS390Guest(virCapsPtr caps)
{
373 374
    static const char *s390_machines[] = { "s390-virtio",
                                           "s390-ccw-virtio" };
375 376 377 378 379 380 381 382
    virCapsGuestMachinePtr *machines = NULL;
    virCapsGuestPtr guest;

    machines = virCapabilitiesAllocMachines(s390_machines,
                                            ARRAY_CARDINALITY(s390_machines));
    if (!machines)
        goto error;

383
    guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_S390X,
384
                                    QEMUBinList[TEST_UTILS_QEMU_BIN_S390X],
385
                                    NULL,
386 387 388 389 390
                                    ARRAY_CARDINALITY(s390_machines),
                                    machines);
    if (!guest)
        goto error;

391
    if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
392 393 394 395
        goto error;

    return 0;

396
 error:
397 398 399 400
    virCapabilitiesFreeMachines(machines, ARRAY_CARDINALITY(s390_machines));
    return -1;
}

401 402 403 404 405 406 407 408 409 410 411 412 413
static int testQemuAddArmGuest(virCapsPtr caps)
{
    static const char *machines[] = { "vexpress-a9",
                                      "vexpress-a15",
                                      "versatilepb" };
    virCapsGuestMachinePtr *capsmachines = NULL;
    virCapsGuestPtr guest;

    capsmachines = virCapabilitiesAllocMachines(machines,
                                                ARRAY_CARDINALITY(machines));
    if (!capsmachines)
        goto error;

414
    guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_ARMV7L,
415
                                    QEMUBinList[TEST_UTILS_QEMU_BIN_ARM],
416
                                    NULL,
417 418 419 420 421
                                    ARRAY_CARDINALITY(machines),
                                    capsmachines);
    if (!guest)
        goto error;

422
    if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
423 424 425 426
        goto error;

    return 0;

427
 error:
428 429 430 431
    virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines));
    return -1;
}

432 433 434 435 436 437 438 439 440 441 442
static int testQemuAddAARCH64Guest(virCapsPtr caps)
{
    static const char *machines[] = { "virt"};
    virCapsGuestMachinePtr *capsmachines = NULL;
    virCapsGuestPtr guest;

    capsmachines = virCapabilitiesAllocMachines(machines,
                                                ARRAY_CARDINALITY(machines));
    if (!capsmachines)
        goto error;

443
    guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_AARCH64,
444
                                    QEMUBinList[TEST_UTILS_QEMU_BIN_AARCH64],
445
                                    NULL,
446 447 448 449 450
                                    ARRAY_CARDINALITY(machines),
                                    capsmachines);
    if (!guest)
        goto error;

451
    if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL))
452 453 454 455
        goto error;

    return 0;

456
 error:
457 458 459
    virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines));
    return -1;
}
460

461 462
virCapsPtr testQemuCapsInit(void)
{
463 464
    virCapsPtr caps;

465
    if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false)))
466 467
        return NULL;

468 469 470 471 472 473 474 475 476 477
    /* Add dummy 'none' security_driver. This is equal to setting
     * security_driver = "none" in qemu.conf. */
    if (VIR_ALLOC_N(caps->host.secModels, 1) < 0)
        goto cleanup;
    caps->host.nsecModels = 1;

    if (VIR_STRDUP(caps->host.secModels[0].model, "none") < 0 ||
        VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0)
        goto cleanup;

478
    if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) ||
479
        !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) ||
480 481
        !(cpuPower8 = virCPUDefCopy(&cpuPower8Data)) ||
        !(cpuPower9 = virCPUDefCopy(&cpuPower9Data)))
482 483
        goto cleanup;

484
    qemuTestSetHostCPU(caps, NULL);
485

486 487
    caps->host.nnumaCell_max = 4;

488
    if (testQemuAddI686Guest(caps) < 0)
489 490
        goto cleanup;

491
    if (testQemuAddX86_64Guest(caps) < 0)
492 493
        goto cleanup;

494 495 496
    if (testQemuAddPPC64Guest(caps))
        goto cleanup;

497 498 499
    if (testQemuAddPPC64LEGuest(caps))
        goto cleanup;

O
Olivia Yin 已提交
500 501 502
    if (testQemuAddPPCGuest(caps))
        goto cleanup;

503 504 505
    if (testQemuAddS390Guest(caps))
        goto cleanup;

506 507 508
    if (testQemuAddArmGuest(caps))
        goto cleanup;

509 510 511
    if (testQemuAddAARCH64Guest(caps))
        goto cleanup;

512
    if (virTestGetDebug()) {
513 514 515 516 517 518
        char *caps_str;

        caps_str = virCapabilitiesFormatXML(caps);
        if (!caps_str)
            goto cleanup;

519
        VIR_TEST_DEBUG("QEMU driver capabilities:\n%s", caps_str);
520 521 522 523

        VIR_FREE(caps_str);
    }

524 525
    return caps;

526
 cleanup:
527 528 529
    caps->host.cpu = NULL;
    virCPUDefFree(cpuDefault);
    virCPUDefFree(cpuHaswell);
530
    virCPUDefFree(cpuPower8);
531
    virObjectUnref(caps);
532 533
    return NULL;
}
534 535


536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
void
qemuTestSetHostArch(virCapsPtr caps,
                    virArch arch)
{
    if (arch == VIR_ARCH_NONE)
        arch = VIR_ARCH_X86_64;
    caps->host.arch = arch;
    qemuTestSetHostCPU(caps, NULL);
}


void
qemuTestSetHostCPU(virCapsPtr caps,
                   virCPUDefPtr cpu)
{
    virArch arch = caps->host.arch;

    if (!cpu) {
        if (ARCH_IS_X86(arch))
            cpu = cpuDefault;
556 557
        else if (ARCH_IS_PPC64(arch))
            cpu = cpuPower8;
558 559 560 561 562 563 564 565
    }

    if (cpu)
        caps->host.arch = cpu->arch;
    caps->host.cpu = cpu;
}


566
virQEMUCapsPtr
567 568
qemuTestParseCapabilities(virCapsPtr caps,
                          const char *capsFile)
569 570 571
{
    virQEMUCapsPtr qemuCaps = NULL;

572
    if (!(qemuCaps = virQEMUCapsNew()) ||
573
        virQEMUCapsLoadCache(caps, qemuCaps, capsFile) < 0)
574 575 576 577 578 579 580 581
        goto error;

    return qemuCaps;

 error:
    virObjectUnref(qemuCaps);
    return NULL;
}
582 583 584

void qemuTestDriverFree(virQEMUDriver *driver)
{
585
    virMutexDestroy(&driver->lock);
586 587 588 589
    if (driver->config) {
        virFileDeleteTree(driver->config->stateDir);
        virFileDeleteTree(driver->config->configDir);
    }
590
    virQEMUCapsCacheFree(driver->qemuCapsCache);
591 592 593
    virObjectUnref(driver->xmlopt);
    virObjectUnref(driver->caps);
    virObjectUnref(driver->config);
594
    virObjectUnref(driver->securityManager);
595 596
}

597
int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache,
598 599
                            virQEMUCapsPtr caps)
{
600 601
    size_t i;
    virQEMUCapsPtr tmpCaps;
602 603

    if (caps) {
604
        tmpCaps = caps;
605
    } else {
606
        if (!(tmpCaps = virQEMUCapsNew()))
607 608 609
            return -ENOMEM;
    }

610 611 612 613 614 615 616 617 618
    for (i = 0; i < ARRAY_CARDINALITY(QEMUBinList); i++) {
        virObjectRef(tmpCaps);
        if (virHashUpdateEntry(cache->binaries,
                               QEMUBinList[i],
                               tmpCaps) < 0) {
            virObjectUnref(tmpCaps);
            return -1;
        }
    }
619

620 621
    if (!caps)
        virObjectUnref(tmpCaps);
622

623
    return 0;
624 625
}

626

627 628 629
# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX"
# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"

630 631
int qemuTestDriverInit(virQEMUDriver *driver)
{
632
    virSecurityManagerPtr mgr = NULL;
633 634
    char statedir[] = STATEDIRTEMPLATE;
    char configdir[] = CONFIGDIRTEMPLATE;
635

636 637
    memset(driver, 0, sizeof(*driver));

638 639 640
    if (virMutexInit(&driver->lock) < 0)
        return -1;

641 642
    driver->config = virQEMUDriverConfigNew(false);
    if (!driver->config)
643
        goto error;
644

645 646 647 648 649
    /* Do this early so that qemuTestDriverFree() doesn't see (unlink) the real
     * dirs. */
    VIR_FREE(driver->config->stateDir);
    VIR_FREE(driver->config->configDir);

650 651 652 653 654 655 656
    /* Overwrite some default paths so it's consistent for tests. */
    VIR_FREE(driver->config->libDir);
    VIR_FREE(driver->config->channelTargetDir);
    if (VIR_STRDUP(driver->config->libDir, "/tmp/lib") < 0 ||
        VIR_STRDUP(driver->config->channelTargetDir, "/tmp/channel") < 0)
        goto error;

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
    if (!mkdtemp(statedir)) {
        virFilePrintf(stderr, "Cannot create fake stateDir");
        goto error;
    }

    if (VIR_STRDUP(driver->config->stateDir, statedir) < 0) {
        rmdir(statedir);
        goto error;
    }

    if (!mkdtemp(configdir)) {
        virFilePrintf(stderr, "Cannot create fake configDir");
        goto error;
    }

    if (VIR_STRDUP(driver->config->configDir, configdir) < 0) {
        rmdir(configdir);
        goto error;
    }

677 678 679 680
    driver->caps = testQemuCapsInit();
    if (!driver->caps)
        goto error;

P
Pavel Fedin 已提交
681 682 683 684 685 686
    /* Using /dev/null for libDir and cacheDir automatically produces errors
     * upon attempt to use any of them */
    driver->qemuCapsCache = virQEMUCapsCacheNew("/dev/null", "/dev/null", 0, 0);
    if (!driver->qemuCapsCache)
        goto error;

687 688 689 690
    driver->xmlopt = virQEMUDriverCreateXMLConf(driver);
    if (!driver->xmlopt)
        goto error;

691
    if (qemuTestCapsCacheInsert(driver->qemuCapsCache, NULL) < 0)
P
Pavel Fedin 已提交
692 693
        goto error;

694 695 696 697 698 699
    if (!(mgr = virSecurityManagerNew("none", "qemu",
                                      VIR_SECURITY_MANAGER_PRIVILEGED)))
        goto error;
    if (!(driver->securityManager = virSecurityManagerNewStack(mgr)))
        goto error;

700 701 702
    return 0;

 error:
703
    virObjectUnref(mgr);
704 705 706
    qemuTestDriverFree(driver);
    return -1;
}
707

708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
int
testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps,
                   int gic)
{
    virGICCapability *gicCapabilities = NULL;
    size_t ngicCapabilities = 0;
    int ret = -1;

    if (VIR_ALLOC_N(gicCapabilities, 2) < 0)
        goto out;

# define IMPL_BOTH \
         VIR_GIC_IMPLEMENTATION_KERNEL|VIR_GIC_IMPLEMENTATION_EMULATED

    if (gic & GIC_V2) {
        gicCapabilities[ngicCapabilities].version = VIR_GIC_VERSION_2;
        gicCapabilities[ngicCapabilities].implementation = IMPL_BOTH;
        ngicCapabilities++;
    }
    if (gic & GIC_V3) {
        gicCapabilities[ngicCapabilities].version = VIR_GIC_VERSION_3;
        gicCapabilities[ngicCapabilities].implementation = IMPL_BOTH;
        ngicCapabilities++;
    }

# undef IMPL_BOTH

    virQEMUCapsSetGICCapabilities(qemuCaps,
                                  gicCapabilities, ngicCapabilities);

    ret = 0;

 out:
    return ret;
}

A
Atsushi SAKAI 已提交
744
#endif