2008-01-29 21:15:54 +03:00
# include <config.h>
2006-08-25 01:46:28 +04:00
# include <unistd.h>
2007-11-26 15:03:34 +03:00
Wed Dec 5 13:48:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
* python/libvir.c, python/libvirt_wrap.h, qemud/qemud.c,
qemud/remote.c, src/internal.h, src/openvz_conf.c,
src/openvz_driver.c, src/proxy_internal.h, src/qemu_conf.c,
src/qemu_driver.c, src/remote_internal.h, src/test.h, src/util.c,
src/xen_unified.c, src/xen_unified.h, tests/nodeinfotest.c,
tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c, tests/reconnect.c,
tests/sexpr2xmltest.c, tests/virshtest.c, tests/xencapstest.c,
tests/xmconfigtest.c, tests/xml2sexprtest.c:
Change #include <> to #include "" for local includes.
Removed many includes from src/internal.h and put them in
the C files which actually use them.
Removed <ansidecl.h> - unused.
Added a comment around __func__.
Removed a clashing redefinition of VERSION symbol.
All limits (PATH_MAX etc) now done in src/internal.h, so we
don't need to include those headers in other files.
2007-12-05 16:56:22 +03:00
# include "internal.h"
2006-08-25 01:46:28 +04:00
# include "testutils.h"
2020-02-09 04:00:06 +03:00
# include "vircommand.h"
2006-08-25 01:46:28 +04:00
2013-06-07 19:10:28 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2011-07-28 19:48:12 +04:00
# ifdef WIN32
int
main ( void )
{
return EXIT_AM_SKIP ;
}
# else
2024-03-20 19:45:56 +03:00
static void testFilterLine ( char * buffer ,
const char * toRemove )
2014-03-18 12:13:43 +04:00
{
2018-09-13 11:55:21 +03:00
char * start ;
2024-03-20 19:45:56 +03:00
while ( ( start = strstr ( buffer , toRemove ) ) ) {
char * end ;
2018-09-13 11:55:21 +03:00
2024-03-20 19:45:56 +03:00
if ( ! ( end = strstr ( start + 1 , " \n " ) ) ) {
* start = ' \0 ' ;
} else {
memmove ( start , end , strlen ( end ) + 1 ) ;
}
2018-09-13 11:55:21 +03:00
}
2006-08-25 01:46:28 +04:00
}
2011-04-25 02:25:10 +04:00
static int
2024-03-12 15:52:48 +03:00
testCompareOutputLit ( const char * expectFile ,
const char * filter ,
const char * const argv [ ] )
2011-04-25 02:25:10 +04:00
{
2024-03-12 19:15:39 +03:00
g_autofree char * actual = NULL ;
2020-02-09 04:00:06 +03:00
const char * empty = " " ;
g_autoptr ( virCommand ) cmd = NULL ;
2024-03-12 19:15:39 +03:00
int exitstatus = 0 ;
2006-08-25 01:46:28 +04:00
2022-08-23 15:35:47 +03:00
cmd = virCommandNewArgs ( argv ) ;
2006-08-25 01:46:28 +04:00
2020-02-09 04:00:06 +03:00
virCommandAddEnvString ( cmd , " LANG=C " ) ;
virCommandSetInputBuffer ( cmd , empty ) ;
2024-03-12 19:15:39 +03:00
virCommandSetOutputBuffer ( cmd , & actual ) ;
virCommandSetErrorBuffer ( cmd , & actual ) ;
2020-02-09 04:00:06 +03:00
2024-03-12 19:15:39 +03:00
if ( virCommandRun ( cmd , & exitstatus ) < 0 )
2020-02-09 04:00:06 +03:00
return - 1 ;
2024-03-12 19:15:39 +03:00
if ( exitstatus ! = 0 ) {
g_autofree char * tmp = g_steal_pointer ( & actual ) ;
actual = g_strdup_printf ( " %s \n ## Exit code: %d \n " , tmp , exitstatus ) ;
2020-02-09 04:00:06 +03:00
}
2024-03-20 19:45:56 +03:00
if ( filter )
testFilterLine ( actual , filter ) ;
2006-08-25 01:46:28 +04:00
2024-03-22 17:10:15 +03:00
if ( virTestCompareToFileFull ( actual , expectFile , false ) < 0 )
return - 1 ;
2006-08-25 01:46:28 +04:00
2020-02-09 04:07:19 +03:00
return 0 ;
2008-11-24 10:11:26 +03:00
}
2006-08-25 01:46:28 +04:00
2019-03-12 17:11:47 +03:00
# define VIRSH_DEFAULT abs_top_builddir " / tools / virsh", \
2006-08-25 01:46:28 +04:00
" --connect " , \
" test:///default "
static char * custom_uri ;
2019-03-12 17:11:47 +03:00
# define VIRSH_CUSTOM abs_top_builddir " / tools / virsh", \
2006-08-25 01:46:28 +04:00
" --connect " , \
custom_uri
2010-10-15 20:34:11 +04:00
struct testInfo {
2024-03-12 15:52:48 +03:00
const char * testname ; /* used to generate output filename */
const char * filter ;
2010-10-15 20:34:11 +04:00
const char * const * argv ;
} ;
2024-03-12 15:52:48 +03:00
static int testCompare ( const void * data )
2014-03-18 12:13:43 +04:00
{
2010-10-15 20:34:11 +04:00
const struct testInfo * info = data ;
2024-03-12 15:52:48 +03:00
g_autofree char * outfile = NULL ;
if ( info - > testname ) {
outfile = g_strdup_printf ( " %s/virshtestdata/%s.out " ,
abs_srcdir , info - > testname ) ;
}
2024-03-22 17:10:15 +03:00
return testCompareOutputLit ( outfile , info - > filter , info - > argv ) ;
2010-10-15 20:34:11 +04:00
}
2008-05-29 23:20:22 +04:00
static int
2011-04-29 20:21:20 +04:00
mymain ( void )
2006-08-25 01:46:28 +04:00
{
int ret = 0 ;
2019-10-22 16:26:14 +03:00
custom_uri = g_strdup_printf ( " test://%s/../examples/xml/test/testnode.xml " ,
abs_srcdir ) ;
2008-02-05 22:27:37 +03:00
2024-03-20 11:48:32 +03:00
# define DO_TEST_SCRIPT(testname_, testfilter, ...) \
{ \
const char * testname = testname_ ; \
g_autofree char * infile = g_strdup_printf ( " %s/virshtestdata/%s.in " , \
abs_srcdir , testname ) ; \
const char * myargv [ ] = { __VA_ARGS__ , NULL , NULL } ; \
const char * * tmp = myargv ; \
2024-03-12 16:34:03 +03:00
const struct testInfo info = { testname , testfilter , myargv } ; \
2024-03-20 11:48:32 +03:00
g_autofree char * scriptarg = NULL ; \
if ( virFileReadAll ( infile , 256 * 1024 , & scriptarg ) < 0 ) { \
fprintf ( stderr , " \n failed to load '%s' \n " , infile ) ; \
ret = - 1 ; \
} \
while ( * tmp ) \
tmp + + ; \
* tmp = scriptarg ; \
if ( virTestRun ( testname , testCompare , & info ) < 0 ) \
ret = - 1 ; \
} while ( 0 ) ;
2024-03-20 19:34:45 +03:00
DO_TEST_SCRIPT ( " info-default " , NULL , VIRSH_DEFAULT ) ;
DO_TEST_SCRIPT ( " info-custom " , NULL , VIRSH_CUSTOM ) ;
2024-03-20 19:48:12 +03:00
DO_TEST_SCRIPT ( " domain-id " , " \n CPU time: " , VIRSH_CUSTOM ) ;
2024-03-20 19:52:19 +03:00
DO_TEST_SCRIPT ( " blkiotune " , NULL , VIRSH_CUSTOM ) ;
2024-03-20 19:58:39 +03:00
DO_TEST_SCRIPT ( " iothreads " , NULL , VIRSH_CUSTOM ) ;
2024-03-20 19:34:45 +03:00
2024-03-12 16:34:03 +03:00
# define DO_TEST_FULL(testname_, filter, ...) \
2017-11-03 15:09:47 +03:00
do { \
2024-03-12 15:38:24 +03:00
const char * testname = testname_ ; \
const char * myargv [ ] = { __VA_ARGS__ , NULL } ; \
2024-03-12 16:34:03 +03:00
const struct testInfo info = { testname , NULL , myargv } ; \
2024-03-12 15:38:24 +03:00
if ( virTestRun ( testname , testCompare , & info ) < 0 ) \
2017-11-03 15:09:47 +03:00
ret = - 1 ; \
2010-10-15 20:34:11 +04:00
} while ( 0 )
2024-03-12 15:38:24 +03:00
/* automatically numbered test invocation */
2024-03-12 16:34:03 +03:00
# define DO_TEST(...) \
DO_TEST_FULL ( virTestCounterNext ( ) , NULL , VIRSH_DEFAULT , __VA_ARGS__ ) ;
2024-03-12 15:38:24 +03:00
2010-10-15 20:34:11 +04:00
/* Arg parsing quote removal tests. */
2024-03-12 15:38:24 +03:00
virTestCounterReset ( " echo-quote-removal- " ) ;
2024-03-12 16:34:03 +03:00
DO_TEST ( " echo a \t b " ) ;
DO_TEST ( " echo \" a \t b \" " ) ;
DO_TEST ( " echo 'a \t b' " ) ;
DO_TEST ( " echo a \\ \\ \t \\ b " ) ;
DO_TEST ( " echo " , " ' " , " \" " , " \\ ;echo \t a " ) ;
DO_TEST ( " echo \\ ' \\ \" \\ ;echo \t a " ) ;
DO_TEST ( " echo \\ ' \\ \" \\ \\ ;echo \t a " ) ;
DO_TEST ( " echo \" ' \" ' \" ' ' \\ ' \" \\ \\ \" " ) ;
2010-10-15 20:34:11 +04:00
/* Tests of echo flags. */
2024-03-20 18:27:18 +03:00
DO_TEST_SCRIPT ( " echo-escaping " , NULL , VIRSH_DEFAULT ) ;
2024-03-12 15:38:24 +03:00
virTestCounterReset ( " echo-escaping- " ) ;
2024-03-12 16:34:03 +03:00
DO_TEST ( " echo " , " a " , " A " , " 0 " , " + " , " * " , " ; " , " . " , " ' " , " \" " , " / " , " ? " , " = " , " " , " \n " , " < " , " > " , " & " ) ;
DO_TEST ( " echo " , " --shell " , " a " , " A " , " 0 " , " + " , " * " , " ; " , " . " , " ' " , " \" " , " / " , " ? " , " = " , " " , " \n " , " < " , " > " , " & " ) ;
DO_TEST ( " echo " , " --xml " , " a " , " A " , " 0 " , " + " , " * " , " ; " , " . " , " ' " , " \" " , " / " , " ? " , " = " , " " , " \n " , " < " , " > " , " & " ) ;
2010-10-15 20:34:11 +04:00
/* Tests of -- handling. */
2024-03-12 15:38:24 +03:00
virTestCounterReset ( " dash-dash-argument- " ) ;
2024-03-12 16:34:03 +03:00
DO_TEST ( " -- " , " echo " , " --shell " , " a " ) ;
DO_TEST ( " -- " , " echo " , " a " , " --shell " ) ;
DO_TEST ( " -- " , " echo " , " -- " , " a " , " --shell " ) ;
DO_TEST ( " echo " , " -- " , " -- " , " --shell " , " a " ) ;
DO_TEST ( " echo --s \\ h'e' \" l \" l -- a " ) ;
DO_TEST ( " echo \t '-' \" - \" \t --shell \t a " ) ;
2010-10-15 20:34:11 +04:00
2012-03-02 22:01:15 +04:00
/* Tests of alias handling. */
2024-03-20 11:48:32 +03:00
DO_TEST_SCRIPT ( " echo-alias " , NULL , VIRSH_DEFAULT ) ;
2024-03-12 16:34:03 +03:00
DO_TEST_FULL ( " echo-alias-argv " , NULL , VIRSH_DEFAULT , " echo " , " --str " , " hello " ) ;
2012-03-02 22:01:15 +04:00
2019-02-21 21:36:32 +03:00
/* Tests of multiple commands. */
2024-03-12 15:38:24 +03:00
virTestCounterReset ( " multiple-commands- " ) ;
2024-03-12 16:34:03 +03:00
DO_TEST ( " echo a; echo b; " ) ;
DO_TEST ( " \n echo a \n echo b \n " ) ;
DO_TEST ( " ec \\ \n ho a \n echo \\ \n b; " ) ;
DO_TEST ( " \" ec \\ \n ho \" a \n echo \" \\ \n b \" ; " ) ;
DO_TEST ( " ec \\ \n ho a \n echo ' \\ \n b'; " ) ;
DO_TEST ( " echo a # b " ) ;
DO_TEST ( " echo a #b \n echo c " ) ;
DO_TEST ( " echo a # b \\ \n echo c " ) ;
DO_TEST ( " echo a '#' b " ) ;
DO_TEST ( " echo a \\ # b " ) ;
DO_TEST ( " #unbalanced; 'quotes \" \n echo a # b " ) ;
DO_TEST ( " \\ # ignored;echo a \n '#also' ignored " ) ;
2019-02-21 21:36:32 +03:00
2021-08-11 16:22:59 +03:00
/* test of splitting in vshStringToArray */
2024-03-20 16:42:46 +03:00
DO_TEST_SCRIPT ( " echo-split " , NULL , VIRSH_DEFAULT , " -q " ) ;
2011-07-28 19:48:12 +04:00
# undef DO_TEST
2010-10-15 20:34:11 +04:00
2024-03-18 17:19:34 +03:00
/* comprehensive coverage of argument assignment */
DO_TEST_SCRIPT ( " argument-assignment " , NULL , VIRSH_DEFAULT , " -k0 " , " -d0 " ) ;
2024-03-18 17:38:39 +03:00
DO_TEST_SCRIPT ( " snapshot-create-args " , NULL , VIRSH_DEFAULT , " -q " ) ;
2024-03-18 17:19:34 +03:00
2012-02-03 03:16:43 +04:00
VIR_FREE ( custom_uri ) ;
2014-03-17 13:38:38 +04:00
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
2006-08-25 01:46:28 +04:00
}
2008-05-29 23:20:22 +04:00
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )
2011-07-28 19:48:12 +04:00
# endif /* WIN32 */