File: qemuxmlactivetest.c

package info (click to toggle)
libvirt 12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212,536 kB
  • sloc: ansic: 537,688; xml: 342,012; python: 12,056; perl: 2,626; sh: 2,175; makefile: 448; javascript: 126; cpp: 22
file content (290 lines) | stat: -rw-r--r-- 8,648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include <config.h>

#include <unistd.h>

#include <sys/types.h>
#include <fcntl.h>

#include "testutils.h"

#include "internal.h"
#include "testutilsqemu.h"
#include "configmake.h"

#define VIR_FROM_THIS VIR_FROM_NONE

static virQEMUDriver driver;

static int
testCompareStatusXMLToXMLFiles(const void *opaque)
{
    const testQemuInfo *data = opaque;
    virDomainObj *obj = NULL;
    g_autofree char *actual = NULL;
    int ret = -1;

    /* this test suite doesn't yet need testQemuInfoInitArgs() */

    if (!(obj = virDomainObjParseFile(data->infile, driver.xmlopt,
                                      VIR_DOMAIN_DEF_PARSE_STATUS |
                                      VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
                                      VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
                                      VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE |
                                      VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL |
                                      VIR_DOMAIN_DEF_PARSE_VOLUME_TRANSLATED))) {
        VIR_TEST_DEBUG("\nfailed to parse '%s'", data->infile);
        goto cleanup;
    }

    if (!(actual = virDomainObjFormat(obj, driver.xmlopt,
                                      VIR_DOMAIN_DEF_FORMAT_SECURE |
                                      VIR_DOMAIN_DEF_FORMAT_STATUS |
                                      VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET |
                                      VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES |
                                      VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST |
                                      VIR_DOMAIN_DEF_FORMAT_VOLUME_TRANSLATED))) {
        VIR_TEST_DEBUG("\nfailed to format back '%s'", data->infile);
        goto cleanup;
    }

    if (virTestCompareToFile(actual, data->outfile) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    virDomainObjEndAPI(&obj);
    return ret;
}


static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/";


static int
testRunStatus(const char *name,
              struct testQemuConf *testConf,
              ...)
{
    g_autofree char *testname = g_strdup_printf("QEMU status XML-2-XML %s", name);
    g_autoptr(testQemuInfo) info = g_new0(testQemuInfo, 1);
    va_list ap;

    info->name = name;
    info->conf = testConf;

    va_start(ap, testConf);
    testQemuInfoSetArgs(info, ap);
    va_end(ap);

    info->infile = g_strdup_printf("%s%s-in.xml", statusPath, info->name);
    info->outfile = g_strdup_printf("%s%s-out.xml", statusPath, info->name);

    if (virTestRun(testname, testCompareStatusXMLToXMLFiles, info) < 0)
        return -1;

    return 0;
}


static int
testqemuActiveXML2XMLCommonPrepare(testQemuInfo *info)
{
    if (info->prepared)
        return 0;

    if (testQemuInfoInitArgs((testQemuInfo *) info) < 0)
        goto error;

    virFileCacheClear(driver.qemuCapsCache);

    if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
        goto error;

    if (!(info->def = virDomainDefParseFile(info->infile,
                                            driver.xmlopt, NULL,
                                            info->parseFlags)))
        goto error;

    if (!virDomainDefCheckABIStability(info->def, info->def, driver.xmlopt)) {
        VIR_TEST_DEBUG("ABI stability check failed on %s", info->infile);
        goto error;
    }

    /* make sure that the XML definition looks active, by setting an ID
     * as otherwise the XML formatter will simply assume that it's inactive */
    if (info->def->id == -1)
        info->def->id = 1337;

    info->prepared = true;
    return 0;

 error:
    info->prep_skip = true;
    info->prepared = true;
    return -1;
}


static int
testqemuActiveXML2XMLCommon(testQemuInfo *info,
                            bool live)
{
    g_autofree char *actual = NULL;
    const char *outfile = info->out_xml_active;
    unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;

    if (info->prep_skip)
        return EXIT_AM_SKIP;

    if (testqemuActiveXML2XMLCommonPrepare(info) < 0)
        return -1;

    if (!live) {
        format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
        outfile = info->out_xml_inactive;
    }

    if (!(actual = virDomainDefFormat(info->def, driver.xmlopt, format_flags))) {
        VIR_TEST_VERBOSE("failed to format output XML\n");
        return -1;
    }

    if (virTestCompareToFile(actual, outfile) < 0)
        return -1;

    return 0;
}


static int
testqemuActiveXML2XMLActive(const void *opaque)
{
    testQemuInfo *info = (testQemuInfo *) opaque;

    return testqemuActiveXML2XMLCommon(info, true);
}


static int
testqemuActiveXML2XMLInactive(const void *opaque)
{
    testQemuInfo *info = (testQemuInfo *) opaque;

    return testqemuActiveXML2XMLCommon(info, false);
}


static void
testRunActive(const char *name,
              const char *suffix,
              struct testQemuConf *testConf,
              int *ret,
              ...)
{
    g_autofree char *name_active = g_strdup_printf("QEMU active-XML -> active-XML %s", name);
    g_autofree char *name_inactive = g_strdup_printf("QEMU activeXML -> inactive-XMLXML %s", name);
    g_autoptr(testQemuInfo) info = g_new0(testQemuInfo, 1);
    va_list ap;

    info->name = name;
    info->conf = testConf;

    va_start(ap, ret);
    testQemuInfoSetArgs(info, ap);
    va_end(ap);

    info->infile = g_strdup_printf("%s/qemuxmlconfdata/%s.xml", abs_srcdir,
                                   info->name);

    info->out_xml_active = g_strdup_printf("%s/qemuxmlactive2xmldata/%s-active%s.xml",
                                           abs_srcdir, info->name, suffix);

    info->out_xml_inactive = g_strdup_printf("%s/qemuxmlactive2xmldata/%s-inactive%s.xml",
                                             abs_srcdir, info->name, suffix);

    virTestRunLog(ret, name_inactive, testqemuActiveXML2XMLInactive, info);
    virTestRunLog(ret, name_active, testqemuActiveXML2XMLActive, info);
}


static int
mymain(void)
{
    int ret = 0;
    g_autoptr(virConnect) conn = NULL;
    g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
    g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
    struct testQemuConf testConf = { .capslatest = capslatest,
                                     .capscache = capscache,
                                     .qapiSchemaCache = NULL };

    if (qemuTestDriverInit(&driver) < 0)
        return EXIT_FAILURE;

    if (!(conn = virGetConnect()))
        goto cleanup;

    virSetConnectInterface(conn);
    virSetConnectNetwork(conn);
    virSetConnectNWFilter(conn);
    virSetConnectNodeDev(conn);
    virSetConnectSecret(conn);
    virSetConnectStorage(conn);

#define DO_TEST_ACTIVE_CAPS_ARCH_LATEST(_name, arch) \
    testRunActive(_name, "." arch "-latest", &testConf, &ret, \
                  ARG_CAPS_ARCH, arch, ARG_CAPS_VER, "latest", ARG_END);

#define DO_TEST_ACTIVE_CAPS_LATEST(_name) \
    DO_TEST_ACTIVE_CAPS_ARCH_LATEST(_name, "x86_64");

    DO_TEST_ACTIVE_CAPS_LATEST("channel-unix-source-path");
    DO_TEST_ACTIVE_CAPS_LATEST("channel-virtio-state");
    DO_TEST_ACTIVE_CAPS_LATEST("disk-active-commit");
    DO_TEST_ACTIVE_CAPS_LATEST("disk-backing-chains-index");
    DO_TEST_ACTIVE_CAPS_LATEST("disk-mirror");
    DO_TEST_ACTIVE_CAPS_LATEST("disk-mirror-old");
    DO_TEST_ACTIVE_CAPS_LATEST("genid");
    DO_TEST_ACTIVE_CAPS_LATEST("genid-auto");
    DO_TEST_ACTIVE_CAPS_LATEST("graphics-vnc-remove-generated-socket");
    DO_TEST_ACTIVE_CAPS_LATEST("seclabel-static-labelskip");

    DO_TEST_ACTIVE_CAPS_ARCH_LATEST("cpu-model-deprecated-features-on", "s390x");
    DO_TEST_ACTIVE_CAPS_ARCH_LATEST("cpu-model-deprecated-features-off", "s390x");

#define DO_TEST_STATUS(_name) \
    do { \
        if (testRunStatus(_name, &testConf, ARG_END) < 0) \
            ret = -1; \
    } while (0)

    DO_TEST_STATUS("blockjob-mirror");
    DO_TEST_STATUS("vcpus-multi");
    DO_TEST_STATUS("modern");
    DO_TEST_STATUS("migration-out-nbd");
    DO_TEST_STATUS("migration-in-params");
    DO_TEST_STATUS("migration-out-params");
    DO_TEST_STATUS("migration-out-nbd-tls");
    DO_TEST_STATUS("migration-out-nbd-bitmaps");
    DO_TEST_STATUS("upgrade");

    DO_TEST_STATUS("blockjob-blockdev");

    DO_TEST_STATUS("backup-pull");
    DO_TEST_STATUS("throttlefilter");

    DO_TEST_STATUS("memory-backing-dir");

    DO_TEST_STATUS("qcow2-data-file");

 cleanup:
    qemuTestDriverFree(&driver);

    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

VIR_TEST_MAIN_PRELOAD(mymain,
                      VIR_TEST_MOCK("virpci"),
                      VIR_TEST_MOCK("virrandom"),
                      VIR_TEST_MOCK("domaincaps"))