Tests: Shouldn't be able to change global slowness.

This can help ensure that we don't leave slowness changes behind in case of
resource exhaustion.
This commit is contained in:
David Goldblatt 2018-05-11 16:43:43 -07:00 committed by David Goldblatt
parent 59e371f463
commit 0379235f47
3 changed files with 19 additions and 1 deletions

View File

@ -117,6 +117,7 @@ void tsd_slow_update(tsd_t *tsd);
*/ */
void tsd_global_slow_inc(tsdn_t *tsdn); void tsd_global_slow_inc(tsdn_t *tsdn);
void tsd_global_slow_dec(tsdn_t *tsdn); void tsd_global_slow_dec(tsdn_t *tsdn);
bool tsd_global_slow();
enum { enum {
/* Common case --> jnz. */ /* Common case --> jnz. */

View File

@ -141,7 +141,7 @@ tsd_local_slow(tsd_t *tsd) {
|| tsd_reentrancy_level_get(tsd) > 0; || tsd_reentrancy_level_get(tsd) > 0;
} }
static bool bool
tsd_global_slow() { tsd_global_slow() {
return atomic_load_u32(&tsd_global_slow_count, ATOMIC_RELAXED) > 0; return atomic_load_u32(&tsd_global_slow_count, ATOMIC_RELAXED) > 0;
} }

View File

@ -110,6 +110,20 @@ p_test_fini(void) {
test_status_string(test_status)); test_status_string(test_status));
} }
static void
check_global_slow(test_status_t *status) {
#ifdef JEMALLOC_UNIT_TEST
/*
* This check needs to peek into tsd internals, which is why it's only
* exposed in unit tests.
*/
if (tsd_global_slow()) {
malloc_printf("Testing increased global slow count\n");
*status = test_status_fail;
}
#endif
}
static test_status_t static test_status_t
p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) { p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
test_status_t ret; test_status_t ret;
@ -136,6 +150,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
if (test_status > ret) { if (test_status > ret) {
ret = test_status; ret = test_status;
} }
check_global_slow(&ret);
/* Reentrant run. */ /* Reentrant run. */
if (do_reentrant) { if (do_reentrant) {
reentrancy = libc_reentrant; reentrancy = libc_reentrant;
@ -145,6 +160,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
if (test_status > ret) { if (test_status > ret) {
ret = test_status; ret = test_status;
} }
check_global_slow(&ret);
reentrancy = arena_new_reentrant; reentrancy = arena_new_reentrant;
test_hooks_libc_hook = NULL; test_hooks_libc_hook = NULL;
@ -153,6 +169,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
if (test_status > ret) { if (test_status > ret) {
ret = test_status; ret = test_status;
} }
check_global_slow(&ret);
} }
} }