Mercurial > hg > freeDiameter
annotate freeDiameter/tests/tests.h @ 29:5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 28 Oct 2009 15:19:50 +0900 |
parents | c5c99c73c2bf |
children | 26685c67d387 |
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); \ | |
67 exit(FAIL); \ | |
68 } | |
69 | |
70 /* Define the macro to pass a test */ | |
71 #define PASSTEST( ){ \ | |
72 fprintf(stderr, "Test %s passed\n", __FILE__); \ | |
73 TRACE_DEBUG(INFO, "Test passed"); \ | |
74 exit(PASS); \ | |
75 } | |
76 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
77 static int test_verbo = 0; |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
78 static struct fd_config conf; |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
79 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
|
80 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
81 /* 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
|
82 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
|
83 |
0 | 84 /* Define the standard check routines */ |
85 #define CHECK( _val, _assert ){ \ | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
86 if (test_verbo > 0) { \ |
0 | 87 fprintf(stderr, \ |
88 "%s:%-4d: CHECK( " #_assert " == "\ | |
89 #_val " )\n", \ | |
90 __FILE__, \ | |
91 __LINE__); \ | |
92 }{ \ | |
93 __typeof__ (_val) __ret = (_assert); \ | |
94 if (__ret != (_val)) { \ | |
95 FAILTEST( "%s:%d: %s == %lx != %lx\n", \ | |
96 __FILE__, \ | |
97 __LINE__, \ | |
98 #_assert, \ | |
99 (unsigned long)__ret, \ | |
100 (unsigned long)(_val)); \ | |
101 }} \ | |
102 } | |
103 | |
104 /* Minimum inits */ | |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
105 #define INIT_FD() { \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
106 memset(fd_g_config, 0, sizeof(struct fd_config)); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
107 CHECK( 0, fd_lib_init() ); \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
108 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
|
109 (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
|
110 (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
|
111 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
|
112 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
|
113 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
|
114 parse_cmdline(argc, argv); \ |
0 | 115 } |
116 | |
117 static inline void parse_cmdline(int argc, char * argv[]) { | |
118 int c; | |
119 int no_timeout = 0; | |
120 while ((c = getopt (argc, argv, "dqn")) != -1) { | |
121 switch (c) { | |
122 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
|
123 test_verbo++; |
0 | 124 break; |
125 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
126 case 'q': /* Decrease verbosity. */ |
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
127 test_verbo--; |
0 | 128 break; |
129 | |
130 case 'n': /* Disable the timeout of the test. */ | |
131 no_timeout = 1; | |
132 break; | |
133 | |
134 default: /* bug: option not considered. */ | |
135 return; | |
136 } | |
137 } | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
138 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; |
0 | 139 if (!no_timeout) |
140 alarm(TEST_TIMEOUT); | |
141 } | |
142 | |
143 #endif /* _TESTS_H */ |