Mercurial > hg > freeDiameter
annotate freeDiameter/tests/tests.h @ 235:8773740401a5
Centralized signal handlers management in the library
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Fri, 05 Mar 2010 19:01:48 +0900 |
parents | 26685c67d387 |
children | 60f34df3e025 |
rev | line source |
---|---|
0 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * | |
4 * * | |
5 * Copyright (c) 2009, WIDE Project and NICT * | |
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 | |
1
bafb831ba688
Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
0
diff
changeset
|
44 #include "fD.h" |
0 | 45 |
46 #include <pthread.h> | |
47 #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
|
48 #include <gcrypt.h> |
0 | 49 |
50 /* Test timeout duration, unless -n is passed on the command line */ | |
51 #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
|
52 #define TEST_TIMEOUT 30 /* in seconds */ |
0 | 53 #endif /* TEST_TIMEOUT */ |
54 | |
55 /* Standard includes */ | |
56 #include <getopt.h> | |
57 #include <time.h> | |
58 #include <libgen.h> | |
59 | |
60 /* Define the return code values */ | |
61 #define PASS 0 | |
62 #define FAIL 1 | |
63 | |
64 /* Define the macro to fail a test with a message */ | |
65 #define FAILTEST( message... ){ \ | |
66 fprintf(stderr, ## message); \ | |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
67 TRACE_DEBUG(INFO, "Test failed"); \ |
0 | 68 exit(FAIL); \ |
69 } | |
70 | |
71 /* Define the macro to pass a test */ | |
72 #define PASSTEST( ){ \ | |
73 fprintf(stderr, "Test %s passed\n", __FILE__); \ | |
74 TRACE_DEBUG(INFO, "Test passed"); \ | |
75 exit(PASS); \ | |
76 } | |
77 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
78 static int test_verbo = 0; |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
79 static struct fd_config conf; |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
80 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
|
81 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
82 /* gcrypt functions to support posix threads */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
83 GCRY_THREAD_OPTION_PTHREAD_IMPL; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
84 |
0 | 85 /* Define the standard check routines */ |
86 #define CHECK( _val, _assert ){ \ | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
87 if (test_verbo > 0) { \ |
0 | 88 fprintf(stderr, \ |
89 "%s:%-4d: CHECK( " #_assert " == "\ | |
90 #_val " )\n", \ | |
91 __FILE__, \ | |
92 __LINE__); \ | |
93 }{ \ | |
94 __typeof__ (_val) __ret = (_assert); \ | |
95 if (__ret != (_val)) { \ | |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
96 FAILTEST( "%s:%d: CHECK FAILED : %s == %lx != %lx\n", \ |
0 | 97 __FILE__, \ |
98 __LINE__, \ | |
99 #_assert, \ | |
100 (unsigned long)__ret, \ | |
101 (unsigned long)(_val)); \ | |
102 }} \ | |
103 } | |
104 | |
105 /* Minimum inits */ | |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
106 #define INIT_FD() { \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
107 memset(fd_g_config, 0, sizeof(struct fd_config)); \ |
235
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
31
diff
changeset
|
108 CHECK( 0, fd_lib_init(1) ); \ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
109 fd_log_threadname(basename(__FILE__)); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
110 (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
111 (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
112 CHECK( 0, gnutls_global_init()); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
113 CHECK( 0, fd_conf_init() ); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
114 CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) ); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
115 parse_cmdline(argc, argv); \ |
0 | 116 } |
117 | |
118 static inline void parse_cmdline(int argc, char * argv[]) { | |
119 int c; | |
120 int no_timeout = 0; | |
121 while ((c = getopt (argc, argv, "dqn")) != -1) { | |
122 switch (c) { | |
123 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
|
124 test_verbo++; |
0 | 125 break; |
126 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
127 case 'q': /* Decrease verbosity. */ |
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
128 test_verbo--; |
0 | 129 break; |
130 | |
131 case 'n': /* Disable the timeout of the test. */ | |
132 no_timeout = 1; | |
133 break; | |
134 | |
135 default: /* bug: option not considered. */ | |
136 return; | |
137 } | |
138 } | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
139 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; |
0 | 140 if (!no_timeout) |
141 alarm(TEST_TIMEOUT); | |
142 } | |
143 | |
144 #endif /* _TESTS_H */ |