2018-05-20 11:22:38 -07:00
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
2013-05-03 03:53:37 -07:00
# include <Ecore.h>
2018-05-13 11:57:43 -07:00
# include <Ecore_Evas.h>
2018-01-25 02:45:37 -08:00
# include <Ecore_File.h>
2013-05-03 03:53:37 -07:00
# include <Ecore_Getopt.h>
2018-01-06 12:40:23 -08:00
# include <Emile.h>
2013-05-03 03:53:37 -07:00
2018-01-06 12:40:23 -08:00
# include "exactness_private.h"
2013-05-03 03:53:37 -07:00
2018-01-06 12:40:23 -08:00
# define SCHEDULER_CMD_SIZE 1024
# define ORIG_SUBDIR "orig"
# define CURRENT_SUBDIR "current"
# define EXACTNESS_PATH_MAX 1024
# define BUF_SIZE 1024
2018-01-06 14:30:05 -08:00
typedef struct
{
EINA_INLIST ;
char * name ;
const char * command ;
} List_Entry ;
2018-01-06 12:40:23 -08:00
typedef enum
{
RUN_SIMULATION ,
RUN_PLAY ,
RUN_INIT
} Run_Mode ;
2018-05-13 01:26:38 -07:00
static unsigned short _running_jobs = 0 , _max_jobs = 1 ;
static Eina_List * _base_dirs = NULL ;
2018-01-06 14:30:05 -08:00
static char * _dest_dir ;
2018-06-04 13:59:02 -07:00
static char * _wrap_command = NULL , * _fonts_dir = NULL ;
2018-01-06 14:30:05 -08:00
static int _verbose = 0 ;
2018-10-20 14:14:55 -07:00
static Eina_Bool _scan_objs = EINA_FALSE , _disable_screenshots = EINA_FALSE , _stabilize_shots = EINA_FALSE ;
2018-01-06 12:40:23 -08:00
2018-01-06 14:30:05 -08:00
static Run_Mode _mode ;
static List_Entry * _next_test_to_run = NULL ;
static unsigned int _tests_executed = 0 ;
2018-01-06 12:40:23 -08:00
2018-01-06 14:30:05 -08:00
static Eina_List * _errors ;
static Eina_List * _compare_errors ;
2018-01-06 12:40:23 -08:00
2018-01-06 14:30:05 -08:00
static Eina_Bool _job_consume ( ) ;
2018-01-06 12:40:23 -08:00
2018-01-06 14:30:05 -08:00
static void
_printf ( int verbose , const char * fmt , . . . )
2018-01-06 12:40:23 -08:00
{
2018-01-06 14:30:05 -08:00
va_list ap ;
if ( ! _verbose | | verbose > _verbose ) return ;
2018-01-06 12:40:23 -08:00
2018-01-06 14:30:05 -08:00
va_start ( ap , fmt ) ;
vprintf ( fmt , ap ) ;
va_end ( ap ) ;
2018-01-06 12:40:23 -08:00
}
2018-05-18 07:23:06 -07:00
static Exactness_Image *
_image_load ( const char * filename )
{
int w , h ;
Evas_Load_Error err ;
Ecore_Evas * ee = ecore_evas_new ( NULL , 0 , 0 , 100 , 100 , NULL ) ;
Eo * e = ecore_evas_get ( ee ) ;
Eo * img = evas_object_image_add ( e ) ;
evas_object_image_file_set ( img , filename , NULL ) ;
err = evas_object_image_load_error_get ( img ) ;
if ( err ! = EVAS_LOAD_ERROR_NONE )
{
fprintf ( stderr , " could not load image '%s'. error string is \" %s \" \n " ,
filename , evas_load_error_str ( err ) ) ;
return NULL ;
}
Exactness_Image * ex_img = malloc ( sizeof ( * ex_img ) ) ;
int len ;
evas_object_image_size_get ( img , & w , & h ) ;
ex_img - > w = w ;
ex_img - > h = h ;
len = w * h * 4 ;
ex_img - > pixels = malloc ( len ) ;
memcpy ( ex_img - > pixels , evas_object_image_data_get ( img , EINA_FALSE ) , len ) ;
ecore_evas_free ( ee ) ;
return ex_img ;
}
static void
_image_save ( Exactness_Image * ex_img , const char * output )
{
Ecore_Evas * ee ;
Eo * e , * img ;
ee = ecore_evas_new ( NULL , 0 , 0 , 100 , 100 , NULL ) ;
e = ecore_evas_get ( ee ) ;
img = evas_object_image_add ( e ) ;
evas_object_image_size_set ( img , ex_img - > w , ex_img - > h ) ;
evas_object_image_data_set ( img , ex_img - > pixels ) ;
evas_object_image_save ( img , output , NULL , NULL ) ;
ecore_evas_free ( ee ) ;
}
static void
_file_compare ( const char * orig_dir , const char * ent_name )
{
Exactness_Image * img1 , * img2 , * imgO = NULL ;
2018-06-04 03:40:22 -07:00
char * filename1 = alloca ( strlen ( orig_dir ) + strlen ( ent_name ) + 20 ) ;
char * filename2 = alloca ( strlen ( _dest_dir ) + strlen ( ent_name ) + 20 ) ;
sprintf ( filename1 , " %s/%s " , orig_dir , ent_name ) ;
sprintf ( filename2 , " %s/%s/%s " , _dest_dir , CURRENT_SUBDIR , ent_name ) ;
2018-05-18 07:23:06 -07:00
img1 = _image_load ( filename1 ) ;
img2 = _image_load ( filename2 ) ;
if ( exactness_image_compare ( img1 , img2 , & imgO ) )
{
2018-06-04 03:40:22 -07:00
char * buf = alloca ( strlen ( _dest_dir ) + strlen ( ent_name ) ) ;
sprintf ( buf , " %s/%s/comp_%s " , _dest_dir , CURRENT_SUBDIR , ent_name ) ;
2018-05-18 07:23:06 -07:00
_image_save ( imgO , buf ) ;
_compare_errors = eina_list_append ( _compare_errors , strdup ( ent_name ) ) ;
}
exactness_image_free ( img1 ) ;
exactness_image_free ( img2 ) ;
exactness_image_free ( imgO ) ;
}
static void
_exu_imgs_unpack ( const char * exu_path , const char * dir , const char * ent_name )
{
Exactness_Unit * unit = exactness_unit_file_read ( exu_path ) ;
Exactness_Image * img ;
Eina_List * itr ;
Ecore_Evas * ee = ecore_evas_new ( NULL , 0 , 0 , 100 , 100 , NULL ) ;
Eo * e = ecore_evas_get ( ee ) ;
int n = 1 ;
if ( ! unit ) return ;
EINA_LIST_FOREACH ( unit - > imgs , itr , img )
{
Eo * o = evas_object_image_add ( e ) ;
2018-06-04 03:40:22 -07:00
char * filename = alloca ( strlen ( dir ) + strlen ( ent_name ) + 20 ) ;
2018-05-18 07:23:06 -07:00
snprintf ( filename , EXACTNESS_PATH_MAX , " %s/%s%c%.3d.png " ,
dir , ent_name , SHOT_DELIMITER , n + + ) ;
evas_object_image_size_set ( o , img - > w , img - > h ) ;
evas_object_image_data_set ( o , img - > pixels ) ;
if ( ! evas_object_image_save ( o , filename , NULL , NULL ) )
{
printf ( " Cannot save widget to <%s> \n " , filename ) ;
}
efl_del ( o ) ;
}
efl_del ( e ) ;
ecore_evas_free ( ee ) ;
}
static void
_run_test_compare ( const List_Entry * ent )
{
2018-06-04 03:40:22 -07:00
char * path = alloca ( EXACTNESS_PATH_MAX ) ;
char * origdir = alloca ( strlen ( _dest_dir ) + 20 ) ;
2018-05-18 07:23:06 -07:00
const char * base_dir ;
Eina_List * itr ;
int n = 1 ;
EINA_LIST_FOREACH ( _base_dirs , itr , base_dir )
{
sprintf ( path , " %s/%s.exu " , base_dir , ent - > name ) ;
if ( ecore_file_exists ( path ) )
{
2018-10-03 02:25:50 -07:00
char * currentdir ;
2018-06-04 03:40:22 -07:00
sprintf ( origdir , " %s/%s/%s " , _dest_dir , CURRENT_SUBDIR , ORIG_SUBDIR ) ;
2018-05-18 07:23:06 -07:00
mkdir ( origdir , 0744 ) ;
_exu_imgs_unpack ( path , origdir , ent - > name ) ;
2018-10-03 02:25:50 -07:00
sprintf ( path , " %s/%s/%s.exu " , _dest_dir , CURRENT_SUBDIR , ent - > name ) ;
currentdir = alloca ( strlen ( _dest_dir ) + 20 ) ;
sprintf ( currentdir , " %s/%s " , _dest_dir , CURRENT_SUBDIR ) ;
_exu_imgs_unpack ( path , currentdir , ent - > name ) ;
2018-05-18 07:23:06 -07:00
goto found ;
}
else
{
sprintf ( path , " %s/%s.rec " , base_dir , ent - > name ) ;
2018-10-30 03:47:15 -07:00
if ( ecore_file_exists ( path ) )
{
sprintf ( origdir , " %s/%s " , _dest_dir , ORIG_SUBDIR ) ;
goto found ;
}
2018-05-18 07:23:06 -07:00
}
}
found :
do
{
sprintf ( path , " %s/%s%c%.3d.png " , origdir , ent - > name , SHOT_DELIMITER , n ) ;
if ( ecore_file_exists ( path ) )
{
sprintf ( path , " %s%c%.3d.png " , ent - > name , SHOT_DELIMITER , n ) ;
_file_compare ( origdir , path ) ;
}
else break ;
n + + ;
} while ( EINA_TRUE ) ;
}
2018-01-07 12:58:38 -08:00
# define CONFIG "ELM_SCALE=1 ELM_FINGER_SIZE=10"
2018-05-13 01:26:38 -07:00
static Eina_Bool
2018-01-06 14:30:05 -08:00
_run_command_prepare ( const List_Entry * ent , char * buf )
2018-01-06 12:40:23 -08:00
{
2018-01-25 02:45:37 -08:00
char scn_path [ EXACTNESS_PATH_MAX ] ;
2018-05-13 01:26:38 -07:00
Eina_Strbuf * sbuf ;
const char * base_dir ;
Eina_List * itr ;
2018-05-13 11:57:43 -07:00
Eina_Bool is_exu ;
2018-05-13 01:26:38 -07:00
EINA_LIST_FOREACH ( _base_dirs , itr , base_dir )
{
2018-05-13 11:57:43 -07:00
is_exu = EINA_TRUE ;
2018-05-13 01:26:38 -07:00
sprintf ( scn_path , " %s/%s.exu " , base_dir , ent - > name ) ;
if ( ecore_file_exists ( scn_path ) ) goto ok ;
else
{
2018-05-13 11:57:43 -07:00
is_exu = EINA_FALSE ;
2018-05-13 01:26:38 -07:00
sprintf ( scn_path , " %s/%s.rec " , base_dir , ent - > name ) ;
if ( ecore_file_exists ( scn_path ) ) goto ok ;
}
}
fprintf ( stderr , " Test %s not found in the provided base directories \n " , ent - > name ) ;
return EINA_FALSE ;
ok :
sbuf = eina_strbuf_new ( ) ;
2018-01-07 12:58:38 -08:00
eina_strbuf_append_printf ( sbuf ,
2018-10-20 14:14:55 -07:00
" %s %s exactness_play %s %s%s %s%.*s %s%s%s-t '%s' " ,
2018-01-07 12:58:38 -08:00
CONFIG , _wrap_command ? _wrap_command : " " ,
_mode = = RUN_SIMULATION ? " -s " : " " ,
2018-06-04 13:59:02 -07:00
_fonts_dir ? " -f " : " " , _fonts_dir ? _fonts_dir : " " ,
2018-01-07 12:58:38 -08:00
_verbose ? " - " : " " , _verbose , " vvvvvvvvvv " ,
2018-02-14 00:11:11 -08:00
_scan_objs ? " --scan-objects " : " " ,
2018-06-10 01:57:28 -07:00
_disable_screenshots ? " --disable-screenshots " : " " ,
2018-10-20 14:14:55 -07:00
_stabilize_shots ? " --stabilize-shots " : " " ,
2018-01-25 02:45:37 -08:00
scn_path
2018-01-07 12:58:38 -08:00
) ;
2018-05-13 11:57:43 -07:00
if ( is_exu )
{
if ( _mode = = RUN_PLAY )
2018-06-07 02:45:39 -07:00
eina_strbuf_append_printf ( sbuf , " -o '%s/%s/%s.exu' " , _dest_dir , CURRENT_SUBDIR , ent - > name ) ;
2018-05-13 11:57:43 -07:00
if ( _mode = = RUN_INIT )
2018-06-07 02:45:39 -07:00
eina_strbuf_append_printf ( sbuf , " -o '%s' " , scn_path ) ;
2018-05-13 11:57:43 -07:00
}
else
{
if ( _mode = = RUN_PLAY )
2018-06-07 02:45:39 -07:00
eina_strbuf_append_printf ( sbuf , " -o '%s/%s' " , _dest_dir , CURRENT_SUBDIR ) ;
2018-05-13 11:57:43 -07:00
if ( _mode = = RUN_INIT )
2018-06-07 02:45:39 -07:00
eina_strbuf_append_printf ( sbuf , " -o '%s/%s' " , _dest_dir , ORIG_SUBDIR ) ;
2018-05-13 11:57:43 -07:00
}
2018-08-28 07:38:19 -07:00
if ( ent - > command )
{
eina_strbuf_append ( sbuf , " -- " ) ;
eina_strbuf_append ( sbuf , ent - > command ) ;
}
2018-01-06 12:40:23 -08:00
strncpy ( buf , eina_strbuf_string_get ( sbuf ) , SCHEDULER_CMD_SIZE - 1 ) ;
eina_strbuf_free ( sbuf ) ;
2018-01-06 14:30:05 -08:00
_printf ( 1 , " Command: %s \n " , buf ) ;
2018-05-13 01:26:38 -07:00
return EINA_TRUE ;
2018-01-06 12:40:23 -08:00
}
2018-05-18 07:23:06 -07:00
static void
_job_compare ( void * data )
{
_run_test_compare ( data ) ;
2018-06-07 02:46:32 -07:00
_running_jobs - - ;
_job_consume ( ) ;
2018-05-18 07:23:06 -07:00
/* If all jobs are done. */
if ( ! _running_jobs ) ecore_main_loop_quit ( ) ;
}
2018-01-06 14:30:05 -08:00
static Eina_Bool
_job_deleted_cb ( void * data EINA_UNUSED , int type EINA_UNUSED , void * event )
2018-01-06 12:40:23 -08:00
{
2018-01-06 14:30:05 -08:00
Ecore_Exe_Event_Del * msg = ( Ecore_Exe_Event_Del * ) event ;
2018-05-18 07:23:06 -07:00
List_Entry * ent = ecore_exe_data_get ( msg - > exe ) ;
2018-01-06 14:30:05 -08:00
if ( ( msg - > exit_code ! = 0 ) | | ( msg - > exit_signal ! = 0 ) )
{
_errors = eina_list_append ( _errors , ent ) ;
}
2018-06-07 02:46:32 -07:00
if ( _mode = = RUN_PLAY )
{
ecore_job_add ( _job_compare , ent ) ;
}
else
{
_running_jobs - - ;
_job_consume ( ) ;
if ( ! _running_jobs ) ecore_main_loop_quit ( ) ;
}
2018-01-06 14:30:05 -08:00
return ECORE_CALLBACK_RENEW ;
2018-01-06 12:40:23 -08:00
}
2018-01-06 14:30:05 -08:00
static Eina_Bool
_job_consume ( )
2018-01-06 12:40:23 -08:00
{
2018-01-06 14:30:05 -08:00
static Ecore_Event_Handler * job_del_callback_handler = NULL ;
char buf [ SCHEDULER_CMD_SIZE ] ;
List_Entry * ent = _next_test_to_run ;
if ( _running_jobs = = _max_jobs ) return EINA_FALSE ;
if ( ! ent ) return EINA_FALSE ;
2018-05-13 01:26:38 -07:00
if ( _run_command_prepare ( ent , buf ) )
2018-01-06 14:30:05 -08:00
{
2018-05-13 01:26:38 -07:00
_running_jobs + + ;
_tests_executed + + ;
2018-01-06 14:30:05 -08:00
2018-05-13 01:26:38 -07:00
if ( ! job_del_callback_handler )
{
job_del_callback_handler = ecore_event_handler_add ( ECORE_EXE_EVENT_DEL ,
_job_deleted_cb , NULL ) ;
}
2018-01-06 14:30:05 -08:00
2018-05-13 01:26:38 -07:00
if ( ! ecore_exe_pipe_run ( buf , ECORE_EXE_TERM_WITH_PARENT , ent ) )
{
fprintf ( stderr , " Failed executing test '%s' \n " , ent - > name ) ;
}
}
2018-01-06 14:30:05 -08:00
_next_test_to_run = EINA_INLIST_CONTAINER_GET (
EINA_INLIST_GET ( ent ) - > next , List_Entry ) ;
return EINA_TRUE ;
2018-01-06 12:40:23 -08:00
}
2018-01-06 14:30:05 -08:00
static void
_scheduler_run ( )
2018-01-06 12:40:23 -08:00
{
2018-01-06 14:30:05 -08:00
while ( _job_consume ( ) ) ;
2018-01-06 12:40:23 -08:00
}
2018-01-06 14:30:05 -08:00
static List_Entry *
_list_file_load ( const char * filename )
2018-01-06 12:40:23 -08:00
{
List_Entry * ret = NULL ;
char buf [ BUF_SIZE ] = " " ;
FILE * file ;
file = fopen ( filename , " r " ) ;
if ( ! file )
{
perror ( " Failed opening list file " ) ;
return NULL ;
}
while ( fgets ( buf , BUF_SIZE , file ) )
{
/* Skip comment/empty lines. */
if ( ( * buf = = ' # ' ) | | ( * buf = = ' \n ' ) | | ( ! * buf ) )
continue ;
char * tmp ;
List_Entry * cur = calloc ( 1 , sizeof ( * cur ) ) ;
cur - > name = strdup ( buf ) ;
/* Set the command to the second half and put a \0 in between. */
tmp = strchr ( cur - > name , ' ' ) ;
if ( tmp )
{
* tmp = ' \0 ' ;
cur - > command = tmp + 1 ;
}
else
{
/* FIXME: error. */
cur - > command = " " ;
}
/* Replace the newline char with a \0. */
tmp = strchr ( cur - > command , ' \n ' ) ;
if ( tmp )
{
* tmp = ' \0 ' ;
}
ret = EINA_INLIST_CONTAINER_GET (
eina_inlist_append ( EINA_INLIST_GET ( ret ) , EINA_INLIST_GET ( cur ) ) ,
List_Entry ) ;
}
return ret ;
}
2018-01-06 14:30:05 -08:00
static void
_list_file_free ( List_Entry * list )
2018-01-06 12:40:23 -08:00
{
while ( list )
{
List_Entry * ent = list ;
list = EINA_INLIST_CONTAINER_GET ( EINA_INLIST_GET ( list ) - > next ,
List_Entry ) ;
free ( ent - > name ) ;
free ( ent ) ;
/* we don't free ent->command because it's allocated together. */
}
}
2013-05-03 03:53:37 -07:00
2013-06-14 05:33:32 -07:00
static int
_errors_sort_cb ( List_Entry * a , List_Entry * b )
{
return strcmp ( a - > name , b - > name ) ;
}
2013-05-03 03:53:37 -07:00
static const Ecore_Getopt optdesc = {
" exactness " ,
" %prog [options] <-r|-p|-i|-s> <list file> " ,
PACKAGE_VERSION ,
" (C) 2013 Enlightenment " ,
" BSD " ,
" A pixel perfect test suite for EFL based applications. " ,
0 ,
{
2018-05-13 01:26:38 -07:00
ECORE_GETOPT_APPEND ( ' b ' , " base-dir " , " The location of the exu/rec files. " , ECORE_GETOPT_TYPE_STR ) ,
2018-01-07 12:58:38 -08:00
ECORE_GETOPT_STORE_STR ( ' o ' , " output " , " The location of the images. " ) ,
2013-05-21 07:33:20 -07:00
ECORE_GETOPT_STORE_STR ( ' w ' , " wrap " , " Use a custom command to launch the tests (e.g valgrind). " ) ,
2013-05-03 03:53:37 -07:00
ECORE_GETOPT_STORE_USHORT ( ' j ' , " jobs " , " The number of jobs to run in parallel. " ) ,
ECORE_GETOPT_STORE_TRUE ( ' p ' , " play " , " Run in play mode. " ) ,
ECORE_GETOPT_STORE_TRUE ( ' i ' , " init " , " Run in init mode. " ) ,
ECORE_GETOPT_STORE_TRUE ( ' s ' , " simulation " , " Run in simulation mode. " ) ,
2018-02-14 00:11:11 -08:00
ECORE_GETOPT_STORE_TRUE ( 0 , " scan-objects " , " Extract information of all the objects at every shot. " ) ,
2018-06-10 01:57:28 -07:00
ECORE_GETOPT_STORE_TRUE ( 0 , " disable-screenshots " , " Disable screenshots. " ) ,
2018-06-04 13:59:02 -07:00
ECORE_GETOPT_STORE_STR ( ' f ' , " fonts-dir " , " Specify a directory of the fonts that should be used. " ) ,
2018-10-20 14:14:55 -07:00
ECORE_GETOPT_STORE_TRUE ( 0 , " stabilize-shots " , " Wait for the frames to be stable before taking the shots. " ) ,
2018-01-06 14:30:05 -08:00
ECORE_GETOPT_COUNT ( ' v ' , " verbose " , " Turn verbose messages on. " ) ,
2013-05-03 03:53:37 -07:00
ECORE_GETOPT_LICENSE ( ' L ' , " license " ) ,
ECORE_GETOPT_COPYRIGHT ( ' C ' , " copyright " ) ,
ECORE_GETOPT_VERSION ( ' V ' , " version " ) ,
ECORE_GETOPT_HELP ( ' h ' , " help " ) ,
ECORE_GETOPT_SENTINEL
}
} ;
int
main ( int argc , char * argv [ ] )
{
int ret = 0 ;
List_Entry * test_list ;
int args = 0 ;
2018-05-13 01:26:38 -07:00
const char * list_file ;
Eina_List * itr ;
const char * base_dir ;
2013-05-09 04:55:24 -07:00
char tmp [ EXACTNESS_PATH_MAX ] ;
2018-01-06 14:30:05 -08:00
Eina_Bool mode_play = EINA_FALSE , mode_init = EINA_FALSE , mode_simulation = EINA_FALSE ;
2018-02-14 00:11:11 -08:00
Eina_Bool want_quit = EINA_FALSE , scan_objs = EINA_FALSE ;
2013-05-03 03:53:37 -07:00
Ecore_Getopt_Value values [ ] = {
2018-05-13 01:26:38 -07:00
ECORE_GETOPT_VALUE_LIST ( _base_dirs ) ,
2018-01-06 14:30:05 -08:00
ECORE_GETOPT_VALUE_STR ( _dest_dir ) ,
ECORE_GETOPT_VALUE_STR ( _wrap_command ) ,
ECORE_GETOPT_VALUE_USHORT ( _max_jobs ) ,
2013-05-03 03:53:37 -07:00
ECORE_GETOPT_VALUE_BOOL ( mode_play ) ,
ECORE_GETOPT_VALUE_BOOL ( mode_init ) ,
ECORE_GETOPT_VALUE_BOOL ( mode_simulation ) ,
2018-02-14 00:11:11 -08:00
ECORE_GETOPT_VALUE_BOOL ( scan_objs ) ,
2018-06-10 01:57:28 -07:00
ECORE_GETOPT_VALUE_BOOL ( _disable_screenshots ) ,
2018-06-04 13:59:02 -07:00
ECORE_GETOPT_VALUE_STR ( _fonts_dir ) ,
2018-10-20 14:14:55 -07:00
ECORE_GETOPT_VALUE_BOOL ( _stabilize_shots ) ,
2018-01-06 14:30:05 -08:00
ECORE_GETOPT_VALUE_INT ( _verbose ) ,
2013-05-03 03:53:37 -07:00
ECORE_GETOPT_VALUE_BOOL ( want_quit ) ,
ECORE_GETOPT_VALUE_BOOL ( want_quit ) ,
ECORE_GETOPT_VALUE_BOOL ( want_quit ) ,
ECORE_GETOPT_VALUE_BOOL ( want_quit ) ,
ECORE_GETOPT_VALUE_NONE
} ;
ecore_init ( ) ;
2018-05-13 11:57:43 -07:00
ecore_evas_init ( ) ;
evas_init ( ) ;
2018-01-06 14:30:05 -08:00
mode_play = mode_init = mode_simulation = EINA_FALSE ;
2013-05-03 03:53:37 -07:00
want_quit = EINA_FALSE ;
2018-01-06 14:30:05 -08:00
_dest_dir = " ./ " ;
2018-02-14 00:11:11 -08:00
_scan_objs = scan_objs ;
2013-05-03 03:53:37 -07:00
args = ecore_getopt_parse ( & optdesc , values , argc , argv ) ;
if ( args < 0 )
{
fprintf ( stderr , " Failed parsing arguments. \n " ) ;
ret = 1 ;
goto end ;
}
else if ( want_quit )
{
ret = 1 ;
goto end ;
}
else if ( args = = argc )
{
fprintf ( stderr , " Expected test list as the last argument.. \n " ) ;
ecore_getopt_help ( stderr , & optdesc ) ;
ret = 1 ;
goto end ;
}
2018-01-06 14:30:05 -08:00
else if ( mode_play + mode_init + mode_simulation ! = 1 )
2013-05-03 03:53:37 -07:00
{
fprintf ( stderr , " At least and only one of the running modes can be set. \n " ) ;
ecore_getopt_help ( stderr , & optdesc ) ;
ret = 1 ;
goto end ;
}
2018-05-13 01:26:38 -07:00
if ( ! _base_dirs ) _base_dirs = eina_list_append ( NULL , " ./recordings " ) ;
2013-05-03 03:53:37 -07:00
2018-05-13 01:26:38 -07:00
list_file = argv [ args ] ;
2013-05-03 03:53:37 -07:00
/* Load the list file and start iterating over the records. */
2018-01-06 14:30:05 -08:00
test_list = _list_file_load ( list_file ) ;
_next_test_to_run = test_list ;
2013-05-03 03:53:37 -07:00
if ( ! test_list )
{
fprintf ( stderr , " No matching tests found in '%s' \n " , list_file ) ;
ret = 1 ;
goto end ;
}
/* Pre-run summary */
fprintf ( stderr , " Running with settings: \n " ) ;
2018-01-06 14:30:05 -08:00
fprintf ( stderr , " \t Concurrent jobs: %d \n " , _max_jobs ) ;
2013-05-03 03:53:37 -07:00
fprintf ( stderr , " \t Test list: %s \n " , list_file ) ;
2018-05-13 01:26:38 -07:00
fprintf ( stderr , " \t Base dirs: \n " ) ;
EINA_LIST_FOREACH ( _base_dirs , itr , base_dir )
fprintf ( stderr , " \t \t %s \n " , base_dir ) ;
2018-01-06 14:30:05 -08:00
fprintf ( stderr , " \t Dest dir: %s \n " , _dest_dir ) ;
2013-05-03 03:53:37 -07:00
2018-01-06 14:30:05 -08:00
if ( mode_play )
2013-05-03 03:53:37 -07:00
{
2018-01-06 14:30:05 -08:00
_mode = RUN_PLAY ;
if ( snprintf ( tmp , EXACTNESS_PATH_MAX , " %s/%s " , _dest_dir , CURRENT_SUBDIR )
2013-05-09 04:55:24 -07:00
> = EXACTNESS_PATH_MAX )
{
fprintf ( stderr , " Path too long: %s " , tmp ) ;
ret = 1 ;
goto end ;
}
mkdir ( tmp , 0744 ) ;
2013-05-03 03:53:37 -07:00
}
else if ( mode_init )
{
2018-01-06 14:30:05 -08:00
_mode = RUN_INIT ;
if ( snprintf ( tmp , EXACTNESS_PATH_MAX , " %s/%s " , _dest_dir , ORIG_SUBDIR )
2013-05-09 04:55:24 -07:00
> = EXACTNESS_PATH_MAX )
{
fprintf ( stderr , " Path too long: %s " , tmp ) ;
ret = 1 ;
goto end ;
}
mkdir ( tmp , 0744 ) ;
2013-05-03 03:53:37 -07:00
}
else if ( mode_simulation )
{
2018-01-06 14:30:05 -08:00
_mode = RUN_SIMULATION ;
2013-05-03 03:53:37 -07:00
}
2018-01-06 14:30:05 -08:00
_scheduler_run ( ) ;
2013-05-03 03:53:37 -07:00
ecore_main_loop_begin ( ) ;
/* Results */
printf ( " ******************************************************* \n " ) ;
2018-05-18 07:23:06 -07:00
if ( mode_play & & EINA_FALSE )
2013-05-03 03:53:37 -07:00
{
List_Entry * list_itr ;
EINA_INLIST_FOREACH ( test_list , list_itr )
{
2018-01-06 14:30:05 -08:00
_run_test_compare ( list_itr ) ;
2013-05-03 03:53:37 -07:00
}
}
printf ( " Finished executing %u out of %u tests. \n " ,
2018-01-06 14:30:05 -08:00
_tests_executed ,
2013-05-03 03:53:37 -07:00
eina_inlist_count ( EINA_INLIST_GET ( test_list ) ) ) ;
2013-06-14 05:33:32 -07:00
/* Sort the errors and the compare_errors. */
2018-01-06 14:30:05 -08:00
_errors = eina_list_sort ( _errors , 0 , ( Eina_Compare_Cb ) _errors_sort_cb ) ;
_compare_errors = eina_list_sort ( _compare_errors , 0 , ( Eina_Compare_Cb ) strcmp ) ;
2013-06-14 05:33:32 -07:00
2018-01-06 14:30:05 -08:00
if ( _errors | | _compare_errors )
2013-05-03 03:53:37 -07:00
{
2013-05-15 08:48:04 -07:00
FILE * report_file ;
char report_filename [ EXACTNESS_PATH_MAX ] = " " ;
/* Generate the filename. */
snprintf ( report_filename , EXACTNESS_PATH_MAX ,
" %s/%s/errors.html " ,
2018-01-06 14:30:05 -08:00
_dest_dir , mode_init ? ORIG_SUBDIR : CURRENT_SUBDIR ) ;
2013-05-15 08:48:04 -07:00
report_file = fopen ( report_filename , " w+ " ) ;
2013-06-12 07:15:02 -07:00
if ( report_file )
2013-05-03 03:53:37 -07:00
{
2013-06-12 07:15:02 -07:00
printf ( " %s %p \n " , report_filename , report_file ) ;
2013-05-15 08:48:04 -07:00
fprintf ( report_file ,
2013-06-12 07:15:02 -07:00
" <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?><!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Strict//EN \" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd \" > "
" <html xmlns= \" http://www.w3.org/1999/xhtml \" ><head><title>Exactness report</title></head><body> " ) ;
2013-05-15 08:48:04 -07:00
2018-01-06 14:30:05 -08:00
if ( _errors )
2013-06-12 07:15:02 -07:00
{
fprintf ( report_file ,
" <h1>Tests that failed execution:</h1><ul> " ) ;
List_Entry * ent ;
printf ( " List of tests that failed execution: \n " ) ;
2018-01-06 14:30:05 -08:00
EINA_LIST_FOREACH ( _errors , itr , ent )
2013-06-12 07:15:02 -07:00
{
printf ( " \t * %s \n " , ent - > name ) ;
fprintf ( report_file , " <li>%s</li> " , ent - > name ) ;
}
fprintf ( report_file , " </ul> " ) ;
2013-05-15 08:48:04 -07:00
}
2013-05-03 03:53:37 -07:00
2018-01-06 14:30:05 -08:00
if ( _compare_errors )
2013-05-15 08:48:04 -07:00
{
2013-06-12 07:15:02 -07:00
fprintf ( report_file ,
" <h1>Images that failed comparison: (Original, Current, Diff)</h1><ul> " ) ;
char * test_name ;
printf ( " List of images that failed comparison: \n " ) ;
2018-01-06 14:30:05 -08:00
EINA_LIST_FREE ( _compare_errors , test_name )
2013-06-12 07:15:02 -07:00
{
2018-05-13 11:57:43 -07:00
Eina_Bool is_from_exu ;
char origpath [ EXACTNESS_PATH_MAX ] ;
snprintf ( origpath , EXACTNESS_PATH_MAX , " %s/%s/orig/%s " ,
_dest_dir , CURRENT_SUBDIR , test_name ) ;
is_from_exu = ecore_file_exists ( origpath ) ;
2013-06-12 07:15:02 -07:00
printf ( " \t * %s \n " , test_name ) ;
2018-05-13 11:57:43 -07:00
fprintf ( report_file , " <li><h2>%s</h2> <img src='%sorig/%s' alt='Original' /> <img src='%s' alt='Current' /> <img src='comp_%s' alt='Diff' /></li> " ,
test_name , is_from_exu ? " " : " ../ " ,
test_name , test_name , test_name ) ;
2013-06-12 07:15:02 -07:00
free ( test_name ) ;
}
fprintf ( report_file , " </ul> " ) ;
2013-05-15 08:48:04 -07:00
}
2013-06-12 07:15:02 -07:00
fprintf ( report_file ,
" </body></html> " ) ;
2013-05-15 08:48:04 -07:00
2013-06-12 07:15:02 -07:00
printf ( " Report html: %s \n " , report_filename ) ;
ret = 1 ;
}
else
{
perror ( " Failed opening report file " ) ;
}
2013-05-03 03:53:37 -07:00
}
2018-01-06 14:30:05 -08:00
_list_file_free ( test_list ) ;
2013-05-03 03:53:37 -07:00
end :
2018-05-13 11:57:43 -07:00
evas_shutdown ( ) ;
ecore_evas_shutdown ( ) ;
2013-05-03 03:53:37 -07:00
ecore_shutdown ( ) ;
return ret ;
}