2006-03-25 17:49:00 +03:00
/*
Unix SMB / CIFS implementation .
SMB torture UI functions
Copyright ( C ) Jelmer Vernooij 2006
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program 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 General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2006-06-17 02:06:09 +04:00
# ifndef __TORTURE_UI_H__
# define __TORTURE_UI_H__
2006-03-25 17:49:00 +03:00
struct torture_test ;
2006-06-17 02:06:09 +04:00
struct torture_context ;
2006-06-17 03:10:15 +04:00
struct torture_suite ;
2006-06-17 02:06:09 +04:00
struct torture_tcase ;
2006-03-25 17:49:00 +03:00
enum torture_result {
TORTURE_OK = 0 ,
TORTURE_FAIL = 1 ,
TORTURE_TODO = 2 ,
TORTURE_SKIP = 3
} ;
2006-10-16 17:06:41 +04:00
/*
* These callbacks should be implemented by any backend that wishes
* to listen to reports from the torture tests .
*/
2006-03-25 17:49:00 +03:00
struct torture_ui_ops
{
2006-06-17 02:06:09 +04:00
void ( * comment ) ( struct torture_context * , const char * ) ;
2006-06-17 03:10:15 +04:00
void ( * suite_start ) ( struct torture_context * , struct torture_suite * ) ;
void ( * suite_finish ) ( struct torture_context * , struct torture_suite * ) ;
2006-06-17 02:06:09 +04:00
void ( * tcase_start ) ( struct torture_context * , struct torture_tcase * ) ;
void ( * tcase_finish ) ( struct torture_context * , struct torture_tcase * ) ;
void ( * test_start ) ( struct torture_context * ,
struct torture_tcase * ,
struct torture_test * ) ;
2006-10-16 17:06:41 +04:00
void ( * test_result ) ( struct torture_context * ,
enum torture_result , const char * reason ) ;
2006-03-25 17:49:00 +03:00
} ;
2006-10-17 00:05:19 +04:00
void torture_ui_test_start ( struct torture_context * context ,
struct torture_tcase * tcase ,
struct torture_test * test ) ;
void torture_ui_test_result ( struct torture_context * context ,
enum torture_result result ,
const char * comment ) ;
2006-10-16 17:06:41 +04:00
/*
* Holds information about a specific run of the testsuite .
* The data in this structure should be considered private to
* the torture tests and should only be used directly by the torture
* code and the ui backends .
*
* Torture tests should instead call the torture_ * ( ) macros and functions
* specified below .
*/
2006-03-25 17:49:00 +03:00
struct torture_context
{
const struct torture_ui_ops * ui_ops ;
void * ui_data ;
2006-03-25 21:45:51 +03:00
2006-06-17 02:06:09 +04:00
struct torture_test * active_test ;
struct torture_tcase * active_tcase ;
2006-03-25 21:45:51 +03:00
int skipped ;
int todo ;
int success ;
int failed ;
2006-06-17 04:17:50 +04:00
2006-10-16 17:06:41 +04:00
bool quiet ; /* Whether tests should avoid writing output to stdout */
2006-06-17 04:17:50 +04:00
enum torture_result last_result ;
char * last_reason ;
2006-06-27 00:09:35 +04:00
char * outputdir ;
2006-10-16 17:06:41 +04:00
int level ;
} ;
/*
* Describes a particular torture test
*/
struct torture_test {
const char * name ;
const char * description ;
bool dangerous ;
/* Function to call to run this test */
bool ( * run ) ( struct torture_context * torture_ctx ,
struct torture_tcase * tcase ,
struct torture_test * test ) ;
struct torture_test * prev , * next ;
/* Pointer to the actual test function. This is run by the
* run ( ) function above . */
void * fn ;
const void * data ;
} ;
/*
* Describes a particular test case .
*/
struct torture_tcase {
const char * name ;
const char * description ;
bool ( * setup ) ( struct torture_context * tcase , void * * data ) ;
bool ( * teardown ) ( struct torture_context * tcase , void * data ) ;
bool fixture_persistent ;
void * data ;
struct torture_test * tests ;
struct torture_tcase * prev , * next ;
2006-03-25 17:49:00 +03:00
} ;
2006-05-22 22:59:29 +04:00
2006-06-17 02:06:09 +04:00
struct torture_suite
{
const char * name ;
2006-10-17 00:05:19 +04:00
const char * path ; /* Used by subunit tests only */
2006-06-17 02:06:09 +04:00
const char * description ;
2006-10-16 17:06:41 +04:00
struct torture_tcase * testcases ;
struct torture_suite * children ;
/* Pointers to siblings of this torture suite */
struct torture_suite * prev , * next ;
2006-06-17 02:06:09 +04:00
} ;
2006-10-16 17:06:41 +04:00
/** Create a new torture suite */
struct torture_suite * torture_suite_create ( TALLOC_CTX * mem_ctx ,
const char * name ) ;
/** Change the setup and teardown functions for a testcase */
2006-06-17 02:06:09 +04:00
void torture_tcase_set_fixture ( struct torture_tcase * tcase ,
2006-10-16 17:06:41 +04:00
bool ( * setup ) ( struct torture_context * , void * * ) ,
bool ( * teardown ) ( struct torture_context * , void * ) ) ;
/* Add another test to run for a particular testcase */
2006-06-17 02:06:09 +04:00
struct torture_test * torture_tcase_add_test ( struct torture_tcase * tcase ,
const char * name ,
2006-10-16 17:06:41 +04:00
bool ( * run ) ( struct torture_context * test , const void * tcase_data ,
2006-06-17 02:06:09 +04:00
const void * test_data ) ,
const void * test_data ) ;
2006-10-16 17:06:41 +04:00
/* Add a testcase to a testsuite */
2006-06-17 02:06:09 +04:00
struct torture_tcase * torture_suite_add_tcase ( struct torture_suite * suite ,
const char * name ) ;
2006-10-16 17:06:41 +04:00
/* Convenience wrapper that adds a testcase against only one
* test will be run */
2006-06-17 02:06:09 +04:00
struct torture_tcase * torture_suite_add_simple_tcase (
struct torture_suite * suite ,
const char * name ,
2006-10-16 17:06:41 +04:00
bool ( * run ) ( struct torture_context * test , const void * test_data ) ,
2006-06-17 02:06:09 +04:00
const void * data ) ;
2006-10-16 17:06:41 +04:00
/* Convenience wrapper that adds a test that doesn't need any
* testcase data */
struct torture_tcase * torture_suite_add_simple_test (
struct torture_suite * suite ,
const char * name ,
bool ( * run ) ( struct torture_context * test ) ) ;
/* Add a child testsuite to an existing testsuite */
bool torture_suite_add_suite ( struct torture_suite * suite ,
struct torture_suite * child ) ;
/* Run the specified testsuite recursively */
bool torture_run_suite ( struct torture_context * context ,
2006-06-17 02:06:09 +04:00
struct torture_suite * suite ) ;
2006-10-16 17:06:41 +04:00
/* Run the specified testcase */
bool torture_run_tcase ( struct torture_context * context ,
2006-06-17 02:06:09 +04:00
struct torture_tcase * tcase ) ;
2006-10-16 17:06:41 +04:00
/* Run the specified test */
bool torture_run_test ( struct torture_context * context ,
2006-06-17 02:06:09 +04:00
struct torture_tcase * tcase ,
struct torture_test * test ) ;
2006-10-16 17:06:41 +04:00
void _torture_fail_ext ( struct torture_context * test , const char * reason , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
void torture_comment ( struct torture_context * test , const char * comment , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
void _torture_skip_ext ( struct torture_context * test , const char * reason , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
# define torture_assert(torture_ctx,expr,cmt) \
2006-05-22 22:59:29 +04:00
if ( ! ( expr ) ) { \
2006-10-16 17:06:41 +04:00
torture_comment ( torture_ctx , __location__ " : Expression `%s' failed \n " , __STRING ( expr ) ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
2006-05-22 22:59:29 +04:00
}
2006-10-16 17:06:41 +04:00
# define torture_assert_werr_equal(torture_ctx, got, expected, cmt) \
2006-06-26 23:23:21 +04:00
do { WERROR __got = got , __expected = expected ; \
if ( ! W_ERROR_EQUAL ( __got , __expected ) ) { \
2006-10-16 17:06:41 +04:00
torture_comment ( torture_ctx , __location__ " : " # got " was %s, expected %s \n " , \
win_errstr ( __got ) , win_errstr ( __expected ) ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
2006-06-26 23:23:21 +04:00
} \
} while ( 0 )
2006-05-22 22:59:29 +04:00
2006-10-16 17:06:41 +04:00
# define torture_assert_ntstatus_equal(torture_ctx,got,expected,cmt) \
2006-06-26 23:23:21 +04:00
do { NTSTATUS __got = got , __expected = expected ; \
if ( ! NT_STATUS_EQUAL ( __got , __expected ) ) { \
2006-10-16 17:06:41 +04:00
torture_comment ( torture_ctx , __location__ " : " # got " was %s, expected %s \n " , \
nt_errstr ( __got ) , nt_errstr ( __expected ) ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
2006-06-26 23:23:21 +04:00
} \
} while ( 0 )
2006-05-22 22:59:29 +04:00
2006-10-16 17:06:41 +04:00
# define torture_assert_casestr_equal(torture_ctx,got,expected,cmt) \
do { const char * __got = ( got ) , * __expected = ( expected ) ; \
if ( ! strequal ( __got , __expected ) ) { \
torture_comment ( torture_ctx , __location__ " : " # got " was %s, expected %s \n " , __got , __expected ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
2006-06-26 23:23:21 +04:00
} \
} while ( 0 )
2006-06-12 23:49:53 +04:00
2006-10-16 17:06:41 +04:00
# define torture_assert_str_equal(torture_ctx,got,expected,cmt)\
do { const char * __got = ( got ) , * __expected = ( expected ) ; \
if ( strcmp_safe ( __got , __expected ) ! = 0 ) { \
torture_comment ( torture_ctx , __location__ " : " # got " was %s, expected %s \n " , __got , __expected ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
2006-06-26 23:23:21 +04:00
} \
} while ( 0 )
2006-06-12 23:49:53 +04:00
2006-10-16 17:06:41 +04:00
# define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
do { int __got = ( got ) , __expected = ( expected ) ; \
if ( __got ! = __expected ) { \
torture_comment ( torture_ctx , __location__ " : " # got " was %d, expected %d \n " , __got , __expected ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
} \
} while ( 0 )
# define torture_assert_errno_equal(torture_ctx,expected,cmt)\
do { int __expected = ( expected ) ; \
if ( errno ! = __expected ) { \
torture_comment ( torture_ctx , __location__ " : errno was %d, expected %s \n " , errno , strerror ( __expected ) ) ; \
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
} \
} while ( 0 )
# define torture_skip(torture_ctx,cmt) do {\
_torture_skip_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return true ; \
} while ( 0 )
# define torture_fail(torture_ctx,cmt) do {\
_torture_fail_ext ( torture_ctx , __location__ " : %s " , cmt ) ; \
return false ; \
} while ( 0 )
# define torture_out stderr
2006-06-12 23:49:53 +04:00
2006-05-22 22:59:29 +04:00
/* Convenience macros */
2006-10-16 17:06:41 +04:00
# define torture_assert_ntstatus_ok(torture_ctx,expr,cmt) \
torture_assert_ntstatus_equal ( torture_ctx , expr , NT_STATUS_OK , cmt )
2006-05-22 22:59:29 +04:00
2006-10-16 17:06:41 +04:00
# define torture_assert_werr_ok(torture_ctx,expr,cmt) \
torture_assert_werr_equal ( torture_ctx , expr , WERR_OK , cmt )
2006-05-22 22:59:29 +04:00
2006-10-16 17:06:41 +04:00
/* Getting settings */
const char * torture_setting_string ( struct torture_context * test , \
const char * name ,
const char * default_value ) ;
2006-05-22 22:59:29 +04:00
2006-10-16 17:06:41 +04:00
int torture_setting_int ( struct torture_context * test ,
const char * name ,
int default_value ) ;
bool torture_setting_bool ( struct torture_context * test ,
const char * name ,
bool default_value ) ;
2006-06-17 02:06:09 +04:00
2006-10-17 03:09:15 +04:00
struct torture_suite * torture_find_suite ( struct torture_suite * parent ,
const char * name ) ;
2006-06-17 02:06:09 +04:00
# endif /* __TORTURE_UI_H__ */