aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_common_logging_runtime_loglevels.c
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-09-26 19:14:36 +0000
committerLRN <lrn1986@gmail.com>2013-09-26 19:14:36 +0000
commit5c9ee2e735fdd8923202b6cda23bbe5770abdcfd (patch)
tree5424d7a1c333517afef1b9fa00423fd463a62c90 /src/util/test_common_logging_runtime_loglevels.c
parentd642961c42f5f498408cca6cca3e81022b4e0dc7 (diff)
downloadgnunet-5c9ee2e735fdd8923202b6cda23bbe5770abdcfd.tar.gz
gnunet-5c9ee2e735fdd8923202b6cda23bbe5770abdcfd.zip
More comments to make the testcase easier to understand later.
Increase code verbosity to make it obvious what is being tested.
Diffstat (limited to 'src/util/test_common_logging_runtime_loglevels.c')
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c134
1 files changed, 98 insertions, 36 deletions
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 28535739d..8edf95194 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -32,6 +32,18 @@
32 32
33#define VERBOSE GNUNET_NO 33#define VERBOSE GNUNET_NO
34 34
35/**
36 * How much time the child is allowed to waste on skipped log calls, at most.
37 * Raspberry Pi takes 33 microseconds tops, this is 3x that value.
38 */
39#define MAX_SKIP_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 100).rel_value_us
40
41/**
42 * How much time non-skipped log call should take, at least.
43 * Keep in sync with the value in the dummy!
44 */
45#define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 200).rel_value_us
46
35static int ok; 47static int ok;
36 48
37static int phase = 0; 49static int phase = 0;
@@ -95,6 +107,10 @@ read_output_line (int phase_from1, int phase_to1, int phase_from2,
95 char *r = p; 107 char *r = p;
96 char t[7]; 108 char t[7];
97 int i, j, stop = 0; 109 int i, j, stop = 0;
110 int level_matches;
111 int delay_is_sane;
112 int delay_is_a_dummy;
113 int delay_outside_of_range;
98 114
99 j = 0; 115 j = 0;
100 int stage = 0; 116 int stage = 0;
@@ -157,15 +173,45 @@ read_output_line (int phase_from1, int phase_to1, int phase_from2,
157 break; 173 break;
158 } 174 }
159 } 175 }
160 if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 1000000 176 level_matches = (strcmp (expect_level, level) == 0);
161 || (!((*delay < delay_lessthan) || (*delay > delay_morethan)) && c != '1' 177 delay_is_sane = (*delay >= 0) && (*delay <= 1000000);
162 && c != '2')) 178 delay_is_a_dummy = (c == 'L');
179 /* Delay must be either less than 'lessthan' (log call is skipped)
180 * or more than 'morethan' (log call is not skipped)
181 */
182 delay_outside_of_range = ((*delay < delay_lessthan) || (*delay > delay_morethan));
183 if (delay_is_a_dummy)
184 delay_outside_of_range = 1;
185
186 if (!stop)
187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong log format?\n");
188 if (!level_matches)
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong log level\n");
190 if (!delay_is_sane)
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay %ld is insane\n", *delay);
192 if (!delay_outside_of_range)
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Delay %ld is not outside of range (%ld ; %ld)\n",
195 *delay, delay_lessthan, delay_morethan, c);
196 if (!stop || !level_matches || !delay_is_sane || !delay_outside_of_range)
163 return NULL; 197 return NULL;
164 *len = *len - i; 198 *len = *len - i;
165 return &r[i]; 199 return &r[i];
166} 200}
167 201
168static char buf[20 * 16]; 202/**
203 * Up to 8 non-skipped GNUNET_log() calls
204 * + extra line with delay for each one
205 */
206#define LOG_MAX_NUM_LINES (8 * 2)
207/**
208 * Actual message is 17 chars at most
209 */
210#define LOG_MAX_LINE_LENGTH (17)
211
212#define LOG_BUFFER_SIZE LOG_MAX_NUM_LINES * LOG_MAX_LINE_LENGTH
213
214static char buf[LOG_BUFFER_SIZE];
169 215
170static char *buf_ptr; 216static char *buf_ptr;
171 217
@@ -218,57 +264,73 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
218 */ 264 */
219 char *p = buf; 265 char *p = buf;
220 266
221 if (bytes == 20 * 16 || 267 if (bytes == LOG_BUFFER_SIZE ||
222 !(p = 268 !(p =
223 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, 269 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1,
224 &delay, level)) || 270 1, phase, p,
271 &bytes, &delay, level)) ||
225 !(p = 272 !(p =
226 read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, &bytes, 273 read_output_line (0, 3, 4, 9, '1', "ERROR", OUTPUT_DELAY,
227 &delays[0], level)) || 274 MAX_SKIP_DELAY, phase, p,
275 &bytes, &delays[0], level)) ||
228 !(p = 276 !(p =
229 read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes, 277 read_output_line (1, 3, 5, 9, 'L', "WARNING", -1,
230 &delay, level)) || 278 1, phase, p,
279 &bytes, &delay, level)) ||
231 !(p = 280 !(p =
232 read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p, 281 read_output_line (0, 3, 4, 9, '1', "WARNING", OUTPUT_DELAY,
282 MAX_SKIP_DELAY, phase, p,
233 &bytes, &delays[1], level)) || 283 &bytes, &delays[1], level)) ||
234 !(p = 284 !(p =
235 read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, 285 read_output_line (2, 3, 6, 7, 'L', "INFO", -1,
236 &delay, level)) || 286 1, phase, p,
287 &bytes, &delay, level)) ||
237 !(p = 288 !(p =
238 read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, &bytes, 289 read_output_line (0, 3, 4, 9, '1', "INFO", OUTPUT_DELAY,
239 &delays[2], level)) || 290 MAX_SKIP_DELAY, phase, p,
291 &bytes, &delays[2], level)) ||
240 !(p = 292 !(p =
241 read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes, 293 read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1,
242 &delay, level)) || 294 1, phase, p,
295 &bytes, &delay, level)) ||
243 !(p = 296 !(p =
244 read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, &bytes, 297 read_output_line (0, 3, 4, 9, '1', "DEBUG", OUTPUT_DELAY,
245 &delays[3], level)) || 298 MAX_SKIP_DELAY, phase, p,
299 &bytes, &delays[3], level)) ||
246 !(p = 300 !(p =
247 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, 301 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1,
248 &delay, level)) || 302 1, phase, p,
303 &bytes, &delay, level)) ||
249 !(p = 304 !(p =
250 read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, &bytes, 305 read_output_line (0, 3, 4, 9, '2', "ERROR", OUTPUT_DELAY,
251 &delays[4], level)) || 306 MAX_SKIP_DELAY, phase, p,
307 &bytes, &delays[4], level)) ||
252 !(p = 308 !(p =
253 read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes, 309 read_output_line (0, 3, 5, 9, 'L', "WARNING", -1,
254 &delay, level)) || 310 1, phase, p,
311 &bytes, &delay, level)) ||
255 !(p = 312 !(p =
256 read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p, 313 read_output_line (0, 3, 4, 9, '2', "WARNING", OUTPUT_DELAY,
314 MAX_SKIP_DELAY, phase, p,
257 &bytes, &delays[5], level)) || 315 &bytes, &delays[5], level)) ||
258 !(p = 316 !(p =
259 read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, 317 read_output_line (-1, -1, 6, 7, 'L', "INFO", -1,
260 &delay, level)) || 318 1, phase, p,
319 &bytes, &delay, level)) ||
261 !(p = 320 !(p =
262 read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, &bytes, 321 read_output_line (0, 3, 4, 9, '2', "INFO", OUTPUT_DELAY,
263 &delays[6], level)) || 322 MAX_SKIP_DELAY, phase, p,
323 &bytes, &delays[6], level)) ||
264 !(p = 324 !(p =
265 read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes, 325 read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1,
266 &delay, level)) || 326 1, phase, p,
327 &bytes, &delay, level)) ||
267 !(p = 328 !(p =
268 read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, &bytes, 329 read_output_line (0, 3, 4, 9, '2', "DEBUG", OUTPUT_DELAY,
269 &delays[7], level))) 330 MAX_SKIP_DELAY, phase, p,
331 &bytes, &delays[7], level)))
270 { 332 {
271 if (bytes == 20 * 16) 333 if (bytes == LOG_BUFFER_SIZE)
272 FPRINTF (stderr, "%s", "Ran out of buffer space!\n"); 334 FPRINTF (stderr, "%s", "Ran out of buffer space!\n");
273 GNUNET_break (0); 335 GNUNET_break (0);
274 ok = 2; 336 ok = 2;