testutilsxen.c 2.5 KB
Newer Older
1 2 3 4 5 6
#include <config.h>

#include <sys/utsname.h>
#include <stdlib.h>

#include "testutilsxen.h"
7 8
#include "domain_conf.h"

9
static int testXenDefaultConsoleType(const char *ostype,
10
                                     virArch arch ATTRIBUTE_UNUSED)
11 12 13 14 15 16
{
    if (STREQ(ostype, "hvm"))
        return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
    else
        return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
}
17

18 19 20 21 22 23
virDomainXMLConfPtr
testXenXMLConfInit(void)
{
    return virDomainXMLConfNew(NULL, NULL);
}

24 25 26 27
virCapsPtr testXenCapsInit(void) {
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
28 29
    virCapsGuestMachinePtr *machines;
    int nmachines;
30 31 32 33 34 35 36
    static const char *const x86_machines[] = {
        "xenfv"
    };
    static const char *const xen_machines[] = {
        "xenpv"
    };

37
    uname(&utsname);
38
    if ((caps = virCapabilitiesNew(VIR_ARCH_I686,
39 40 41
                                   0, 0)) == NULL)
        return NULL;

42 43
    caps->defaultConsoleTargetType = testXenDefaultConsoleType;

44 45 46 47
    nmachines = ARRAY_CARDINALITY(x86_machines);
    if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
        goto cleanup;

48
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
49
                                         "/usr/lib/xen/bin/qemu-dm", NULL,
50
                                         nmachines, machines)) == NULL)
51
        goto cleanup;
52 53
    machines = NULL;

54 55 56 57 58 59 60 61
    if (virCapabilitiesAddGuestDomain(guest,
                                      "xen",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

62 63 64 65
    nmachines = ARRAY_CARDINALITY(xen_machines);
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

66
    if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_I686,
67
                                         "/usr/lib/xen/bin/qemu-dm", NULL,
68
                                         nmachines, machines)) == NULL)
69
        goto cleanup;
70 71
    machines = NULL;

72 73 74 75 76 77 78 79 80 81 82
    if (virCapabilitiesAddGuestDomain(guest,
                                      "xen",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

    return caps;

cleanup:
83
    virCapabilitiesFreeMachines(machines, nmachines);
84
    virObjectUnref(caps);
85 86
    return NULL;
}