bhyvexml2argvtest.c 4.0 KB
Newer Older
R
Roman Bogorodskiy 已提交
1 2 3 4 5 6 7 8
#include <config.h>

#include "testutils.h"

#ifdef WITH_BHYVE

# include "datatypes.h"

9
# include "bhyve/bhyve_capabilities.h"
R
Roman Bogorodskiy 已提交
10 11 12 13 14 15 16 17
# include "bhyve/bhyve_utils.h"
# include "bhyve/bhyve_command.h"

# define VIR_FROM_THIS VIR_FROM_BHYVE

static bhyveConn driver;

static int testCompareXMLToArgvFiles(const char *xml,
18 19 20
                                     const char *cmdline,
                                     const char *ldcmdline,
                                     const char *dmcmdline)
R
Roman Bogorodskiy 已提交
21
{
22
    char *actualargv = NULL, *actualld = NULL, *actualdm = NULL;
R
Roman Bogorodskiy 已提交
23
    virDomainDefPtr vmdef = NULL;
24
    virCommandPtr cmd = NULL, ldcmd = NULL;
R
Roman Bogorodskiy 已提交
25
    virConnectPtr conn;
R
Roman Bogorodskiy 已提交
26 27
    int ret = -1;

R
Roman Bogorodskiy 已提交
28 29
    if (!(conn = virGetConnect()))
        goto out;
R
Roman Bogorodskiy 已提交
30 31

    if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
32
                                        VIR_DOMAIN_DEF_PARSE_INACTIVE)))
R
Roman Bogorodskiy 已提交
33 34
        goto out;

35
    conn->privateData = &driver;
R
Roman Bogorodskiy 已提交
36

R
Roman Bogorodskiy 已提交
37
    if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false)))
R
Roman Bogorodskiy 已提交
38 39 40 41 42
        goto out;

    if (!(actualargv = virCommandToString(cmd)))
        goto out;

43 44 45 46 47 48 49 50 51 52
    if (!(ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "<device.map>",
                                              &actualdm)))
        goto out;

    if (actualdm != NULL)
        virTrimSpaces(actualdm, NULL);

    if (!(actualld = virCommandToString(ldcmd)))
        goto out;

C
Cole Robinson 已提交
53
    if (virtTestCompareToFile(actualargv, cmdline) < 0)
R
Roman Bogorodskiy 已提交
54 55
        goto out;

C
Cole Robinson 已提交
56
    if (virtTestCompareToFile(actualld, ldcmdline) < 0)
57 58
        goto out;

C
Cole Robinson 已提交
59 60 61
    if (virFileExists(dmcmdline) || actualdm) {
        if (virtTestCompareToFile(actualdm, dmcmdline) < 0)
            goto out;
62 63
    }

R
Roman Bogorodskiy 已提交
64 65 66 67
    ret = 0;

 out:
    VIR_FREE(actualargv);
68 69
    VIR_FREE(actualld);
    VIR_FREE(actualdm);
R
Roman Bogorodskiy 已提交
70
    virCommandFree(cmd);
71
    virCommandFree(ldcmd);
R
Roman Bogorodskiy 已提交
72 73 74 75 76 77 78 79 80 81
    virDomainDefFree(vmdef);
    return ret;
}

static int
testCompareXMLToArgvHelper(const void *data)
{
    int ret = -1;
    const char *name = data;
    char *xml = NULL;
82
    char *args = NULL, *ldargs = NULL, *dmargs = NULL;
R
Roman Bogorodskiy 已提交
83 84 85 86

    if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
                    abs_srcdir, name) < 0 ||
        virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
87 88 89 90
                    abs_srcdir, name) < 0 ||
        virAsprintf(&ldargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
                    abs_srcdir, name) < 0 ||
        virAsprintf(&dmargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
R
Roman Bogorodskiy 已提交
91 92 93
                    abs_srcdir, name) < 0)
        goto cleanup;

94
    ret = testCompareXMLToArgvFiles(xml, args, ldargs, dmargs);
R
Roman Bogorodskiy 已提交
95 96 97 98 99 100 101 102 103 104 105 106

 cleanup:
    VIR_FREE(xml);
    VIR_FREE(args);
    return ret;
}

static int
mymain(void)
{
    int ret = 0;

107
    if ((driver.caps = virBhyveCapsBuild()) == NULL)
R
Roman Bogorodskiy 已提交
108 109 110 111 112 113 114 115 116 117 118 119
        return EXIT_FAILURE;

    if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)) == NULL)
        return EXIT_FAILURE;

# define DO_TEST(name)                                        \
    do {                                                      \
        if (virtTestRun("BHYVE XML-2-ARGV " name,             \
                       testCompareXMLToArgvHelper, name) < 0) \
            ret = -1;                                         \
    } while (0)

120
    driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
R
Roman Bogorodskiy 已提交
121
    driver.bhyvecaps = BHYVE_CAP_RTC_UTC;
R
Roman Bogorodskiy 已提交
122 123 124

    DO_TEST("base");
    DO_TEST("acpiapic");
R
Roman Bogorodskiy 已提交
125
    DO_TEST("disk-cdrom");
R
Roman Bogorodskiy 已提交
126 127
    DO_TEST("disk-virtio");
    DO_TEST("macaddr");
128 129
    DO_TEST("serial");
    DO_TEST("console");
130
    DO_TEST("grub-defaults");
131 132
    DO_TEST("grub-bootorder");
    DO_TEST("grub-bootorder2");
133 134 135
    DO_TEST("bhyveload-explicitargs");
    DO_TEST("custom-loader");
    DO_TEST("disk-cdrom-grub");
136
    DO_TEST("serial-grub");
R
Roman Bogorodskiy 已提交
137
    DO_TEST("localtime");
138 139 140 141

    driver.grubcaps = 0;

    DO_TEST("serial-grub-nocons");
R
Roman Bogorodskiy 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

    virObjectUnref(driver.caps);
    virObjectUnref(driver.xmlopt);

    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyvexml2argvmock.so")

#else

int main(void)
{
    return EXIT_AM_SKIP;
}

#endif /* WITH_BHYVE */