From: Timo Sirainen Date: Tue, 1 Oct 2024 07:51:00 +0000 (+0300) Subject: lib: base64 tests - Reduce loop counts with valgrind to save time X-Git-Tag: 2.4.0~1445 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3fca3589f7c5b254b2a181ee112c25f7dbcd5e1c;p=thirdparty%2Fdovecot%2Fcore.git lib: base64 tests - Reduce loop counts with valgrind to save time --- diff --git a/src/lib/test-base64.c b/src/lib/test-base64.c index 85e85e6ffb..15edafa31f 100644 --- a/src/lib/test-base64.c +++ b/src/lib/test-base64.c @@ -4,6 +4,8 @@ #include "str.h" #include "base64.h" +static unsigned int loop_count; + static void test_base64_encode(void) { const struct { @@ -110,7 +112,7 @@ static void test_base64_random(void) dest = t_str_new(256); test_begin("base64 encode/decode with random input"); - for (i = 0; i < 1000; i++) { + for (i = 0; i < loop_count; i++) { max = i_rand_limit(sizeof(buf)); for (j = 0; j < max; j++) buf[j] = i_rand_uchar(); @@ -234,7 +236,7 @@ static void test_base64url_random(void) dest = t_str_new(256); test_begin("base64url encode/decode with random input"); - for (i = 0; i < 1000; i++) { + for (i = 0; i < loop_count; i++) { max = i_rand_limit(sizeof(buf)); for (j = 0; j < max; j++) buf[j] = i_rand_uchar(); @@ -1094,7 +1096,7 @@ test_base64_random_lowlevel_case(const struct base64_scheme *b64, enum base64_decode_flags dec_flags, size_t max_line_len) { - unsigned char in_buf[512]; + unsigned char in_buf[ON_VALGRIND ? 128 : 512]; size_t in_buf_size; buffer_t *buf1, *buf2; unsigned int i, j; @@ -1106,7 +1108,7 @@ test_base64_random_lowlevel_case(const struct base64_scheme *b64, buf2 = t_buffer_create(MAX_BASE64_ENCODED_SIZE(sizeof(in_buf))); /* one block */ - for (i = 0; i < 1000; i++) { + for (i = 0; i < loop_count; i++) { in_buf_size = i_rand_limit(sizeof(in_buf)); for (j = 0; j < in_buf_size; j++) in_buf[j] = i_rand_uchar(); @@ -1127,7 +1129,7 @@ test_base64_random_lowlevel_case(const struct base64_scheme *b64, } /* streaming; single-byte trickle */ - for (i = 0; i < 1000; i++) { + for (i = 0; i < loop_count; i++) { in_buf_size = i_rand_limit(sizeof(in_buf)); for (j = 0; j < in_buf_size; j++) in_buf[j] = i_rand_uchar(); @@ -1148,7 +1150,7 @@ test_base64_random_lowlevel_case(const struct base64_scheme *b64, } /* streaming; random chunks */ - for (i = 0; i < 1000; i++) { + for (i = 0; i < loop_count; i++) { in_buf_size = i_rand_limit(sizeof(in_buf)); for (j = 0; j < in_buf_size; j++) in_buf[j] = i_rand_uchar(); @@ -1304,6 +1306,7 @@ static void test_base64_encode_lines(void) void test_base64(void) { + loop_count = ON_VALGRIND ? 100 : 1000; test_base64_encode(); test_base64_decode(); test_base64_random(); diff --git a/src/lib/test-istream-base64-decoder.c b/src/lib/test-istream-base64-decoder.c index ea45f6d6d9..598c08f03c 100644 --- a/src/lib/test-istream-base64-decoder.c +++ b/src/lib/test-istream-base64-decoder.c @@ -132,14 +132,14 @@ test_istream_base64_io_random(void) unsigned char in_buf[2048]; size_t in_buf_size; buffer_t *out_buf; - unsigned int i, j; + unsigned int i, j, loop_count = ON_VALGRIND ? 100 : 4000; int ret; out_buf = t_buffer_create(sizeof(in_buf)); test_begin("istream base64 random I/O"); - for (i = 0; !test_has_failed() && i < 4000; i++) { + for (i = 0; !test_has_failed() && i < loop_count; i++) { struct istream *input1, *input2, *input3, *input4, *input5; struct istream *sinput1, *sinput2, *sinput3, *sinput4; struct istream *top_input;