qemucapabilitiestest.c 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (C) 2011-2013 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#include <config.h>

#include "testutils.h"
#include "testutilsqemu.h"
#include "qemumonitortestutils.h"
25
#define __QEMU_CAPSPRIV_H_ALLOW__
26
#include "qemu/qemu_capspriv.h"
27 28 29 30

#define VIR_FROM_THIS VIR_FROM_NONE

typedef struct _testQemuData testQemuData;
31
typedef testQemuData *testQemuDataPtr;
32 33
struct _testQemuData {
    virDomainXMLOptionPtr xmlopt;
34
    const char *archName;
35 36 37 38 39 40 41 42
    const char *base;
};


static int
testQemuCaps(const void *opaque)
{
    int ret = -1;
E
Eric Blake 已提交
43
    const testQemuData *data = opaque;
44 45
    char *repliesFile = NULL;
    char *capsFile = NULL;
46
    qemuMonitorTestPtr mon = NULL;
47
    virQEMUCapsPtr capsActual = NULL;
48
    char *actual = NULL;
49

50 51
    if (virAsprintf(&repliesFile, "%s/qemucapabilitiesdata/%s.%s.replies",
                    abs_srcdir, data->base, data->archName) < 0 ||
52
        virAsprintf(&capsFile, "%s/qemucapabilitiesdata/%s.%s.xml",
53
                    abs_srcdir, data->base, data->archName) < 0)
54 55
        goto cleanup;

56
    if (!(mon = qemuMonitorTestNewFromFile(repliesFile, data->xmlopt, false)))
57 58
        goto cleanup;

59 60 61
    if (!(capsActual = virQEMUCapsNew()) ||
        virQEMUCapsInitQMPMonitor(capsActual,
                                  qemuMonitorTestGetMonitor(mon)) < 0)
62 63
        goto cleanup;

64 65 66 67 68
    if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM) &&
        virQEMUCapsInitQMPMonitorTCG(capsActual,
                                     qemuMonitorTestGetMonitor(mon)) < 0)
        goto cleanup;

69
    if (!(actual = virQEMUCapsFormatCache(capsActual, 0, 0)))
70 71
        goto cleanup;

72
    if (virTestCompareToFile(actual, capsFile) < 0)
73 74 75
        goto cleanup;

    ret = 0;
76
 cleanup:
77 78
    VIR_FREE(repliesFile);
    VIR_FREE(capsFile);
79
    VIR_FREE(actual);
80
    qemuMonitorTestFree(mon);
81
    virObjectUnref(capsActual);
82 83 84
    return ret;
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

static int
testQemuCapsCopy(const void *opaque)
{
    int ret = -1;
    const testQemuData *data = opaque;
    char *capsFile = NULL;
    virCapsPtr caps = NULL;
    virQEMUCapsPtr orig = NULL;
    virQEMUCapsPtr copy = NULL;
    char *actual = NULL;

    if (virAsprintf(&capsFile, "%s/qemucapabilitiesdata/%s.%s.xml",
                    abs_srcdir, data->base, data->archName) < 0)
        goto cleanup;

    if (!(caps = virCapabilitiesNew(virArchFromString(data->archName),
                                    false, false)))
        goto cleanup;

105
    if (!(orig = qemuTestParseCapabilities(caps, capsFile)))
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        goto cleanup;

    if (!(copy = virQEMUCapsNewCopy(orig)))
        goto cleanup;

    if (!(actual = virQEMUCapsFormatCache(copy, 0, 0)))
        goto cleanup;

    if (virTestCompareToFile(actual, capsFile) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    VIR_FREE(capsFile);
    virObjectUnref(caps);
    virObjectUnref(orig);
    virObjectUnref(copy);
    VIR_FREE(actual);
    return ret;
}


129 130 131 132
static int
mymain(void)
{
    int ret = 0;
133
    virQEMUDriver driver;
134 135 136 137 138 139 140 141
    testQemuData data;

#if !WITH_YAJL
    fputs("libvirt not compiled with yajl, skipping this test\n", stderr);
    return EXIT_AM_SKIP;
#endif

    if (virThreadInitialize() < 0 ||
142
        qemuTestDriverInit(&driver) < 0)
143 144 145 146
        return EXIT_FAILURE;

    virEventRegisterDefaultImpl();

147
    data.xmlopt = driver.xmlopt;
148

149 150 151 152
#define DO_TEST(arch, name)                                             \
    do {                                                                \
        data.archName = arch;                                           \
        data.base = name;                                               \
153
        if (virTestRun(name "(" arch ")", testQemuCaps, &data) < 0)     \
154
            ret = -1;                                                   \
155 156 157
        if (virTestRun("copy " name "(" arch ")",                       \
                       testQemuCapsCopy, &data) < 0)                    \
            ret = -1;                                                   \
158
    } while (0)
159

160 161 162 163 164
    DO_TEST("x86_64", "caps_1.2.2");
    DO_TEST("x86_64", "caps_1.3.1");
    DO_TEST("x86_64", "caps_1.4.2");
    DO_TEST("x86_64", "caps_1.5.3");
    DO_TEST("x86_64", "caps_1.6.0");
165
    DO_TEST("x86_64", "caps_1.7.0");
166 167 168 169
    DO_TEST("x86_64", "caps_2.1.1");
    DO_TEST("x86_64", "caps_2.4.0");
    DO_TEST("x86_64", "caps_2.5.0");
    DO_TEST("x86_64", "caps_2.6.0");
170
    DO_TEST("x86_64", "caps_2.7.0");
171
    DO_TEST("x86_64", "caps_2.8.0");
P
Pavel Hrdina 已提交
172
    DO_TEST("x86_64", "caps_2.9.0");
173 174 175
    DO_TEST("aarch64", "caps_2.6.0-gicv2");
    DO_TEST("aarch64", "caps_2.6.0-gicv3");
    DO_TEST("ppc64le", "caps_2.6.0");
176 177
    DO_TEST("s390x", "caps_2.7.0");
    DO_TEST("s390x", "caps_2.8.0");
178

J
Jiri Denemark 已提交
179 180 181 182 183
    /*
     * Run "tests/qemucapsprobe /path/to/qemu/binary >foo.replies"
     * to generate updated or new *.replies data files.
     */

184 185
    qemuTestDriverFree(&driver);

186 187 188
    return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

189
VIR_TEST_MAIN(mymain)