Mercurial > hg > freeDiameter
annotate freeDiameter/tests/tests.h @ 2:d8ce06172629
Added a global debug level var
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Mon, 31 Aug 2009 17:32:22 +0900 |
parents | bafb831ba688 |
children | ef303f1078ab |
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> | |
48 | |
49 /* Test timeout duration, unless -n is passed on the command line */ | |
50 #ifndef TEST_TIMEOUT | |
51 #define TEST_TIMEOUT 5 /* 5 seconds */ | |
52 #endif /* TEST_TIMEOUT */ | |
53 | |
54 /* Standard includes */ | |
55 #include <getopt.h> | |
56 #include <time.h> | |
57 #include <libgen.h> | |
58 | |
59 /* Define the return code values */ | |
60 #define PASS 0 | |
61 #define FAIL 1 | |
62 | |
63 /* Define the macro to fail a test with a message */ | |
64 #define FAILTEST( message... ){ \ | |
65 fprintf(stderr, ## message); \ | |
66 exit(FAIL); \ | |
67 } | |
68 | |
69 /* Define the macro to pass a test */ | |
70 #define PASSTEST( ){ \ | |
71 fprintf(stderr, "Test %s passed\n", __FILE__); \ | |
72 TRACE_DEBUG(INFO, "Test passed"); \ | |
73 exit(PASS); \ | |
74 } | |
75 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
76 static int test_verbo = 0; |
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
77 |
0 | 78 /* Define the standard check routines */ |
79 #define CHECK( _val, _assert ){ \ | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
80 if (test_verbo > 0) { \ |
0 | 81 fprintf(stderr, \ |
82 "%s:%-4d: CHECK( " #_assert " == "\ | |
83 #_val " )\n", \ | |
84 __FILE__, \ | |
85 __LINE__); \ | |
86 }{ \ | |
87 __typeof__ (_val) __ret = (_assert); \ | |
88 if (__ret != (_val)) { \ | |
89 FAILTEST( "%s:%d: %s == %lx != %lx\n", \ | |
90 __FILE__, \ | |
91 __LINE__, \ | |
92 #_assert, \ | |
93 (unsigned long)__ret, \ | |
94 (unsigned long)(_val)); \ | |
95 }} \ | |
96 } | |
97 | |
98 /* Minimum inits */ | |
99 #define INIT_FD() { \ | |
100 pthread_key_create(&fd_log_thname, free); \ | |
101 fd_log_threadname(basename(__FILE__)); \ | |
102 CHECK( 0, fd_dict_init(&fd_g_dict) ); \ | |
103 CHECK( 0, fd_dict_base_protocol(fd_g_dict) ); \ | |
104 parse_cmdline(argc, argv); \ | |
105 } | |
106 | |
107 static inline void parse_cmdline(int argc, char * argv[]) { | |
108 int c; | |
109 int no_timeout = 0; | |
110 while ((c = getopt (argc, argv, "dqn")) != -1) { | |
111 switch (c) { | |
112 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
|
113 test_verbo++; |
0 | 114 break; |
115 | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
116 case 'q': /* Decrease verbosity. */ |
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
117 test_verbo--; |
0 | 118 break; |
119 | |
120 case 'n': /* Disable the timeout of the test. */ | |
121 no_timeout = 1; | |
122 break; | |
123 | |
124 default: /* bug: option not considered. */ | |
125 return; | |
126 } | |
127 } | |
2
d8ce06172629
Added a global debug level var
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
128 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; |
0 | 129 if (!no_timeout) |
130 alarm(TEST_TIMEOUT); | |
131 } | |
132 | |
133 #endif /* _TESTS_H */ |