nodedevxml2xmltest.c 2.0 KB
Newer Older
M
Mark McLoughlin 已提交
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 "node_device_conf.h"
#include "testutilsqemu.h"
15
#include "virstring.h"
M
Mark McLoughlin 已提交
16

17 18 19 20
static int
testCompareXMLToXMLFiles(const char *xml)
{
    char *xmlData = NULL;
M
Mark McLoughlin 已提交
21 22 23 24
    char *actual = NULL;
    int ret = -1;
    virNodeDeviceDefPtr dev = NULL;

25
    if (virtTestLoadFile(xml, &xmlData) < 0)
M
Mark McLoughlin 已提交
26 27
        goto fail;

28
    if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE, NULL)))
M
Mark McLoughlin 已提交
29 30
        goto fail;

31
    if (!(actual = virNodeDeviceDefFormat(dev)))
M
Mark McLoughlin 已提交
32 33 34 35 36 37 38 39 40 41
        goto fail;

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

    ret = 0;

 fail:
42 43
    VIR_FREE(xmlData);
    VIR_FREE(actual);
M
Mark McLoughlin 已提交
44 45 46 47
    virNodeDeviceDefFree(dev);
    return ret;
}

48 49 50 51 52 53 54 55 56 57 58 59
static int
testCompareXMLToXMLHelper(const void *data)
{
    int result = -1;
    char *xml = NULL;

    if (virAsprintf(&xml, "%s/nodedevschemadata/%s.xml",
                    abs_srcdir, (const char*)data) < 0)
        return -1;

    result = testCompareXMLToXMLFiles(xml);

60
    VIR_FREE(xml);
61
    return result;
M
Mark McLoughlin 已提交
62 63 64 65
}


static int
E
Eric Blake 已提交
66
mymain(void)
M
Mark McLoughlin 已提交
67 68 69 70 71 72 73 74 75 76
{
    int ret = 0;

#define DO_TEST(name) \
    if (virtTestRun("Node device XML-2-XML " name, \
                    1, testCompareXMLToXMLHelper, (name)) < 0) \
        ret = -1

    DO_TEST("computer");
    DO_TEST("DVD_GCC_4247N");
77
    DO_TEST("DVD_with_media");
M
Mark McLoughlin 已提交
78 79 80 81 82 83 84 85 86 87 88
    DO_TEST("net_00_13_02_b9_f9_d3");
    DO_TEST("net_00_15_58_2f_e9_55");
    DO_TEST("pci_1002_71c4");
    DO_TEST("pci_8086_27c5_scsi_host_0");
    DO_TEST("pci_8086_27c5_scsi_host_scsi_device_lun0");
    DO_TEST("pci_8086_27c5_scsi_host_scsi_host");
    DO_TEST("pci_8086_27c5_scsi_host");
    DO_TEST("storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE");
    DO_TEST("usb_device_1d6b_1_0000_00_1d_0_if0");
    DO_TEST("usb_device_1d6b_1_0000_00_1d_0");

89
    return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
M
Mark McLoughlin 已提交
90 91 92
}

VIRT_TEST_MAIN(mymain)