dovecot-2.1: test-istream-concat unit test improved.
dovecot at dovecot.org
dovecot at dovecot.org
Tue Feb 4 23:30:32 EET 2014
details: http://hg.dovecot.org/dovecot-2.1/rev/a8408943ded7
changeset: 15010:a8408943ded7
user: Timo Sirainen <tss at iki.fi>
date: Mon Feb 03 11:38:51 2014 -0500
description:
test-istream-concat unit test improved.
Still pretty ugly to test with randomness, but at least it caught the bug.
diffstat:
src/lib/test-istream-concat.c | 26 +++++++++++++++++---------
1 files changed, 17 insertions(+), 9 deletions(-)
diffs (68 lines):
diff -r b93e49f114e7 -r a8408943ded7 src/lib/test-istream-concat.c
--- a/src/lib/test-istream-concat.c Mon Feb 03 11:37:48 2014 -0500
+++ b/src/lib/test-istream-concat.c Mon Feb 03 11:38:51 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,19 @@
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);
+ 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 {
+ (void)i_stream_get_data(input, &size);
+ 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,7 +95,6 @@
}
}
}
- (void)i_stream_get_data(input, &size);
}
for (i = 0; i < stream_count; i++)
i_stream_unref(&streams[i]);
More information about the dovecot-cvs
mailing list