2016-04-26 16:04:55 +03:00
/*
* Copyright ( C ) 2016 Red Hat , Inc .
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library . If not , see
* < http : //www.gnu.org/licenses/>.
*/
# include <config.h>
# include "testutils.h"
# include "internal.h"
2017-07-21 16:09:54 +03:00
# include "virarch.h"
2016-04-26 16:04:55 +03:00
# include "virthread.h"
# include "qemu/qemu_capabilities.h"
2018-12-13 17:53:50 +03:00
# define LIBVIRT_QEMU_CAPSPRIV_H_ALLOW
2016-04-26 16:04:55 +03:00
# include "qemu/qemu_capspriv.h"
# define VIR_FROM_THIS VIR_FROM_NONE
static void
2019-10-14 15:45:03 +03:00
eventLoop ( void * opaque G_GNUC_UNUSED )
2016-04-26 16:04:55 +03:00
{
while ( 1 ) {
if ( virEventRunDefaultImpl ( ) < 0 ) {
fprintf ( stderr , " Failed to run event loop: %s \n " ,
2016-05-19 22:10:18 +03:00
virGetLastErrorMessage ( ) ) ;
2016-04-26 16:04:55 +03:00
}
}
}
int
main ( int argc , char * * argv )
{
virThread thread ;
2021-03-11 10:16:13 +03:00
virQEMUCaps * caps ;
2021-04-06 14:00:00 +03:00
virArch host ;
virArch guest ;
2020-01-09 21:01:44 +03:00
const char * mock = VIR_TEST_MOCK ( " qemucapsprobe " ) ;
2016-04-26 16:04:55 +03:00
2020-01-09 21:01:44 +03:00
if ( ! virFileIsExecutable ( mock ) ) {
perror ( mock ) ;
return EXIT_FAILURE ;
}
VIR_TEST_PRELOAD ( mock ) ;
2016-04-26 16:04:55 +03:00
2020-05-06 12:50:31 +03:00
virFileActivateDirOverrideForProg ( argv [ 0 ] ) ;
2016-04-26 16:04:55 +03:00
if ( argc ! = 2 ) {
fprintf ( stderr , " %s QEMU_binary \n " , argv [ 0 ] ) ;
return EXIT_FAILURE ;
}
2019-09-16 19:44:23 +03:00
if ( virInitialize ( ) < 0 ) {
2016-04-26 16:04:55 +03:00
fprintf ( stderr , " Failed to initialize libvirt " ) ;
return EXIT_FAILURE ;
}
if ( virEventRegisterDefaultImpl ( ) < 0 ) {
fprintf ( stderr , " Failed to register event implementation: %s \n " ,
2016-05-19 22:10:18 +03:00
virGetLastErrorMessage ( ) ) ;
2016-04-26 16:04:55 +03:00
return EXIT_FAILURE ;
}
if ( virThreadCreate ( & thread , false , eventLoop , NULL ) < 0 )
return EXIT_FAILURE ;
2017-07-21 16:09:54 +03:00
if ( ! ( caps = virQEMUCapsNewForBinaryInternal ( VIR_ARCH_NONE , argv [ 1 ] , " /tmp " ,
2021-08-02 17:44:30 +03:00
- 1 , - 1 , NULL , 0 , NULL , NULL ) ) )
2016-04-26 16:04:55 +03:00
return EXIT_FAILURE ;
2021-04-06 14:00:00 +03:00
host = virArchFromHost ( ) ;
guest = virQEMUCapsGetArch ( caps ) ;
if ( host ! = guest ) {
fprintf ( stderr ,
" WARNING: guest architecture '%s' does not match host '%s'. \n "
" WARNING: When generating capabilities for the libvirt test \n "
" WARNING: suite, it is strongly desired to generate capabilities \n "
" WARNING: on the native host to capture KVM related features. \n " ,
virArchToString ( guest ) , virArchToString ( host ) ) ;
}
2016-04-26 16:04:55 +03:00
virObjectUnref ( caps ) ;
return EXIT_SUCCESS ;
}