gint main(gint argc, gchar **argv) #endif { gint i, j, c, iterations = 1; StringArray *tests_to_run = NULL; gdouble time_start; gboolean report_time = FALSE; gboolean quiet = FALSE; gboolean global_failure = FALSE; gboolean no_final_time_labels = FALSE; gboolean debug = FALSE; #if HAVE_GETOPT_H static struct option long_options [] = { {"help", no_argument, 0, 'h'}, {"time", no_argument, 0, 't'}, {"quiet", no_argument, 0, 'q'}, {"iterations", required_argument, 0, 'i'}, {"debug", no_argument, 0, 'd'}, {"no-labels", no_argument, 0, 'n'}, {0, 0, 0, 0} }; while((c = getopt_long(argc, argv, "dhtqni:", long_options, NULL)) != -1) { switch(c) { case 'h': print_help(argv[0]); return 1; case 't': report_time = TRUE; break; case 'i': iterations = atoi(optarg); break; case 'q': quiet = TRUE; break; case 'n': no_final_time_labels = TRUE; break; case 'd': debug = TRUE; break; } } for (i = optind; i < argc; i++) { if (argv[i][0] == '-') { continue; } tests_to_run = string_array_append(tests_to_run, argv[i]); } #endif time_start = get_timestamp(); for (j = 0; test_groups[j].name != NULL; j++) { gboolean run = TRUE; gchar *tests = NULL; gchar *group = NULL; if (tests_to_run != NULL) { gint k; run = FALSE; for (k = 0; k < tests_to_run->length; k++) { gchar *user = tests_to_run->strings[k]; const gchar *table = test_groups[j].name; size_t user_len = strlen(user); size_t table_len = strlen(table); if (strncmp(user, table, table_len) == 0) { if (user_len > table_len && user[table_len] != ':') { break; } run = TRUE; group = tests_to_run->strings[k]; break; } } } if (run) { gboolean passed; gchar **split = NULL; if (debug && test_groups[j].handler != fake_tests_init) { printf("Skipping %s, in driver debug mode\n", test_groups[j].name); continue; } else if (!debug && test_groups[j].handler == fake_tests_init) { continue; } if (group != NULL) { split = eg_strsplit(group, ":", -1); if (split != NULL) { gint m; for (m = 0; split[m] != NULL; m++) { if (m == 1) { tests = strdup(split[m]); break; } } eg_strfreev(split); } } passed = run_group(&(test_groups[j]), iterations, quiet, report_time, tests); if (tests != NULL) { g_free(tests); } if (!passed && !global_failure) { global_failure = TRUE; } } } if (!quiet) { gdouble pass_percentage = ((gdouble)global_passed / (gdouble)global_tests) * 100.0; printf("=============================\n"); printf("Overall result: %s : %d / %d (%g%%)\n", global_failure ? "FAILED" : "OK", global_passed, global_tests, pass_percentage); } if (report_time) { gdouble duration = get_timestamp() - time_start; if (no_final_time_labels) { printf("%g\n", duration); } else { printf("%s Total Time: %g\n", DRIVER_NAME, duration); } } if (tests_to_run != NULL) { string_array_free(tests_to_run); } return global_tests - global_passed; }
gboolean run_group(Group *group, gint iterations, gboolean quiet, gboolean time, gchar *tests_to_run_s) { Test *tests = group->handler(); gint i, j, passed = 0, total = 0; gdouble start_time_group, start_time_test; gchar **tests_to_run = NULL; if(!quiet) { if(iterations > 1) { printf("[%s] (%dx)\n", group->name, iterations); } else { printf("[%s]\n", group->name); } } if(tests_to_run_s != NULL) { tests_to_run = eg_strsplit(tests_to_run_s, ",", -1); } start_time_group = get_timestamp(); for(i = 0; tests[i].name != NULL; i++) { gchar *result = ""; gboolean iter_pass, run; iter_pass = FALSE; if(tests_to_run != NULL) { gint j; run = FALSE; for(j = 0; tests_to_run[j] != NULL; j++) { if(strcmp(tests_to_run[j], tests[i].name) == 0) { run = TRUE; break; } } } else { run = TRUE; } if(!run) { continue; } total++; if(!quiet) { printf(" %s: ", tests[i].name); } start_time_test = get_timestamp(); for(j = 0; j < iterations; j++) { iter_pass = run_test(&(tests[i]), &result); if(!iter_pass) { break; } } if(iter_pass) { passed++; if(!quiet) { if(time) { printf("OK (%g)\n", get_timestamp() - start_time_test); } else { printf("OK\n"); } } } else { if(!quiet) { printf("FAILED (%s)\n", result); } if(last_result == result) { last_result = NULL; g_free(result); } } } global_passed += passed; global_tests += total; if(!quiet) { gdouble pass_percentage = ((gdouble)passed / (gdouble)total) * 100.0; if(time) { printf(" %d / %d (%g%%, %g)\n", passed, total, pass_percentage, get_timestamp() - start_time_group); } else { printf(" %d / %d (%g%%)\n", passed, total, pass_percentage); } } if(tests_to_run != NULL) { eg_strfreev(tests_to_run); } return passed == total; }