mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
20986e58aa
A few of the tests were missing basic sanity checks, while most of them were doing copy-and-paste initialization (in fact, some of them pasted the argc > 1 check more than once!). It's much nicer to do things in one common place, and minimizes the size of the next patch that fixes getcwd usage. * tests/testutils.h (EXIT_AM_HARDFAIL): New define. (progname, abs_srcdir): Define for all tests. (VIRT_TEST_MAIN): Change callback signature. * tests/testutils.c (virtTestMain): Do more common init. * tests/commandtest.c (mymain): Simplify. * tests/cputest.c (mymain): Likewise. * tests/esxutilstest.c (mymain): Likewise. * tests/eventtest.c (mymain): Likewise. * tests/hashtest.c (mymain): Likewise. * tests/networkxml2xmltest.c (mymain): Likewise. * tests/nodedevxml2xmltest.c (myname): Likewise. * tests/nodeinfotest.c (mymain): Likewise. * tests/nwfilterxml2xmltest.c (mymain): Likewise. * tests/qemuargv2xmltest.c (mymain): Likewise. * tests/qemuhelptest.c (mymain): Likewise. * tests/qemuxml2argvtest.c (mymain): Likewise. * tests/qemuxml2xmltest.c (mymain): Likewise. * tests/qparamtest.c (mymain): Likewise. * tests/sexpr2xmltest.c (mymain): Likewise. * tests/sockettest.c (mymain): Likewise. * tests/statstest.c (mymain): Likewise. * tests/storagepoolxml2xmltest.c (mymain): Likewise. * tests/storagevolxml2xmltest.c (mymain): Likewise. * tests/virbuftest.c (mymain): Likewise. * tests/virshtest.c (mymain): Likewise. * tests/vmx2xmltest.c (mymain): Likewise. * tests/xencapstest.c (mymain): Likewise. * tests/xmconfigtest.c (mymain): Likewise. * tests/xml2sexprtest.c (mymain): Likewise. * tests/xml2vmxtest.c (mymain): Likewise.
84 lines
1.9 KiB
C
84 lines
1.9 KiB
C
#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"
|
|
|
|
#define MAX_FILE 4096
|
|
|
|
|
|
static int testCompareXMLToXMLFiles(const char *xml) {
|
|
char xmlData[MAX_FILE];
|
|
char *xmlPtr = &(xmlData[0]);
|
|
char *actual = NULL;
|
|
int ret = -1;
|
|
virNodeDeviceDefPtr dev = NULL;
|
|
|
|
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
|
goto fail;
|
|
|
|
if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE)))
|
|
goto fail;
|
|
|
|
if (!(actual = virNodeDeviceDefFormat(dev)))
|
|
goto fail;
|
|
|
|
if (STRNEQ(xmlData, actual)) {
|
|
virtTestDifference(stderr, xmlData, actual);
|
|
goto fail;
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
fail:
|
|
free(actual);
|
|
virNodeDeviceDefFree(dev);
|
|
return ret;
|
|
}
|
|
|
|
static int testCompareXMLToXMLHelper(const void *data) {
|
|
char xml[PATH_MAX];
|
|
snprintf(xml, PATH_MAX, "%s/nodedevschemadata/%s.xml",
|
|
abs_srcdir, (const char*)data);
|
|
return testCompareXMLToXMLFiles(xml);
|
|
}
|
|
|
|
|
|
static int
|
|
mymain(void)
|
|
{
|
|
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");
|
|
DO_TEST("DVD_with_media");
|
|
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");
|
|
|
|
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
|
}
|
|
|
|
VIRT_TEST_MAIN(mymain)
|