storagevolxml2xmltest.c 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

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

#include "internal.h"
#include "testutils.h"
#include "storage_conf.h"
#include "testutilsqemu.h"
15
#include "virstring.h"
16

17 18
#define VIR_FROM_THIS VIR_FROM_NONE

19 20 21 22 23 24 25
static int
testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
                         const char *outxml)
{
    char *poolXmlData = NULL;
    char *inXmlData = NULL;
    char *outXmlData = NULL;
26 27 28 29 30
    char *actual = NULL;
    int ret = -1;
    virStoragePoolDefPtr pool = NULL;
    virStorageVolDefPtr dev = NULL;

31
    if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
32
        goto fail;
33
    if (virtTestLoadFile(inxml, &inXmlData) < 0)
34
        goto fail;
35
    if (virtTestLoadFile(outxml, &outXmlData) < 0)
36 37
        goto fail;

38
    if (!(pool = virStoragePoolDefParseString(poolXmlData)))
39 40
        goto fail;

41
    if (!(dev = virStorageVolDefParseString(pool, inXmlData)))
42 43
        goto fail;

44
    if (!(actual = virStorageVolDefFormat(pool, dev)))
45 46 47 48 49 50 51 52 53 54
        goto fail;

    if (STRNEQ(outXmlData, actual)) {
        virtTestDifference(stderr, outXmlData, actual);
        goto fail;
    }

    ret = 0;

 fail:
55 56 57 58
    VIR_FREE(poolXmlData);
    VIR_FREE(inXmlData);
    VIR_FREE(outXmlData);
    VIR_FREE(actual);
59 60 61 62 63 64 65 66 67 68
    virStoragePoolDefFree(pool);
    virStorageVolDefFree(dev);
    return ret;
}

struct testInfo {
    const char *pool;
    const char *name;
};

69 70 71 72
static int
testCompareXMLToXMLHelper(const void *data)
{
    int result = -1;
73
    const struct testInfo *info = data;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    char *poolxml = NULL;
    char *inxml = NULL;
    char *outxml = NULL;

    if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
                    abs_srcdir, info->pool) < 0 ||
        virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
                    abs_srcdir, info->name) < 0 ||
        virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
                    abs_srcdir, info->name) < 0) {
        goto cleanup;
    }

    result = testCompareXMLToXMLFiles(poolxml, inxml, outxml);

89
 cleanup:
90 91 92
    VIR_FREE(poolxml);
    VIR_FREE(inxml);
    VIR_FREE(outxml);
93

94
    return result;
95 96 97 98
}


static int
E
Eric Blake 已提交
99
mymain(void)
100 101 102
{
    int ret = 0;

103 104 105 106 107 108 109
#define DO_TEST(pool, name)                                     \
    do {                                                        \
        struct testInfo info = { pool, name };                  \
        if (virtTestRun("Storage Vol XML-2-XML " name,          \
                        testCompareXMLToXMLHelper, &info) < 0)  \
            ret = -1;                                           \
    }                                                           \
110
    while (0);
111 112

    DO_TEST("pool-dir", "vol-file");
113
    DO_TEST("pool-dir", "vol-file-naming");
114 115
    DO_TEST("pool-dir", "vol-file-backing");
    DO_TEST("pool-dir", "vol-qcow2");
116 117
    DO_TEST("pool-dir", "vol-qcow2-1.1");
    DO_TEST("pool-dir", "vol-qcow2-lazy");
118 119
    DO_TEST("pool-dir", "vol-qcow2-0.10-lazy");
    DO_TEST("pool-dir", "vol-qcow2-nobacking");
120 121 122
    DO_TEST("pool-disk", "vol-partition");
    DO_TEST("pool-logical", "vol-logical");
    DO_TEST("pool-logical", "vol-logical-backing");
123
    DO_TEST("pool-sheepdog", "vol-sheepdog");
124
    DO_TEST("pool-gluster", "vol-gluster-dir");
125

126
    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
127 128 129
}

VIRT_TEST_MAIN(mymain)