Use MALLOC_CONF rather than malloc_conf for tests.

malloc_conf does not reliably work with MSVC, which complains of
"inconsistent dll linkage", i.e. its inability to support the
application overriding malloc_conf when dynamically linking/loading.
Work around this limitation by adding test harness support for per test
shell script sourcing, and converting all tests to use MALLOC_CONF
instead of malloc_conf.
This commit is contained in:
Jason Evans 2017-02-21 23:40:06 -08:00
parent 8ac7937eb5
commit de49674fbd
35 changed files with 119 additions and 80 deletions

View File

@ -1,9 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_FILL
const char *malloc_conf = "junk:false";
#endif
#include "test/extent_hooks.h" #include "test/extent_hooks.h"
static void static void

View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="junk:false"
fi

View File

@ -1,9 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_FILL
const char *malloc_conf = "junk:false";
#endif
static unsigned static unsigned
get_nsizes_impl(const char *cmd) { get_nsizes_impl(const char *cmd) {
unsigned ret; unsigned ret;

View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="junk:false"
fi

View File

@ -1,9 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_FILL
const char *malloc_conf = "junk:false";
#endif
/* /*
* Use a separate arena for xallocx() extension/contraction tests so that * Use a separate arena for xallocx() extension/contraction tests so that
* internal allocation e.g. by heap profiling can't interpose allocations where * internal allocation e.g. by heap profiling can't interpose allocations where

View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="junk:false"
fi

View File

@ -11,6 +11,18 @@ case @abi@ in
;; ;;
esac esac
# Make a copy of the @JEMALLOC_CPREFIX@MALLOC_CONF passed in to this script, so
# it can be repeatedly concatenated with per test settings.
export MALLOC_CONF_ALL=${@JEMALLOC_CPREFIX@MALLOC_CONF}
# Concatenate the individual test's MALLOC_CONF and MALLOC_CONF_ALL.
export_malloc_conf() {
if [ "x${MALLOC_CONF}" != "x" -a "x${MALLOC_CONF_ALL}" != "x" ] ; then
export @JEMALLOC_CPREFIX@MALLOC_CONF="${MALLOC_CONF},${MALLOC_CONF_ALL}"
else
export @JEMALLOC_CPREFIX@MALLOC_CONF="${MALLOC_CONF}${MALLOC_CONF_ALL}"
fi
}
# Corresponds to test_status_t. # Corresponds to test_status_t.
pass_code=0 pass_code=0
skip_code=1 skip_code=1
@ -24,7 +36,22 @@ for t in $@; do
echo echo
fi fi
echo "=== ${t} ===" echo "=== ${t} ==="
${t}@exe@ @abs_srcroot@ @abs_objroot@ if [ -e "@srcroot@${t}.sh" ] ; then
# Source the shell script corresponding to the test in a subshell and
# execute the test. This allows the shell script to set MALLOC_CONF, which
# is then used to set @JEMALLOC_CPREFIX@MALLOC_CONF (thus allowing the
# per test shell script to ignore the @JEMALLOC_CPREFIX@ detail).
$(enable_fill=@enable_fill@ \
enable_prof=@enable_prof@ \
enable_tcache=@enable_tcache@ \
. @srcroot@${t}.sh && \
export_malloc_conf && \
${t}@exe@ @abs_srcroot@ @abs_objroot@)
else
$(export MALLOC_CONF= && \
export_malloc_conf &&
${t}@exe@ @abs_srcroot@ @abs_objroot@)
fi
result_code=$? result_code=$?
case ${result_code} in case ${result_code} in
${pass_code}) ${pass_code})

View File

@ -1,5 +1,4 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#define ARENA_RESET_PROF_C_ #define ARENA_RESET_PROF_C_
const char *malloc_conf = "prof:true,lg_prof_sample:0";
#include "arena_reset.c" #include "arena_reset.c"

View File

@ -0,0 +1,3 @@
#!/bin/sh
export MALLOC_CONF="prof:true,lg_prof_sample:0"

View File

@ -1,11 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
const char *malloc_conf = "decay_time:1"
#ifdef JEMALLOC_TCACHE
",lg_tcache_max:0"
#endif
;
static nstime_monotonic_t *nstime_monotonic_orig; static nstime_monotonic_t *nstime_monotonic_orig;
static nstime_update_t *nstime_update_orig; static nstime_update_t *nstime_update_orig;

6
test/unit/decay.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/sh
export MALLOC_CONF="decay_time:1"
if [ "x${enable_tcache}" = "x1" ] ; then
export MALLOC_CONF="${MALLOC_CONF},lg_tcache_max:0"
fi

View File

@ -1,13 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_FILL
# ifndef JEMALLOC_TEST_JUNK_OPT
# define JEMALLOC_TEST_JUNK_OPT "junk:true"
# endif
const char *malloc_conf =
"abort:false,zero:false," JEMALLOC_TEST_JUNK_OPT;
#endif
static arena_dalloc_junk_small_t *arena_dalloc_junk_small_orig; static arena_dalloc_junk_small_t *arena_dalloc_junk_small_orig;
static large_dalloc_junk_t *large_dalloc_junk_orig; static large_dalloc_junk_t *large_dalloc_junk_orig;
static large_dalloc_maybe_junk_t *large_dalloc_maybe_junk_orig; static large_dalloc_maybe_junk_t *large_dalloc_maybe_junk_orig;

5
test/unit/junk.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="abort:false,zero:false,junk:true"
fi

View File

@ -1,3 +1 @@
#define JEMALLOC_TEST_JUNK_OPT "junk:alloc"
#include "junk.c" #include "junk.c"
#undef JEMALLOC_TEST_JUNK_OPT

5
test/unit/junk_alloc.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="abort:false,zero:false,junk:alloc"
fi

View File

@ -1,3 +1 @@
#define JEMALLOC_TEST_JUNK_OPT "junk:free"
#include "junk.c" #include "junk.c"
#undef JEMALLOC_TEST_JUNK_OPT

5
test/unit/junk_free.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="abort:false,zero:false,junk:free"
fi

View File

@ -1,8 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
/* Immediately purge to minimize fragmentation. */
const char *malloc_conf = "decay_time:-1";
/* /*
* Size class that is a divisor of the page size, ideally 4+ regions per run. * Size class that is a divisor of the page size, ideally 4+ regions per run.
*/ */

4
test/unit/pack.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Immediately purge to minimize fragmentation.
export MALLOC_CONF="decay_time:-1"

View File

@ -5,11 +5,6 @@
#define DUMP_INTERVAL 1 #define DUMP_INTERVAL 1
#define BT_COUNT_CHECK_INTERVAL 5 #define BT_COUNT_CHECK_INTERVAL 5
#ifdef JEMALLOC_PROF
const char *malloc_conf =
"prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0";
#endif
static int static int
prof_dump_open_intercept(bool propagate_err, const char *filename) { prof_dump_open_intercept(bool propagate_err, const char *filename) {
int fd; int fd;

5
test/unit/prof_accum.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0"
fi

View File

@ -1,10 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_PROF
const char *malloc_conf =
"prof:true,prof_thread_active_init:false,lg_prof_sample:0";
#endif
static void static void
mallctl_bool_get(const char *name, bool expected, const char *func, int line) { mallctl_bool_get(const char *name, bool expected, const char *func, int line) {
bool old; bool old;

5
test/unit/prof_active.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_thread_active_init:false,lg_prof_sample:0"
fi

View File

@ -1,9 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_PROF
const char *malloc_conf = "prof:true,prof_active:false,prof_gdump:true";
#endif
static bool did_prof_dump_open; static bool did_prof_dump_open;
static int static int

6
test/unit/prof_gdump.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_active:false,prof_gdump:true"
fi

View File

@ -1,18 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
const char *malloc_conf = ""
#ifdef JEMALLOC_PROF
"prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0"
",lg_prof_interval:0"
# ifdef JEMALLOC_TCACHE
","
# endif
#endif
#ifdef JEMALLOC_TCACHE
"tcache:false"
#endif
;
static bool did_prof_dump_open; static bool did_prof_dump_open;
static int static int

12
test/unit/prof_idump.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0,lg_prof_interval:0"
if [ "x${enable_tcache}" = "x1" ] ; then
export MALLOC_CONF="${MALLOC_CONF},tcache:false"
fi
elif [ "x${enable_tcache}" = "x1" ] ; then
export MALLOC_CONF="tcache:false"
fi

View File

@ -1,10 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_PROF
const char *malloc_conf =
"prof:true,prof_active:false,lg_prof_sample:0";
#endif
static int static int
prof_dump_open_intercept(bool propagate_err, const char *filename) { prof_dump_open_intercept(bool propagate_err, const char *filename) {
int fd; int fd;

5
test/unit/prof_reset.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_active:false,lg_prof_sample:0"
fi

View File

@ -1,9 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_PROF
const char *malloc_conf = "prof:true,lg_prof_sample:0";
#endif
TEST_BEGIN(test_prof_realloc) { TEST_BEGIN(test_prof_realloc) {
tsdn_t *tsdn; tsdn_t *tsdn;
int flags; int flags;

5
test/unit/prof_tctx.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,lg_prof_sample:0"
fi

View File

@ -1,9 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_PROF
const char *malloc_conf = "prof:true,prof_active:false";
#endif
static void static void
mallctl_thread_name_get_impl(const char *thread_name_expected, const char *func, mallctl_thread_name_get_impl(const char *thread_name_expected, const char *func,
int line) { int line) {

View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_active:false"
fi

View File

@ -1,10 +1,5 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
#ifdef JEMALLOC_FILL
const char *malloc_conf =
"abort:false,junk:false,zero:true";
#endif
static void static void
test_zero(size_t sz_min, size_t sz_max) { test_zero(size_t sz_min, size_t sz_max) {
uint8_t *s; uint8_t *s;

5
test/unit/zero.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ "x${enable_fill}" = "x1" ] ; then
export MALLOC_CONF="abort:false,junk:false,zero:true"
fi