2 * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
22 #include "testutils.h"
24 int tu_debugging_enabled = FALSE;
27 alarm_hdlr(int sig G_GNUC_UNUSED)
29 fprintf(stderr, "-- TEST TIMED OUT --\n");
33 /* Call testfn in a forked process, such that any failures will trigger a
34 * test failure, but allow the other tests to proceed.
37 callinfork(TestUtilsTest *test, int ignore_timeouts)
43 switch (pid = fork()) {
45 /* kill the test after a bit */
46 signal(SIGALRM, alarm_hdlr);
47 if (!ignore_timeouts) alarm(test->timeout);
57 waitpid(pid, &status, 0);
59 fprintf(stderr, " PASS %s\n", test->name);
61 fprintf(stderr, " FAIL %s\n", test->name);
71 printf("USAGE: <test-script> [-d] [-h] [testname [testname [..]]]\n"
73 "\t-h: this message\n"
74 "\t-d: print debugging messages\n"
75 "\t-t: ignore timeouts\n"
77 "If no test names are specified, all tests are run. Available tests:\n"
80 printf("\t%s\n", tests->name);
86 ignore_debug_messages(
87 const gchar *log_domain G_GNUC_UNUSED,
88 GLogLevelFlags log_level G_GNUC_UNUSED,
89 const gchar *message G_GNUC_UNUSED,
90 gpointer user_data G_GNUC_UNUSED)
103 int ignore_timeouts = 0;
105 /* first_parse the command line */
107 if (strcmp(argv[1], "-d") == 0) {
108 tu_debugging_enabled = TRUE;
109 } else if (strcmp(argv[1], "-t") == 0) {
110 ignore_timeouts = TRUE;
111 } else if (strcmp(argv[1], "-h") == 0) {
117 for (t = tests; t->fn; t++) {
118 if (strcmp(argv[1], t->name) == 0) {
126 fprintf(stderr, "Test '%s' not found\n", argv[1]);
136 /* Make sure g_critical and g_error will exit */
137 g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
139 /* and silently drop debug messages unless we're debugging */
140 if (!tu_debugging_enabled) {
141 g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, ignore_debug_messages, NULL);
144 /* Now actually run the tests */
146 for (t = tests; t->fn; t++) {
147 if (run_all || t->selected) {
148 success = callinfork(t, ignore_timeouts) && success;