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 |
|
44 #include "fd.h" |
|
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 static int test_verbosity = 0; |
|
55 |
|
56 /* Standard includes */ |
|
57 #include <getopt.h> |
|
58 #include <time.h> |
|
59 #include <libgen.h> |
|
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); \ |
|
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 |
|
78 /* Define the standard check routines */ |
|
79 #define CHECK( _val, _assert ){ \ |
|
80 if (test_verbosity > 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. */ |
|
113 test_verbosity++; |
|
114 break; |
|
115 |
|
116 case 'q': /* Decrease verbosity then remove debug messages. */ |
|
117 test_verbosity--; |
|
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 } |
|
128 if (!no_timeout) |
|
129 alarm(TEST_TIMEOUT); |
|
130 } |
|
131 |
|
132 #endif /* _TESTS_H */ |