"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib/test-cpu-limit.c" between
dovecot-2.3.16.tar.gz and dovecot-2.3.17.tar.gz

About: Dovecot is an IMAP and POP3 server, written with security primarily in mind.

test-cpu-limit.c  (dovecot-2.3.16):test-cpu-limit.c  (dovecot-2.3.17)
skipping to change at line 71 skipping to change at line 71
climit = cpu_limit_init(2, type); climit = cpu_limit_init(2, type);
usage = get_cpu_time(type); usage = get_cpu_time(type);
while (!cpu_limit_exceeded(climit)) while (!cpu_limit_exceeded(climit))
test_cpu_loop_once(); test_cpu_loop_once();
cpu_limit_deinit(&climit); cpu_limit_deinit(&climit);
cpu = get_cpu_time(type); cpu = get_cpu_time(type);
diff_msecs = timeval_diff_msecs(&cpu, &usage); diff_msecs = timeval_diff_msecs(&cpu, &usage);
test_assert_cmp(diff_msecs, >=, 2000 - ALLOW_MSECS_BELOW); test_assert_cmp(diff_msecs, >=, 2000 - ALLOW_MSECS_BELOW);
if ((type & CPU_LIMIT_TYPE_SYSTEM) == 0)
test_assert_cmp(diff_msecs, <=, 2000 + ALLOW_MSECS_ABOVE);
lib_signals_deinit(); lib_signals_deinit();
test_end(); test_end();
} }
static void test_cpu_limit_nested(enum cpu_limit_type type, const char *type_str ) static void test_cpu_limit_nested(enum cpu_limit_type type, const char *type_str )
{ {
struct cpu_limit *climit1, *climit2; struct cpu_limit *climit1, *climit2;
struct timeval usage1, usage2, cpu; struct timeval usage1, cpu;
unsigned int n; unsigned int n;
int diff_msecs; int diff_msecs;
test_begin(t_strdup_printf("cpu limit - nested (%s)", type_str)); test_begin(t_strdup_printf("cpu limit - nested (%s)", type_str));
lib_signals_init(); lib_signals_init();
climit1 = cpu_limit_init(3, type); climit1 = cpu_limit_init(3, type);
usage1 = get_cpu_time(type); usage1 = get_cpu_time(type);
while (!cpu_limit_exceeded(climit1) && !test_has_failed()) { while (!cpu_limit_exceeded(climit1) && !test_has_failed()) {
climit2 = cpu_limit_init(1, type); climit2 = cpu_limit_init(1, type);
usage2 = get_cpu_time(type);
while (!cpu_limit_exceeded(climit2) && !test_has_failed()) while (!cpu_limit_exceeded(climit2) && !test_has_failed())
test_cpu_loop_once(); test_cpu_loop_once();
cpu_limit_deinit(&climit2); cpu_limit_deinit(&climit2);
cpu = get_cpu_time(type);
/* we may have looped only for a short time in case climit1
was triggered during this loop. */
diff_msecs = timeval_diff_msecs(&cpu, &usage2);
if ((type & CPU_LIMIT_TYPE_SYSTEM) == 0)
test_assert_cmp(diff_msecs, <=, 1000 + ALLOW_MSECS_ABOVE)
;
} }
cpu_limit_deinit(&climit1); cpu_limit_deinit(&climit1);
cpu = get_cpu_time(type); cpu = get_cpu_time(type);
diff_msecs = timeval_diff_msecs(&cpu, &usage1); diff_msecs = timeval_diff_msecs(&cpu, &usage1);
test_assert_cmp(diff_msecs, >=, 3000 - ALLOW_MSECS_BELOW); test_assert_cmp(diff_msecs, >=, 3000 - ALLOW_MSECS_BELOW);
if ((type & CPU_LIMIT_TYPE_SYSTEM) == 0)
test_assert_cmp(diff_msecs, <=, 3000 + ALLOW_MSECS_ABOVE);
lib_signals_deinit(); lib_signals_deinit();
test_end(); test_end();
test_begin(t_strdup_printf("cpu limit - nested2 (%s)", type_str)); test_begin(t_strdup_printf("cpu limit - nested2 (%s)", type_str));
lib_signals_init(); lib_signals_init();
climit1 = cpu_limit_init(3, type); climit1 = cpu_limit_init(3, type);
usage1 = get_cpu_time(type); usage1 = get_cpu_time(type);
n = 0; n = 0;
while (!cpu_limit_exceeded(climit1) && !test_has_failed()) { while (!cpu_limit_exceeded(climit1) && !test_has_failed()) {
if (++n >= 3) { if (++n >= 3) {
/* Consume last second in top cpu limit */ /* Consume last second in top cpu limit */
test_cpu_loop_once(); test_cpu_loop_once();
continue; continue;
} }
climit2 = cpu_limit_init(1, type); climit2 = cpu_limit_init(1, type);
usage2 = get_cpu_time(type);
while (!cpu_limit_exceeded(climit2) && !test_has_failed()) while (!cpu_limit_exceeded(climit2) && !test_has_failed())
test_cpu_loop_once(); test_cpu_loop_once();
cpu_limit_deinit(&climit2); cpu_limit_deinit(&climit2);
cpu = get_cpu_time(type);
/* we may have looped only for a short time in case climit1
was triggered during this loop. */
diff_msecs = timeval_diff_msecs(&cpu, &usage2);
if ((type & CPU_LIMIT_TYPE_SYSTEM) == 0)
test_assert_cmp(diff_msecs, <=, 1000 + ALLOW_MSECS_ABOVE)
;
} }
cpu_limit_deinit(&climit1); cpu_limit_deinit(&climit1);
cpu = get_cpu_time(type); cpu = get_cpu_time(type);
diff_msecs = timeval_diff_msecs(&cpu, &usage1); diff_msecs = timeval_diff_msecs(&cpu, &usage1);
test_assert_cmp(diff_msecs, >=, 3000 - ALLOW_MSECS_BELOW); test_assert_cmp(diff_msecs, >=, 3000 - ALLOW_MSECS_BELOW);
if ((type & CPU_LIMIT_TYPE_SYSTEM) == 0)
test_assert_cmp(diff_msecs, <=, 3000 + ALLOW_MSECS_ABOVE);
i_unlink_if_exists(test_path); i_unlink_if_exists(test_path);
lib_signals_deinit(); lib_signals_deinit();
test_end(); test_end();
} }
void test_cpu_limit(void) void test_cpu_limit(void)
{ {
test_cpu_limit_simple(CPU_LIMIT_TYPE_USER, "user"); 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_SYSTEM, "system");
 End of changes. 8 change blocks. 
23 lines changed or deleted 1 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)