2012-12-14 19:08:25 +04:00
/*
* sysinfotest . c : Testcase ( s ) for virSysinfoRead
*
2013-11-20 02:50:56 +04:00
* Copyright ( C ) 2013 Red Hat , Inc .
2012-12-14 19:08:25 +04:00
* Copyright IBM Corp . 2012
*
* 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 <unistd.h>
# include "internal.h"
2012-12-04 16:04:07 +04:00
# include "virbuffer.h"
2012-12-13 19:31:53 +04:00
# include "virsysinfo.h"
2012-12-14 19:08:25 +04:00
# include "testutils.h"
# include "virfile.h"
2013-04-03 14:36:23 +04:00
# include "virstring.h"
2012-12-14 19:08:25 +04:00
2018-12-13 17:53:50 +03:00
# define LIBVIRT_VIRSYSINFOPRIV_H_ALLOW
2017-03-06 17:25:07 +03:00
# include "virsysinfopriv.h"
2013-06-07 19:10:28 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2012-12-14 19:08:25 +04:00
struct testSysinfoData {
2017-03-06 17:56:46 +03:00
virSysinfoDefPtr ( * func ) ( void ) ; /* sysinfo gathering function */
2012-12-14 19:08:25 +04:00
char * decoder ; /* name of dmi decoder binary/script */
char * sysinfo ; /* name of /proc/sysinfo substitute file */
char * cpuinfo ; /* name of /proc/cpuinfo substitute file */
char * expected ; /* (required) file containing output of virSysinfoFormat */
} ;
static int
testSysinfo ( const void * data )
{
int result = - 1 ;
const char * sysfsActualData ;
virSysinfoDefPtr ret = NULL ;
virBuffer buf = VIR_BUFFER_INITIALIZER ;
const struct testSysinfoData * testdata = data ;
virSysinfoSetup ( testdata - > decoder , testdata - > sysinfo , testdata - > cpuinfo ) ;
if ( ! testdata - > expected | |
2017-03-06 17:56:46 +03:00
! ( ret = testdata - > func ( ) ) )
2012-12-14 19:08:25 +04:00
goto cleanup ;
2013-11-20 02:50:56 +04:00
if ( virSysinfoFormat ( & buf , ret ) < 0 )
2012-12-14 19:08:25 +04:00
goto cleanup ;
if ( ! ( sysfsActualData = virBufferCurrentContent ( & buf ) ) )
goto cleanup ;
2016-05-26 18:01:53 +03:00
if ( virTestCompareToFile ( sysfsActualData , testdata - > expected ) < 0 )
2012-12-14 19:08:25 +04:00
goto cleanup ;
result = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2012-12-14 19:08:25 +04:00
virSysinfoDefFree ( ret ) ;
virBufferFreeAndReset ( & buf ) ;
return result ;
}
static int
sysinfotest_run ( const char * test ,
2017-03-06 17:56:46 +03:00
virSysinfoDefPtr ( * func ) ( void ) ,
2012-12-14 19:08:25 +04:00
const char * decoder ,
const char * sysinfo ,
const char * cpuinfo ,
const char * expected )
{
2018-03-11 18:27:22 +03:00
struct testSysinfoData testdata = { 0 } ;
2012-12-14 19:08:25 +04:00
int ret = EXIT_FAILURE ;
2017-03-06 17:56:46 +03:00
testdata . func = func ;
2012-12-14 19:08:25 +04:00
if ( ( decoder & &
virAsprintf ( & testdata . decoder , " %s/%s " , abs_srcdir , decoder ) < 0 ) | |
( sysinfo & &
virAsprintf ( & testdata . sysinfo , " %s/%s " , abs_srcdir , sysinfo ) < 0 ) | |
( cpuinfo & &
virAsprintf ( & testdata . cpuinfo , " %s/%s " , abs_srcdir , cpuinfo ) < 0 ) | |
( expected & &
virAsprintf ( & testdata . expected , " %s/%s " , abs_srcdir , expected ) < 0 ) ) {
goto error ;
}
2016-05-26 18:01:50 +03:00
if ( virTestRun ( test , testSysinfo , & testdata ) < 0 )
2012-12-14 19:08:25 +04:00
goto error ;
ret = EXIT_SUCCESS ;
2014-03-25 10:53:44 +04:00
error :
2012-12-14 19:08:25 +04:00
VIR_FREE ( testdata . decoder ) ;
VIR_FREE ( testdata . sysinfo ) ;
VIR_FREE ( testdata . cpuinfo ) ;
VIR_FREE ( testdata . expected ) ;
return ret ;
}
2017-03-06 17:56:46 +03:00
# define TEST_FULL(name, func, decoder) \
if ( sysinfotest_run ( name " sysinfo " , func , decoder , \
" /sysinfodata/ " name " sysinfo.data " , \
" /sysinfodata/ " name " cpuinfo.data " , \
" /sysinfodata/ " name " sysinfo.expect " ) ! = EXIT_SUCCESS ) \
ret = EXIT_FAILURE
2012-12-14 19:08:25 +04:00
2017-03-06 17:56:46 +03:00
# define TEST(name, func) \
TEST_FULL ( name , func , NULL )
2012-12-14 19:08:25 +04:00
2013-04-03 21:58:50 +04:00
static int
2017-03-06 17:56:46 +03:00
mymain ( void )
2013-04-03 21:58:50 +04:00
{
2015-05-12 19:21:18 +03:00
int ret = EXIT_SUCCESS ;
2017-03-06 17:56:46 +03:00
TEST ( " s390 " , virSysinfoReadS390 ) ;
2018-01-12 14:38:02 +03:00
TEST ( " s390-freq " , virSysinfoReadS390 ) ;
2017-03-06 17:56:46 +03:00
TEST ( " ppc " , virSysinfoReadPPC ) ;
TEST_FULL ( " x86 " , virSysinfoReadX86 , " /sysinfodata/dmidecode.sh " ) ;
TEST ( " arm " , virSysinfoReadARM ) ;
TEST ( " arm-rpi2 " , virSysinfoReadARM ) ;
TEST ( " aarch64 " , virSysinfoReadARM ) ;
2017-03-06 18:20:25 +03:00
TEST ( " aarch64-moonshot " , virSysinfoReadARM ) ;
2015-05-12 19:21:18 +03:00
return ret ;
2013-04-03 21:58:50 +04:00
}
2017-03-06 17:56:46 +03:00
# undef TEST
# undef TEST_FULL
2013-10-08 17:49:09 +04:00
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )