12 # include "internal.h"
13 # include "qemu/qemu_conf.h"
14 # include "qemu/qemu_domain.h"
15 # include "testutilsqemu.h"
16 # include "virstring.h"
18 # define VIR_FROM_THIS VIR_FROM_NONE
20 static virQEMUDriver driver
;
23 TEST_INTERNAL
= 1 << 0, /* Test use of INTERNAL parse/format flag */
24 TEST_REDEFINE
= 1 << 1, /* Test use of REDEFINE parse flag */
25 TEST_RUNNING
= 1 << 2, /* Set snapshot state to running after parse */
29 testCompareXMLToXMLFiles(const char *inxml
,
34 char *inXmlData
= NULL
;
35 char *outXmlData
= NULL
;
38 unsigned int parseflags
= VIR_DOMAIN_SNAPSHOT_PARSE_DISKS
;
39 unsigned int formatflags
= VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE
;
41 VIR_AUTOUNREF(virDomainSnapshotDefPtr
) def
= NULL
;
43 if (flags
& TEST_INTERNAL
) {
44 parseflags
|= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL
;
45 formatflags
|= VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL
;
48 if (flags
& TEST_REDEFINE
)
49 parseflags
|= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE
;
51 if (virTestLoadFile(inxml
, &inXmlData
) < 0)
54 if (virTestLoadFile(outxml
, &outXmlData
) < 0)
57 if (!(def
= virDomainSnapshotDefParseString(inXmlData
, driver
.caps
,
58 driver
.xmlopt
, NULL
, &cur
,
62 if (!(flags
& TEST_INTERNAL
))
64 formatflags
|= VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT
;
66 if (flags
& TEST_RUNNING
) {
69 def
->state
= VIR_DOMAIN_RUNNING
;
72 if (!(actual
= virDomainSnapshotDefFormat(uuid
, def
, driver
.caps
,
77 if (STRNEQ(outXmlData
, actual
)) {
78 virTestDifferenceFull(stderr
, outXmlData
, outxml
, actual
, inxml
);
95 long long creationTime
;
98 static long long mocktime
;
101 testSnapshotPostParse(virDomainMomentDefPtr def
)
105 if (def
->creationTime
)
107 def
->creationTime
= mocktime
;
109 virAsprintf(&def
->name
, "%lld", def
->creationTime
) < 0)
115 testCompareXMLToXMLHelper(const void *data
)
117 const struct testInfo
*info
= data
;
119 mocktime
= info
->creationTime
;
120 return testCompareXMLToXMLFiles(info
->inxml
, info
->outxml
, info
->uuid
,
130 if (qemuTestDriverInit(&driver
) < 0)
133 virDomainXMLOptionSetMomentPostParse(driver
.xmlopt
,
134 testSnapshotPostParse
);
136 # define DO_TEST(prefix, name, inpath, outpath, uuid, time, flags) \
138 const struct testInfo info = {abs_srcdir "/" inpath "/" name ".xml", \
139 abs_srcdir "/" outpath "/" name ".xml", \
140 uuid, time, flags}; \
141 if (virTestRun("SNAPSHOT XML-2-XML " prefix " " name, \
142 testCompareXMLToXMLHelper, &info) < 0) \
146 # define DO_TEST_IN(name, uuid) DO_TEST("in->in", name, \
147 "qemudomainsnapshotxml2xmlin", \
148 "qemudomainsnapshotxml2xmlin", \
151 # define DO_TEST_OUT(name, uuid, internal) \
152 DO_TEST("out->out", name, "qemudomainsnapshotxml2xmlout", \
153 "qemudomainsnapshotxml2xmlout", uuid, 0, internal | TEST_REDEFINE)
155 # define DO_TEST_INOUT(name, uuid, time, flags) \
156 DO_TEST("in->out", name, \
157 "qemudomainsnapshotxml2xmlin",\
158 "qemudomainsnapshotxml2xmlout",\
161 /* Unset or set all envvars here that are copied in qemudBuildCommandLine
162 * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
163 * values for these envvars */
164 setenv("PATH", "/bin", 1);
166 DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
168 DO_TEST_OUT("disk_snapshot_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
170 DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
172 DO_TEST_OUT("noparent_nodescription_noactive", NULL
, 0);
173 DO_TEST_OUT("noparent_nodescription", NULL
, TEST_INTERNAL
);
174 DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
175 DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
176 DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
179 DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
181 DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
182 1272917631, TEST_RUNNING
);
183 DO_TEST_INOUT("external_vm", NULL
, 1555419243, 0);
184 DO_TEST_INOUT("disk_snapshot", NULL
, 1555419243, 0);
185 DO_TEST_INOUT("disk_driver_name_null", NULL
, 1555419243, 0);
186 DO_TEST_INOUT("disk-seclabel", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 581484660, 0);
188 DO_TEST_IN("name_and_description", NULL
);
189 DO_TEST_IN("description_only", NULL
);
190 DO_TEST_IN("name_only", NULL
);
192 qemuTestDriverFree(&driver
);
194 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
197 VIR_TEST_MAIN(mymain
)
207 #endif /* WITH_QEMU */