commit a4447ced22f7eb1e558ddd824e06c8f3708e3400 Author: Jacob Welsh AuthorDate: Sat Nov 26 01:43:47 2022 +0000 Commit: Jacob Welsh CommitDate: Sat Nov 26 01:43:47 2022 +0000 Type: cutting wasteful costs lib: cut down on the more aggressive cpu limit testing and unsolicited fuzz testing because it's too damn slow diff --git a/src/lib/test-base64.c b/src/lib/test-base64.c index d024890ed4..5c6a660ebd 100644 --- a/src/lib/test-base64.c +++ b/src/lib/test-base64.c @@ -1106,7 +1106,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 < 50; 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 +1127,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 < 50; 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 +1148,7 @@ test_base64_random_lowlevel_case(const struct base64_scheme *b64, } /* streaming; random chunks */ - for (i = 0; i < 1000; i++) { + for (i = 0; i < 50; i++) { in_buf_size = i_rand_limit(sizeof(in_buf)); for (j = 0; j < in_buf_size; j++) in_buf[j] = i_rand_uchar(); diff --git a/src/lib/test-cpu-limit.c b/src/lib/test-cpu-limit.c index c4c1090ecc..ed9d2d3b99 100644 --- a/src/lib/test-cpu-limit.c +++ b/src/lib/test-cpu-limit.c @@ -9,14 +9,6 @@ #include #include -/* The CPU limits aren't exact. Allow this much leniency in the time - comparisons. Note that system CPU usage can grow very large on loaded - systems, so we're not checking its upper limit at all. */ -#define ALLOW_MSECS_BELOW 500 -#define ALLOW_MSECS_ABOVE 3000 - -static const char *const test_path = ".test.cpulimit"; - static struct timeval get_cpu_time(enum cpu_limit_type type) { struct rusage rusage; @@ -39,13 +31,6 @@ static void test_cpu_loop_once(void) /* consume some user CPU */ for (unsigned int i = 0; i < 10000; i++) guid_128_generate(guid); - /* consume some system CPU */ - int fd = creat(test_path, 0600); - if (fd == -1) - i_fatal("creat(%s) failed: %m", test_path); - if (write(fd, guid, sizeof(guid)) < 0) - i_fatal("write(%s) failed: %m", test_path); - i_close_fd(&fd); } static void @@ -58,8 +43,8 @@ test_cpu_limit_simple(enum cpu_limit_type type, const char *type_str) test_begin(t_strdup_printf("cpu limit - simple (%s)", type_str)); lib_signals_init(); - climit = cpu_limit_init(2, type); usage = get_cpu_time(type); + climit = cpu_limit_init(1, type); while (!cpu_limit_exceeded(climit)) test_cpu_loop_once(); @@ -67,69 +52,8 @@ test_cpu_limit_simple(enum cpu_limit_type type, const char *type_str) cpu_limit_deinit(&climit); cpu = get_cpu_time(type); diff_msecs = timeval_diff_msecs(&cpu, &usage); - test_assert_cmp(diff_msecs, >=, 2000 - ALLOW_MSECS_BELOW); - - lib_signals_deinit(); - test_end(); -} - -static void test_cpu_limit_nested(enum cpu_limit_type type, const char *type_str) -{ - struct cpu_limit *climit1, *climit2; - struct timeval usage1, cpu; - unsigned int n; - int diff_msecs; - - test_begin(t_strdup_printf("cpu limit - nested (%s)", type_str)); - - lib_signals_init(); - climit1 = cpu_limit_init(3, type); - usage1 = get_cpu_time(type); - - while (!cpu_limit_exceeded(climit1) && !test_has_failed()) { - climit2 = cpu_limit_init(1, type); - - while (!cpu_limit_exceeded(climit2) && !test_has_failed()) - test_cpu_loop_once(); - - cpu_limit_deinit(&climit2); - } - - cpu_limit_deinit(&climit1); - cpu = get_cpu_time(type); - diff_msecs = timeval_diff_msecs(&cpu, &usage1); - test_assert_cmp(diff_msecs, >=, 3000 - ALLOW_MSECS_BELOW); - - lib_signals_deinit(); - test_end(); - - test_begin(t_strdup_printf("cpu limit - nested2 (%s)", type_str)); - - lib_signals_init(); - climit1 = cpu_limit_init(3, type); - usage1 = get_cpu_time(type); - - n = 0; - while (!cpu_limit_exceeded(climit1) && !test_has_failed()) { - if (++n >= 3) { - /* Consume last second in top cpu limit */ - test_cpu_loop_once(); - continue; - } - climit2 = cpu_limit_init(1, type); - - while (!cpu_limit_exceeded(climit2) && !test_has_failed()) - test_cpu_loop_once(); - - cpu_limit_deinit(&climit2); - } - - cpu_limit_deinit(&climit1); - cpu = get_cpu_time(type); - diff_msecs = timeval_diff_msecs(&cpu, &usage1); - test_assert_cmp(diff_msecs, >=, 3000 - ALLOW_MSECS_BELOW); + test_assert_cmp(diff_msecs, >=, 1000); - i_unlink_if_exists(test_path); lib_signals_deinit(); test_end(); } @@ -137,9 +61,4 @@ static void test_cpu_limit_nested(enum cpu_limit_type type, const char *type_str void test_cpu_limit(void) { test_cpu_limit_simple(CPU_LIMIT_TYPE_USER, "user"); - test_cpu_limit_simple(CPU_LIMIT_TYPE_SYSTEM, "system"); - test_cpu_limit_simple(CPU_LIMIT_TYPE_ALL, "all"); - test_cpu_limit_nested(CPU_LIMIT_TYPE_USER, "user"); - test_cpu_limit_nested(CPU_LIMIT_TYPE_SYSTEM, "system"); - test_cpu_limit_nested(CPU_LIMIT_TYPE_ALL, "all"); } diff --git a/src/lib/test-istream-base64-decoder.c b/src/lib/test-istream-base64-decoder.c index ea45f6d6d9..7215a18d79 100644 --- a/src/lib/test-istream-base64-decoder.c +++ b/src/lib/test-istream-base64-decoder.c @@ -139,7 +139,7 @@ test_istream_base64_io_random(void) test_begin("istream base64 random I/O"); - for (i = 0; !test_has_failed() && i < 4000; i++) { + for (i = 0; !test_has_failed() && i < 400; i++) { struct istream *input1, *input2, *input3, *input4, *input5; struct istream *sinput1, *sinput2, *sinput3, *sinput4; struct istream *top_input;