testutilsqemu.c 3.3 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

virCapsPtr testQemuCapsInit(void) {
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
14 15
    virCapsGuestMachinePtr *machines;
    int nmachines;
16 17 18 19 20 21 22 23 24 25 26 27
    static const char *const x86_machines[] = {
        "pc", "isapc"
    };
    static const char *const xen_machines[] = {
        "xenner"
    };

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

28 29 30 31
    nmachines = 2;
    if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
        goto cleanup;

32 33
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
                                         "/usr/bin/qemu", NULL,
34
                                         nmachines, machines)) == NULL)
35
        goto cleanup;
36 37
    machines = NULL;

38 39 40 41 42 43 44 45
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

46 47 48 49
    nmachines = 2;
    if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
        goto cleanup;

50 51
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64,
                                         "/usr/bin/qemu-system-x86_64", NULL,
52
                                         nmachines, machines)) == NULL)
53
        goto cleanup;
54 55
    machines = NULL;

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

71 72 73 74
    nmachines = 1;
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

75 76
    if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64,
                                         "/usr/bin/xenner", NULL,
77
                                         1, machines)) == NULL)
78
        goto cleanup;
79 80
    machines = NULL;

81 82 83 84 85 86 87 88
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

89 90 91 92 93 94 95 96 97 98 99 100
    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);
    }

101 102 103
    return caps;

cleanup:
104
    virCapabilitiesFreeMachines(machines, nmachines);
105 106 107
    virCapabilitiesFree(caps);
    return NULL;
}
A
Atsushi SAKAI 已提交
108
#endif