File: test_common.h

package info (click to toggle)
adios 1.13.1-31
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,692 kB
  • sloc: ansic: 133,236; f90: 8,791; sh: 7,779; python: 7,648; xml: 3,793; makefile: 2,996; cpp: 2,340; java: 626; sed: 16; perl: 8
file content (276 lines) | stat: -rw-r--r-- 9,756 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/**
 * @file: test_common.h
 * @author: Magda Slawinska, aka Magic Magg, magg dot gatech at gmail dot com
 * @date: Dec 19, 2012
 * Modified: Jan 03, 2013
 * The utility macros
 */

#ifndef TEST_COMMON_H_
#define TEST_COMMON_H_

#include <stdio.h>
#include <stdlib.h>


#define DBG_TEST_FAILED_STR		"TEST_FAILED"
#define DBG_TEST_PASSED_STR		"TEST_PASSED"

#define DEBUG

//! Debug printing verbosity
#define DBG_LEVEL   DBG_MESSAGE

// New debug messaging state. There is no sense of a "level" for debugging. Each of these define the
// purpose of the messages and is enabled/disabled per file

//! system cannot continue, e.g. malloc
#define DBG_ERROR   0
//!
#define DBG_CRITICAL 1
//! some serious problems
#define DBG_WARNING 2
#define DBG_MESSAGE 3
//! messages about state or configuration; high-level flow
#define DBG_INFO    4
//!  func args, variable values, etc; full flow, may slow system down
#define DBG_DEBUG   5

#define DBG_ERROR_STR 		"ERROR\t"
#define DBG_CRITICAL_STR 	"CRITICAL\t"
#define DBG_WARNING_STR 	"WARNING\t"
#define DBG_MESSAGE_STR 	"MESSAGE\t"
#define DBG_INFO_STR		"INFO\t"
#define DBG_DEBUG_STR		"DEBUG\t"
#define DBG_TODO_STR		"TODO\t"

