summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorGuilherme Goncalves <guilherme.p.gonc@gmail.com>2014-12-08 21:12:41 (GMT)
committerJason Evans <jasone@canonware.com>2014-12-15 01:07:26 (GMT)
commit2c5cb613dfbdf58f88152321b63e60c58cd23972 (patch)
tree9c32a6519cb435203141d19a0c0f60fa111803e0 /test/unit
parentb74041fb6e279bd8bbc133250241249f90cd619f (diff)
downloadjemalloc-2c5cb613dfbdf58f88152321b63e60c58cd23972.zip
jemalloc-2c5cb613dfbdf58f88152321b63e60c58cd23972.tar.gz
jemalloc-2c5cb613dfbdf58f88152321b63e60c58cd23972.tar.bz2
Introduce two new modes of junk filling: "alloc" and "free".
In addition to true/false, opt.junk can now be either "alloc" or "free", giving applications the possibility of junking memory only on allocation or deallocation. This resolves #172.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/junk.c41
-rw-r--r--test/unit/junk_alloc.c3
-rw-r--r--test/unit/junk_free.c3
-rw-r--r--test/unit/mallctl.c2
4 files changed, 33 insertions, 16 deletions
diff --git a/test/unit/junk.c b/test/unit/junk.c
index 1522a61..733f661 100644
--- a/test/unit/junk.c
+++ b/test/unit/junk.c
@@ -1,8 +1,11 @@
#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,junk:true,zero:false,redzone:true,quarantine:0";
+ "abort:false,zero:false,redzone:true,quarantine:0," JEMALLOC_TEST_JUNK_OPT;
#endif
static arena_dalloc_junk_small_t *arena_dalloc_junk_small_orig;
@@ -69,12 +72,14 @@ test_junk(size_t sz_min, size_t sz_max)
char *s;
size_t sz_prev, sz, i;
- arena_dalloc_junk_small_orig = arena_dalloc_junk_small;
- arena_dalloc_junk_small = arena_dalloc_junk_small_intercept;
- arena_dalloc_junk_large_orig = arena_dalloc_junk_large;
- arena_dalloc_junk_large = arena_dalloc_junk_large_intercept;
- huge_dalloc_junk_orig = huge_dalloc_junk;
- huge_dalloc_junk = huge_dalloc_junk_intercept;
+ if (opt_junk_free) {
+ arena_dalloc_junk_small_orig = arena_dalloc_junk_small;
+ arena_dalloc_junk_small = arena_dalloc_junk_small_intercept;
+ arena_dalloc_junk_large_orig = arena_dalloc_junk_large;
+ arena_dalloc_junk_large = arena_dalloc_junk_large_intercept;
+ huge_dalloc_junk_orig = huge_dalloc_junk;
+ huge_dalloc_junk = huge_dalloc_junk_intercept;
+ }
sz_prev = 0;
s = (char *)mallocx(sz_min, 0);
@@ -92,9 +97,11 @@ test_junk(size_t sz_min, size_t sz_max)
}
for (i = sz_prev; i < sz; i++) {
- assert_c_eq(s[i], 0xa5,
- "Newly allocated byte %zu/%zu isn't junk-filled",
- i, sz);
+ if (opt_junk_alloc) {
+ assert_c_eq(s[i], 0xa5,
+ "Newly allocated byte %zu/%zu isn't "
+ "junk-filled", i, sz);
+ }
s[i] = 'a';
}
@@ -103,7 +110,7 @@ test_junk(size_t sz_min, size_t sz_max)
s = (char *)rallocx(s, sz+1, 0);
assert_ptr_not_null((void *)s,
"Unexpected rallocx() failure");
- assert_true(saw_junking,
+ assert_true(!opt_junk_free || saw_junking,
"Expected region of size %zu to be junk-filled",
sz);
}
@@ -111,12 +118,14 @@ test_junk(size_t sz_min, size_t sz_max)
watch_junking(s);
dallocx(s, 0);
- assert_true(saw_junking,
+ assert_true(!opt_junk_free || saw_junking,
"Expected region of size %zu to be junk-filled", sz);
- arena_dalloc_junk_small = arena_dalloc_junk_small_orig;
- arena_dalloc_junk_large = arena_dalloc_junk_large_orig;
- huge_dalloc_junk = huge_dalloc_junk_orig;
+ if (opt_junk_free) {
+ arena_dalloc_junk_small = arena_dalloc_junk_small_orig;
+ arena_dalloc_junk_large = arena_dalloc_junk_large_orig;
+ huge_dalloc_junk = huge_dalloc_junk_orig;
+ }
}
TEST_BEGIN(test_junk_small)
@@ -204,6 +213,7 @@ TEST_BEGIN(test_junk_redzone)
arena_redzone_corruption_t *arena_redzone_corruption_orig;
test_skip_if(!config_fill);
+ test_skip_if(!opt_junk_alloc || !opt_junk_free);
arena_redzone_corruption_orig = arena_redzone_corruption;
arena_redzone_corruption = arena_redzone_corruption_replacement;
@@ -234,6 +244,7 @@ int
main(void)
{
+ assert(opt_junk_alloc || opt_junk_free);
return (test(
test_junk_small,
test_junk_large,
diff --git a/test/unit/junk_alloc.c b/test/unit/junk_alloc.c
new file mode 100644
index 0000000..8db3331
--- /dev/null
+++ b/test/unit/junk_alloc.c
@@ -0,0 +1,3 @@
+#define JEMALLOC_TEST_JUNK_OPT "junk:alloc"
+#include "junk.c"
+#undef JEMALLOC_TEST_JUNK_OPT
diff --git a/test/unit/junk_free.c b/test/unit/junk_free.c
new file mode 100644
index 0000000..482a61d
--- /dev/null
+++ b/test/unit/junk_free.c
@@ -0,0 +1,3 @@
+#define JEMALLOC_TEST_JUNK_OPT "junk:free"
+#include "junk.c"
+#undef JEMALLOC_TEST_JUNK_OPT
diff --git a/test/unit/mallctl.c b/test/unit/mallctl.c
index 028a971..f4b7d1a 100644
--- a/test/unit/mallctl.c
+++ b/test/unit/mallctl.c
@@ -164,7 +164,7 @@ TEST_BEGIN(test_mallctl_opt)
TEST_MALLCTL_OPT(size_t, narenas, always);
TEST_MALLCTL_OPT(ssize_t, lg_dirty_mult, always);
TEST_MALLCTL_OPT(bool, stats_print, always);
- TEST_MALLCTL_OPT(bool, junk, fill);
+ TEST_MALLCTL_OPT(const char *, junk, fill);
TEST_MALLCTL_OPT(size_t, quarantine, fill);
TEST_MALLCTL_OPT(bool, redzone, fill);
TEST_MALLCTL_OPT(bool, zero, fill);