dovecot-2.2: lib-test: use the new srand() tracking helpers to a...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 27 13:22:47 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/06f29889af37
changeset: 17532:06f29889af37
user:      Phil Carmody <phil at dovecot.fi>
date:      Fri Jun 27 16:17:07 2014 +0300
description:
lib-test: use the new srand() tracking helpers to aid debugging
We can only be sure we know the entirity of the stream of numbers returned
by rand if rand_set_seed has been called precisely once, as after that we
can't be sure when it was called a 2nd or further time. However, at least
we can know that that has happened. (Likewise, any calls to srand() will
disturb the flow.)

Most unit test cases should be simple enough that there should be only one
seeding.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib-test/test-common.c |  14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diffs (36 lines):

diff -r 14f505c1c6f4 -r 06f29889af37 src/lib-test/test-common.c
--- a/src/lib-test/test-common.c	Fri Jun 27 16:16:16 2014 +0300
+++ b/src/lib-test/test-common.c	Fri Jun 27 16:17:07 2014 +0300
@@ -164,11 +164,24 @@
 	test_success = FALSE;
 }
 
+static void
+test_dump_rand_state(void)
+{
+	if (rand_get_seed_count() > 0)
+		printf("test: random seed #%i was %u\n", 
+		       rand_get_seed_count(),
+		       rand_get_last_seed());
+	else
+		printf("test: random seed unknown\n");
+}
+
 void test_end(void)
 {
 	i_assert(test_prefix != NULL);
 
 	test_out("", test_success);
+	if (!test_success)
+		test_dump_rand_state();
 	i_free_and_null(test_prefix);
 	test_success = FALSE;
 }
@@ -217,6 +230,7 @@
 test_error_handler(const struct failure_context *ctx,
 		   const char *format, va_list args)
 {
+	test_dump_rand_state();
 	default_error_handler(ctx, format, args);
 #ifdef DEBUG
 	if (ctx->type == LOG_TYPE_WARNING &&


More information about the dovecot-cvs mailing list