2008-10-23 23:30:41 +04:00
/*
Unix SMB / CIFS implementation .
Samba utility functions
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2008
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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "lib/torture/torture.h"
2014-12-14 01:11:06 +03:00
static void subunit_send_event ( char const * const event ,
char const * const name ,
char const * const details )
{
if ( NULL = = details ) {
printf ( " %s: %s \n " , event , name ) ;
} else {
printf ( " %s: %s [ \n " , event , name ) ;
printf ( " %s " , details ) ;
if ( details [ strlen ( details ) - 1 ] ! = ' \n ' )
puts ( " " ) ;
puts ( " ] " ) ;
}
fflush ( stdout ) ;
}
2008-10-23 23:30:41 +04:00
2010-09-23 06:55:58 +04:00
static void torture_subunit_suite_start ( struct torture_context * ctx ,
2008-10-23 23:30:41 +04:00
struct torture_suite * suite )
{
}
2010-09-23 06:55:58 +04:00
static char * torture_subunit_test_name ( struct torture_context * ctx ,
2008-10-23 23:30:41 +04:00
struct torture_tcase * tcase ,
struct torture_test * test )
{
if ( ! strcmp ( tcase - > name , test - > name ) ) {
2010-09-23 06:55:58 +04:00
return talloc_strdup ( ctx , test - > name ) ;
2008-10-23 23:30:41 +04:00
} else {
2010-09-23 06:55:58 +04:00
return talloc_asprintf ( ctx , " %s.%s " , tcase - > name , test - > name ) ;
2008-10-23 23:30:41 +04:00
}
}
2010-09-23 08:03:05 +04:00
static void torture_subunit_report_time ( struct torture_context * tctx )
{
struct timespec tp ;
struct tm * tmp ;
char timestr [ 200 ] ;
if ( clock_gettime ( CLOCK_REALTIME , & tp ) ! = 0 ) {
perror ( " clock_gettime " ) ;
return ;
}
2018-01-25 07:23:06 +03:00
tmp = gmtime ( & tp . tv_sec ) ;
2010-09-23 08:03:05 +04:00
if ( ! tmp ) {
2018-01-25 07:23:06 +03:00
perror ( " gmtime " ) ;
2010-09-23 08:03:05 +04:00
return ;
}
if ( strftime ( timestr , sizeof ( timestr ) , " %Y-%m-%d %H:%M:%S " , tmp ) < = 0 ) {
perror ( " strftime " ) ;
return ;
}
printf ( " time: %s.%06ld \n " , timestr , tp . tv_nsec / 1000 ) ;
}
static void torture_subunit_test_start ( struct torture_context * context ,
2008-10-23 23:30:41 +04:00
struct torture_tcase * tcase ,
struct torture_test * test )
{
2010-09-23 08:03:05 +04:00
char * fullname = torture_subunit_test_name ( context , context - > active_tcase , context - > active_test ) ;
2014-12-14 01:11:06 +03:00
subunit_send_event ( " test " , fullname , NULL ) ;
2010-09-23 08:03:05 +04:00
torture_subunit_report_time ( context ) ;
2010-09-23 06:55:58 +04:00
talloc_free ( fullname ) ;
2008-10-23 23:30:41 +04:00
}
2010-09-23 06:55:58 +04:00
static void torture_subunit_test_result ( struct torture_context * context ,
2008-10-23 23:30:41 +04:00
enum torture_result res , const char * reason )
{
2010-09-23 06:55:58 +04:00
char * fullname = torture_subunit_test_name ( context , context - > active_tcase , context - > active_test ) ;
2014-12-14 01:11:06 +03:00
const char * result_str = " unknown " ;
2010-09-23 08:03:05 +04:00
torture_subunit_report_time ( context ) ;
2008-10-23 23:30:41 +04:00
switch ( res ) {
case TORTURE_OK :
2014-12-14 01:11:06 +03:00
result_str = " success " ;
2008-10-23 23:30:41 +04:00
break ;
case TORTURE_FAIL :
2014-12-14 01:11:06 +03:00
result_str = " failure " ;
2008-10-23 23:30:41 +04:00
break ;
case TORTURE_ERROR :
2014-12-14 01:11:06 +03:00
result_str = " error " ;
2008-10-23 23:30:41 +04:00
break ;
case TORTURE_SKIP :
2014-12-14 01:11:06 +03:00
result_str = " skip " ;
2008-10-23 23:30:41 +04:00
break ;
}
2014-12-14 01:11:06 +03:00
subunit_send_event ( result_str , fullname , reason ) ;
2010-09-23 06:55:58 +04:00
talloc_free ( fullname ) ;
2008-10-23 23:30:41 +04:00
}
2010-09-23 06:55:58 +04:00
static void torture_subunit_comment ( struct torture_context * test ,
2008-10-23 23:30:41 +04:00
const char * comment )
{
fprintf ( stderr , " %s " , comment ) ;
}
2010-09-23 06:55:58 +04:00
static void torture_subunit_warning ( struct torture_context * test ,
2008-10-23 23:30:41 +04:00
const char * comment )
{
fprintf ( stderr , " WARNING!: %s \n " , comment ) ;
}
2010-09-23 06:55:58 +04:00
static void torture_subunit_progress ( struct torture_context * tctx , int offset , enum torture_progress_whence whence )
2010-03-31 04:57:47 +04:00
{
switch ( whence ) {
case TORTURE_PROGRESS_SET :
printf ( " progress: %d \n " , offset ) ;
break ;
case TORTURE_PROGRESS_CUR :
printf ( " progress: %+-d \n " , offset ) ;
break ;
case TORTURE_PROGRESS_POP :
printf ( " progress: pop \n " ) ;
break ;
case TORTURE_PROGRESS_PUSH :
printf ( " progress: push \n " ) ;
break ;
default :
fprintf ( stderr , " Invalid call to progress() \n " ) ;
break ;
}
}
2008-10-23 23:30:41 +04:00
const struct torture_ui_ops torture_subunit_ui_ops = {
2010-09-23 06:55:58 +04:00
. comment = torture_subunit_comment ,
. warning = torture_subunit_warning ,
. test_start = torture_subunit_test_start ,
. test_result = torture_subunit_test_result ,
. suite_start = torture_subunit_suite_start ,
. progress = torture_subunit_progress ,
2010-09-23 08:03:05 +04:00
. report_time = torture_subunit_report_time ,
2008-10-23 23:30:41 +04:00
} ;