#define p_test_failed(fmt, args...)                             \
    do {                                                  \
	 fprintf(stderr, "%s "fmt, DBG_TEST_FAILED_STR,  ##args);	\
         fflush(stdout);  											\
    } while(0)

#define p_test_passed(fmt, args...)                             \
    do {if(test_verbose){					   \
         fprintf(stderr, "%s "fmt, DBG_TEST_PASSED_STR,  ##args);  \
         fflush(stdout);  											\
	}} while(0)

#define test_failed(prog_name, rank)                             \
    do {                                                  \
	 fprintf(stdout, "%s\t\tProgram name: %s\tRank: %d\n", DBG_TEST_FAILED_STR, prog_name, rank);	\
         fflush(stdout);  											\
    } while(0)

#define test_passed(prog_name, rank)                             \
    do {                                                  \
         fprintf(stdout, "%s\t\tProgram name: %s\tRank: %d\n", DBG_TEST_PASSED_STR, prog_name, rank);  \
         fflush(stdout);  											\
    } while(0)





//! @todo do something like that but smarter without unnecessary copying
#define p_error(fmt, args...)                             				\
    do {                                                                \
        if((DBG_ERROR) <= DBG_LEVEL) {                                  \
            fprintf(stderr, "%s(%d) %s:%s:%d: " fmt, DBG_ERROR_STR, (DBG_ERROR), __FILE__, __FUNCTION__, __LINE__, ##args);   \
            fflush(stdout);  											\
        }                                                               \
    } while(0)


#define p_warn(fmt, args...) \
	do {                                                                \
        if((DBG_WARNING) <= DBG_LEVEL) {                                      \
        	fprintf(stderr, "%s(%d) %s:%s:%d: " fmt, DBG_WARN_STR, (DBG_ERROR), __FILE__, __FUNCTION__, __LINE__, ##args);   \
            fflush(stdout);												\
        }                                                               \
    } while(0)

#define p_info(fmt, args...) \
	do {                                                                \
        if((DBG_INFO) <= DBG_LEVEL) {                                      \
        	fprintf(stderr, "%s(%d) %s:%s:%d: " fmt, DBG_INFO_STR, (DBG_ERROR), __FILE__, __FUNCTION__, __LINE__, ##args);   \
            fflush(stdout);												\
        }                                                               \
    } while(0)

#define p_debug(fmt, args...) \
	do {                                                                \
        if((DBG_DEBUG) <= DBG_LEVEL) {                                      \
        	fprintf(stderr, "%s(%d) %s:%s:%d: " fmt, DBG_DEBUG_STR, (DBG_ERROR), __FILE__, __FUNCTION__, __LINE__, ##args);   \
            fflush(stdout);												\
        }                                                               \
    } while(0)


// ------------------------------------
// define some useful macro idioms
// ADIOS UTILS
#define CLOSE_ADIOS_READER(handle, method) \
	adios_read_close(handle); 		 						\
	adios_read_finalize_method(method);						\
	MPI_Finalize();

/**
 * The macro gets the options from the command line
 * It assumes presence and visibility of a few variables such as argc, argv
 *
 * @param adios_opts The structure where adios related command line options will be stored
 *
 * The macro causes to return DIAG_ERR if getting options returned errors
 */
static int test_verbose = 0;

#define GET_ENTRY_OPTIONS(adios_opts, help_string)	\
	if (1 == argc){ \
		p_error("See '-h' for options. At least transport param needs to be specified. Quitting ...\n"); \
		return DIAG_ERR; \
	} \
	do { \
		int show_help = 0; \
		if( DIAG_OK != get_options(&adios_opts, argc, argv, &show_help, &test_verbose) ){ \
			p_error("Got from get_options(). Quitting ...\n."); \
			return DIAG_ERR; \
		} \
		if (show_help){ \
			usage(argv[0], help_string); \
			return DIAG_OK; \
		} \
	} while(0)

/**
 * checks if the adios call returned not zero and sets the error
 * if yes. Sets the error means increasing err_count++
 * @param fn_call adios function call
 * @param (in/out) err_count incremented if the error observed
 */
#define SET_ERROR_IF_NOT_ZERO(fn_call, err_count)             \
	do { \
		int _error_code = fn_call;                                         \
		if (_error_code != 0){                                             \
			p_error("rank %d %s (%d) %s\n", rank, #fn_call, adios_errno, adios_errmsg()) ;\
			err_count++;                                                   \
		} \
	} while(0)
/**
 * checks if the adios call returned not zero
 * err_count++
 * @param fn_call adios function call
 * @param (in/out) err_count incremented if the error observed
 */
#define SET_ERROR_IF_ZERO(fn_call, err_count)             \
	do { \
		int _error_code = fn_call;                                         \
		if (_error_code == 0){                                             \
			p_error("rank %d: %s: (%d) %s\n", rank, #fn_call, adios_errno, adios_errmsg()) ;\
			err_count++;                                                   \
		} \
	} while(0)
/**
 * prints the info; closes adios and returns the error code
 * if the err_count is set to a positive number
 *
 * @param err_count The variable that positive value indicates that there is an error
 */
#define RET_IF_ERROR(err_count, rank) \
	if ( err_count > 0) { \
		p_info("Rank %d: Quitting ...\n", rank); \
		return DIAG_ERR;                     \
	}

/**
 * prints the info; closes adios and returns the error code
 * if the err_count is set to a positive number
 *
 * @param err_count The variable that positive value indicates that there is an error
 * @param rank the rank that closes the adios
 * @param handle adios handle to close ADIOS
 * @param method what method to close
 */
#define RET_AND_CLOSE_ADIOS_READER_IF_ERROR(err_count, rank, handle, method) \
	if ( err_count > 0) { \
		p_error("rank %d: Quitting ...\n", rank); \
		CLOSE_ADIOS_READER(handle, method);                              \
		return DIAG_ERR;                     \
	}

/**
 * prints the info; closes adios and returns the error code
 * if the err_count is set to a positive number
 *
 * @param test_res the test result
 * @param rank the rank that closes the adios
 * @param handle adios handle to close ADIOS
 * @param method what method to close
 */
#define RET_AND_CLOSE_ADIOS_READER_IF_TEST_FAILED(test_res, rank, handle, method) \
	if ( TEST_FAILED == test_res.result ) { \
		p_test_failed("%s: rank %d\n", test_res.name, rank); \
		CLOSE_ADIOS_READER(handle, method);                 \
		return DIAG_ERR;                                    \
	}
/**
 * breaks the loop if error count is positive
 *
 * @param err_count The variable that positive value indicates that ther is an error
 */
#define BREAK_IF_ERROR(err_count) \
	if ( err_count > 0) { \
		break; \
	}



// -------------------------------
// test macros
// -------------------------------
/**
 * assumes that err_count is defined
 * @param value_ref The reference value
 * @param value     The actual value
 * @param err_count The value of the error counter; if the error increases
 *                  the value will be increased
 * @param test_res  The result of the test
 */
#define TEST_INT_EQUAL(value_ref, value, err_count, test_res) \
	if (value != value_ref ){ \
		test_res = TEST_FAILED; \
		p_test_failed("("#value_ref" != "#value"  -> expected=%d, got=%d)\n", value_ref, value); \
		err_count++; \
	}

/**
 * assumes that err_count is defined
 * @param value_ref The reference value
 * @param value     The actual value
 * @param err_count The value of the error counter; if the error increases
 *                  the value will be increased
 * @param test_res  The result of the test
 */
#define TEST_LONG_EQUAL(value_ref, value, err_count, test_res) \
	if (value != value_ref ){ \
		test_res = TEST_FAILED; \
		p_test_failed("("#value_ref" != "#value"  -> expected=%" PRIu64 ", got=%" PRIu64 ")\n", value_ref, value); \
		err_count++; \
	}

/**
 * assumes that err_count is defined
 * @param value_ref The reference value
 * @param value     The actual value
 * @param err_count The value of the error counter; if the error increases
 *                  the value will be increased
 * @param test_res  The result of the test
 */
#define TEST_DOUBLE_EQUAL(value_ref, value, err_count, test_res) \
	if (value != value_ref ){ \
		test_res = TEST_FAILED; \
		p_test_failed("("#value_ref" != "#value"  -> expected=%g, got=%g)\n", value_ref, value); \
		err_count++; \
	}

#endif /* TEST_COMMON_H_ */