diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-06 09:17:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-06 09:17:11 +0000 |
commit | c7862e3f63acaa648653a30e567a875d42d6b4c2 (patch) | |
tree | 20666f467fdd9a83846e01ce37e1a6ee0923bd05 /src/util | |
parent | 0b7df31372e4eb63732f03f8754607a4dee2b80d (diff) | |
download | gnunet-c7862e3f63acaa648653a30e567a875d42d6b4c2.tar.gz gnunet-c7862e3f63acaa648653a30e567a875d42d6b4c2.zip |
-speed up logging test, fix logging testcase to always log at DEBUG level
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/server_mst.c | 23 | ||||
-rw-r--r-- | src/util/test_common_logging_dummy.c | 10 | ||||
-rw-r--r-- | src/util/test_common_logging_runtime_loglevels.c | 2 |
3 files changed, 26 insertions, 9 deletions
diff --git a/src/util/server_mst.c b/src/util/server_mst.c index 0a6eee49c..61617706e 100644 --- a/src/util/server_mst.c +++ b/src/util/server_mst.c | |||
@@ -132,6 +132,8 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | |||
132 | unsigned long offset; | 132 | unsigned long offset; |
133 | int ret; | 133 | int ret; |
134 | 134 | ||
135 | GNUNET_assert (mst->off <= mst->pos); | ||
136 | GNUNET_assert (mst->pos <= mst->curr_buf); | ||
135 | #if DEBUG_SERVER_MST | 137 | #if DEBUG_SERVER_MST |
136 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 138 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
137 | "Server-mst receives %u bytes with %u bytes already in private buffer\n", | 139 | "Server-mst receives %u bytes with %u bytes already in private buffer\n", |
@@ -142,6 +144,7 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | |||
142 | while (mst->pos > 0) | 144 | while (mst->pos > 0) |
143 | { | 145 | { |
144 | do_align: | 146 | do_align: |
147 | GNUNET_assert (mst->pos >= mst->off); | ||
145 | if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || | 148 | if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || |
146 | (0 != (mst->off % ALIGN_FACTOR))) | 149 | (0 != (mst->off % ALIGN_FACTOR))) |
147 | { | 150 | { |
@@ -176,15 +179,18 @@ do_align: | |||
176 | GNUNET_break_op (0); | 179 | GNUNET_break_op (0); |
177 | return GNUNET_SYSERR; | 180 | return GNUNET_SYSERR; |
178 | } | 181 | } |
179 | if (mst->curr_buf - mst->off < want) | 182 | if ( (mst->curr_buf - mst->off < want) && |
183 | (mst->off > 0) ) | ||
180 | { | 184 | { |
181 | /* need more space */ | 185 | /* can get more space by moving */ |
182 | mst->pos -= mst->off; | 186 | mst->pos -= mst->off; |
183 | memmove (ibuf, &ibuf[mst->off], mst->pos); | 187 | memmove (ibuf, &ibuf[mst->off], mst->pos); |
184 | mst->off = 0; | 188 | mst->off = 0; |
185 | } | 189 | } |
186 | if (want > mst->curr_buf) | 190 | if (mst->curr_buf < want) |
187 | { | 191 | { |
192 | /* need to get more space by growing buffer */ | ||
193 | GNUNET_assert (0 == mst->off); | ||
188 | mst->hdr = GNUNET_realloc (mst->hdr, want); | 194 | mst->hdr = GNUNET_realloc (mst->hdr, want); |
189 | ibuf = (char *) mst->hdr; | 195 | ibuf = (char *) mst->hdr; |
190 | mst->curr_buf = want; | 196 | mst->curr_buf = want; |
@@ -193,6 +199,7 @@ do_align: | |||
193 | if (mst->pos - mst->off < want) | 199 | if (mst->pos - mst->off < want) |
194 | { | 200 | { |
195 | delta = GNUNET_MIN (want - (mst->pos - mst->off), size); | 201 | delta = GNUNET_MIN (want - (mst->pos - mst->off), size); |
202 | GNUNET_assert (mst->pos + delta <= mst->curr_buf); | ||
196 | memcpy (&ibuf[mst->pos], buf, delta); | 203 | memcpy (&ibuf[mst->pos], buf, delta); |
197 | mst->pos += delta; | 204 | mst->pos += delta; |
198 | buf += delta; | 205 | buf += delta; |
@@ -225,6 +232,7 @@ do_align: | |||
225 | mst->pos = 0; | 232 | mst->pos = 0; |
226 | } | 233 | } |
227 | } | 234 | } |
235 | GNUNET_assert (0 == mst->pos); | ||
228 | while (size > 0) | 236 | while (size > 0) |
229 | { | 237 | { |
230 | #if DEBUG_SERVER_MST | 238 | #if DEBUG_SERVER_MST |
@@ -235,7 +243,7 @@ do_align: | |||
235 | if (size < sizeof (struct GNUNET_MessageHeader)) | 243 | if (size < sizeof (struct GNUNET_MessageHeader)) |
236 | break; | 244 | break; |
237 | offset = (unsigned long) buf; | 245 | offset = (unsigned long) buf; |
238 | need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; | 246 | need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; |
239 | if (GNUNET_NO == need_align) | 247 | if (GNUNET_NO == need_align) |
240 | { | 248 | { |
241 | /* can try to do zero-copy and process directly from original buffer */ | 249 | /* can try to do zero-copy and process directly from original buffer */ |
@@ -248,7 +256,7 @@ do_align: | |||
248 | return GNUNET_SYSERR; | 256 | return GNUNET_SYSERR; |
249 | } | 257 | } |
250 | if (size < want) | 258 | if (size < want) |
251 | break; /* or not, buffer incomplete, so copy to private buffer... */ | 259 | break; /* or not: buffer incomplete, so copy to private buffer... */ |
252 | if (one_shot == GNUNET_SYSERR) | 260 | if (one_shot == GNUNET_SYSERR) |
253 | { | 261 | { |
254 | /* cannot call callback again, but return value saying that | 262 | /* cannot call callback again, but return value saying that |
@@ -278,12 +286,15 @@ copy: | |||
278 | ibuf = (char *) mst->hdr; | 286 | ibuf = (char *) mst->hdr; |
279 | mst->curr_buf = size + mst->pos; | 287 | mst->curr_buf = size + mst->pos; |
280 | } | 288 | } |
281 | GNUNET_assert (mst->pos + size <= mst->curr_buf); | 289 | GNUNET_assert (size + mst->pos <= mst->curr_buf); |
282 | memcpy (&ibuf[mst->pos], buf, size); | 290 | memcpy (&ibuf[mst->pos], buf, size); |
283 | mst->pos += size; | 291 | mst->pos += size; |
284 | } | 292 | } |
285 | if (purge) | 293 | if (purge) |
294 | { | ||
286 | mst->off = 0; | 295 | mst->off = 0; |
296 | mst->pos = 0; | ||
297 | } | ||
287 | #if DEBUG_SERVER_MST | 298 | #if DEBUG_SERVER_MST |
288 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 299 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
289 | "Server-mst leaves %u bytes in private buffer\n", | 300 | "Server-mst leaves %u bytes in private buffer\n", |
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c index 9f6756ff4..a1f479976 100644 --- a/src/util/test_common_logging_dummy.c +++ b/src/util/test_common_logging_dummy.c | |||
@@ -25,11 +25,17 @@ | |||
25 | * @author LRN | 25 | * @author LRN |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #undef GNUNET_EXTRA_LOGGING | ||
29 | #define GNUNET_EXTRA_LOGGING GNUNET_YES | ||
30 | |||
28 | #include "gnunet_common.h" | 31 | #include "gnunet_common.h" |
29 | #include "gnunet_time_lib.h" | 32 | #include "gnunet_time_lib.h" |
30 | #include "gnunet_network_lib.h" | 33 | #include "gnunet_network_lib.h" |
31 | 34 | ||
32 | #define MS200 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) | 35 | /** |
36 | * Delay introduced between operations, useful for debugging. | ||
37 | */ | ||
38 | #define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 0) | ||
33 | 39 | ||
34 | static void | 40 | static void |
35 | my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | 41 | my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, |
@@ -44,7 +50,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | |||
44 | static int | 50 | static int |
45 | expensive_func () | 51 | expensive_func () |
46 | { | 52 | { |
47 | return GNUNET_NETWORK_socket_select (NULL, NULL, NULL, MS200); | 53 | return GNUNET_NETWORK_socket_select (NULL, NULL, NULL, OUTPUT_DELAY); |
48 | } | 54 | } |
49 | 55 | ||
50 | #define pr(kind,lvl) {\ | 56 | #define pr(kind,lvl) {\ |
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c index 092f06041..d1f264c70 100644 --- a/src/util/test_common_logging_runtime_loglevels.c +++ b/src/util/test_common_logging_runtime_loglevels.c | |||
@@ -43,7 +43,7 @@ static struct GNUNET_DISK_PipeHandle *pipe_stdout; | |||
43 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 43 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
44 | 44 | ||
45 | static void | 45 | static void |
46 | runone (); | 46 | runone (void); |
47 | 47 | ||
48 | static void | 48 | static void |
49 | end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 49 | end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |