You need to sign in or sign up before continuing.
nodedevxml2xmltest.c 2.7 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
#define VIR_FROM_THIS VIR_FROM_NONE

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

27
    if (virTestLoadFile(xml, &xmlData) < 0)
M
Mark McLoughlin 已提交
28 29
        goto fail;

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

33
    if (!(actual = virNodeDeviceDefFormat(dev)))
M
Mark McLoughlin 已提交
34 35 36
        goto fail;

    if (STRNEQ(xmlData, actual)) {
37
        virTestDifferenceFull(stderr, xmlData, xml, actual, NULL);
M
Mark McLoughlin 已提交
38 39 40 41 42 43
        goto fail;
    }

    ret = 0;

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

50 51 52 53 54 55 56 57 58 59 60 61
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);

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


static int
E
Eric Blake 已提交
68
mymain(void)
M
Mark McLoughlin 已提交
69 70 71
{
    int ret = 0;

72
#define DO_TEST(name)                                           \
73 74
    if (virTestRun("Node device XML-2-XML " name,               \
                   testCompareXMLToXMLHelper, (name)) < 0)      \
M
Mark McLoughlin 已提交
75 76 77 78
        ret = -1

    DO_TEST("computer");
    DO_TEST("DVD_GCC_4247N");
79
    DO_TEST("DVD_with_media");
M
Mark McLoughlin 已提交
80 81 82
    DO_TEST("net_00_13_02_b9_f9_d3");
    DO_TEST("net_00_15_58_2f_e9_55");
    DO_TEST("pci_1002_71c4");
83
    DO_TEST("pci_8086_10c9_sriov_pf");
M
Mark McLoughlin 已提交
84
    DO_TEST("pci_8086_27c5_scsi_host_0");
J
John Ferlan 已提交
85
    DO_TEST("pci_8086_27c5_scsi_host_0_unique_id");
M
Mark McLoughlin 已提交
86 87 88 89
    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");
90
    DO_TEST("storage_serial_3600c0ff000d7a2a5d463ff4902000000");
M
Mark McLoughlin 已提交
91 92
    DO_TEST("usb_device_1d6b_1_0000_00_1d_0_if0");
    DO_TEST("usb_device_1d6b_1_0000_00_1d_0");
93 94
    DO_TEST("pci_8086_4238_pcie_wireless");
    DO_TEST("pci_8086_0c0c_snd_hda_intel");
95 96
    DO_TEST("pci_0000_00_02_0_header_type");
    DO_TEST("pci_0000_00_1c_0_header_type");
97
    DO_TEST("scsi_target0_0_0");
98 99 100 101 102
    DO_TEST("pci_0000_02_10_7_sriov");
    DO_TEST("pci_0000_02_10_7_sriov_vfs");
    DO_TEST("pci_0000_02_10_7_sriov_zero_vfs_max_count");
    DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all");
    DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all_header_type");
M
Mark McLoughlin 已提交
103

104
    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
M
Mark McLoughlin 已提交
105 106 107
}

VIRT_TEST_MAIN(mymain)