2020-10-05 18:47:01 +03:00
# include <config.h>
# include <unistd.h>
# include <sys/types.h>
# include <fcntl.h>
# include "testutils.h"
# include "internal.h"
# include "testutilsqemu.h"
# include "configmake.h"
# define VIR_FROM_THIS VIR_FROM_NONE
static virQEMUDriver driver ;
static int
testCompareStatusXMLToXMLFiles ( const void * opaque )
{
const struct testQemuInfo * data = opaque ;
2021-03-11 10:16:13 +03:00
virDomainObj * obj = NULL ;
2020-10-05 18:47:01 +03:00
g_autofree char * actual = NULL ;
int ret = - 1 ;
2021-08-17 16:30:44 +03:00
if ( testQemuInfoInitArgs ( ( struct testQemuInfo * ) data ) < 0 )
return - 1 ;
2023-03-02 19:44:21 +03:00
virFileCacheClear ( driver . qemuCapsCache ) ;
2021-08-17 16:30:44 +03:00
if ( qemuTestCapsCacheInsert ( driver . qemuCapsCache , data - > qemuCaps ) < 0 )
return - 1 ;
2020-10-05 18:47:01 +03:00
if ( ! ( obj = virDomainObjParseFile ( data - > infile , driver . xmlopt ,
VIR_DOMAIN_DEF_PARSE_STATUS |
VIR_DOMAIN_DEF_PARSE_ACTUAL_NET |
VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE |
VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL ) ) ) {
VIR_TEST_DEBUG ( " \n failed to parse '%s' " , data - > infile ) ;
goto cleanup ;
}
if ( ! ( actual = virDomainObjFormat ( obj , driver . xmlopt ,
VIR_DOMAIN_DEF_FORMAT_SECURE |
VIR_DOMAIN_DEF_FORMAT_STATUS |
VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET |
VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES |
VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST ) ) ) {
VIR_TEST_DEBUG ( " \n failed to format back '%s' " , data - > infile ) ;
goto cleanup ;
}
if ( virTestCompareToFile ( actual , data - > outfile ) < 0 )
goto cleanup ;
ret = 0 ;
cleanup :
virDomainObjEndAPI ( & obj ) ;
return ret ;
}
static const char * statusPath = abs_srcdir " /qemustatusxml2xmldata/ " ;
static void
testInfoSetStatusPaths ( struct testQemuInfo * info )
{
info - > infile = g_strdup_printf ( " %s%s-in.xml " , statusPath , info - > name ) ;
info - > outfile = g_strdup_printf ( " %s%s-out.xml " , statusPath , info - > name ) ;
}
static int
mymain ( void )
{
int ret = 0 ;
2021-08-17 17:26:58 +03:00
g_autoptr ( GHashTable ) capslatest = testQemuGetLatestCaps ( ) ;
2022-07-13 23:26:51 +03:00
g_autoptr ( GHashTable ) capscache = virHashNew ( virObjectUnref ) ;
2020-10-05 18:47:01 +03:00
g_autoptr ( virConnect ) conn = NULL ;
2021-08-17 17:26:58 +03:00
struct testQemuConf testConf = { . capslatest = capslatest ,
. capscache = capscache ,
2021-08-20 17:34:26 +03:00
. qapiSchemaCache = NULL } ;
2020-10-05 18:47:01 +03:00
if ( ! capslatest )
return EXIT_FAILURE ;
if ( qemuTestDriverInit ( & driver ) < 0 )
return EXIT_FAILURE ;
if ( ! ( conn = virGetConnect ( ) ) )
goto cleanup ;
virSetConnectInterface ( conn ) ;
virSetConnectNetwork ( conn ) ;
virSetConnectNWFilter ( conn ) ;
virSetConnectNodeDev ( conn ) ;
virSetConnectSecret ( conn ) ;
virSetConnectStorage ( conn ) ;
# define DO_TEST_STATUS(_name) \
do { \
static struct testQemuInfo info = { \
. name = _name , \
} ; \
2021-08-17 16:30:44 +03:00
testQemuInfoSetArgs ( & info , & testConf , ARG_END ) ; \
2020-10-05 18:47:01 +03:00
testInfoSetStatusPaths ( & info ) ; \
\
if ( virTestRun ( " QEMU status XML-2-XML " _name , \
testCompareStatusXMLToXMLFiles , & info ) < 0 ) \
ret = - 1 ; \
\
testQemuInfoClear ( & info ) ; \
} while ( 0 )
DO_TEST_STATUS ( " blockjob-mirror " ) ;
DO_TEST_STATUS ( " vcpus-multi " ) ;
DO_TEST_STATUS ( " modern " ) ;
DO_TEST_STATUS ( " migration-out-nbd " ) ;
DO_TEST_STATUS ( " migration-in-params " ) ;
DO_TEST_STATUS ( " migration-out-params " ) ;
DO_TEST_STATUS ( " migration-out-nbd-tls " ) ;
2021-02-10 22:37:20 +03:00
DO_TEST_STATUS ( " migration-out-nbd-bitmaps " ) ;
2020-10-05 18:47:01 +03:00
DO_TEST_STATUS ( " upgrade " ) ;
DO_TEST_STATUS ( " blockjob-blockdev " ) ;
DO_TEST_STATUS ( " backup-pull " ) ;
cleanup :
qemuTestDriverFree ( & driver ) ;
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
}
VIR_TEST_MAIN_PRELOAD ( mymain ,
VIR_TEST_MOCK ( " virpci " ) ,
VIR_TEST_MOCK ( " virrandom " ) ,
2020-11-09 15:23:25 +03:00
VIR_TEST_MOCK ( " domaincaps " ) )