]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: base64 tests - Reduce loop counts with valgrind to save time
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 1 Oct 2024 07:51:00 +0000 (10:51 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 1 Oct 2024 09:45:00 +0000 (09:45 +0000)
src/lib/test-base64.c
src/lib/test-istream-base64-decoder.c

index 85e85e6ffb343f225dccac9a5720a73e90845e8f..15edafa31fe27db0dbeb64d79309018ae8d7a3e6 100644 (file)
@@ -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();
index ea45f6d6d9c9b39be5d674b3d83f636d49793b43..598c08f03c94e9e4a96c4e54a76569277bdc0048 100644 (file)
@@ -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;