dovecot-2.2: test-istream-concat unit test improved.

dovecot at dovecot.org dovecot at dovecot.org
Tue Feb 4 18:22:57 EET 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/e1db4af9e2c1
changeset: 17125:e1db4af9e2c1
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Feb 03 11:38:40 2014 -0500
description:
test-istream-concat unit test improved.
Still pretty ugly to test with randomness, but at least it caught the bug in v2.1.

diffstat:

 src/lib/test-istream-concat.c |  31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diffs (76 lines):

diff -r 1c298212ab70 -r e1db4af9e2c1 src/lib/test-istream-concat.c
--- a/src/lib/test-istream-concat.c	Mon Feb 03 10:53:59 2014 -0500
+++ b/src/lib/test-istream-concat.c	Mon Feb 03 11:38:40 2014 -0500
@@ -8,6 +8,10 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#define TEST_MAX_ISTREAM_COUNT 10
+#define TEST_MAX_ISTREAM_SIZE 1024
+#define TEST_MAX_BUFFER_SIZE 128
+
 static void test_istream_concat_one(unsigned int buffer_size)
 {
 	static const char *input_string = "xyz";
@@ -47,17 +51,17 @@
 
 static void test_istream_concat_random(void)
 {
-	struct istream **streams, *input;
+	struct istream **streams, *input, *input1, *input2;
 	const unsigned char *data;
 	unsigned char *w_data;
 	size_t size = 0;
 	unsigned int i, j, offset, stream_count, data_len;
 
-	srand(1234);
-	stream_count = (rand() % 10) + 2;
+	srand(3);
+	stream_count = (rand() % TEST_MAX_ISTREAM_COUNT) + 2;
 	streams = t_new(struct istream *, stream_count + 1);
 	for (i = 0, offset = 0; i < stream_count; i++) {
-		data_len = rand() % 100 + 1;
+		data_len = rand() % TEST_MAX_ISTREAM_SIZE + 1;
 		w_data = t_malloc(data_len);
 		for (j = 0; j < data_len; j++)
 			w_data[j] = offset++;
@@ -68,14 +72,21 @@
 	i_assert(offset > 0);
 
 	input = i_stream_create_concat(streams);
-	for (i = 0; i < 100; i++) {
+	i_stream_set_max_buffer_size(input, TEST_MAX_BUFFER_SIZE);
+	input1 = i_stream_create_limit(input, (uoff_t)-1);
+	input2 = i_stream_create_limit(input, (uoff_t)-1);
+	i_stream_unref(&input);
+
+	for (i = 0; i < 1000; i++) {
+		input = i % 2 == 0 ? input1 : input2;
 		if (rand() % 3 == 0) {
 			i_stream_seek(input, rand() % offset);
 		} else {
 			ssize_t ret = i_stream_read(input);
-			if (input->v_offset + size == offset)
-				test_assert(ret < 0);
-			else {
+			size = i_stream_get_data_size(input);
+			if (ret == -2) {
+				test_assert(size >= TEST_MAX_BUFFER_SIZE);
+			} else if (input->v_offset + size != offset) {
 				test_assert(ret > 0);
 				test_assert(input->v_offset + ret <= offset);
 				i_stream_skip(input, rand() % ret);
@@ -86,11 +97,11 @@
 				}
 			}
 		}
-		size = i_stream_get_data_size(input);
 	}
 	for (i = 0; i < stream_count; i++)
 		i_stream_unref(&streams[i]);
-	i_stream_unref(&input);
+	i_stream_unref(&input1);
+	i_stream_unref(&input2);
 }
 
 void test_istream_concat(void)


More information about the dovecot-cvs mailing list