#include #include #include "list_file.h" #include "exactness_config.h" #include "run_test.h" #include "scheduler.h" #include "config.h" static int _errors_sort_cb(List_Entry *a, List_Entry *b) { return strcmp(a->name, b->name); } static void _exactness_errors_sort(Exactness_Ctx *ctx) { ctx->errors = eina_list_sort(ctx->errors, 0, (Eina_Compare_Cb) _errors_sort_cb); ctx->compare_errors = eina_list_sort(ctx->compare_errors, 0, (Eina_Compare_Cb) strcmp); } static const Ecore_Getopt optdesc = { "exactness", "%prog [options] <-r|-p|-i|-s> ", 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."), ECORE_GETOPT_STORE_STR('w', "wrap", "Use a custom command to launch the tests (e.g valgrind)."), 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 = ""; char tmp[EXACTNESS_PATH_MAX]; 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), ECORE_GETOPT_VALUE_STR(exactness_config.wrap_command), 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(); ecore_evas_init(); mode_record = mode_play = mode_init = mode_simulation = EINA_FALSE; want_quit = EINA_FALSE; exactness_config.base_dir = "./recordings"; exactness_config.dest_dir = "./"; exactness_config.wrap_command = ""; 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, "\tConcurrent jobs: %d\n", exactness_config.jobs); fprintf(stderr, "\tTest list: %s\n", list_file); fprintf(stderr, "\tBase dir: %s\n", exactness_config.base_dir); fprintf(stderr, "\tDest dir: %s\n", exactness_config.dest_dir); if (mode_record) { scheduler_run(run_test_record, test_list); } else if (mode_play) { 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); scheduler_run(run_test_play, test_list); } else if (mode_init) { 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); 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))); /* Sort the errors and the compare_errors. */ _exactness_errors_sort(&exactness_ctx); if (exactness_ctx.errors || exactness_ctx.compare_errors) { 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+"); if (report_file) { printf("%s %p\n", report_filename, report_file); fprintf(report_file, "" "Exactness report"); if (exactness_ctx.errors) { fprintf(report_file, "

Tests that failed execution:

    "); 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, "
  • %s
  • ", ent->name); } fprintf(report_file, "
"); } if (exactness_ctx.compare_errors) { fprintf(report_file, "

Images that failed comparison: (Original, Current, Diff)

    "); 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, "
  • %s

    Original Current Diff
  • ", test_name, test_name, test_name, test_name); free(test_name); } fprintf(report_file, "
"); } fprintf(report_file, ""); printf("Report html: %s\n", report_filename); ret = 1; } else { perror("Failed opening report file"); } } list_file_free(test_list); end: ecore_evas_shutdown(); ecore_shutdown(); return ret; }