testutilsqemu.c 3.6 KB
Newer Older
1
#include <config.h>
A
Atsushi SAKAI 已提交
2
#ifdef WITH_QEMU
3 4 5 6
#include <sys/utsname.h>
#include <stdlib.h>

#include "testutilsqemu.h"
7 8
#include "testutils.h"
#include "memory.h"
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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;
}

27 28 29 30
virCapsPtr testQemuCapsInit(void) {
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
31 32
    virCapsGuestMachinePtr *machines;
    int nmachines;
33 34 35 36 37 38 39 40 41
    static const char *const xen_machines[] = {
        "xenner"
    };

    uname (&utsname);
    if ((caps = virCapabilitiesNew(utsname.machine,
                                   0, 0)) == NULL)
        return NULL;

42
    if ((machines = testQemuAllocMachines(&nmachines)) == NULL)
43 44
        goto cleanup;

45 46
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
                                         "/usr/bin/qemu", NULL,
47
                                         nmachines, machines)) == NULL)
48
        goto cleanup;
49 50
    machines = NULL;

51 52 53 54 55 56 57 58
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

59
    if ((machines = testQemuAllocMachines(&nmachines)) == NULL)
60 61
        goto cleanup;

62 63
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64,
                                         "/usr/bin/qemu-system-x86_64", NULL,
64
                                         nmachines, machines)) == NULL)
65
        goto cleanup;
66 67
    machines = NULL;

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

83
    nmachines = ARRAY_CARDINALITY(xen_machines);
84 85 86
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

87 88
    if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64,
                                         "/usr/bin/xenner", NULL,
89
                                         nmachines, machines)) == NULL)
90
        goto cleanup;
91 92
    machines = NULL;

93 94 95 96 97 98 99 100
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

101 102 103 104 105 106 107 108 109 110 111 112
    if (testDebug) {
        char *caps_str;

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

        fprintf(stderr, "QEMU driver capabilities:\n%s", caps_str);

        VIR_FREE(caps_str);
    }

113 114 115
    return caps;

cleanup:
116
    virCapabilitiesFreeMachines(machines, nmachines);
117 118 119
    virCapabilitiesFree(caps);
    return NULL;
}
A
Atsushi SAKAI 已提交
120
#endif