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 | /* 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 | |
---|
76 | static int test_verbo = 0; |
---|
77 | static struct fd_config conf; |
---|
78 | struct fd_config * fd_g_config = &conf; |
---|
79 | |
---|
80 | /* Define the standard check routines */ |
---|
81 | #define CHECK( _val, _assert ){ \ |
---|
82 | if (test_verbo > 0) { \ |
---|
83 | fprintf(stderr, \ |
---|
84 | "%s:%-4d: CHECK( " #_assert " == "\ |
---|
85 | #_val " )\n", \ |
---|
86 | __FILE__, \ |
---|
87 | __LINE__); \ |
---|
88 | }{ \ |
---|
89 | __typeof__ (_val) __ret = (_assert); \ |
---|
90 | if (__ret != (_val)) { \ |
---|
91 | FAILTEST( "%s:%d: %s == %lx != %lx\n", \ |
---|
92 | __FILE__, \ |
---|
93 | __LINE__, \ |
---|
94 | #_assert, \ |
---|
95 | (unsigned long)__ret, \ |
---|
96 | (unsigned long)(_val)); \ |
---|
97 | }} \ |
---|
98 | } |
---|
99 | |
---|
100 | /* Minimum inits */ |
---|
101 | #define INIT_FD() { \ |
---|
102 | memset(fd_g_config, 0, sizeof(struct fd_config)); \ |
---|
103 | CHECK( 0, fd_lib_init() ); \ |
---|
104 | fd_log_threadname(basename(__FILE__)); \ |
---|
105 | CHECK( 0, fd_conf_init() ); \ |
---|
106 | CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) ); \ |
---|
107 | parse_cmdline(argc, argv); \ |
---|
108 | } |
---|
109 | |
---|
110 | static inline void parse_cmdline(int argc, char * argv[]) { |
---|
111 | int c; |
---|
112 | int no_timeout = 0; |
---|
113 | while ((c = getopt (argc, argv, "dqn")) != -1) { |
---|
114 | switch (c) { |
---|
115 | case 'd': /* Increase verbosity of debug messages. */ |
---|
116 | test_verbo++; |
---|
117 | break; |
---|
118 | |
---|
119 | case 'q': /* Decrease verbosity. */ |
---|
120 | test_verbo--; |
---|
121 | break; |
---|
122 | |
---|
123 | case 'n': /* Disable the timeout of the test. */ |
---|
124 | no_timeout = 1; |
---|
125 | break; |
---|
126 | |
---|
127 | default: /* bug: option not considered. */ |
---|
128 | return; |
---|
129 | } |
---|
130 | } |
---|
131 | fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; |
---|
132 | if (!no_timeout) |
---|
133 | alarm(TEST_TIMEOUT); |
---|
134 | } |
---|
135 | |
---|
136 | #endif /* _TESTS_H */ |
---|