Mercurial > hg > freeDiameter
comparison 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 |
comparison
equal
deleted
inserted
replaced
728:6169b4c5b256 | 729:5d8ac5da7092 |
---|---|
74 #define PASSTEST( ){ \ | 74 #define PASSTEST( ){ \ |
75 fprintf(stderr, "Test %s passed\n", __FILE__); \ | 75 fprintf(stderr, "Test %s passed\n", __FILE__); \ |
76 TRACE_DEBUG(INFO, "Test passed"); \ | 76 TRACE_DEBUG(INFO, "Test passed"); \ |
77 (void)fd_core_shutdown(); \ | 77 (void)fd_core_shutdown(); \ |
78 (void)fd_core_wait_shutdown_complete(); \ | 78 (void)fd_core_wait_shutdown_complete(); \ |
79 (void)fd_thr_term(&timeout_thr); \ | 79 (void)fd_thr_term(&signal_thr); \ |
80 exit(PASS); \ | 80 exit(PASS); \ |
81 } | 81 } |
82 | 82 |
83 static int test_verbo = 0; | 83 static int test_verbo = 0; |
84 static struct fd_config conf; | 84 static struct fd_config conf; |
102 (unsigned long)__ret, \ | 102 (unsigned long)__ret, \ |
103 (unsigned long)(_val)); \ | 103 (unsigned long)(_val)); \ |
104 }} \ | 104 }} \ |
105 } | 105 } |
106 | 106 |
107 static pthread_t timeout_thr; | 107 static pthread_t signal_thr; |
108 static void * timeout_catch(void * arg) | 108 static void * signal_catch(void * arg) |
109 { | 109 { |
110 int sig; | 110 int sig; |
111 sigset_t ss; | 111 sigset_t ss; |
112 fd_log_threadname ( "Test alarm catcher" ); | 112 fd_log_threadname ( "Signal catcher" ); |
113 | 113 |
114 sigemptyset(&ss); | 114 sigemptyset(&ss); |
115 | |
116 /* We use SIGALRM */ | |
115 sigaddset(&ss, SIGALRM); | 117 sigaddset(&ss, SIGALRM); |
116 | 118 |
119 /* Unblock any other signal for this thread, so that default handler is enabled */ | |
120 CHECK_SYS_DO( pthread_sigmask( SIG_SETMASK, &ss, NULL ), ); | |
121 | |
122 /* Now wait for sigwait or cancelation */ | |
117 CHECK_POSIX_DO( sigwait(&ss, &sig), ); | 123 CHECK_POSIX_DO( sigwait(&ss, &sig), ); |
118 | |
119 FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute."); | 124 FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute."); |
120 | 125 |
121 return NULL; | 126 return NULL; |
122 } | 127 } |
123 | 128 |
162 } | 167 } |
163 } | 168 } |
164 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; | 169 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; |
165 if (!no_timeout) { | 170 if (!no_timeout) { |
166 alarm(TEST_TIMEOUT); | 171 alarm(TEST_TIMEOUT); |
167 CHECK( 0, pthread_create(&timeout_thr, NULL, timeout_catch, NULL) ); | |
168 } | 172 } |
173 CHECK( 0, pthread_create(&signal_thr, NULL, signal_catch, NULL) ); | |
169 } | 174 } |
170 | 175 |
171 static inline void test_init(int argc, char * argv[], char *fname) | 176 static inline void test_init(int argc, char * argv[], char *fname) |
172 { | 177 { |
178 sigset_t sig_all; | |
179 sigfillset(&sig_all); | |
180 | |
181 CHECK( 0, pthread_sigmask(SIG_BLOCK, &sig_all, NULL)); | |
182 | |
173 memset(fd_g_config, 0, sizeof(struct fd_config)); | 183 memset(fd_g_config, 0, sizeof(struct fd_config)); |
174 | 184 |
175 CHECK( 0, fd_libproto_init() ); | 185 CHECK( 0, fd_libproto_init() ); |
176 | 186 |
177 fd_log_threadname(basename(fname)); | 187 fd_log_threadname(basename(fname)); |
188 | |
189 /* Parse the command line */ | |
190 parse_cmdline(argc, argv); | |
178 | 191 |
179 /* Initialize gcrypt and gnutls */ | 192 /* Initialize gcrypt and gnutls */ |
180 (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); | 193 (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); |
181 (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); | 194 (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); |
182 CHECK( 0, gnutls_global_init()); | 195 CHECK( 0, gnutls_global_init()); |
191 CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) ); | 204 CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) ); |
192 | 205 |
193 /* Initialize only the sessions */ | 206 /* Initialize only the sessions */ |
194 CHECK( 0, fd_sess_start() ); | 207 CHECK( 0, fd_sess_start() ); |
195 | 208 |
196 /* Parse the command line */ | |
197 parse_cmdline(argc, argv); | |
198 | |
199 return; | 209 return; |
200 } | 210 } |
201 #define INIT_FD() test_init(argc, argv, __FILE__); | 211 #define INIT_FD() test_init(argc, argv, __FILE__); |
202 | 212 |
203 #endif /* _TESTS_H */ | 213 #endif /* _TESTS_H */ |