libvirt/tests/nodedevxml2xmltest.c

173 lines
5.5 KiB
C
Raw Permalink Normal View History

2009-02-24 15:53:31 +00:00
#include <config.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include "internal.h"
#include "testutils.h"
#include "node_device_conf.h"
#define VIR_FROM_THIS VIR_FROM_NONE
struct TestData {
const char *filename;
unsigned int flags;
};
static int
testCompareXMLToXMLFiles(const char *xml, const char *outfile, unsigned int flags)
{
g_autofree char *xmlData = NULL;
g_autofree char *actual = NULL;
2009-02-24 15:53:31 +00:00
int ret = -1;
virNodeDeviceDef *dev = NULL;
virNodeDevCapsDef *caps;
2009-02-24 15:53:31 +00:00
if (virTestLoadFile(xml, &xmlData) < 0)
2009-02-24 15:53:31 +00:00
goto fail;
if (!(dev = virNodeDeviceDefParse(xmlData, NULL, EXISTING_DEVICE, NULL,
NULL, NULL, false)))
2009-02-24 15:53:31 +00:00
goto fail;
/* Calculate some things that are not read in */
for (caps = dev->caps; caps; caps = caps->next) {
virNodeDevCapData *data = &caps->data;
if (caps->data.type == VIR_NODE_DEV_CAP_STORAGE) {
if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE) {
if (data->storage.flags &
VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE) {
data->storage.logical_block_size = 2048;
data->storage.num_blocks =
data->storage.removable_media_size /
data->storage.logical_block_size;
}
} else {
data->storage.logical_block_size = 512;
data->storage.num_blocks = data->storage.size /
data->storage.logical_block_size;
}
}
}
test: nodedev: fill active_config at driver startup time Commit v10.0.0-265-ge67bca23e4 added a `active_config` and `defined_config` to nodedev mdev internal XML handling. `defined_config` can be filled at XML parse time, but `active_config` must be filled in by nodedev driver. This wasn't implemented for the test driver however, which caused virt-manager test suite regressions. Working example: ``` $ virsh --connect test:///home/crobinso/src/virt-manager/tests/data/testdriver/testdriver.xml nodedev-dumpxml mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110 <device> <name>mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110</name> <path>/sys/devices/css0/0.0.0023/8e37ee90-2b51-45e3-9b25-bf8283c03110</path> <parent>css_0_0_0023</parent> <capability type='mdev'> <type id='vfio_ccw-io'/> <iommuGroup number='0'/> </capability> </device> ``` Broken example: ``` $ virsh --connect test:///home/crobinso/src/virt-manager/tests/data/testdriver/testdriver.xml nodedev-dumpxml mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110 <device> <name>mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110</name> <path>/sys/devices/css0/0.0.0023/8e37ee90-2b51-45e3-9b25-bf8283c03110</path> <parent>css_0_0_0023</parent> <capability type='mdev'> <iommuGroup number='0'/> </capability> </device> ``` There's already code that does what we want in the test suite. Move it to a shared function, and call it in test driver when creating a nodedev from driver startup XML. Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-04-06 19:13:40 +00:00
if (!(flags & VIR_NODE_DEVICE_XML_INACTIVE))
virNodeDeviceSyncMdevActiveConfig(dev);
if (!(actual = virNodeDeviceDefFormat(dev, flags)))
2009-02-24 15:53:31 +00:00
goto fail;
if (virTestCompareToFile(actual, outfile) < 0)
2009-02-24 15:53:31 +00:00
goto fail;
ret = 0;
fail:
virNodeDeviceDefFree(dev);
return ret;
}
static int
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
const struct TestData *tdata = data;
g_autofree char *xml = NULL;
g_autofree char *outfile = NULL;
xml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
tdata->filename);
if (tdata->flags & VIR_NODE_DEVICE_XML_INACTIVE)
outfile = g_strdup_printf("%s/nodedevxml2xmlout/%s_inactive.xml", abs_srcdir,
tdata->filename);
else
outfile = g_strdup_printf("%s/nodedevxml2xmlout/%s.xml", abs_srcdir,
tdata->filename);
result = testCompareXMLToXMLFiles(xml, outfile, tdata->flags);
return result;
2009-02-24 15:53:31 +00:00
}
static int
tests: simplify common setup 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.
2011-04-29 16:21:20 +00:00
mymain(void)
2009-02-24 15:53:31 +00:00
{
int ret = 0;
#define DO_TEST_FLAGS(desc, filename, flags) \
do { \
struct TestData data = { filename, flags }; \
if (virTestRun(desc, testCompareXMLToXMLHelper, &data) < 0) \
ret = -1; \
} \
while (0)
#define DO_TEST(name) \
DO_TEST_FLAGS("Node device XML-2-XML " name, name, 0)
#define DO_TEST_INACTIVE(name) \
DO_TEST_FLAGS("Node device XML-2-XML INACTIVE " name, \
name, VIR_NODE_DEVICE_XML_INACTIVE)
2009-02-24 15:53:31 +00:00
DO_TEST("computer");
DO_TEST("DVD_GCC_4247N");
DO_TEST("DVD_with_media");
2009-02-24 15:53:31 +00:00
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_10c9_sriov_pf");
2009-02-24 15:53:31 +00:00
DO_TEST("pci_8086_27c5_scsi_host_0");
DO_TEST("pci_8086_27c5_scsi_host_0_unique_id");
2009-02-24 15:53:31 +00:00
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("storage_serial_3600c0ff000d7a2a5d463ff4902000000");
2009-02-24 15:53:31 +00:00
DO_TEST("usb_device_1d6b_1_0000_00_1d_0_if0");
DO_TEST("usb_device_1d6b_1_0000_00_1d_0");
DO_TEST("pci_8086_4238_pcie_wireless");
DO_TEST("pci_8086_0c0c_snd_hda_intel");
DO_TEST("pci_0000_00_02_0_header_type");
DO_TEST("pci_0000_00_1c_0_header_type");
DO_TEST("scsi_target0_0_0");
DO_TEST("scsi_target1_0_0");
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");
DO_TEST("drm_renderD129");
DO_TEST("pci_0000_02_10_7_mdev_types");
DO_TEST("pci_0000_42_00_0_vpd");
DO_TEST("mdev_3627463d_b7f0_4fea_b468_f1da537d301b");
DO_TEST_INACTIVE("mdev_3627463d_b7f0_4fea_b468_f1da537d301b");
DO_TEST("ccw_0_0_ffff");
DO_TEST("css_0_0_ffff");
DO_TEST("css_0_0_ffff_channel_dev_addr");
DO_TEST("css_0_0_fffe_mdev_types");
DO_TEST("css_0_0_fffe_mdev_types_channel_dev_addr");
DO_TEST("ap_card07");
DO_TEST("ap_07_0038");
DO_TEST("ap_matrix");
DO_TEST("ap_matrix_mdev_types");
DO_TEST("mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad");
DO_TEST("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
DO_TEST("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
DO_TEST("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
DO_TEST_INACTIVE("mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad");
DO_TEST_INACTIVE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
DO_TEST_INACTIVE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
DO_TEST_INACTIVE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
DO_TEST("hba_vport_ops");
DO_TEST("mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c");
DO_TEST_INACTIVE("mdev_c60cc60c_c60c_c60c_c60c_c60cc60cc60c");
2009-02-24 15:53:31 +00:00
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
2009-02-24 15:53:31 +00:00
}
VIR_TEST_MAIN(mymain)