2010-09-22 07:11:43 +04:00
/*
2006-03-25 17:49:00 +03:00
Unix SMB / CIFS implementation .
SMB torture UI functions
2008-11-16 02:58:08 +03:00
Copyright ( C ) Jelmer Vernooij 2006 - 2008
2010-09-22 07:11:43 +04:00
2006-03-25 17:49:00 +03:00
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
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-03-25 17:49:00 +03:00
( at your option ) any later version .
2010-09-22 07:11:43 +04:00
2006-03-25 17:49:00 +03:00
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 .
2010-09-22 07:11:43 +04:00
2006-03-25 17:49:00 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-03-25 17:49:00 +03:00
*/
2008-11-18 03:35:10 +03:00
# include "source4/include/includes.h"
2008-11-16 02:58:08 +03:00
# include "../torture/torture.h"
2008-10-11 23:31:42 +04:00
# include "../lib/util/dlinklist.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2007-09-16 18:39:19 +04:00
# include "system/filesys.h"
2010-07-06 09:22:31 +04:00
# include "system/dir.h"
2008-01-08 07:34:46 +03:00
2010-09-22 07:11:43 +04:00
2008-11-01 02:24:55 +03:00
struct torture_results * torture_results_init ( TALLOC_CTX * mem_ctx , const struct torture_ui_ops * ui_ops )
{
struct torture_results * results = talloc_zero ( mem_ctx , struct torture_results ) ;
results - > ui_ops = ui_ops ;
results - > returncode = true ;
if ( ui_ops - > init )
ui_ops - > init ( results ) ;
return results ;
}
2008-10-23 23:30:41 +04:00
/**
* Initialize a torture context
*/
2008-12-29 22:24:57 +03:00
struct torture_context * torture_context_init ( struct tevent_context * event_ctx ,
2008-11-01 02:24:55 +03:00
struct torture_results * results )
2008-01-08 07:34:46 +03:00
{
2008-04-14 20:43:37 +04:00
struct torture_context * torture = talloc_zero ( event_ctx ,
2008-01-08 07:34:46 +03:00
struct torture_context ) ;
2008-10-31 18:37:02 +03:00
if ( torture = = NULL )
return NULL ;
2008-04-14 20:43:37 +04:00
torture - > ev = event_ctx ;
2008-11-01 02:24:55 +03:00
torture - > results = talloc_reference ( torture , results ) ;
2008-01-08 07:34:46 +03:00
return torture ;
}
2006-03-25 17:49:00 +03:00
2008-10-31 18:37:02 +03:00
/**
* Create a sub torture context
*/
struct torture_context * torture_context_child ( struct torture_context * parent )
{
struct torture_context * subtorture = talloc_zero ( parent , struct torture_context ) ;
if ( subtorture = = NULL )
return NULL ;
subtorture - > ev = talloc_reference ( subtorture , parent - > ev ) ;
subtorture - > lp_ctx = talloc_reference ( subtorture , parent - > lp_ctx ) ;
subtorture - > outputdir = talloc_reference ( subtorture , parent - > outputdir ) ;
2008-11-01 02:24:55 +03:00
subtorture - > results = talloc_reference ( subtorture , parent - > results ) ;
2008-10-31 18:37:02 +03:00
return subtorture ;
2010-09-14 01:22:35 +04:00
}
2008-10-31 18:37:02 +03:00
2007-09-12 11:29:29 +04:00
/**
2010-07-06 09:22:31 +04:00
create a temporary directory under the output dir
2007-09-12 11:29:29 +04:00
*/
2010-09-22 07:11:43 +04:00
_PUBLIC_ NTSTATUS torture_temp_dir ( struct torture_context * tctx ,
const char * prefix , char * * tempdir )
2007-09-12 11:29:29 +04:00
{
SMB_ASSERT ( tctx - > outputdir ! = NULL ) ;
2010-09-22 07:11:43 +04:00
* tempdir = talloc_asprintf ( tctx , " %s/%s.XXXXXX " , tctx - > outputdir ,
2007-10-14 15:28:01 +04:00
prefix ) ;
2007-09-12 11:29:29 +04:00
NT_STATUS_HAVE_NO_MEMORY ( * tempdir ) ;
if ( mkdtemp ( * tempdir ) = = NULL ) {
2011-06-20 08:55:32 +04:00
return map_nt_error_from_unix_common ( errno ) ;
2007-09-12 11:29:29 +04:00
}
return NT_STATUS_OK ;
}
2010-07-06 09:22:31 +04:00
static int local_deltree ( const char * path )
{
2010-10-13 12:42:45 +04:00
int ret = 0 ;
2010-07-06 09:22:31 +04:00
struct dirent * dirent ;
DIR * dir = opendir ( path ) ;
if ( ! dir ) {
char * error = talloc_asprintf ( NULL , " Could not open directory %s " , path ) ;
perror ( error ) ;
talloc_free ( error ) ;
return - 1 ;
}
while ( ( dirent = readdir ( dir ) ) ) {
char * name ;
if ( ( strcmp ( dirent - > d_name , " . " ) = = 0 ) | | ( strcmp ( dirent - > d_name , " .. " ) = = 0 ) ) {
continue ;
}
name = talloc_asprintf ( NULL , " %s/%s " , path ,
dirent - > d_name ) ;
if ( name = = NULL ) {
closedir ( dir ) ;
return - 1 ;
}
2010-10-11 13:44:10 +04:00
DEBUG ( 0 , ( " About to remove %s \n " , name ) ) ;
2010-07-06 09:22:31 +04:00
ret = remove ( name ) ;
if ( ret = = 0 ) {
talloc_free ( name ) ;
continue ;
}
if ( errno = = ENOTEMPTY ) {
ret = local_deltree ( name ) ;
if ( ret = = 0 ) {
ret = remove ( name ) ;
}
}
talloc_free ( name ) ;
if ( ret ! = 0 ) {
char * error = talloc_asprintf ( NULL , " Could not remove %s " , path ) ;
perror ( error ) ;
talloc_free ( error ) ;
break ;
}
}
closedir ( dir ) ;
2011-02-18 17:02:35 +03:00
rmdir ( path ) ;
2010-07-06 09:22:31 +04:00
return ret ;
}
_PUBLIC_ NTSTATUS torture_deltree_outputdir ( struct torture_context * tctx )
{
2011-02-10 07:05:08 +03:00
if ( tctx - > outputdir = = NULL ) {
return NT_STATUS_OK ;
}
2010-07-06 09:22:31 +04:00
if ( ( strcmp ( tctx - > outputdir , " / " ) = = 0 )
| | ( strcmp ( tctx - > outputdir , " " ) = = 0 ) ) {
return NT_STATUS_INVALID_PARAMETER ;
}
if ( local_deltree ( tctx - > outputdir ) = = - 1 ) {
if ( errno ! = 0 ) {
2011-06-20 08:55:32 +04:00
return map_nt_error_from_unix_common ( errno ) ;
2010-07-06 09:22:31 +04:00
}
return NT_STATUS_UNSUCCESSFUL ;
}
return NT_STATUS_OK ;
}
2008-10-23 23:30:41 +04:00
/**
* Comment on the status / progress of a test
*/
2006-10-17 23:36:55 +04:00
void torture_comment ( struct torture_context * context , const char * comment , . . . )
2006-06-13 03:03:02 +04:00
{
2006-06-17 02:06:09 +04:00
va_list ap ;
char * tmp ;
2006-06-17 03:10:15 +04:00
2008-11-01 02:24:55 +03:00
if ( ! context - > results - > ui_ops - > comment )
2006-06-17 03:10:15 +04:00
return ;
2006-06-17 02:06:09 +04:00
va_start ( ap , comment ) ;
tmp = talloc_vasprintf ( context , comment , ap ) ;
2009-06-12 15:01:41 +04:00
va_end ( ap ) ;
2010-09-22 07:11:43 +04:00
2008-11-01 02:24:55 +03:00
context - > results - > ui_ops - > comment ( context , tmp ) ;
2010-09-22 07:11:43 +04:00
2006-06-17 02:06:09 +04:00
talloc_free ( tmp ) ;
}
2006-06-13 03:03:02 +04:00
2008-10-23 23:30:41 +04:00
/**
* Print a warning about the current test
*/
2007-03-06 00:28:55 +03:00
void torture_warning ( struct torture_context * context , const char * comment , . . . )
{
va_list ap ;
char * tmp ;
2008-11-01 02:24:55 +03:00
if ( ! context - > results - > ui_ops - > warning )
2007-03-06 00:28:55 +03:00
return ;
va_start ( ap , comment ) ;
tmp = talloc_vasprintf ( context , comment , ap ) ;
2009-06-12 15:01:41 +04:00
va_end ( ap ) ;
2007-03-06 00:28:55 +03:00
2008-11-01 02:24:55 +03:00
context - > results - > ui_ops - > warning ( context , tmp ) ;
2007-03-06 00:28:55 +03:00
talloc_free ( tmp ) ;
}
2008-10-23 23:30:41 +04:00
/**
* Store the result of a torture test .
*/
2006-10-17 23:06:50 +04:00
void torture_result ( struct torture_context * context ,
2007-08-11 21:08:22 +04:00
enum torture_result result , const char * fmt , . . . )
2006-06-17 02:06:09 +04:00
{
va_list ap ;
2006-06-17 03:10:15 +04:00
2006-06-17 02:06:09 +04:00
va_start ( ap , fmt ) ;
2007-10-05 12:54:27 +04:00
if ( context - > last_reason ) {
torture_warning ( context , " %s " , context - > last_reason ) ;
talloc_free ( context - > last_reason ) ;
}
2006-10-17 23:06:50 +04:00
context - > last_result = result ;
2006-06-17 04:17:50 +04:00
context - > last_reason = talloc_vasprintf ( context , fmt , ap ) ;
2006-06-17 02:06:09 +04:00
va_end ( ap ) ;
}
2006-03-25 17:49:00 +03:00
2008-10-23 23:30:41 +04:00
/**
* Create a new torture suite
*/
2006-06-17 02:06:09 +04:00
struct torture_suite * torture_suite_create ( TALLOC_CTX * ctx , const char * name )
{
2006-10-17 00:05:19 +04:00
struct torture_suite * suite = talloc_zero ( ctx , struct torture_suite ) ;
2006-03-25 17:49:00 +03:00
2006-06-17 02:06:09 +04:00
suite - > name = talloc_strdup ( suite , name ) ;
suite - > testcases = NULL ;
2006-10-16 17:06:41 +04:00
suite - > children = NULL ;
2006-06-13 03:03:02 +04:00
2006-06-17 02:06:09 +04:00
return suite ;
}
2008-10-23 23:30:41 +04:00
/**
* Set 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 ,
2007-10-07 02:28:14 +04:00
bool ( * setup ) ( struct torture_context * , void * * ) ,
bool ( * teardown ) ( struct torture_context * , void * ) )
2006-06-17 02:06:09 +04:00
{
tcase - > setup = setup ;
tcase - > teardown = teardown ;
2006-03-25 17:49:00 +03:00
}
2007-12-24 22:04:56 +03:00
static bool wrap_test_with_testcase_const ( struct torture_context * torture_ctx ,
2007-09-07 17:31:15 +04:00
struct torture_tcase * tcase ,
struct torture_test * test )
2006-10-16 17:06:41 +04:00
{
2007-12-24 22:04:56 +03:00
bool ( * fn ) ( struct torture_context * ,
2007-09-07 17:31:15 +04:00
const void * tcase_data ,
const void * test_data ) ;
2006-10-16 17:06:41 +04:00
fn = test - > fn ;
return fn ( torture_ctx , tcase - > data , test - > data ) ;
}
2008-10-23 23:30:41 +04:00
/**
* Add a test that uses const data to a testcase
*/
2007-12-24 22:04:56 +03:00
struct torture_test * torture_tcase_add_test_const ( struct torture_tcase * tcase ,
const char * name ,
bool ( * run ) ( struct torture_context * , const void * tcase_data ,
const void * test_data ) ,
const void * data )
2006-03-25 17:49:00 +03:00
{
2006-06-17 02:06:09 +04:00
struct torture_test * test = talloc ( tcase , struct torture_test ) ;
2006-03-25 17:49:00 +03:00
test - > name = talloc_strdup ( test , name ) ;
2006-06-17 02:06:09 +04:00
test - > description = NULL ;
2007-12-24 22:04:56 +03:00
test - > run = wrap_test_with_testcase_const ;
2006-10-16 17:06:41 +04:00
test - > fn = run ;
2007-08-31 19:43:03 +04:00
test - > dangerous = false ;
2006-06-17 02:06:09 +04:00
test - > data = data ;
2006-03-25 17:49:00 +03:00
2006-09-14 15:47:13 +04:00
DLIST_ADD_END ( tcase - > tests , test , struct torture_test * ) ;
2006-06-13 03:03:02 +04:00
return test ;
2006-03-25 17:49:00 +03:00
}
2008-10-23 23:30:41 +04:00
/**
* Add a new testcase
*/
2007-10-14 15:28:01 +04:00
bool torture_suite_init_tcase ( struct torture_suite * suite ,
struct torture_tcase * tcase ,
const char * name )
2007-08-28 18:42:37 +04:00
{
2006-06-17 02:06:09 +04:00
tcase - > name = talloc_strdup ( tcase , name ) ;
tcase - > description = NULL ;
tcase - > setup = NULL ;
tcase - > teardown = NULL ;
2007-10-07 02:28:14 +04:00
tcase - > fixture_persistent = true ;
2006-06-17 02:06:09 +04:00
tcase - > tests = NULL ;
2006-10-16 17:06:41 +04:00
DLIST_ADD_END ( suite - > testcases , tcase , struct torture_tcase * ) ;
2006-06-17 02:06:09 +04:00
2007-08-28 18:42:37 +04:00
return true ;
}
struct torture_tcase * torture_suite_add_tcase ( struct torture_suite * suite ,
const char * name )
{
struct torture_tcase * tcase = talloc ( suite , struct torture_tcase ) ;
if ( ! torture_suite_init_tcase ( suite , tcase , name ) )
return NULL ;
2006-06-17 02:06:09 +04:00
return tcase ;
}
2010-03-31 04:57:47 +04:00
int torture_suite_children_count ( const struct torture_suite * suite )
{
int ret = 0 ;
struct torture_tcase * tcase ;
struct torture_test * test ;
struct torture_suite * tsuite ;
for ( tcase = suite - > testcases ; tcase ; tcase = tcase - > next ) {
for ( test = tcase - > tests ; test ; test = test - > next ) {
ret + + ;
}
}
for ( tsuite = suite - > children ; tsuite ; tsuite = tsuite - > next ) {
ret + + ;
}
return ret ;
}
2008-10-23 23:30:41 +04:00
/**
* Run a torture test suite .
*/
2007-10-07 02:28:14 +04:00
bool torture_run_suite ( struct torture_context * context ,
2007-10-14 15:28:01 +04:00
struct torture_suite * suite )
2010-09-22 07:11:43 +04:00
{
return torture_run_suite_restricted ( context , suite , NULL ) ;
}
bool torture_run_suite_restricted ( struct torture_context * context ,
struct torture_suite * suite , const char * * restricted )
2006-06-17 02:06:09 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-06-17 02:06:09 +04:00
struct torture_tcase * tcase ;
2006-10-16 17:06:41 +04:00
struct torture_suite * tsuite ;
2006-06-17 02:06:09 +04:00
2008-11-01 02:24:55 +03:00
if ( context - > results - > ui_ops - > suite_start )
context - > results - > ui_ops - > suite_start ( context , suite ) ;
2006-06-17 03:10:15 +04:00
2010-09-22 07:11:43 +04:00
/* FIXME: Adjust torture_suite_children_count if restricted != NULL */
context - > results - > ui_ops - > progress ( context ,
torture_suite_children_count ( suite ) , TORTURE_PROGRESS_SET ) ;
2006-10-18 02:06:43 +04:00
2006-06-17 02:06:09 +04:00
for ( tcase = suite - > testcases ; tcase ; tcase = tcase - > next ) {
2010-09-22 07:11:43 +04:00
ret & = torture_run_tcase_restricted ( context , tcase , restricted ) ;
2006-06-17 02:06:09 +04:00
}
2006-06-17 03:10:15 +04:00
2006-10-16 17:06:41 +04:00
for ( tsuite = suite - > children ; tsuite ; tsuite = tsuite - > next ) {
2010-03-31 04:57:47 +04:00
context - > results - > ui_ops - > progress ( context , 0 , TORTURE_PROGRESS_PUSH ) ;
2010-09-22 07:11:43 +04:00
ret & = torture_run_suite_restricted ( context , tsuite , restricted ) ;
2010-03-31 04:57:47 +04:00
context - > results - > ui_ops - > progress ( context , 0 , TORTURE_PROGRESS_POP ) ;
2006-10-16 17:06:41 +04:00
}
2008-11-01 02:24:55 +03:00
if ( context - > results - > ui_ops - > suite_finish )
context - > results - > ui_ops - > suite_finish ( context , suite ) ;
2006-10-16 17:06:41 +04:00
2006-06-17 02:06:09 +04:00
return ret ;
2006-03-25 17:49:00 +03:00
}
2007-10-14 15:28:01 +04:00
void torture_ui_test_start ( struct torture_context * context ,
struct torture_tcase * tcase ,
struct torture_test * test )
2006-10-17 00:05:19 +04:00
{
2008-11-01 02:24:55 +03:00
if ( context - > results - > ui_ops - > test_start )
context - > results - > ui_ops - > test_start ( context , tcase , test ) ;
2006-10-17 00:05:19 +04:00
}
2007-10-14 15:28:01 +04:00
void torture_ui_test_result ( struct torture_context * context ,
enum torture_result result ,
const char * comment )
2006-10-17 00:05:19 +04:00
{
2008-11-01 02:24:55 +03:00
if ( context - > results - > ui_ops - > test_result )
context - > results - > ui_ops - > test_result ( context , result , comment ) ;
2006-10-17 00:05:19 +04:00
2007-01-30 15:10:42 +03:00
if ( result = = TORTURE_ERROR | | result = = TORTURE_FAIL )
2008-11-01 02:24:55 +03:00
context - > results - > returncode = false ;
2006-10-17 00:05:19 +04:00
}
2010-09-22 07:11:43 +04:00
static bool test_needs_running ( const char * name , const char * * restricted )
{
int i ;
if ( restricted = = NULL )
return true ;
for ( i = 0 ; restricted [ i ] ; i + + ) {
if ( ! strcmp ( name , restricted [ i ] ) )
return true ;
}
return false ;
}
2007-09-02 20:17:12 +04:00
static bool internal_torture_run_test ( struct torture_context * context ,
2006-06-17 02:48:50 +04:00
struct torture_tcase * tcase ,
struct torture_test * test ,
2010-09-22 07:11:43 +04:00
bool already_setup ,
const char * * restricted )
2006-06-17 02:48:50 +04:00
{
2007-09-02 20:17:12 +04:00
bool success ;
2010-09-22 07:11:43 +04:00
char * subunit_testname = NULL ;
2006-06-17 02:48:50 +04:00
2006-10-18 02:06:43 +04:00
if ( tcase = = NULL | | strcmp ( test - > name , tcase - > name ) ! = 0 ) {
2010-09-22 07:11:43 +04:00
subunit_testname = talloc_asprintf ( context , " %s.%s " , tcase - > name , test - > name ) ;
} else {
2010-09-23 08:03:05 +04:00
subunit_testname = talloc_strdup ( context , test - > name ) ;
2006-10-18 02:06:43 +04:00
}
2007-08-31 19:43:03 +04:00
2010-09-22 07:11:43 +04:00
if ( ! test_needs_running ( subunit_testname , restricted ) )
return true ;
2006-06-17 02:48:50 +04:00
context - > active_tcase = tcase ;
context - > active_test = test ;
2006-06-17 04:17:50 +04:00
2006-10-17 00:05:19 +04:00
torture_ui_test_start ( context , tcase , test ) ;
2006-06-17 02:48:50 +04:00
2006-06-17 04:17:50 +04:00
context - > last_reason = NULL ;
context - > last_result = TORTURE_OK ;
2007-09-02 20:17:12 +04:00
if ( ! already_setup & & tcase - > setup & &
! tcase - > setup ( context , & ( tcase - > data ) ) ) {
if ( context - > last_reason = = NULL )
context - > last_reason = talloc_strdup ( context , " Setup failure " ) ;
context - > last_result = TORTURE_ERROR ;
success = false ;
} else if ( test - > dangerous & &
2007-08-31 19:43:03 +04:00
! torture_setting_bool ( context , " dangerous " , false ) ) {
context - > last_result = TORTURE_SKIP ;
context - > last_reason = talloc_asprintf ( context ,
" disabled %s - enable dangerous tests to use " , test - > name ) ;
2007-09-07 20:27:02 +04:00
success = true ;
2007-08-31 19:43:03 +04:00
} else {
2007-09-02 20:17:12 +04:00
success = test - > run ( context , tcase , test ) ;
2007-08-31 19:43:03 +04:00
2007-09-02 20:17:12 +04:00
if ( ! success & & context - > last_result = = TORTURE_OK ) {
2007-08-31 19:43:03 +04:00
if ( context - > last_reason = = NULL )
2012-05-03 15:42:57 +04:00
context - > last_reason = talloc_strdup ( context ,
2012-05-03 18:38:31 +04:00
" Unknown error/failure. Missing torture_fail() or torture_assert_*() call? " ) ;
2007-08-31 19:43:03 +04:00
context - > last_result = TORTURE_ERROR ;
}
2006-06-21 21:47:19 +04:00
}
2006-06-17 04:17:50 +04:00
2007-09-02 20:17:12 +04:00
if ( ! already_setup & & tcase - > teardown & & ! tcase - > teardown ( context , tcase - > data ) ) {
if ( context - > last_reason = = NULL )
context - > last_reason = talloc_strdup ( context , " Setup failure " ) ;
context - > last_result = TORTURE_ERROR ;
success = false ;
}
2007-08-31 19:43:03 +04:00
torture_ui_test_result ( context , context - > last_result ,
context - > last_reason ) ;
2006-10-17 00:05:19 +04:00
2006-06-17 04:17:50 +04:00
talloc_free ( context - > last_reason ) ;
2006-06-17 02:48:50 +04:00
context - > active_test = NULL ;
context - > active_tcase = NULL ;
2007-09-02 20:17:12 +04:00
return success ;
2006-06-17 02:48:50 +04:00
}
2010-09-22 07:11:43 +04:00
bool torture_run_tcase ( struct torture_context * context ,
2007-10-14 15:28:01 +04:00
struct torture_tcase * tcase )
2010-09-22 07:11:43 +04:00
{
return torture_run_tcase_restricted ( context , tcase , NULL ) ;
}
bool torture_run_tcase_restricted ( struct torture_context * context ,
struct torture_tcase * tcase , const char * * restricted )
2006-06-17 02:06:09 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-06-17 02:06:09 +04:00
struct torture_test * test ;
2010-08-12 23:36:24 +04:00
bool setup_succeeded = true ;
const char * setup_reason = " Setup failed " ;
2006-06-17 02:06:09 +04:00
context - > active_tcase = tcase ;
2008-11-01 02:24:55 +03:00
if ( context - > results - > ui_ops - > tcase_start )
context - > results - > ui_ops - > tcase_start ( context , tcase ) ;
2006-06-17 02:06:09 +04:00
2010-08-12 23:36:24 +04:00
if ( tcase - > fixture_persistent & & tcase - > setup ) {
setup_succeeded = tcase - > setup ( context , & tcase - > data ) ;
}
if ( ! setup_succeeded ) {
/* Uh-oh. The setup failed, so we can't run any of the tests
* in this testcase . The subunit format doesn ' t specify what
* to do here , so we keep the failure reason , and manually
* use it to fail every test .
*/
if ( context - > last_reason ! = NULL ) {
setup_reason = talloc_asprintf ( context ,
" Setup failed: %s " , context - > last_reason ) ;
}
2006-06-17 03:10:15 +04:00
}
2006-06-17 02:06:09 +04:00
for ( test = tcase - > tests ; test ; test = test - > next ) {
2010-08-12 23:36:24 +04:00
if ( setup_succeeded ) {
ret & = internal_torture_run_test ( context , tcase , test ,
2010-09-22 07:11:43 +04:00
tcase - > fixture_persistent , restricted ) ;
2010-08-12 23:36:24 +04:00
} else {
context - > active_tcase = tcase ;
context - > active_test = test ;
torture_ui_test_start ( context , tcase , test ) ;
torture_ui_test_result ( context , TORTURE_FAIL , setup_reason ) ;
}
2006-06-17 02:06:09 +04:00
}
2010-08-12 23:36:24 +04:00
if ( setup_succeeded & & tcase - > fixture_persistent & & tcase - > teardown & &
! tcase - > teardown ( context , tcase - > data ) ) {
2007-09-02 20:17:12 +04:00
ret = false ;
2010-08-12 23:36:24 +04:00
}
2006-06-17 02:06:09 +04:00
context - > active_tcase = NULL ;
2010-08-12 23:36:24 +04:00
context - > active_test = NULL ;
2006-06-17 02:06:09 +04:00
2008-11-01 02:24:55 +03:00
if ( context - > results - > ui_ops - > tcase_finish )
context - > results - > ui_ops - > tcase_finish ( context , tcase ) ;
2006-06-17 03:10:15 +04:00
2010-08-12 23:36:24 +04:00
return ( ! setup_succeeded ) ? false : ret ;
2006-06-17 02:06:09 +04:00
}
2007-10-07 02:28:14 +04:00
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-03-25 17:49:00 +03:00
{
2010-09-22 07:11:43 +04:00
return internal_torture_run_test ( context , tcase , test , false , NULL ) ;
}
bool torture_run_test_restricted ( struct torture_context * context ,
struct torture_tcase * tcase ,
struct torture_test * test ,
const char * * restricted )
{
return internal_torture_run_test ( context , tcase , test , false , restricted ) ;
2006-03-25 17:49:00 +03:00
}
2006-10-16 17:06:41 +04:00
int torture_setting_int ( struct torture_context * test , const char * name ,
int default_value )
{
2010-07-16 08:32:42 +04:00
return lpcfg_parm_int ( test - > lp_ctx , NULL , " torture " , name , default_value ) ;
2006-10-16 17:06:41 +04:00
}
2009-11-18 02:23:23 +03:00
unsigned long torture_setting_ulong ( struct torture_context * test ,
const char * name ,
unsigned long default_value )
{
2010-07-16 08:32:42 +04:00
return lpcfg_parm_ulong ( test - > lp_ctx , NULL , " torture " , name ,
2009-11-18 02:23:23 +03:00
default_value ) ;
}
2007-08-28 04:16:58 +04:00
double torture_setting_double ( struct torture_context * test , const char * name ,
double default_value )
{
2010-07-16 08:32:42 +04:00
return lpcfg_parm_double ( test - > lp_ctx , NULL , " torture " , name , default_value ) ;
2007-08-28 04:16:58 +04:00
}
2006-10-16 17:06:41 +04:00
bool torture_setting_bool ( struct torture_context * test , const char * name ,
bool default_value )
{
2010-07-16 08:32:42 +04:00
return lpcfg_parm_bool ( test - > lp_ctx , NULL , " torture " , name , default_value ) ;
2006-10-16 17:06:41 +04:00
}
2007-10-14 15:28:01 +04:00
const char * torture_setting_string ( struct torture_context * test ,
const char * name ,
const char * default_value )
2006-03-25 17:49:00 +03:00
{
2007-12-03 04:58:12 +03:00
const char * ret ;
SMB_ASSERT ( test ! = NULL ) ;
SMB_ASSERT ( test - > lp_ctx ! = NULL ) ;
2010-07-16 08:32:42 +04:00
ret = lpcfg_parm_string ( test - > lp_ctx , NULL , " torture " , name ) ;
2006-05-22 22:59:29 +04:00
2006-06-17 02:06:09 +04:00
if ( ret = = NULL )
return default_value ;
return ret ;
2006-03-25 17:49:00 +03:00
}
2007-12-24 22:04:56 +03:00
static bool wrap_test_with_simple_tcase_const (
struct torture_context * torture_ctx ,
struct torture_tcase * tcase ,
struct torture_test * test )
2006-06-12 23:49:53 +04:00
{
2006-10-16 17:06:41 +04:00
bool ( * fn ) ( struct torture_context * , const void * tcase_data ) ;
fn = test - > fn ;
2006-06-17 02:06:09 +04:00
2006-10-16 17:06:41 +04:00
return fn ( torture_ctx , test - > data ) ;
2006-06-12 23:49:53 +04:00
}
2007-12-24 22:04:56 +03:00
struct torture_tcase * torture_suite_add_simple_tcase_const (
2007-10-14 15:28:01 +04:00
struct torture_suite * suite , const char * name ,
bool ( * run ) ( struct torture_context * test , const void * ) ,
const void * data )
2006-03-25 17:49:00 +03:00
{
2006-06-17 02:06:09 +04:00
struct torture_tcase * tcase ;
2007-12-24 22:04:56 +03:00
struct torture_test * test ;
2006-06-17 02:06:09 +04:00
tcase = torture_suite_add_tcase ( suite , name ) ;
2006-06-21 21:47:19 +04:00
2006-10-16 17:06:41 +04:00
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
2007-12-24 22:04:56 +03:00
test - > run = wrap_test_with_simple_tcase_const ;
2006-10-16 17:06:41 +04:00
test - > fn = run ;
test - > data = data ;
2007-08-28 18:42:37 +04:00
test - > dangerous = false ;
2006-10-16 17:06:41 +04:00
DLIST_ADD_END ( tcase - > tests , test , struct torture_test * ) ;
return tcase ;
}
static bool wrap_simple_test ( struct torture_context * torture_ctx ,
2007-10-14 15:28:01 +04:00
struct torture_tcase * tcase ,
struct torture_test * test )
2006-10-16 17:06:41 +04:00
{
bool ( * fn ) ( struct torture_context * ) ;
fn = test - > fn ;
return fn ( torture_ctx ) ;
}
struct torture_tcase * torture_suite_add_simple_test (
struct torture_suite * suite ,
const char * name ,
bool ( * run ) ( struct torture_context * test ) )
{
struct torture_test * test ;
struct torture_tcase * tcase ;
tcase = torture_suite_add_tcase ( suite , name ) ;
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
test - > run = wrap_simple_test ;
test - > fn = run ;
test - > dangerous = false ;
DLIST_ADD_END ( tcase - > tests , test , struct torture_test * ) ;
2006-06-17 02:06:09 +04:00
return tcase ;
}
2008-10-23 23:30:41 +04:00
/**
* Add a child testsuite to a testsuite .
*/
2006-10-16 17:06:41 +04:00
bool torture_suite_add_suite ( struct torture_suite * suite ,
2007-10-14 15:28:01 +04:00
struct torture_suite * child )
2006-10-16 17:06:41 +04:00
{
if ( child = = NULL )
return false ;
DLIST_ADD_END ( suite - > children , child , struct torture_suite * ) ;
/* FIXME: Check for duplicates and return false if the
* added suite already exists as a child */
return true ;
}
2008-10-23 23:30:41 +04:00
/**
* Find the child testsuite with the specified name .
*/
2006-10-17 03:09:15 +04:00
struct torture_suite * torture_find_suite ( struct torture_suite * parent ,
2007-10-14 15:28:01 +04:00
const char * name )
2006-10-16 17:06:41 +04:00
{
2006-10-17 03:09:15 +04:00
struct torture_suite * child ;
for ( child = parent - > children ; child ; child = child - > next )
if ( ! strcmp ( child - > name , name ) )
return child ;
2006-10-16 17:06:41 +04:00
return NULL ;
}
2007-08-26 19:16:40 +04:00
2007-12-24 22:04:56 +03:00
static bool wrap_test_with_simple_test_const ( struct torture_context * torture_ctx ,
2007-10-14 15:28:01 +04:00
struct torture_tcase * tcase ,
struct torture_test * test )
2007-08-26 19:16:40 +04:00
{
bool ( * fn ) ( struct torture_context * , const void * tcase_data ) ;
fn = test - > fn ;
return fn ( torture_ctx , tcase - > data ) ;
}
2007-12-24 22:04:56 +03:00
struct torture_test * torture_tcase_add_simple_test_const (
2007-08-26 19:16:40 +04:00
struct torture_tcase * tcase ,
const char * name ,
2007-12-24 22:04:56 +03:00
bool ( * run ) ( struct torture_context * test ,
const void * tcase_data ) )
2007-08-26 19:16:40 +04:00
{
2007-12-24 22:04:56 +03:00
struct torture_test * test ;
2007-08-26 19:16:40 +04:00
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
2007-12-24 22:04:56 +03:00
test - > run = wrap_test_with_simple_test_const ;
2007-08-26 19:16:40 +04:00
test - > fn = run ;
test - > data = NULL ;
2007-08-28 18:42:37 +04:00
test - > dangerous = false ;
2007-08-26 19:16:40 +04:00
DLIST_ADD_END ( tcase - > tests , test , struct torture_test * ) ;
return test ;
}
2007-12-24 22:06:57 +03:00
static bool wrap_test_with_simple_test ( struct torture_context * torture_ctx ,
struct torture_tcase * tcase ,
struct torture_test * test )
{
bool ( * fn ) ( struct torture_context * , void * tcase_data ) ;
fn = test - > fn ;
return fn ( torture_ctx , tcase - > data ) ;
}
struct torture_test * torture_tcase_add_simple_test ( struct torture_tcase * tcase ,
const char * name ,
bool ( * run ) ( struct torture_context * test , void * tcase_data ) )
{
struct torture_test * test ;
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
test - > run = wrap_test_with_simple_test ;
test - > fn = run ;
test - > data = NULL ;
test - > dangerous = false ;
DLIST_ADD_END ( tcase - > tests , test , struct torture_test * ) ;
return test ;
}
2010-09-23 08:03:05 +04:00
void torture_ui_report_time ( struct torture_context * context )
{
if ( context - > results - > ui_ops - > report_time )
context - > results - > ui_ops - > report_time ( context ) ;
}