2 * Copyright (C) 2011-2013 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
23 #include "virbuffer.h"
25 #include "testutils.h"
26 #include "testutilsqemu.h"
27 #include "qemumonitortestutils.h"
28 #include "qemu/qemu_migration_params.h"
29 #define LIBVIRT_QEMU_MIGRATION_PARAMSPRIV_H_ALLOW
30 #include "qemu/qemu_migration_paramspriv.h"
31 #include "qemu/qemu_monitor.h"
33 #define VIR_FROM_THIS VIR_FROM_NONE
35 typedef struct _qemuMigParamsData qemuMigParamsData
;
36 struct _qemuMigParamsData
{
37 virDomainXMLOptionPtr xmlopt
;
43 qemuMigParamsTestFormatXML(virBufferPtr buf
,
44 qemuMigrationParamsPtr migParams
)
46 virBufferAddLit(buf
, "<test>\n");
47 virBufferAdjustIndent(buf
, 2);
50 qemuMigrationParamsFormat(buf
, migParams
);
52 virBufferAdjustIndent(buf
, -2);
53 virBufferAddLit(buf
, "</test>\n");
58 qemuMigParamsTestXML2XML(const void *opaque
)
60 const qemuMigParamsData
*data
= opaque
;
61 virBuffer buf
= VIR_BUFFER_INITIALIZER
;
64 xmlXPathContextPtr ctxt
= NULL
;
65 qemuMigrationParamsPtr migParams
= NULL
;
66 char *actualXML
= NULL
;
69 if (virAsprintf(&xmlFile
, "%s/qemumigparamsdata/%s.xml",
70 abs_srcdir
, data
->name
) < 0)
73 if (!(doc
= virXMLParseFileCtxt(xmlFile
, &ctxt
)))
76 if (qemuMigrationParamsParse(ctxt
, &migParams
) < 0)
79 qemuMigParamsTestFormatXML(&buf
, migParams
);
81 if (!(actualXML
= virBufferContentAndReset(&buf
)))
84 if (virTestCompareToFile(actualXML
, xmlFile
) < 0)
92 qemuMigrationParamsFree(migParams
);
93 virBufferFreeAndReset(&buf
);
94 xmlXPathFreeContext(ctxt
);
101 qemuMigParamsTestXML(const void *opaque
)
103 const qemuMigParamsData
*data
= opaque
;
104 virBuffer buf
= VIR_BUFFER_INITIALIZER
;
105 char *replyFile
= NULL
;
106 char *xmlFile
= NULL
;
107 qemuMonitorTestPtr mon
= NULL
;
108 virJSONValuePtr params
= NULL
;
109 qemuMigrationParamsPtr migParams
= NULL
;
110 char *actualXML
= NULL
;
113 if (virAsprintf(&replyFile
, "%s/qemumigparamsdata/%s.reply",
114 abs_srcdir
, data
->name
) < 0 ||
115 virAsprintf(&xmlFile
, "%s/qemumigparamsdata/%s.xml",
116 abs_srcdir
, data
->name
) < 0)
119 if (!(mon
= qemuMonitorTestNewFromFile(replyFile
, data
->xmlopt
, true)))
122 if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon
),
126 if (!(migParams
= qemuMigrationParamsFromJSON(params
)))
129 qemuMigParamsTestFormatXML(&buf
, migParams
);
131 if (!(actualXML
= virBufferContentAndReset(&buf
)))
134 if (virTestCompareToFile(actualXML
, xmlFile
) < 0)
143 virJSONValueFree(params
);
144 qemuMigrationParamsFree(migParams
);
145 virBufferFreeAndReset(&buf
);
146 qemuMonitorTestFree(mon
);
152 qemuMigParamsTestJSON(const void *opaque
)
154 const qemuMigParamsData
*data
= opaque
;
155 char *replyFile
= NULL
;
156 char *jsonFile
= NULL
;
157 qemuMonitorTestPtr mon
= NULL
;
158 virJSONValuePtr paramsIn
= NULL
;
159 virJSONValuePtr paramsOut
= NULL
;
160 qemuMigrationParamsPtr migParams
= NULL
;
161 char *actualJSON
= NULL
;
164 if (virAsprintf(&replyFile
, "%s/qemumigparamsdata/%s.reply",
165 abs_srcdir
, data
->name
) < 0 ||
166 virAsprintf(&jsonFile
, "%s/qemumigparamsdata/%s.json",
167 abs_srcdir
, data
->name
) < 0)
170 if (!(mon
= qemuMonitorTestNewFromFile(replyFile
, data
->xmlopt
, true)))
173 if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon
),
177 if (!(migParams
= qemuMigrationParamsFromJSON(paramsIn
)))
180 if (!(paramsOut
= qemuMigrationParamsToJSON(migParams
)) ||
181 !(actualJSON
= virJSONValueToString(paramsOut
, true)))
184 if (virTestCompareToFile(actualJSON
, jsonFile
) < 0)
192 VIR_FREE(actualJSON
);
193 virJSONValueFree(paramsIn
);
194 virJSONValueFree(paramsOut
);
195 qemuMigrationParamsFree(migParams
);
196 qemuMonitorTestFree(mon
);
204 virQEMUDriver driver
;
208 fputs("libvirt not compiled with JSON support, skipping this test\n", stderr
);
212 if (virThreadInitialize() < 0 ||
213 qemuTestDriverInit(&driver
) < 0)
216 virEventRegisterDefaultImpl();
218 #define DO_TEST(name) \
220 qemuMigParamsData data = { \
221 driver.xmlopt, name \
223 if (virTestRun(name " (xml)", qemuMigParamsTestXML, &data) < 0) \
225 if (virTestRun(name " (json)", qemuMigParamsTestJSON, &data) < 0) \
227 if (virTestRun(name " (xml2xml)", qemuMigParamsTestXML2XML, &data) < 0) \
231 DO_TEST("unsupported");
235 DO_TEST("tls-enabled");
236 DO_TEST("tls-hostname");
238 qemuTestDriverFree(&driver
);
240 return (ret
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
243 VIR_TEST_MAIN(mymain
)