Mercurial > hg > freeDiameter
annotate tests/tests.h @ 689:933d098fc75d
Cleanups in msg_log feature
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 20 Jan 2011 14:24:13 +0900 |
parents | 684f9e0e0c96 |
children | 16c373df0947 |
rev | line source |
---|---|
0 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * | |
4 * * | |
662
2e94ef0515d7
Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
658
diff
changeset
|
5 * Copyright (c) 2011, WIDE Project and NICT * |
0 | 6 * All rights reserved. * |
7 * * | |
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * | |
9 * permitted provided that the following conditions are met: * | |
10 * * | |
11 * * Redistributions of source code must retain the above * | |
12 * copyright notice, this list of conditions and the * | |
13 * following disclaimer. * | |
14 * * | |
15 * * Redistributions in binary form must reproduce the above * | |
16 * copyright notice, this list of conditions and the * | |
17 * following disclaimer in the documentation and/or other * | |
18 * materials provided with the distribution. * | |
19 * * | |
20 * * Neither the name of the WIDE Project or NICT nor the * | |
21 * names of its contributors may be used to endorse or * | |
22 * promote products derived from this software without * | |
23 * specific prior written permission of WIDE Project and * | |
24 * NICT. * | |
25 * * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * | |
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * | |
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * | |
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * | |
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * | |
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * | |
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * | |
34 *********************************************************************************************************/ | |
35 | |
36 /* This file contains the definition of our test harness. | |
37 * The harness is very simple yet. | |
38 * It may be interessant to go to dejagnu later... | |
39 * | |
40 */ | |
41 #ifndef _TESTS_H | |
42 #define _TESTS_H | |
43 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
44 #include "fdproto-internal.h" |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
45 #include "fdcore-internal.h" |
0 | 46 |
47 #include <pthread.h> | |
48 #include <errno.h> | |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
49 #include <gcrypt.h> |
0 | 50 |
51 /* Test timeout duration, unless -n is passed on the command line */ | |
52 #ifndef TEST_TIMEOUT | |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
53 #define TEST_TIMEOUT 30 /* in seconds */ |
0 | 54 #endif /* TEST_TIMEOUT */ |
55 | |
56 /* Standard includes */ | |
57 #include <getopt.h> | |
58 #include <time.h> | |
59 #include <libgen.h> | |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
60 #include <signal.h> |
0 | 61 |
62 /* Define the return code values */ | |
63 #define PASS 0 | |
64 #define FAIL 1 | |
65 | |
66 /* Define the macro to fail a test with a message */ | |
67 #define FAILTEST( message... ){ \ | |
68 fprintf(stderr, ## message); \ | |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
69 TRACE_DEBUG(INFO, "Test failed"); \ |
0 | 70 exit(FAIL); \ |
71 } | |
72 | |
73 /* Define the macro to pass a test */ | |
74 #define PASSTEST( ){ \ | |
75 fprintf(stderr, "Test %s passed\n", __FILE__); \ | |
76 TRACE_DEBUG(INFO, "Test passed"); \ | |
676
684f9e0e0c96
Clean termination of tests when possible
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
77 (void)fd_core_shutdown(); \ |
684f9e0e0c96
Clean termination of tests when possible
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
78 (void)fd_core_wait_shutdown_complete(); \ |
689
933d098fc75d
Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
676
diff
changeset
|
79 (void)fd_thr_term(&timeout_thr); \ |
0 | 80 exit(PASS); \ |
81 } | |
82 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
83 static int test_verbo = 0; |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
84 static struct fd_config conf; |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
85 struct fd_config * fd_g_config = &conf; |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
86 |
0 | 87 /* Define the standard check routines */ |
88 #define CHECK( _val, _assert ){ \ | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
89 if (test_verbo > 0) { \ |
0 | 90 fprintf(stderr, \ |
91 "%s:%-4d: CHECK( " #_assert " == "\ | |
92 #_val " )\n", \ | |
93 __FILE__, \ | |
94 __LINE__); \ | |
95 }{ \ | |
96 __typeof__ (_val) __ret = (_assert); \ | |
97 if (__ret != (_val)) { \ | |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
98 FAILTEST( "%s:%d: CHECK FAILED : %s == %lx != %lx\n", \ |
0 | 99 __FILE__, \ |
100 __LINE__, \ | |
101 #_assert, \ | |
102 (unsigned long)__ret, \ | |
103 (unsigned long)(_val)); \ | |
104 }} \ | |
105 } | |
106 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
107 static pthread_t timeout_thr; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
108 static void * timeout_catch(void * arg) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
109 { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
110 int sig; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
111 sigset_t ss; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
112 fd_log_threadname ( "timeout catcher" ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
113 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
114 sigemptyset(&ss); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
115 sigaddset(&ss, SIGALRM); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
116 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
117 CHECK_POSIX_DO( sigwait(&ss, &sig), ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
118 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
119 FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute."); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
120 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
121 return NULL; |
0 | 122 } |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
123 |
0 | 124 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
125 GCRY_THREAD_OPTION_PTHREAD_IMPL; |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
126 |
0 | 127 static inline void parse_cmdline(int argc, char * argv[]) { |
128 int c; | |
129 int no_timeout = 0; | |
480
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
130 while ((c = getopt (argc, argv, "dqnf:F:")) != -1) { |
0 | 131 switch (c) { |
132 case 'd': /* Increase verbosity of debug messages. */ | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
133 test_verbo++; |
0 | 134 break; |
135 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
136 case 'q': /* Decrease verbosity. */ |
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
137 test_verbo--; |
0 | 138 break; |
139 | |
140 case 'n': /* Disable the timeout of the test. */ | |
141 no_timeout = 1; | |
142 break; | |
143 | |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
144 case 'f': /* Full debug for the function with this name. */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
145 #ifdef DEBUG |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
146 fd_debug_one_function = optarg; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
147 #else /* DEBUG */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
148 TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature"); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
149 #endif /* DEBUG */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
150 break; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
151 |
480
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
152 case 'F': /* Full debug for the functions in file with this name. */ |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
153 #ifdef DEBUG |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
154 fd_debug_one_file = optarg; |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
155 #else /* DEBUG */ |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
156 TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature"); |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
157 #endif /* DEBUG */ |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
158 break; |
907b00ae3679
Allow file-based debug in tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
462
diff
changeset
|
159 |
0 | 160 default: /* bug: option not considered. */ |
161 return; | |
162 } | |
163 } | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
164 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
165 if (!no_timeout) { |
0 | 166 alarm(TEST_TIMEOUT); |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
167 CHECK( 0, pthread_create(&timeout_thr, NULL, timeout_catch, NULL) ); |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
168 } |
0 | 169 } |
170 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
171 static inline void test_init(int argc, char * argv[]) |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
172 { |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
173 memset(fd_g_config, 0, sizeof(struct fd_config)); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
174 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
175 CHECK( 0, fd_libproto_init() ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
176 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
177 fd_log_threadname(basename(__FILE__)); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
178 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
179 /* Initialize gcrypt and gnutls */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
180 (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
181 (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
182 CHECK( 0, gnutls_global_init()); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
183 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
184 /* Initialize the config */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
185 CHECK( 0, fd_conf_init() ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
186 |
689
933d098fc75d
Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
676
diff
changeset
|
187 /* Initialize the message logging facility */ |
933d098fc75d
Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
676
diff
changeset
|
188 fd_msg_log_init(fd_g_config->cnf_dict); |
933d098fc75d
Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
676
diff
changeset
|
189 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
190 /* Add definitions of the base protocol */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
191 CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
192 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
193 /* Initialize only the sessions */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
194 CHECK( 0, fd_sess_start() ); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
195 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
196 /* Parse the command line */ |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
197 parse_cmdline(argc, argv); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
198 |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
199 return; |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
200 } |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
201 #define INIT_FD() test_init(argc, argv); |
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
481
diff
changeset
|
202 |
0 | 203 #endif /* _TESTS_H */ |