2 * Copyright (c) 2009 Mark Heily <mark@heily.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
26 static int __thread testnum = 1;
27 static int __thread error_flag = 1;
28 static char __thread * cur_test_id = NULL;
30 /* FIXME: not portable beyond linux */
32 error_handler(int signum)
37 /* FIXME: the symbols aren't printing */
38 printf("***** ERROR: Program received signal %d *****\n", signum);
39 backtrace_symbols_fd(buf, sizeof(buf) / sizeof(void *), 2);
41 printf("***** ERROR: Program received signal %d *****\n", signum);
50 printf(" *** TEST FAILED: %s\n", cur_test_id);
51 //TODO: print detailed log
54 "+OK All %d tests completed.\n", testnum - 1);
59 test_begin(const char *func)
63 cur_test_id = strdup(func);
65 printf("%d: %s\n", testnum++, cur_test_id);
66 //TODO: redirect stdout/err to logfile
81 atexit(testing_atexit);
83 /* Install a signal handler for crashes and hangs */
84 memset(&sa, 0, sizeof(sa));
85 sa.sa_handler = error_handler;
86 sigemptyset(&sa.sa_mask);
87 sigaction(SIGSEGV, &sa, NULL);
88 sigaction(SIGABRT, &sa, NULL);
89 sigaction(SIGINT, &sa, NULL);
98 /* Generate a unique ID */
100 testing_make_uid(void)
102 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
105 pthread_mutex_lock(&mtx);
109 pthread_mutex_unlock(&mtx);