2011-07-01 21:58:15 +04:00
# include <config.h>
# include <unistd.h>
# include "internal.h"
# include "testutils.h"
2012-12-13 21:44:57 +04:00
# include "virutil.h"
2011-07-01 21:58:15 +04:00
static const char * diskNames [ ] = {
" sda " , " sdb " , " sdc " , " sdd " , " sde " , " sdf " , " sdg " , " sdh " , " sdi " , " sdj " , " sdk " , " sdl " , " sdm " , " sdn " , " sdo " , " sdp " , " sdq " , " sdr " , " sds " , " sdt " , " sdu " , " sdv " , " sdw " , " sdx " , " sdy " , " sdz " ,
" sdaa " , " sdab " , " sdac " , " sdad " , " sdae " , " sdaf " , " sdag " , " sdah " , " sdai " , " sdaj " , " sdak " , " sdal " , " sdam " , " sdan " , " sdao " , " sdap " , " sdaq " , " sdar " , " sdas " , " sdat " , " sdau " , " sdav " , " sdaw " , " sdax " , " sday " , " sdaz " ,
" sdba " , " sdbb " , " sdbc " , " sdbd " , " sdbe " , " sdbf " , " sdbg " , " sdbh " , " sdbi " , " sdbj " , " sdbk " , " sdbl " , " sdbm " , " sdbn " , " sdbo " , " sdbp " , " sdbq " , " sdbr " , " sdbs " , " sdbt " , " sdbu " , " sdbv " , " sdbw " , " sdbx " , " sdby " , " sdbz " ,
" sdca " , " sdcb " , " sdcc " , " sdcd " , " sdce " , " sdcf " , " sdcg " , " sdch " , " sdci " , " sdcj " , " sdck " , " sdcl " , " sdcm " , " sdcn " , " sdco " , " sdcp " , " sdcq " , " sdcr " , " sdcs " , " sdct " , " sdcu " , " sdcv " , " sdcw " , " sdcx " , " sdcy " , " sdcz " ,
" sdda " , " sddb " , " sddc " , " sddd " , " sdde " , " sddf " , " sddg " , " sddh " , " sddi " , " sddj " , " sddk " , " sddl " , " sddm " , " sddn " , " sddo " , " sddp " , " sddq " , " sddr " , " sdds " , " sddt " , " sddu " , " sddv " , " sddw " , " sddx " , " sddy " , " sddz " ,
" sdea " , " sdeb " , " sdec " , " sded " , " sdee " , " sdef " , " sdeg " , " sdeh " , " sdei " , " sdej " , " sdek " , " sdel " , " sdem " , " sden " , " sdeo " , " sdep " , " sdeq " , " sder " , " sdes " , " sdet " , " sdeu " , " sdev " , " sdew " , " sdex " , " sdey " , " sdez " ,
" sdfa " , " sdfb " , " sdfc " , " sdfd " , " sdfe " , " sdff " , " sdfg " , " sdfh " , " sdfi " , " sdfj " , " sdfk " , " sdfl " , " sdfm " , " sdfn " , " sdfo " , " sdfp " , " sdfq " , " sdfr " , " sdfs " , " sdft " , " sdfu " , " sdfv " , " sdfw " , " sdfx " , " sdfy " , " sdfz " ,
" sdga " , " sdgb " , " sdgc " , " sdgd " , " sdge " , " sdgf " , " sdgg " , " sdgh " , " sdgi " , " sdgj " , " sdgk " , " sdgl " , " sdgm " , " sdgn " , " sdgo " , " sdgp " , " sdgq " , " sdgr " , " sdgs " , " sdgt " , " sdgu " , " sdgv " , " sdgw " , " sdgx " , " sdgy " , " sdgz " ,
" sdha " , " sdhb " , " sdhc " , " sdhd " , " sdhe " , " sdhf " , " sdhg " , " sdhh " , " sdhi " , " sdhj " , " sdhk " , " sdhl " , " sdhm " , " sdhn " , " sdho " , " sdhp " , " sdhq " , " sdhr " , " sdhs " , " sdht " , " sdhu " , " sdhv " , " sdhw " , " sdhx " , " sdhy " , " sdhz " ,
" sdia " , " sdib " , " sdic " , " sdid " , " sdie " , " sdif " , " sdig " , " sdih " , " sdii " , " sdij " , " sdik " , " sdil " , " sdim " , " sdin " , " sdio " , " sdip " , " sdiq " , " sdir " , " sdis " , " sdit " , " sdiu " , " sdiv " , " sdiw " , " sdix " , " sdiy " , " sdiz "
} ;
2015-11-13 16:14:44 +03:00
struct testDiskName
{
const char * name ;
int idx ;
int partition ;
} ;
static struct testDiskName diskNamesPart [ ] = {
{ " sda0 " , 0 , 0 } ,
{ " sdb10 " , 1 , 10 } ,
{ " sdc2147483647 " , 2 , 2147483647 } ,
} ;
static const char * diskNamesInvalid [ ] = {
2017-02-15 14:14:58 +03:00
" sda00 " , " sda01 " , " sdb-1 " ,
" vd2 "
2015-11-13 16:14:44 +03:00
} ;
2011-07-01 21:58:15 +04:00
static int
2019-10-14 15:45:03 +03:00
testIndexToDiskName ( const void * data G_GNUC_UNUSED )
2011-07-01 21:58:15 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2011-07-01 21:58:15 +04:00
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( diskNames ) ; + + i ) {
2020-07-28 23:01:22 +03:00
g_autofree char * diskName = NULL ;
2011-07-01 21:58:15 +04:00
diskName = virIndexToDiskName ( i , " sd " ) ;
tests: Use virTestCompareToString() more
Instead of using:
if (STRNEQ(a, b)) {
virTestDifference(stderr, a, b);
...
}
we can use:
if (virTestCompareToString(a, b) < ) {
...
}
Generated by the following spatch:
@@
expression a, b;
@@
- if (STRNEQ(a, b)) {
+ if (virTestCompareToString(a, b) < 0) {
...
- virTestDifference(stderr, a, b);
...
}
and its variations (STRNEQ_NULLABLE() instead of STRNEQ(), then
in some cases variables passed to STRNEQ() are in reversed order
when compared to virTestCompareToString()).
However, coccinelle failed to recognize the pattern in
testNWFilterEBIPTablesAllTeardown() so I had to fix it manually.
Also, I manually fixed testFormat() in tests/sockettest.c as I
didn't bother writing another spatch rule just for that.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2022-11-30 11:57:49 +03:00
if ( virTestCompareToString ( diskNames [ i ] , diskName ) < 0 ) {
2011-07-01 21:58:15 +04:00
return - 1 ;
}
}
return 0 ;
}
static int
2019-10-14 15:45:03 +03:00
testDiskNameToIndex ( const void * data G_GNUC_UNUSED )
2011-07-01 21:58:15 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
int idx ;
2011-07-01 21:58:15 +04:00
for ( i = 0 ; i < 100000 ; + + i ) {
2020-07-28 23:01:22 +03:00
g_autofree char * diskName = NULL ;
2011-07-01 21:58:15 +04:00
diskName = virIndexToDiskName ( i , " sd " ) ;
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
idx = virDiskNameToIndex ( diskName ) ;
2011-07-01 21:58:15 +04:00
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
if ( idx < 0 | | idx ! = i ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " \n Expect [%zu] " , i ) ;
VIR_TEST_DEBUG ( " Actual [%d] " , idx ) ;
2011-07-01 21:58:15 +04:00
return - 1 ;
}
}
return 0 ;
}
2015-11-13 16:14:44 +03:00
static int
2019-10-14 15:45:03 +03:00
testDiskNameParse ( const void * data G_GNUC_UNUSED )
2015-11-13 16:14:44 +03:00
{
size_t i ;
int idx ;
int partition ;
struct testDiskName * disk = NULL ;
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( diskNamesPart ) ; + + i ) {
2015-11-13 16:14:44 +03:00
disk = & diskNamesPart [ i ] ;
if ( virDiskNameParse ( disk - > name , & idx , & partition ) )
return - 1 ;
if ( disk - > idx ! = idx ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " \n Expect [%d] " , disk - > idx ) ;
VIR_TEST_DEBUG ( " Actual [%d] " , idx ) ;
2015-11-13 16:14:44 +03:00
return - 1 ;
}
if ( disk - > partition ! = partition ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " \n Expect [%d] " , disk - > partition ) ;
VIR_TEST_DEBUG ( " Actual [%d] " , partition ) ;
2015-11-13 16:14:44 +03:00
return - 1 ;
}
}
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( diskNamesInvalid ) ; + + i ) {
2015-11-13 16:14:44 +03:00
if ( ! virDiskNameParse ( diskNamesInvalid [ i ] , & idx , & partition ) ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " Should Fail [%s] " , diskNamesInvalid [ i ] ) ;
2015-11-13 16:14:44 +03:00
return - 1 ;
}
}
return 0 ;
}
2011-07-01 21:58:15 +04:00
struct testVersionString
{
const char * string ;
bool allowMissing ;
int result ;
unsigned long version ;
} ;
static struct testVersionString versions [ ] = {
{ " 2.6.38-8-generic " , false , 0 , 1000000 * 2 + 1000 * 6 + 38 } ,
{ " 3.0-1-virtual " , true , 0 , 1000000 * 3 + 1000 * 0 + 0 } ,
{ " 5 " , true , 0 , 1000000 * 5 + 1000 * 0 + 0 } ,
{ " 4.1.0 " , false , 0 , 1000000 * 4 + 1000 * 1 + 0 } ,
{ " 12.345.678 " , false , 0 , 1000000 * 12 + 1000 * 345 + 678 } ,
{ " 1.234.5678 " , false , - 1 , 0 } ,
{ " 1.2345.678 " , false , - 1 , 0 } ,
{ " 12345.6.78 " , false , - 1 , 0 } ,
{ " 123456789 " , true , - 1 , 0 } ,
{ " 3.0-2-virtual " , false , - 1 , 0 } ,
{ " no-number-here " , false , - 1 , 0 } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testParseVersionString ( const void * data G_GNUC_UNUSED )
2011-07-01 21:58:15 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
int result ;
size_t i ;
2011-07-01 21:58:15 +04:00
unsigned long version ;
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( versions ) ; + + i ) {
2020-02-24 02:47:18 +03:00
result = virStringParseVersion ( & version , versions [ i ] . string ,
2011-07-01 21:58:15 +04:00
versions [ i ] . allowMissing ) ;
if ( result ! = versions [ i ] . result ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " \n Version string [%s] " , versions [ i ] . string ) ;
VIR_TEST_DEBUG ( " Expect result [%d] " , versions [ i ] . result ) ;
VIR_TEST_DEBUG ( " Actual result [%d] " , result ) ;
2011-07-01 21:58:15 +04:00
return - 1 ;
}
2014-11-13 17:20:43 +03:00
if ( result < 0 )
2011-07-01 21:58:15 +04:00
continue ;
if ( version ! = versions [ i ] . version ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " \n Version string [%s] " , versions [ i ] . string ) ;
VIR_TEST_DEBUG ( " Expect version [%lu] " , versions [ i ] . version ) ;
VIR_TEST_DEBUG ( " Actual version [%lu] " , version ) ;
2011-07-01 21:58:15 +04:00
return - 1 ;
}
}
return 0 ;
}
2014-11-18 19:13:38 +03:00
struct testRoundData {
unsigned int input ;
unsigned int output ;
} ;
static struct testRoundData roundData [ ] = {
{ 0 , 0 } ,
{ 1 , 1 } ,
{ 1000 , 1024 } ,
{ 1024 , 1024 } ,
{ 1025 , 2048 } ,
{ UINT_MAX , 0 } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testRoundValueToPowerOfTwo ( const void * data G_GNUC_UNUSED )
2014-11-18 19:13:38 +03:00
{
unsigned int result ;
size_t i ;
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( roundData ) ; i + + ) {
2014-11-18 19:13:38 +03:00
result = VIR_ROUND_UP_POWER_OF_TWO ( roundData [ i ] . input ) ;
if ( roundData [ i ] . output ! = result ) {
2019-05-03 11:31:02 +03:00
VIR_TEST_DEBUG ( " \n Input number [%u] " , roundData [ i ] . input ) ;
VIR_TEST_DEBUG ( " Expected number [%u] " , roundData [ i ] . output ) ;
VIR_TEST_DEBUG ( " Actual number [%u] " , result ) ;
2014-11-18 19:13:38 +03:00
return - 1 ;
}
}
return 0 ;
}
2017-11-03 15:09:47 +03:00
# define TEST_OVERFLOW(var, val, expect) \
tmp = val ; \
if ( VIR_ASSIGN_IS_OVERFLOW ( var , tmp ) ! = expect ) { \
fprintf ( stderr , " \n overflow check failed: " \
" var: " # var " val: " # val " \n " ) ; \
return - 1 ; \
2015-05-27 11:54:38 +03:00
}
static int
2019-10-14 15:45:03 +03:00
testOverflowCheckMacro ( const void * data G_GNUC_UNUSED )
2015-05-27 11:54:38 +03:00
{
long long tmp ;
2015-06-08 11:24:08 +03:00
uint8_t luchar ;
int8_t lchar ;
2015-05-27 11:54:38 +03:00
TEST_OVERFLOW ( luchar , 254 , false ) ;
TEST_OVERFLOW ( luchar , 255 , false ) ;
TEST_OVERFLOW ( luchar , 256 , true ) ;
TEST_OVERFLOW ( luchar , 767 , true ) ;
TEST_OVERFLOW ( lchar , 127 , false ) ;
TEST_OVERFLOW ( lchar , - 128 , false ) ;
TEST_OVERFLOW ( lchar , - 129 , true ) ;
TEST_OVERFLOW ( lchar , 128 , true ) ;
return 0 ;
}
2020-06-15 11:28:06 +03:00
struct testKernelCmdlineNextParamData
{
const char * cmdline ;
const char * param ;
const char * val ;
const char * next ;
} ;
static struct testKernelCmdlineNextParamData kEntries [ ] = {
{ " arg1 arg2 arg3=val1 " , " arg1 " , NULL , " arg2 arg3=val1 " } ,
{ " arg1=val1 arg2 arg3=val3 arg4 " , " arg1 " , " val1 " , " arg2 arg3=val3 arg4 " } ,
{ " arg1=sub1=val1,sub2=val2 arg3=val3 arg4 " , " arg1 " , " sub1=val1,sub2=val2 " , " arg3=val3 arg4 " } ,
{ " arg3=val3 " , " arg3 " , " val3 " , " " } ,
{ " arg3=val3 " , " arg3 " , " val3 " , " " } ,
{ " arg-3=val3 arg4 " , " arg-3 " , " val3 " , " arg4 " } ,
{ " arg_3=val3 arg4 " , " arg_3 " , " val3 " , " arg4 " } ,
{ " arg2= \" value with space \" arg3=val3 " , " arg2 " , " value with space " , " arg3=val3 " } ,
{ " arg2= \" value with space \" arg3=val3 " , " arg2 " , " value with space " , " arg3=val3 " } ,
{ " \" arg2=value with space \" arg3=val3 " , " arg2 " , " value with space " , " arg3=val3 " } ,
{ " arg2= \" val \" ue arg3 " , " arg2 " , " val \" ue " , " arg3 " } ,
{ " arg2=value \" long \" arg3 " , " arg2 " , " value \" long \" " , " arg3 " } ,
{ " \" arg2 with space=value with space \" arg3 " , " arg2 with space " , " value with space " , " arg3 " } ,
{ " arg2 \" with space=val2 \" arg3 " , " arg2 \" with space " , " val2 \" " , " arg3 " } ,
{ " arg2longer=someval \" long \" arg2=val2 " , " arg2longer " , " someval \" long \" " , " arg2=val2 " } ,
{ " =val1 arg2=val2 " , " =val1 " , NULL , " arg2=val2 " } ,
{ " " , NULL , NULL , " " } ,
{ " " , NULL , NULL , " " } ,
} ;
static int
testKernelCmdlineNextParam ( const void * data G_GNUC_UNUSED )
{
const char * next ;
size_t i ;
for ( i = 0 ; i < G_N_ELEMENTS ( kEntries ) ; + + i ) {
g_autofree char * param = NULL ;
g_autofree char * val = NULL ;
next = virKernelCmdlineNextParam ( kEntries [ i ] . cmdline , & param , & val ) ;
if ( STRNEQ_NULLABLE ( param , kEntries [ i ] . param ) | |
STRNEQ_NULLABLE ( val , kEntries [ i ] . val ) | |
STRNEQ ( next , kEntries [ i ] . next ) ) {
VIR_TEST_DEBUG ( " \n Kernel cmdline [%s] " , kEntries [ i ] . cmdline ) ;
VIR_TEST_DEBUG ( " Expect param [%s] " , kEntries [ i ] . param ) ;
VIR_TEST_DEBUG ( " Actual param [%s] " , param ) ;
VIR_TEST_DEBUG ( " Expect value [%s] " , kEntries [ i ] . val ) ;
VIR_TEST_DEBUG ( " Actual value [%s] " , val ) ;
VIR_TEST_DEBUG ( " Expect next [%s] " , kEntries [ i ] . next ) ;
VIR_TEST_DEBUG ( " Actual next [%s] " , next ) ;
return - 1 ;
}
}
return 0 ;
}
struct testKernelCmdlineMatchData
{
const char * cmdline ;
const char * arg ;
const char * values [ 2 ] ;
virKernelCmdlineFlags flags ;
bool result ;
} ;
static struct testKernelCmdlineMatchData kMatchEntries [ ] = {
{ " arg1 myarg=no arg2=val2 myarg=yes arg4=val4 myarg=no arg5 " , " myarg " , { " 1 " , " y " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST | VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ , false } ,
{ " arg1 myarg=no arg2=val2 myarg=yes arg4=val4 myarg=no arg5 " , " myarg " , { " on " , " yes " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST | VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ , true } ,
{ " arg1 myarg=no arg2=val2 myarg=yes arg4=val4 myarg=no arg5 " , " myarg " , { " 1 " , " y " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST | VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX , true } ,
{ " arg1 myarg=no arg2=val2 myarg=yes arg4=val4 myarg=no arg5 " , " myarg " , { " a " , " b " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST | VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX , false } ,
{ " arg1 myarg=no arg2=val2 myarg=yes arg4=val4 myarg=no arg5 " , " myarg " , { " on " , " yes " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ , false } ,
{ " arg1 myarg=no arg2=val2 myarg=yes arg4=val4 myarg=no arg5 " , " myarg " , { " 1 " , " y " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX , false } ,
{ " arg1 myarg=no arg2=val2 arg4=val4 myarg=yes arg5 " , " myarg " , { " on " , " yes " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ , true } ,
{ " arg1 myarg=no arg2=val2 arg4=val4 myarg=yes arg5 " , " myarg " , { " 1 " , " y " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX , true } ,
{ " arg1 myarg=no arg2=val2 arg4=val4 myarg arg5 " , " myarg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , true } ,
{ " arg1 myarg arg2=val2 arg4=val4 myarg=yes arg5 " , " myarg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST , true } ,
{ " arg1 myarg arg2=val2 arg4=val4 myarg=yes arg5 " , " myarg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , false } ,
{ " arg1 my-arg=no arg2=val2 arg4=val4 my_arg=yes arg5 " , " my-arg " , { " on " , " yes " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , true } ,
{ " arg1 my-arg=no arg2=val2 arg4=val4 my_arg=yes arg5 " , " my-arg " , { " on " , " yes " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ , true } ,
{ " arg1 my-arg arg2=val2 arg4=val4 my_arg=yes arg5 " , " my_arg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST , true } ,
{ " arg1 my-arg arg2=val2 arg4=val4 my-arg=yes arg5 " , " my_arg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST , true } ,
{ " =arg1 my-arg arg2=val2 arg4=val4 my-arg=yes arg5 " , " my_arg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST , true } ,
{ " my-arg =arg1 arg2=val2 arg4=val4 my-arg=yes arg5 " , " =arg1 " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , true } ,
{ " arg1 arg2=val2 myarg=sub1=val1 arg5 " , " myarg " , { " sub1=val1 " , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , true } ,
{ " arg1 arg2= " , " arg2 " , { " " , " " } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ , true } ,
{ " " , " myarg " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , false } ,
{ " " , " " , { NULL , NULL } , VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST , false } ,
} ;
static int
testKernelCmdlineMatchParam ( const void * data G_GNUC_UNUSED )
{
bool result ;
size_t i , lenValues ;
for ( i = 0 ; i < G_N_ELEMENTS ( kMatchEntries ) ; + + i ) {
if ( kMatchEntries [ i ] . values [ 0 ] = = NULL )
lenValues = 0 ;
else
lenValues = G_N_ELEMENTS ( kMatchEntries [ i ] . values ) ;
result = virKernelCmdlineMatchParam ( kMatchEntries [ i ] . cmdline ,
kMatchEntries [ i ] . arg ,
kMatchEntries [ i ] . values ,
lenValues ,
kMatchEntries [ i ] . flags ) ;
if ( result ! = kMatchEntries [ i ] . result ) {
VIR_TEST_DEBUG ( " \n Kernel cmdline [%s] " , kMatchEntries [ i ] . cmdline ) ;
VIR_TEST_DEBUG ( " Kernel argument [%s] " , kMatchEntries [ i ] . arg ) ;
VIR_TEST_DEBUG ( " Kernel values [%s] [%s] " , kMatchEntries [ i ] . values [ 0 ] ,
kMatchEntries [ i ] . values [ 1 ] ) ;
if ( kMatchEntries [ i ] . flags & VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX )
VIR_TEST_DEBUG ( " Flag [VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX] " ) ;
if ( kMatchEntries [ i ] . flags & VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ )
VIR_TEST_DEBUG ( " Flag [VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ] " ) ;
if ( kMatchEntries [ i ] . flags & VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST )
VIR_TEST_DEBUG ( " Flag [VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST] " ) ;
if ( kMatchEntries [ i ] . flags & VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST )
VIR_TEST_DEBUG ( " Flag [VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST] " ) ;
VIR_TEST_DEBUG ( " Expect result [%d] " , kMatchEntries [ i ] . result ) ;
VIR_TEST_DEBUG ( " Actual result [%d] " , result ) ;
return - 1 ;
}
}
return 0 ;
}
2014-11-18 19:13:38 +03:00
2011-07-01 21:58:15 +04:00
static int
mymain ( void )
{
int result = 0 ;
2016-05-26 18:02:00 +03:00
virTestQuiesceLibvirtErrors ( true ) ;
2011-07-01 21:58:15 +04:00
2017-11-03 15:09:47 +03:00
# define DO_TEST(_name) \
do { \
if ( virTestRun ( " Util " # _name , test # # _name , \
NULL ) < 0 ) { \
result = - 1 ; \
} \
2011-07-01 21:58:15 +04:00
} while ( 0 )
DO_TEST ( IndexToDiskName ) ;
DO_TEST ( DiskNameToIndex ) ;
2015-11-13 16:14:44 +03:00
DO_TEST ( DiskNameParse ) ;
2011-07-01 21:58:15 +04:00
DO_TEST ( ParseVersionString ) ;
2014-11-18 19:13:38 +03:00
DO_TEST ( RoundValueToPowerOfTwo ) ;
2015-05-27 11:54:38 +03:00
DO_TEST ( OverflowCheckMacro ) ;
2020-06-15 11:28:06 +03:00
DO_TEST ( KernelCmdlineNextParam ) ;
DO_TEST ( KernelCmdlineMatchParam ) ;
2011-07-01 21:58:15 +04:00
return result = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )