Mercurial > hg > freeDiameter
annotate freeDiameter/tests/tests.h @ 236:60f34df3e025
Remove dependency on signalent.h
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Mon, 08 Mar 2010 14:10:30 +0900 |
parents | 8773740401a5 |
children | 5df55136361b |
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> | |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
59 #include <signal.h> |
0 | 60 |
61 /* Define the return code values */ | |
62 #define PASS 0 | |
63 #define FAIL 1 | |
64 | |
65 /* Define the macro to fail a test with a message */ | |
66 #define FAILTEST( message... ){ \ | |
67 fprintf(stderr, ## message); \ | |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
68 TRACE_DEBUG(INFO, "Test failed"); \ |
0 | 69 exit(FAIL); \ |
70 } | |
71 | |
72 /* Define the macro to pass a test */ | |
73 #define PASSTEST( ){ \ | |
74 fprintf(stderr, "Test %s passed\n", __FILE__); \ | |
75 TRACE_DEBUG(INFO, "Test passed"); \ | |
76 exit(PASS); \ | |
77 } | |
78 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
79 static int test_verbo = 0; |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
80 static struct fd_config conf; |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
3
diff
changeset
|
81 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
|
82 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
83 /* 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
|
84 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
|
85 |
0 | 86 /* Define the standard check routines */ |
87 #define CHECK( _val, _assert ){ \ | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
88 if (test_verbo > 0) { \ |
0 | 89 fprintf(stderr, \ |
90 "%s:%-4d: CHECK( " #_assert " == "\ | |
91 #_val " )\n", \ | |
92 __FILE__, \ | |
93 __LINE__); \ | |
94 }{ \ | |
95 __typeof__ (_val) __ret = (_assert); \ | |
96 if (__ret != (_val)) { \ | |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
97 FAILTEST( "%s:%d: CHECK FAILED : %s == %lx != %lx\n", \ |
0 | 98 __FILE__, \ |
99 __LINE__, \ | |
100 #_assert, \ | |
101 (unsigned long)__ret, \ | |
102 (unsigned long)(_val)); \ | |
103 }} \ | |
104 } | |
105 | |
106 /* Minimum inits */ | |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
107 #define INIT_FD() { \ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
10
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 (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
|
112 (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
|
113 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
|
114 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
|
115 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
|
116 parse_cmdline(argc, argv); \ |
0 | 117 } |
118 | |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
119 static void test_timeout(int signal) |
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
120 { |
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
121 FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute."); |
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
122 } |
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
123 |
0 | 124 static inline void parse_cmdline(int argc, char * argv[]) { |
125 int c; | |
126 int no_timeout = 0; | |
127 while ((c = getopt (argc, argv, "dqn")) != -1) { | |
128 switch (c) { | |
129 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
|
130 test_verbo++; |
0 | 131 break; |
132 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
133 case 'q': /* Decrease verbosity. */ |
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
134 test_verbo--; |
0 | 135 break; |
136 | |
137 case 'n': /* Disable the timeout of the test. */ | |
138 no_timeout = 1; | |
139 break; | |
140 | |
141 default: /* bug: option not considered. */ | |
142 return; | |
143 } | |
144 } | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
145 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
|
146 if (!no_timeout) { |
0 | 147 alarm(TEST_TIMEOUT); |
236
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
148 fd_sig_register(SIGALRM, "Test.harness", test_timeout); |
60f34df3e025
Remove dependency on signalent.h
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
235
diff
changeset
|
149 } |
0 | 150 } |
151 | |
152 #endif /* _TESTS_H */ |