Mercurial > hg > freeDiameter
diff tests/tests.h @ 729:5d8ac5da7092
Fixed timeout handling + minor fixes
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 24 Feb 2011 17:19:14 +0900 |
parents | 712a0bb8d3bf |
children | ef199d6185df |
line wrap: on
line diff
--- a/tests/tests.h Thu Feb 24 10:48:05 2011 +0900 +++ b/tests/tests.h Thu Feb 24 17:19:14 2011 +0900 @@ -76,7 +76,7 @@ TRACE_DEBUG(INFO, "Test passed"); \ (void)fd_core_shutdown(); \ (void)fd_core_wait_shutdown_complete(); \ - (void)fd_thr_term(&timeout_thr); \ + (void)fd_thr_term(&signal_thr); \ exit(PASS); \ } @@ -104,18 +104,23 @@ }} \ } -static pthread_t timeout_thr; -static void * timeout_catch(void * arg) +static pthread_t signal_thr; +static void * signal_catch(void * arg) { int sig; sigset_t ss; - fd_log_threadname ( "Test alarm catcher" ); + fd_log_threadname ( "Signal catcher" ); sigemptyset(&ss); + + /* We use SIGALRM */ sigaddset(&ss, SIGALRM); + /* Unblock any other signal for this thread, so that default handler is enabled */ + CHECK_SYS_DO( pthread_sigmask( SIG_SETMASK, &ss, NULL ), ); + + /* Now wait for sigwait or cancelation */ CHECK_POSIX_DO( sigwait(&ss, &sig), ); - FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute."); return NULL; @@ -164,18 +169,26 @@ fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; if (!no_timeout) { alarm(TEST_TIMEOUT); - CHECK( 0, pthread_create(&timeout_thr, NULL, timeout_catch, NULL) ); } + CHECK( 0, pthread_create(&signal_thr, NULL, signal_catch, NULL) ); } static inline void test_init(int argc, char * argv[], char *fname) { + sigset_t sig_all; + sigfillset(&sig_all); + + CHECK( 0, pthread_sigmask(SIG_BLOCK, &sig_all, NULL)); + memset(fd_g_config, 0, sizeof(struct fd_config)); CHECK( 0, fd_libproto_init() ); fd_log_threadname(basename(fname)); + /* Parse the command line */ + parse_cmdline(argc, argv); + /* Initialize gcrypt and gnutls */ (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); @@ -193,9 +206,6 @@ /* Initialize only the sessions */ CHECK( 0, fd_sess_start() ); - /* Parse the command line */ - parse_cmdline(argc, argv); - return; } #define INIT_FD() test_init(argc, argv, __FILE__);