From e85e588e45fd3bac1ddc3778e6f8bfe3f668f634 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 21 Feb 2017 23:40:06 -0800 Subject: [PATCH] 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. --- test/integration/chunk.c | 4 ---- test/integration/chunk.sh | 5 +++++ test/integration/mallocx.c | 4 ---- test/integration/mallocx.sh | 5 +++++ test/integration/xallocx.c | 4 ---- test/integration/xallocx.sh | 5 +++++ test/test.sh.in | 29 ++++++++++++++++++++++++++++- test/unit/arena_reset.c | 4 ---- test/unit/arena_reset.sh | 5 +++++ test/unit/decay.c | 2 -- test/unit/decay.sh | 3 +++ test/unit/junk.c | 8 -------- test/unit/junk.sh | 5 +++++ test/unit/junk_alloc.c | 2 -- test/unit/junk_alloc.sh | 5 +++++ test/unit/junk_free.c | 2 -- test/unit/junk_free.sh | 5 +++++ test/unit/lg_chunk.c | 7 ------- test/unit/lg_chunk.sh | 6 ++++++ test/unit/pack.c | 8 -------- test/unit/pack.sh | 5 +++++ test/unit/prof_accum.c | 5 ----- test/unit/prof_accum.sh | 5 +++++ test/unit/prof_active.c | 5 ----- test/unit/prof_active.sh | 5 +++++ test/unit/prof_gdump.c | 4 ---- test/unit/prof_gdump.sh | 6 ++++++ test/unit/prof_idump.c | 6 ------ test/unit/prof_idump.sh | 7 +++++++ test/unit/prof_reset.c | 5 ----- test/unit/prof_reset.sh | 5 +++++ test/unit/prof_tctx.sh | 5 +++++ test/unit/prof_thread_name.c | 4 ---- test/unit/prof_thread_name.sh | 5 +++++ test/unit/quarantine.c | 8 +------- test/unit/quarantine.sh | 8 ++++++++ test/unit/zero.c | 5 ----- test/unit/zero.sh | 5 +++++ 38 files changed, 129 insertions(+), 87 deletions(-) create mode 100644 test/integration/chunk.sh create mode 100644 test/integration/mallocx.sh create mode 100644 test/integration/xallocx.sh create mode 100644 test/unit/arena_reset.sh create mode 100644 test/unit/decay.sh create mode 100644 test/unit/junk.sh create mode 100644 test/unit/junk_alloc.sh create mode 100644 test/unit/junk_free.sh create mode 100644 test/unit/lg_chunk.sh create mode 100644 test/unit/pack.sh create mode 100644 test/unit/prof_accum.sh create mode 100644 test/unit/prof_active.sh create mode 100644 test/unit/prof_gdump.sh create mode 100644 test/unit/prof_idump.sh create mode 100644 test/unit/prof_reset.sh create mode 100644 test/unit/prof_tctx.sh create mode 100644 test/unit/prof_thread_name.sh create mode 100644 test/unit/quarantine.sh create mode 100644 test/unit/zero.sh diff --git a/test/integration/chunk.c b/test/integration/chunk.c index 94cf0025..997567a7 100644 --- a/test/integration/chunk.c +++ b/test/integration/chunk.c @@ -1,9 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_FILL -const char *malloc_conf = "junk:false"; -#endif - static chunk_hooks_t orig_hooks; static chunk_hooks_t old_hooks; diff --git a/test/integration/chunk.sh b/test/integration/chunk.sh new file mode 100644 index 00000000..0cc21873 --- /dev/null +++ b/test/integration/chunk.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="junk:false" +fi diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c index d709eb30..5a9058d4 100644 --- a/test/integration/mallocx.c +++ b/test/integration/mallocx.c @@ -1,9 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_FILL -const char *malloc_conf = "junk:false"; -#endif - static unsigned get_nsizes_impl(const char *cmd) { diff --git a/test/integration/mallocx.sh b/test/integration/mallocx.sh new file mode 100644 index 00000000..0cc21873 --- /dev/null +++ b/test/integration/mallocx.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="junk:false" +fi diff --git a/test/integration/xallocx.c b/test/integration/xallocx.c index 67e0a0e7..2517a812 100644 --- a/test/integration/xallocx.c +++ b/test/integration/xallocx.c @@ -1,9 +1,5 @@ #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 * internal allocation e.g. by heap profiling can't interpose allocations where diff --git a/test/integration/xallocx.sh b/test/integration/xallocx.sh new file mode 100644 index 00000000..0cc21873 --- /dev/null +++ b/test/integration/xallocx.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="junk:false" +fi diff --git a/test/test.sh.in b/test/test.sh.in index a39f99f6..f0f0f979 100644 --- a/test/test.sh.in +++ b/test/test.sh.in @@ -11,6 +11,18 @@ case @abi@ in ;; 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. pass_code=0 skip_code=1 @@ -24,7 +36,22 @@ for t in $@; do echo fi 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=$? case ${result_code} in ${pass_code}) diff --git a/test/unit/arena_reset.c b/test/unit/arena_reset.c index adf9baa5..ec1c214e 100644 --- a/test/unit/arena_reset.c +++ b/test/unit/arena_reset.c @@ -1,9 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_PROF -const char *malloc_conf = "prof:true,lg_prof_sample:0"; -#endif - static unsigned get_nsizes_impl(const char *cmd) { diff --git a/test/unit/arena_reset.sh b/test/unit/arena_reset.sh new file mode 100644 index 00000000..8fcc7d8a --- /dev/null +++ b/test/unit/arena_reset.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_prof}" = "x1" ] ; then + export MALLOC_CONF="prof:true,lg_prof_sample:0" +fi diff --git a/test/unit/decay.c b/test/unit/decay.c index 5af8f807..2d8d69d1 100644 --- a/test/unit/decay.c +++ b/test/unit/decay.c @@ -1,7 +1,5 @@ #include "test/jemalloc_test.h" -const char *malloc_conf = "purge:decay,decay_time:1"; - static nstime_monotonic_t *nstime_monotonic_orig; static nstime_update_t *nstime_update_orig; diff --git a/test/unit/decay.sh b/test/unit/decay.sh new file mode 100644 index 00000000..7b8f470e --- /dev/null +++ b/test/unit/decay.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +export MALLOC_CONF="purge:decay,decay_time:1" diff --git a/test/unit/junk.c b/test/unit/junk.c index 460bd524..bbd83fb9 100644 --- a/test/unit/junk.c +++ b/test/unit/junk.c @@ -1,13 +1,5 @@ #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,redzone:true,quarantine:0," JEMALLOC_TEST_JUNK_OPT; -#endif - static arena_dalloc_junk_small_t *arena_dalloc_junk_small_orig; static arena_dalloc_junk_large_t *arena_dalloc_junk_large_orig; static huge_dalloc_junk_t *huge_dalloc_junk_orig; diff --git a/test/unit/junk.sh b/test/unit/junk.sh new file mode 100644 index 00000000..e19c313e --- /dev/null +++ b/test/unit/junk.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="abort:false,zero:false,redzone:true,quarantine:0,junk:true" +fi diff --git a/test/unit/junk_alloc.c b/test/unit/junk_alloc.c index a5895b5c..a442a0ca 100644 --- a/test/unit/junk_alloc.c +++ b/test/unit/junk_alloc.c @@ -1,3 +1 @@ -#define JEMALLOC_TEST_JUNK_OPT "junk:alloc" #include "junk.c" -#undef JEMALLOC_TEST_JUNK_OPT diff --git a/test/unit/junk_alloc.sh b/test/unit/junk_alloc.sh new file mode 100644 index 00000000..984387d3 --- /dev/null +++ b/test/unit/junk_alloc.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="abort:false,zero:false,redzone:true,quarantine:0,junk:alloc" +fi diff --git a/test/unit/junk_free.c b/test/unit/junk_free.c index bb5183c9..a442a0ca 100644 --- a/test/unit/junk_free.c +++ b/test/unit/junk_free.c @@ -1,3 +1 @@ -#define JEMALLOC_TEST_JUNK_OPT "junk:free" #include "junk.c" -#undef JEMALLOC_TEST_JUNK_OPT diff --git a/test/unit/junk_free.sh b/test/unit/junk_free.sh new file mode 100644 index 00000000..a5c21a57 --- /dev/null +++ b/test/unit/junk_free.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="abort:false,zero:false,redzone:true,quarantine:0,junk:free" +fi diff --git a/test/unit/lg_chunk.c b/test/unit/lg_chunk.c index 7e5df381..d4f77b79 100644 --- a/test/unit/lg_chunk.c +++ b/test/unit/lg_chunk.c @@ -1,12 +1,5 @@ #include "test/jemalloc_test.h" -/* - * Make sure that opt.lg_chunk clamping is sufficient. In practice, this test - * program will fail a debug assertion during initialization and abort (rather - * than the test soft-failing) if clamping is insufficient. - */ -const char *malloc_conf = "lg_chunk:0"; - TEST_BEGIN(test_lg_chunk_clamp) { void *p; diff --git a/test/unit/lg_chunk.sh b/test/unit/lg_chunk.sh new file mode 100644 index 00000000..103eef1a --- /dev/null +++ b/test/unit/lg_chunk.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# Make sure that opt.lg_chunk clamping is sufficient. In practice, this test +# program will fail a debug assertion during initialization and abort (rather +# than the test soft-failing) if clamping is insufficient. +export MALLOC_CONF="lg_chunk:0" diff --git a/test/unit/pack.c b/test/unit/pack.c index 0b6ffcd2..991faa6b 100644 --- a/test/unit/pack.c +++ b/test/unit/pack.c @@ -1,13 +1,5 @@ #include "test/jemalloc_test.h" -const char *malloc_conf = - /* Use smallest possible chunk size. */ - "lg_chunk:0" - /* Immediately purge to minimize fragmentation. */ - ",lg_dirty_mult:-1" - ",decay_time:-1" - ; - /* * Size class that is a divisor of the page size, ideally 4+ regions per run. */ diff --git a/test/unit/pack.sh b/test/unit/pack.sh new file mode 100644 index 00000000..a58151d9 --- /dev/null +++ b/test/unit/pack.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# Use smallest possible chunk size. Immediately purge to minimize +# fragmentation. +export MALLOC_CONF="lg_chunk:0,lg_dirty_mult:-1,decay_time:-1" diff --git a/test/unit/prof_accum.c b/test/unit/prof_accum.c index d941b5bc..031f0837 100644 --- a/test/unit/prof_accum.c +++ b/test/unit/prof_accum.c @@ -5,11 +5,6 @@ #define DUMP_INTERVAL 1 #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 prof_dump_open_intercept(bool propagate_err, const char *filename) { diff --git a/test/unit/prof_accum.sh b/test/unit/prof_accum.sh new file mode 100644 index 00000000..b3e13fc5 --- /dev/null +++ b/test/unit/prof_accum.sh @@ -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 diff --git a/test/unit/prof_active.c b/test/unit/prof_active.c index d00943a4..a906beb7 100644 --- a/test/unit/prof_active.c +++ b/test/unit/prof_active.c @@ -1,10 +1,5 @@ #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 mallctl_bool_get(const char *name, bool expected, const char *func, int line) { diff --git a/test/unit/prof_active.sh b/test/unit/prof_active.sh new file mode 100644 index 00000000..0167cb10 --- /dev/null +++ b/test/unit/prof_active.sh @@ -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 diff --git a/test/unit/prof_gdump.c b/test/unit/prof_gdump.c index 996cb670..b88a74c5 100644 --- a/test/unit/prof_gdump.c +++ b/test/unit/prof_gdump.c @@ -1,9 +1,5 @@ #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 int diff --git a/test/unit/prof_gdump.sh b/test/unit/prof_gdump.sh new file mode 100644 index 00000000..3f600d20 --- /dev/null +++ b/test/unit/prof_gdump.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ "x${enable_prof}" = "x1" ] ; then + export MALLOC_CONF="prof:true,prof_active:false,prof_gdump:true" +fi + diff --git a/test/unit/prof_idump.c b/test/unit/prof_idump.c index 16c6462d..87734a4a 100644 --- a/test/unit/prof_idump.c +++ b/test/unit/prof_idump.c @@ -1,11 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_PROF -const char *malloc_conf = - "prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0," - "lg_prof_interval:0"; -#endif - static bool did_prof_dump_open; static int diff --git a/test/unit/prof_idump.sh b/test/unit/prof_idump.sh new file mode 100644 index 00000000..08a1b628 --- /dev/null +++ b/test/unit/prof_idump.sh @@ -0,0 +1,7 @@ +#!/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" +fi + + diff --git a/test/unit/prof_reset.c b/test/unit/prof_reset.c index 59d70796..87b0d0c0 100644 --- a/test/unit/prof_reset.c +++ b/test/unit/prof_reset.c @@ -1,10 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_PROF -const char *malloc_conf = - "prof:true,prof_active:false,lg_prof_sample:0"; -#endif - static int prof_dump_open_intercept(bool propagate_err, const char *filename) { diff --git a/test/unit/prof_reset.sh b/test/unit/prof_reset.sh new file mode 100644 index 00000000..43c516a0 --- /dev/null +++ b/test/unit/prof_reset.sh @@ -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 diff --git a/test/unit/prof_tctx.sh b/test/unit/prof_tctx.sh new file mode 100644 index 00000000..8fcc7d8a --- /dev/null +++ b/test/unit/prof_tctx.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_prof}" = "x1" ] ; then + export MALLOC_CONF="prof:true,lg_prof_sample:0" +fi diff --git a/test/unit/prof_thread_name.c b/test/unit/prof_thread_name.c index 9ec54977..3251853b 100644 --- a/test/unit/prof_thread_name.c +++ b/test/unit/prof_thread_name.c @@ -1,9 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_PROF -const char *malloc_conf = "prof:true,prof_active:false"; -#endif - static void mallctl_thread_name_get_impl(const char *thread_name_expected, const char *func, int line) diff --git a/test/unit/prof_thread_name.sh b/test/unit/prof_thread_name.sh new file mode 100644 index 00000000..298c1058 --- /dev/null +++ b/test/unit/prof_thread_name.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_prof}" = "x1" ] ; then + export MALLOC_CONF="prof:true,prof_active:false" +fi diff --git a/test/unit/quarantine.c b/test/unit/quarantine.c index bbd48a51..6068768b 100644 --- a/test/unit/quarantine.c +++ b/test/unit/quarantine.c @@ -1,13 +1,7 @@ #include "test/jemalloc_test.h" +/* Keep in sync with definition in quarantine.sh. */ #define QUARANTINE_SIZE 8192 -#define STRINGIFY_HELPER(x) #x -#define STRINGIFY(x) STRINGIFY_HELPER(x) - -#ifdef JEMALLOC_FILL -const char *malloc_conf = "abort:false,junk:true,redzone:true,quarantine:" - STRINGIFY(QUARANTINE_SIZE); -#endif void quarantine_clear(void) diff --git a/test/unit/quarantine.sh b/test/unit/quarantine.sh new file mode 100644 index 00000000..e3c6932c --- /dev/null +++ b/test/unit/quarantine.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Keep in sync with definition in quarantine.c. +export QUARANTINE_SIZE=8192 + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="abort:false,junk:true,redzone:true,quarantine:${QUARANTINE_SIZE}" +fi diff --git a/test/unit/zero.c b/test/unit/zero.c index 30ebe37a..573993a2 100644 --- a/test/unit/zero.c +++ b/test/unit/zero.c @@ -1,10 +1,5 @@ #include "test/jemalloc_test.h" -#ifdef JEMALLOC_FILL -const char *malloc_conf = - "abort:false,junk:false,zero:true,redzone:false,quarantine:0"; -#endif - static void test_zero(size_t sz_min, size_t sz_max) { diff --git a/test/unit/zero.sh b/test/unit/zero.sh new file mode 100644 index 00000000..24488f0f --- /dev/null +++ b/test/unit/zero.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_fill}" = "x1" ] ; then + export MALLOC_CONF="abort:false,junk:false,zero:true,redzone:false,quarantine:0" +fi