summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2014-10-02 00:51:52 (GMT)
committerJason Evans <jasone@canonware.com>2014-10-02 05:28:23 (GMT)
commitcc9e626ea97eb294f337c674685b8b5c9d5524b7 (patch)
treee9b5fd95b36be128acdf6183ac8f4fd97f633cb2 /test
parentf8034540a16a6f4fc7948e4783747ca1e9055823 (diff)
downloadjemalloc-cc9e626ea97eb294f337c674685b8b5c9d5524b7.zip
jemalloc-cc9e626ea97eb294f337c674685b8b5c9d5524b7.tar.gz
jemalloc-cc9e626ea97eb294f337c674685b8b5c9d5524b7.tar.bz2
Refactor permuted backtrace test allocation.
Refactor permuted backtrace test allocation that was originally used only by the prof_accum test, so that it can be used by other heap profiling test binaries.
Diffstat (limited to 'test')
-rw-r--r--test/include/test/btalloc.h31
-rw-r--r--test/include/test/jemalloc_test.h.in1
-rw-r--r--test/src/btalloc.c8
-rw-r--r--test/src/btalloc_0.c3
-rw-r--r--test/src/btalloc_1.c3
-rw-r--r--test/unit/prof_accum.c9
-rw-r--r--test/unit/prof_accum.h35
-rw-r--r--test/unit/prof_accum_a.c3
-rw-r--r--test/unit/prof_accum_b.c3
9 files changed, 53 insertions, 43 deletions
diff --git a/test/include/test/btalloc.h b/test/include/test/btalloc.h
new file mode 100644
index 0000000..c3f9d4d
--- /dev/null
+++ b/test/include/test/btalloc.h
@@ -0,0 +1,31 @@
+/* btalloc() provides a mechanism for allocating via permuted backtraces. */
+void *btalloc(size_t size, unsigned bits);
+
+#define btalloc_n_proto(n) \
+void *btalloc_##n(size_t size, unsigned bits);
+btalloc_n_proto(0)
+btalloc_n_proto(1)
+
+#define btalloc_n_gen(n) \
+void * \
+btalloc_##n(size_t size, unsigned bits) \
+{ \
+ void *p; \
+ \
+ if (bits == 0) \
+ p = mallocx(size, 0); \
+ else { \
+ switch (bits & 0x1U) { \
+ case 0: \
+ p = (btalloc_0(size, bits >> 1)); \
+ break; \
+ case 1: \
+ p = (btalloc_1(size, bits >> 1)); \
+ break; \
+ default: not_reached(); \
+ } \
+ } \
+ /* Intentionally sabotage tail call optimization. */ \
+ assert_ptr_not_null(p, "Unexpected mallocx() failure"); \
+ return (p); \
+}
diff --git a/test/include/test/jemalloc_test.h.in b/test/include/test/jemalloc_test.h.in
index a93c4f6..6018e58 100644
--- a/test/include/test/jemalloc_test.h.in
+++ b/test/include/test/jemalloc_test.h.in
@@ -133,6 +133,7 @@
/*
* Common test utilities.
*/
+#include "test/btalloc.h"
#include "test/math.h"
#include "test/mtx.h"
#include "test/mq.h"
diff --git a/test/src/btalloc.c b/test/src/btalloc.c
new file mode 100644
index 0000000..9a253d9
--- /dev/null
+++ b/test/src/btalloc.c
@@ -0,0 +1,8 @@
+#include "test/jemalloc_test.h"
+
+void *
+btalloc(size_t size, unsigned bits)
+{
+
+ return (btalloc_0(size, bits));
+}
diff --git a/test/src/btalloc_0.c b/test/src/btalloc_0.c
new file mode 100644
index 0000000..77d8904
--- /dev/null
+++ b/test/src/btalloc_0.c
@@ -0,0 +1,3 @@
+#include "test/jemalloc_test.h"
+
+btalloc_n_gen(0)
diff --git a/test/src/btalloc_1.c b/test/src/btalloc_1.c
new file mode 100644
index 0000000..4c126c3
--- /dev/null
+++ b/test/src/btalloc_1.c
@@ -0,0 +1,3 @@
+#include "test/jemalloc_test.h"
+
+btalloc_n_gen(1)
diff --git a/test/unit/prof_accum.c b/test/unit/prof_accum.c
index 050a8a7..fd229e0 100644
--- a/test/unit/prof_accum.c
+++ b/test/unit/prof_accum.c
@@ -1,4 +1,9 @@
-#include "prof_accum.h"
+#include "test/jemalloc_test.h"
+
+#define NTHREADS 4
+#define NALLOCS_PER_THREAD 50
+#define DUMP_INTERVAL 1
+#define BT_COUNT_CHECK_INTERVAL 5
#ifdef JEMALLOC_PROF
const char *malloc_conf =
@@ -20,7 +25,7 @@ static void *
alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration)
{
- return (alloc_0(thd_ind*NALLOCS_PER_THREAD + iteration));
+ return (btalloc(1, thd_ind*NALLOCS_PER_THREAD + iteration));
}
static void *
diff --git a/test/unit/prof_accum.h b/test/unit/prof_accum.h
deleted file mode 100644
index 109d86b..0000000
--- a/test/unit/prof_accum.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "test/jemalloc_test.h"
-
-#define NTHREADS 4
-#define NALLOCS_PER_THREAD 50
-#define DUMP_INTERVAL 1
-#define BT_COUNT_CHECK_INTERVAL 5
-
-#define alloc_n_proto(n) \
-void *alloc_##n(unsigned bits);
-alloc_n_proto(0)
-alloc_n_proto(1)
-
-#define alloc_n_gen(n) \
-void * \
-alloc_##n(unsigned bits) \
-{ \
- void *p; \
- \
- if (bits == 0) \
- p = mallocx(1, 0); \
- else { \
- switch (bits & 0x1U) { \
- case 0: \
- p = (alloc_0(bits >> 1)); \
- break; \
- case 1: \
- p = (alloc_1(bits >> 1)); \
- break; \
- default: not_reached(); \
- } \
- } \
- /* Intentionally sabotage tail call optimization. */ \
- assert_ptr_not_null(p, "Unexpected mallocx() failure"); \
- return (p); \
-}
diff --git a/test/unit/prof_accum_a.c b/test/unit/prof_accum_a.c
deleted file mode 100644
index 42ad521..0000000
--- a/test/unit/prof_accum_a.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "prof_accum.h"
-
-alloc_n_gen(0)
diff --git a/test/unit/prof_accum_b.c b/test/unit/prof_accum_b.c
deleted file mode 100644
index 60d9dab..0000000
--- a/test/unit/prof_accum_b.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "prof_accum.h"
-
-alloc_n_gen(1)