2009-02-24 18:53:31 +03: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"
# include "testutilsqemu.h"
2013-04-03 14:36:23 +04:00
# include "virstring.h"
2009-02-24 18:53:31 +03:00
2013-06-07 19:10:28 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2011-04-25 02:25:10 +04:00
static int
2021-05-15 00:28:58 +03:00
testCompareXMLToXMLFiles ( const char * xml , const char * outfile )
2011-04-25 02:25:10 +04:00
{
char * xmlData = NULL ;
2009-02-24 18:53:31 +03:00
char * actual = NULL ;
int ret = - 1 ;
2021-03-11 10:16:13 +03:00
virNodeDeviceDef * dev = NULL ;
virNodeDevCapsDef * caps ;
2009-02-24 18:53:31 +03:00
2016-05-26 18:01:52 +03:00
if ( virTestLoadFile ( xml , & xmlData ) < 0 )
2009-02-24 18:53:31 +03:00
goto fail ;
2012-02-10 08:51:47 +04:00
if ( ! ( dev = virNodeDeviceDefParseString ( xmlData , EXISTING_DEVICE , NULL ) ) )
2009-02-24 18:53:31 +03:00
goto fail ;
2018-05-19 15:00:58 +03:00
/* Calculate some things that are not read in */
for ( caps = dev - > caps ; caps ; caps = caps - > next ) {
2021-03-11 10:16:13 +03:00
virNodeDevCapData * data = & caps - > data ;
2018-05-19 15:00:58 +03:00
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 ;
}
}
}
2010-02-10 13:40:18 +03:00
if ( ! ( actual = virNodeDeviceDefFormat ( dev ) ) )
2009-02-24 18:53:31 +03:00
goto fail ;
2021-05-15 00:28:58 +03:00
if ( virTestCompareToFile ( actual , outfile ) < 0 )
2009-02-24 18:53:31 +03:00
goto fail ;
ret = 0 ;
fail :
2012-02-03 03:16:43 +04:00
VIR_FREE ( xmlData ) ;
VIR_FREE ( actual ) ;
2009-02-24 18:53:31 +03:00
virNodeDeviceDefFree ( dev ) ;
return ret ;
}
2011-04-25 02:25:10 +04:00
static int
testCompareXMLToXMLHelper ( const void * data )
{
int result = - 1 ;
char * xml = NULL ;
2021-05-15 00:28:58 +03:00
g_autofree char * outfile = NULL ;
2011-04-25 02:25:10 +04:00
2019-10-22 16:26:14 +03:00
xml = g_strdup_printf ( " %s/nodedevschemadata/%s.xml " , abs_srcdir ,
( const char * ) data ) ;
2011-04-25 02:25:10 +04:00
2021-05-15 00:28:58 +03:00
outfile = g_strdup_printf ( " %s/nodedevxml2xmlout/%s.xml " , abs_srcdir ,
( const char * ) data ) ;
result = testCompareXMLToXMLFiles ( xml , outfile ) ;
2011-04-25 02:25:10 +04:00
2012-02-03 03:16:43 +04:00
VIR_FREE ( xml ) ;
2011-04-25 02:25:10 +04:00
return result ;
2009-02-24 18:53:31 +03:00
}
static int
2011-04-29 20:21:20 +04:00
mymain ( void )
2009-02-24 18:53:31 +03:00
{
int ret = 0 ;
2017-11-03 15:09:47 +03:00
# define DO_TEST(name) \
if ( virTestRun ( " Node device XML-2-XML " name , \
testCompareXMLToXMLHelper , ( name ) ) < 0 ) \
2009-02-24 18:53:31 +03:00
ret = - 1
DO_TEST ( " computer " ) ;
DO_TEST ( " DVD_GCC_4247N " ) ;
2009-12-14 16:58:23 +03:00
DO_TEST ( " DVD_with_media " ) ;
2009-02-24 18:53:31 +03:00
DO_TEST ( " net_00_13_02_b9_f9_d3 " ) ;
DO_TEST ( " net_00_15_58_2f_e9_55 " ) ;
DO_TEST ( " pci_1002_71c4 " ) ;
2013-06-23 22:01:00 +04:00
DO_TEST ( " pci_8086_10c9_sriov_pf " ) ;
2009-02-24 18:53:31 +03:00
DO_TEST ( " pci_8086_27c5_scsi_host_0 " ) ;
2014-06-05 21:17:05 +04:00
DO_TEST ( " pci_8086_27c5_scsi_host_0_unique_id " ) ;
2009-02-24 18:53:31 +03: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 " ) ;
2017-02-15 00:04:10 +03:00
DO_TEST ( " storage_serial_3600c0ff000d7a2a5d463ff4902000000 " ) ;
2009-02-24 18:53:31 +03:00
DO_TEST ( " usb_device_1d6b_1_0000_00_1d_0_if0 " ) ;
DO_TEST ( " usb_device_1d6b_1_0000_00_1d_0 " ) ;
2014-05-15 12:13:45 +04:00
DO_TEST ( " pci_8086_4238_pcie_wireless " ) ;
DO_TEST ( " pci_8086_0c0c_snd_hda_intel " ) ;
2016-04-03 22:01:06 +03:00
DO_TEST ( " pci_0000_00_02_0_header_type " ) ;
DO_TEST ( " pci_0000_00_1c_0_header_type " ) ;
2016-03-21 17:49:30 +03:00
DO_TEST ( " scsi_target0_0_0 " ) ;
2017-05-22 09:38:25 +03:00
DO_TEST ( " scsi_target1_0_0 " ) ;
2016-04-03 22:01:06 +03:00
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 " ) ;
2017-02-15 00:04:12 +03:00
DO_TEST ( " drm_renderD129 " ) ;
2017-03-06 19:17:34 +03:00
DO_TEST ( " pci_0000_02_10_7_mdev_types " ) ;
2017-03-06 19:18:48 +03:00
DO_TEST ( " mdev_3627463d_b7f0_4fea_b468_f1da537d301b " ) ;
2017-05-22 09:38:22 +03:00
DO_TEST ( " ccw_0_0_ffff " ) ;
2020-09-14 22:11:44 +03:00
DO_TEST ( " css_0_0_ffff " ) ;
2020-11-11 15:45:22 +03:00
DO_TEST ( " css_0_0_fffe_mdev_types " ) ;
2020-12-03 20:59:34 +03:00
DO_TEST ( " ap_card07 " ) ;
2020-12-03 20:59:36 +03:00
DO_TEST ( " ap_07_0038 " ) ;
2020-12-03 20:59:39 +03:00
DO_TEST ( " ap_matrix " ) ;
2020-12-03 20:59:43 +03:00
DO_TEST ( " ap_matrix_mdev_types " ) ;
2020-12-03 20:59:39 +03:00
DO_TEST ( " mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad " ) ;
2009-02-24 18:53:31 +03:00
2014-03-17 13:38:38 +04:00
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
2009-02-24 18:53:31 +03:00
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )