2014-05-19 12:47:31 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2020-02-16 21:59:28 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-05-19 12:47:31 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_VBOX
|
|
|
|
|
|
|
|
# include "vbox/vbox_snapshot_conf.h"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
static const char *testSnapshotXMLVariableLineRegexStr =
|
|
|
|
"lastStateChange=[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z";
|
|
|
|
|
2019-11-13 15:06:45 +00:00
|
|
|
GRegex *testSnapshotXMLVariableLineRegex = NULL;
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
testFilterXML(char *xml)
|
|
|
|
{
|
2020-07-02 23:35:41 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2014-05-19 12:47:31 +00:00
|
|
|
char **xmlLines = NULL;
|
|
|
|
char **xmlLine;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if (!(xmlLines = virStringSplit(xml, "\n", 0))) {
|
|
|
|
VIR_FREE(xml);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
for (xmlLine = xmlLines; *xmlLine; xmlLine++) {
|
2019-11-13 15:06:45 +00:00
|
|
|
if (g_regex_match(testSnapshotXMLVariableLineRegex, *xmlLine, 0, NULL))
|
2014-05-19 12:47:31 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
virBufferStrcat(&buf, *xmlLine, "\n", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
cleanup:
|
2020-08-02 17:36:03 +00:00
|
|
|
g_strfreev(xmlLines);
|
2014-05-19 12:47:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLtoXMLFiles(const char *xml)
|
|
|
|
{
|
|
|
|
char *xmlData = NULL;
|
|
|
|
char *actual = NULL;
|
|
|
|
char *pathResult = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virVBoxSnapshotConfMachinePtr machine = NULL;
|
2014-07-01 13:23:36 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
pathResult = g_strdup(abs_builddir "/vboxsnapshotxmldata/testResult.vbox");
|
2014-05-19 12:47:31 +00:00
|
|
|
|
2014-07-01 13:23:36 +00:00
|
|
|
if (virFileMakePath(abs_builddir "/vboxsnapshotxmldata") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(xml, &xmlData) < 0)
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
if (!(machine = virVBoxSnapshotConfLoadVboxFile(xml, (char*)"")))
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
if (virVBoxSnapshotConfSaveVboxFile(machine, pathResult) < 0)
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(pathResult, &actual) < 0)
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
if (!(actual = testFilterXML(actual)))
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
if (!(xmlData = testFilterXML(xmlData)))
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
if (STRNEQ(actual, xmlData)) {
|
2016-05-26 15:01:51 +00:00
|
|
|
virTestDifference(stderr, xmlData, actual);
|
2014-07-01 13:23:36 +00:00
|
|
|
goto cleanup;
|
2014-05-19 12:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-07-01 13:23:36 +00:00
|
|
|
cleanup:
|
|
|
|
unlink(pathResult);
|
|
|
|
rmdir(abs_builddir "/vboxsnapshotxmldata");
|
2014-05-19 12:47:31 +00:00
|
|
|
VIR_FREE(xmlData);
|
|
|
|
VIR_FREE(actual);
|
|
|
|
virVBoxSnapshotConfMachineFree(machine);
|
|
|
|
VIR_FREE(pathResult);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToXMLHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
xml = g_strdup_printf("%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir,
|
|
|
|
(const char *)data);
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
result = testCompareXMLtoXMLFiles(xml);
|
|
|
|
|
|
|
|
VIR_FREE(xml);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2019-11-13 15:06:45 +00:00
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
|
|
|
|
testSnapshotXMLVariableLineRegex = g_regex_new(testSnapshotXMLVariableLineRegexStr,
|
|
|
|
0, 0, &err);
|
2014-05-19 12:47:31 +00:00
|
|
|
|
2019-11-13 15:06:45 +00:00
|
|
|
if (!testSnapshotXMLVariableLineRegex) {
|
2014-05-19 12:47:31 +00:00
|
|
|
ret = -1;
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
"failed to compile test regex");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST(name) \
|
|
|
|
if (virTestRun("VBox Snapshot XML-2-XML " name, \
|
|
|
|
testCompareXMLToXMLHelper, (name)) < 0) \
|
2014-05-19 12:47:31 +00:00
|
|
|
ret = -1
|
|
|
|
|
|
|
|
DO_TEST("2disks-nosnap");
|
|
|
|
DO_TEST("2disks-1snap");
|
|
|
|
DO_TEST("2disks-2snap");
|
|
|
|
DO_TEST("2disks-3snap");
|
|
|
|
DO_TEST("2disks-3snap-brother");
|
|
|
|
|
|
|
|
cleanup:
|
2020-09-08 12:57:14 +00:00
|
|
|
if (testSnapshotXMLVariableLineRegex)
|
|
|
|
g_regex_unref(testSnapshotXMLVariableLineRegex);
|
2014-05-19 12:47:31 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|
2014-05-19 12:47:31 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
2020-01-24 20:30:04 +00:00
|
|
|
#endif /* WITH_VBOX */
|