Fix an interaction between the oversize_threshold test and bgthds.

Also added the shared utility to check if background_thread is enabled.
This commit is contained in:
Qi Wang 2021-05-12 16:00:38 -07:00 committed by Qi Wang
parent 5417938215
commit 08089589f7
6 changed files with 30 additions and 34 deletions

17
test/include/test/bgthd.h Normal file
View File

@ -0,0 +1,17 @@
/*
* Shared utility for checking if background_thread is enabled, which affects
* the purging behavior and assumptions in some tests.
*/
static inline bool
is_background_thread_enabled(void) {
bool enabled;
size_t sz = sizeof(bool);
int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0);
if (ret == ENOENT) {
return false;
}
assert_d_eq(ret, 0, "Unexpected mallctl error");
return enabled;
}

View File

@ -128,6 +128,7 @@ static const bool config_debug =
#include "test/test.h"
#include "test/timer.h"
#include "test/thd.h"
#include "test/bgthd.h"
#define MEXP 19937
#include "test/SFMT.h"

View File

@ -2,18 +2,6 @@
#include "test/extent_hooks.h"
static bool
check_background_thread_enabled(void) {
bool enabled;
size_t sz = sizeof(bool);
int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0);
if (ret == ENOENT) {
return false;
}
expect_d_eq(ret, 0, "Unexpected mallctl error");
return enabled;
}
static void
test_extent_body(unsigned arena_ind) {
void *p;
@ -177,7 +165,7 @@ test_manual_hook_body(void) {
expect_ptr_ne(old_hooks->merge, extent_merge_hook,
"Unexpected extent_hooks error");
if (!check_background_thread_enabled()) {
if (!is_background_thread_enabled()) {
test_extent_body(arena_ind);
}
@ -235,7 +223,7 @@ TEST_BEGIN(test_extent_auto_hook) {
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz,
(void *)&new_hooks, new_size), 0, "Unexpected mallctl() failure");
test_skip_if(check_background_thread_enabled());
test_skip_if(is_background_thread_enabled());
test_extent_body(arena_ind);
}
TEST_END

View File

@ -9,18 +9,6 @@ static unsigned nupdates_mock;
static nstime_t time_mock;
static bool monotonic_mock;
static bool
check_background_thread_enabled(void) {
bool enabled;
size_t sz = sizeof(bool);
int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0);
if (ret == ENOENT) {
return false;
}
expect_d_eq(ret, 0, "Unexpected mallctl error");
return enabled;
}
static bool
nstime_monotonic_mock(void) {
return monotonic_mock;
@ -184,7 +172,7 @@ generate_dirty(unsigned arena_ind, size_t size) {
}
TEST_BEGIN(test_decay_ticks) {
test_skip_if(check_background_thread_enabled());
test_skip_if(is_background_thread_enabled());
test_skip_if(opt_hpa);
ticker_geom_t *decay_ticker;
@ -417,7 +405,7 @@ decay_ticker_helper(unsigned arena_ind, int flags, bool dirty, ssize_t dt,
}
TEST_BEGIN(test_decay_ticker) {
test_skip_if(check_background_thread_enabled());
test_skip_if(is_background_thread_enabled());
test_skip_if(opt_hpa);
#define NPS 2048
ssize_t ddt = opt_dirty_decay_ms;
@ -476,7 +464,7 @@ TEST_BEGIN(test_decay_ticker) {
TEST_END
TEST_BEGIN(test_decay_nonmonotonic) {
test_skip_if(check_background_thread_enabled());
test_skip_if(is_background_thread_enabled());
test_skip_if(opt_hpa);
#define NPS (SMOOTHSTEP_NSTEPS + 1)
int flags = (MALLOCX_ARENA(0) | MALLOCX_TCACHE_NONE);
@ -534,7 +522,7 @@ TEST_BEGIN(test_decay_nonmonotonic) {
TEST_END
TEST_BEGIN(test_decay_now) {
test_skip_if(check_background_thread_enabled());
test_skip_if(is_background_thread_enabled());
test_skip_if(opt_hpa);
unsigned arena_ind = do_arena_create(0, 0);
@ -555,7 +543,7 @@ TEST_BEGIN(test_decay_now) {
TEST_END
TEST_BEGIN(test_decay_never) {
test_skip_if(check_background_thread_enabled() || !config_stats);
test_skip_if(is_background_thread_enabled() || !config_stats);
test_skip_if(opt_hpa);
unsigned arena_ind = do_arena_create(-1, -1);

View File

@ -106,14 +106,16 @@ TEST_BEGIN(test_oversize_threshold) {
/* Allocating and freeing half a megabyte should leave them dirty. */
void *ptr = mallocx(512 * 1024, MALLOCX_ARENA(arena));
dallocx(ptr, MALLOCX_TCACHE_NONE);
if (!is_background_thread_enabled()) {
expect_zu_lt(max_purged, 512 * 1024, "Expected no 512k purge");
}
/* Purge again to reset everything out. */
arena_mallctl("arena.%u.purge", arena, NULL, NULL, NULL, 0);
max_purged = 0;
/*
* Allocating and freeing 2 megabytes should leave them dirty because of
* Allocating and freeing 2 megabytes should have them purged because of
* the oversize threshold.
*/
ptr = mallocx(2 * 1024 * 1024, MALLOCX_ARENA(arena));

View File

@ -119,7 +119,7 @@ TEST_BEGIN(test_stats_arenas_summary) {
"Unexepected mallctl() result");
if (config_stats) {
if (!background_thread_enabled() && !opt_hpa) {
if (!is_background_thread_enabled() && !opt_hpa) {
expect_u64_gt(dirty_npurge + muzzy_npurge, 0,
"At least one purge should have occurred");
}