2013-05-03 03:53:37 -07:00
# include <Ecore.h>
# include <Ecore_Getopt.h>
# include "list_file.h"
# include "exactness_config.h"
# include "run_test.h"
# include "scheduler.h"
# include "config.h"
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 ,
{
ECORE_GETOPT_STORE_STR ( ' b ' , " base-dir " , " The location of the rec files. " ) ,
ECORE_GETOPT_STORE_STR ( ' d ' , " dest-dir " , " 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 ( ' r ' , " record " , " Run in record mode. " ) ,
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. " ) ,
ECORE_GETOPT_STORE_TRUE ( ' v ' , " verbose " , " Turn verbose messages on. " ) ,
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 ;
const char * list_file = " " ;
2013-05-09 04:55:24 -07:00
char tmp [ EXACTNESS_PATH_MAX ] ;
2013-05-03 03:53:37 -07:00
Eina_Bool mode_record , mode_play , mode_init , mode_simulation ;
Eina_Bool want_quit ;
Ecore_Getopt_Value values [ ] = {
ECORE_GETOPT_VALUE_STR ( exactness_config . base_dir ) ,
ECORE_GETOPT_VALUE_STR ( exactness_config . dest_dir ) ,
2013-05-21 07:33:20 -07:00
ECORE_GETOPT_VALUE_STR ( exactness_config . wrap_command ) ,
2013-05-03 03:53:37 -07:00
ECORE_GETOPT_VALUE_USHORT ( exactness_config . jobs ) ,
ECORE_GETOPT_VALUE_BOOL ( mode_record ) ,
ECORE_GETOPT_VALUE_BOOL ( mode_play ) ,
ECORE_GETOPT_VALUE_BOOL ( mode_init ) ,
ECORE_GETOPT_VALUE_BOOL ( mode_simulation ) ,
ECORE_GETOPT_VALUE_BOOL ( exactness_config . verbose ) ,
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 ( ) ;
mode_record = mode_play = mode_init = mode_simulation = EINA_FALSE ;
want_quit = EINA_FALSE ;
2013-05-17 03:23:24 -07:00
exactness_config . base_dir = " ./recordings " ;
2013-05-03 03:53:37 -07:00
exactness_config . dest_dir = " ./ " ;
2013-05-21 07:33:20 -07:00
exactness_config . wrap_command = " " ;
2013-05-03 03:53:37 -07:00
exactness_config . jobs = 1 ;
exactness_config . verbose = EINA_FALSE ;
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 ;
}
else if ( mode_record + mode_play + mode_init + mode_simulation ! = 1 )
{
fprintf ( stderr , " At least and only one of the running modes can be set. \n " ) ;
ecore_getopt_help ( stderr , & optdesc ) ;
ret = 1 ;
goto end ;
}
list_file = argv [ args ] ;
/* Load the list file and start iterating over the records. */
test_list = list_file_load ( list_file ) ;
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 " ) ;
fprintf ( stderr , " \t Concurrent jobs: %d \n " , exactness_config . jobs ) ;
fprintf ( stderr , " \t Test list: %s \n " , list_file ) ;
fprintf ( stderr , " \t Base dir: %s \n " , exactness_config . base_dir ) ;
fprintf ( stderr , " \t Dest dir: %s \n " , exactness_config . dest_dir ) ;
if ( mode_record )
{
scheduler_run ( run_test_record , test_list ) ;
}
else if ( mode_play )
{
2013-05-09 04:55:24 -07:00
if ( snprintf ( tmp , EXACTNESS_PATH_MAX , " %s/%s " , exactness_config . dest_dir , CURRENT_SUBDIR )
> = 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
scheduler_run ( run_test_play , test_list ) ;
}
else if ( mode_init )
{
2013-05-09 04:55:24 -07:00
if ( snprintf ( tmp , EXACTNESS_PATH_MAX , " %s/%s " , exactness_config . dest_dir , ORIG_SUBDIR )
> = 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
scheduler_run ( run_test_init , test_list ) ;
}
else if ( mode_simulation )
{
scheduler_run ( run_test_simulation , test_list ) ;
}
ecore_main_loop_begin ( ) ;
/* Results */
printf ( " ******************************************************* \n " ) ;
if ( mode_play )
{
List_Entry * list_itr ;
EINA_INLIST_FOREACH ( test_list , list_itr )
{
run_test_compare ( list_itr ) ;
}
}
printf ( " Finished executing %u out of %u tests. \n " ,
exactness_ctx . tests_executed ,
eina_inlist_count ( EINA_INLIST_GET ( test_list ) ) ) ;
2013-05-15 08:48:04 -07:00
if ( exactness_ctx . errors | | exactness_ctx . 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 " ,
exactness_config . dest_dir , CURRENT_SUBDIR ) ;
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
2013-06-12 07:15:02 -07:00
if ( exactness_ctx . errors )
{
fprintf ( report_file ,
" <h1>Tests that failed execution:</h1><ul> " ) ;
Eina_List * itr ;
List_Entry * ent ;
printf ( " List of tests that failed execution: \n " ) ;
EINA_LIST_FOREACH ( exactness_ctx . errors , itr , ent )
{
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
2013-06-12 07:15:02 -07:00
if ( exactness_ctx . 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 " ) ;
EINA_LIST_FREE ( exactness_ctx . compare_errors , test_name )
{
printf ( " \t * %s \n " , test_name ) ;
fprintf ( report_file , " <li><h2>%s</h2> <img src='../orig/%s' alt='Original' /> <img src='%s' alt='Current' /> <img src='comp_%s' alt='Diff' /></li> " , test_name , test_name , test_name , test_name ) ;
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
}
list_file_free ( test_list ) ;
end :
ecore_shutdown ( ) ;
return ret ;
}