2 * EGLib Unit Test Driver
5 * Aaron Bockover (abockover@novell.com)
7 * (C) 2006 Novell, Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 static void print_help(char *s)
42 printf("Usage: %s [options] [test1 test2 ... testN]\n\n", s);
43 printf(" options are:\n");
44 printf(" --help|-h show this help\n");
45 printf(" --time|-t time the tests\n");
46 printf(" --iterations|-i number of times to run tests\n");
47 printf(" --quiet|-q do not print test results; if -t\n");
48 printf(" is passed, the time will print\n\n");
49 printf(" test1..testN name of test to run (all run by default)\n\n");
50 printf(" available tests:\n");
52 for(i = 0; test_groups[i].name != NULL; i++) {
53 printf(" %s\n", test_groups[i].name);
59 gint main(gint argc, gchar **argv)
61 gint i, j, c, iterations = 1;
62 GList *tests_to_run = NULL;
63 double time_start, time_end;
65 gboolean report_time = FALSE;
66 gboolean quiet = FALSE;
68 static struct option long_options [] = {
69 {"help", no_argument, 0, 'h'},
70 {"time", no_argument, 0, 't'},
71 {"iterations", required_argument, 0, 'i'},
75 while((c = getopt_long(argc, argv, "htqi:", long_options, NULL)) != -1) { switch(c) {
83 iterations = atoi(optarg);
91 for(i = optind; i < argc; i++) {
92 if(argv[i][0] == '-') {
96 tests_to_run = g_list_append(tests_to_run, argv[i]);
99 gettimeofday(&tp, NULL);
100 time_start = (double)tp.tv_sec + (1.e-6) * tp.tv_usec;
102 for(i = 0; i < iterations; i++) {
103 for(j = 0; test_groups[j].name != NULL; j++) {
106 if(tests_to_run != NULL) {
109 for(k = 0, n = g_list_length(tests_to_run); k < n; k++) {
110 if(strcmp((char *)g_list_nth_data(tests_to_run, k),
111 test_groups[j].name) == 0) {
120 run_group(&(test_groups[j]), &total, &passed, quiet);
122 printf(" -- %d / %d (%g%%) --\n", passed, total,
123 ((gdouble)passed / (gdouble)total) * 100.0);
129 gettimeofday(&tp, NULL);
130 time_end = (double)tp.tv_sec + (1.e-6) * tp.tv_usec;
133 gdouble duration = time_end - time_start;
134 printf("Total Time: %gs\n", duration);
137 if(tests_to_run != NULL) {
138 g_list_free(tests_to_run);