summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/include/test/jemalloc_test.h.in111
-rw-r--r--test/include/test/test.h2
-rw-r--r--test/include/test/thread.h12
-rw-r--r--test/integration/ALLOCM_ARENA.c (renamed from test/ALLOCM_ARENA.c)3
-rw-r--r--test/integration/ALLOCM_ARENA.exp (renamed from test/ALLOCM_ARENA.exp)0
-rw-r--r--test/integration/aligned_alloc.c (renamed from test/aligned_alloc.c)6
-rw-r--r--test/integration/aligned_alloc.exp (renamed from test/aligned_alloc.exp)0
-rw-r--r--test/integration/allocated.c (renamed from test/allocated.c)21
-rw-r--r--test/integration/allocated.exp (renamed from test/allocated.exp)0
-rw-r--r--test/integration/allocm.c (renamed from test/allocm.c)9
-rw-r--r--test/integration/allocm.exp (renamed from test/allocm.exp)0
-rw-r--r--test/integration/jemalloc_integration.h.in (renamed from test/jemalloc_test.h.in)15
-rw-r--r--test/integration/mremap.c (renamed from test/mremap.c)3
-rw-r--r--test/integration/mremap.exp (renamed from test/mremap.exp)0
-rw-r--r--test/integration/posix_memalign.c (renamed from test/posix_memalign.c)6
-rw-r--r--test/integration/posix_memalign.exp (renamed from test/posix_memalign.exp)0
-rw-r--r--test/integration/rallocm.c (renamed from test/rallocm.c)5
-rw-r--r--test/integration/rallocm.exp (renamed from test/rallocm.exp)0
-rw-r--r--test/integration/thread_arena.c (renamed from test/thread_arena.c)3
-rw-r--r--test/integration/thread_arena.exp (renamed from test/thread_arena.exp)0
-rw-r--r--test/integration/thread_tcache_enabled.c (renamed from test/thread_tcache_enabled.c)3
-rw-r--r--test/integration/thread_tcache_enabled.exp (renamed from test/thread_tcache_enabled.exp)0
-rw-r--r--test/src/test.c28
-rw-r--r--test/src/thread.c35
-rw-r--r--test/test.sh.in37
-rw-r--r--test/unit/bitmap.c (renamed from test/bitmap.c)4
-rw-r--r--test/unit/bitmap.exp (renamed from test/bitmap.exp)0
27 files changed, 253 insertions, 50 deletions
diff --git a/test/include/test/jemalloc_test.h.in b/test/include/test/jemalloc_test.h.in
new file mode 100644
index 0000000..1d18eec
--- /dev/null
+++ b/test/include/test/jemalloc_test.h.in
@@ -0,0 +1,111 @@
+#include <stdlib.h>
+#include <stdbool.h>
+
+/******************************************************************************/
+/*
+ * Define always-enabled assertion macros, so that test assertions execute even
+ * if assertions are disabled in the library code. These definitions must
+ * exist prior to including "jemalloc/internal/util.h".
+ */
+#define assert(e) do { \
+ if (!(e)) { \
+ malloc_printf( \
+ "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \
+ __FILE__, __LINE__, #e); \
+ abort(); \
+ } \
+} while (0)
+
+#define not_reached() do { \
+ malloc_printf( \
+ "<jemalloc>: %s:%d: Unreachable code reached\n", \
+ __FILE__, __LINE__); \
+ abort(); \
+} while (0)
+
+#define not_implemented() do { \
+ malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \
+ __FILE__, __LINE__); \
+ abort(); \
+} while (0)
+
+#define assert_not_implemented(e) do { \
+ if (!(e)) \
+ not_implemented(); \
+} while (0)
+
+/******************************************************************************/
+/*
+ * For unit tests, expose all public and private interfaces.
+ */
+#ifdef JEMALLOC_UNIT_TEST
+# define JEMALLOC_JET
+# include "jemalloc/internal/jemalloc_internal.h"
+
+/******************************************************************************/
+/*
+ * For integration tests, expose the public jemalloc interfaces, but only
+ * expose the minimum necessary internal utility code (to avoid re-implementing
+ * essentially identical code within the test infrastructure).
+ */
+#elif defined(JEMALLOC_INTEGRATION_TEST)
+# define JEMALLOC_MANGLE
+# include "jemalloc/jemalloc@install_suffix@.h"
+# include "jemalloc/internal/jemalloc_internal_defs.h"
+
+# define JEMALLOC_N(n) @private_namespace@##n
+# include "jemalloc/internal/private_namespace.h"
+
+# include <inttypes.h>
+# include <stdarg.h>
+# include <errno.h>
+# define JEMALLOC_CC_SILENCE
+# define JEMALLOC_H_TYPES
+# define JEMALLOC_H_STRUCTS
+# define JEMALLOC_H_EXTERNS
+# define JEMALLOC_H_INLINES
+# include "jemalloc/internal/util.h"
+# undef JEMALLOC_H_TYPES
+# undef JEMALLOC_H_STRUCTS
+# undef JEMALLOC_H_EXTERNS
+# undef JEMALLOC_H_INLINES
+# undef JEMALLOC_CC_SILENCE
+
+/******************************************************************************/
+/*
+ * For stress tests, expose the public jemalloc interfaces with name mangling
+ * so that they can be tested as e.g. malloc() and free(). Also expose the
+ * public jemalloc interfaces with jet_ prefixes, so that stress tests can use
+ * a separate allocator for their internal data structures.
+ */
+#elif defined(JEMALLOC_STRESS_TEST)
+# define JEMALLOC_NO_DEMANGLE
+# include "jemalloc/jemalloc@install_suffix@.h"
+# include "jemalloc/internal/public_unnamespace.h"
+# undef JEMALLOC_NO_DEMANGLE
+
+# include "jemalloc/jemalloc_protos_jet.h"
+
+# define JEMALLOC_JET
+# include "jemalloc/internal/jemalloc_internal.h"
+# include "jemalloc/internal/public_unnamespace.h"
+# undef JEMALLOC_JET
+
+# define JEMALLOC_MANGLE
+# include "jemalloc/jemalloc_mangle@install_suffix@.h"
+
+/******************************************************************************/
+/*
+ * This header does dangerous things, the effects of which only test code
+ * should be subject to.
+ */
+#else
+# error "This header cannot be included outside a testing context"
+#endif
+
+/******************************************************************************/
+/*
+ * Common test utilities.
+ */
+#include "test/test.h"
+#include "test/thread.h"
diff --git a/test/include/test/test.h b/test/include/test/test.h
new file mode 100644
index 0000000..ddbc55f
--- /dev/null
+++ b/test/include/test/test.h
@@ -0,0 +1,2 @@
+void test_fail(const char *format, ...) JEMALLOC_ATTR(format(printf, 1, 2));
+void test_skip(const char *format, ...) JEMALLOC_ATTR(format(printf, 1, 2));
diff --git a/test/include/test/thread.h b/test/include/test/thread.h
new file mode 100644
index 0000000..e3c0e27
--- /dev/null
+++ b/test/include/test/thread.h
@@ -0,0 +1,12 @@
+
+/* Abstraction layer for threading in tests */
+#ifdef _WIN32
+#include <windows.h>
+typedef HANDLE je_thread_t;
+#else
+#include <pthread.h>
+typedef pthread_t je_thread_t;
+#endif
+
+void je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg);
+void je_thread_join(je_thread_t thread, void **ret);
diff --git a/test/ALLOCM_ARENA.c b/test/integration/ALLOCM_ARENA.c
index ca91b62..e83056c 100644
--- a/test/ALLOCM_ARENA.c
+++ b/test/integration/ALLOCM_ARENA.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
#define NTHREADS 10
diff --git a/test/ALLOCM_ARENA.exp b/test/integration/ALLOCM_ARENA.exp
index 369a88d..369a88d 100644
--- a/test/ALLOCM_ARENA.exp
+++ b/test/integration/ALLOCM_ARENA.exp
diff --git a/test/aligned_alloc.c b/test/integration/aligned_alloc.c
index 5a9b0ca..2c44751 100644
--- a/test/aligned_alloc.c
+++ b/test/integration/aligned_alloc.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
#define CHUNK 0x400000
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
@@ -96,10 +95,9 @@ main(void)
char buf[BUFERROR_BUF];
buferror(buf, sizeof(buf));
- malloc_printf(
+ test_fail(
"Error for size %zu (%#zx): %s\n",
size, size, buf);
- exit(1);
}
total += malloc_usable_size(ps[i]);
if (total >= (MAXALIGN << 1))
diff --git a/test/aligned_alloc.exp b/test/integration/aligned_alloc.exp
index b5061c7..b5061c7 100644
--- a/test/aligned_alloc.exp
+++ b/test/integration/aligned_alloc.exp
diff --git a/test/allocated.c b/test/integration/allocated.c
index b1a9cfd..73ea738 100644
--- a/test/allocated.c
+++ b/test/integration/allocated.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
void *
je_thread_start(void *arg)
@@ -18,9 +17,8 @@ je_thread_start(void *arg)
#endif
goto label_return;
}
- malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
+ test_fail("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
- exit(1);
}
sz = sizeof(ap0);
if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
@@ -30,9 +28,8 @@ je_thread_start(void *arg)
#endif
goto label_return;
}
- malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
+ test_fail("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
- exit(1);
}
assert(*ap0 == a0);
@@ -44,9 +41,8 @@ je_thread_start(void *arg)
#endif
goto label_return;
}
- malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
+ test_fail("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
- exit(1);
}
sz = sizeof(dp0);
if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
@@ -56,17 +52,14 @@ je_thread_start(void *arg)
#endif
goto label_return;
}
- malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
+ test_fail("%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
- exit(1);
}
assert(*dp0 == d0);
p = malloc(1);
- if (p == NULL) {
- malloc_printf("%s(): Error in malloc()\n", __func__);
- exit(1);
- }
+ if (p == NULL)
+ test_fail("%s(): Error in malloc()\n", __func__);
sz = sizeof(a1);
mallctl("thread.allocated", &a1, &sz, NULL, 0);
diff --git a/test/allocated.exp b/test/integration/allocated.exp
index 369a88d..369a88d 100644
--- a/test/allocated.exp
+++ b/test/integration/allocated.exp
diff --git a/test/allocm.c b/test/integration/allocm.c
index 80be673..3b89282 100644
--- a/test/allocm.c
+++ b/test/integration/allocm.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
#define CHUNK 0x400000
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
@@ -144,21 +143,19 @@ main(void)
r = nallocm(&nsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) {
- malloc_printf(
+ test_fail(
"nallocm() error for size %zu"
" (%#zx): %d\n",
sz, sz, r);
- exit(1);
}
rsz = 0;
r = allocm(&ps[i], &rsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) {
- malloc_printf(
+ test_fail(
"allocm() error for size %zu"
" (%#zx): %d\n",
sz, sz, r);
- exit(1);
}
if (rsz < sz) {
malloc_printf(
diff --git a/test/allocm.exp b/test/integration/allocm.exp
index b5061c7..b5061c7 100644
--- a/test/allocm.exp
+++ b/test/integration/allocm.exp
diff --git a/test/jemalloc_test.h.in b/test/integration/jemalloc_integration.h.in
index e38b48e..4730aab 100644
--- a/test/jemalloc_test.h.in
+++ b/test/integration/jemalloc_integration.h.in
@@ -6,7 +6,7 @@
#include "jemalloc/jemalloc@install_suffix@.h"
#include "jemalloc/internal/jemalloc_internal.h"
-/* Abstraction layer for threading in tests */
+/* Abstraction layer for threading in tests. */
#ifdef _WIN32
#include <windows.h>
@@ -17,15 +17,14 @@ je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
{
LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
*thread = CreateThread(NULL, 0, routine, arg, 0, NULL);
- if (*thread == NULL) {
- malloc_printf("Error in CreateThread()\n");
- exit(1);
- }
+ if (*thread == NULL)
+ test_fail("Error in CreateThread()\n");
}
void
je_thread_join(je_thread_t thread, void **ret)
{
+
WaitForSingleObject(thread, INFINITE);
}
@@ -38,10 +37,8 @@ void
je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
{
- if (pthread_create(thread, NULL, proc, arg) != 0) {
- malloc_printf("Error in pthread_create()\n");
- exit(1);
- }
+ if (pthread_create(thread, NULL, proc, arg) != 0)
+ test_fail("Error in pthread_create()\n");
}
void
diff --git a/test/mremap.c b/test/integration/mremap.c
index 47efa7c..cdef9de 100644
--- a/test/mremap.c
+++ b/test/integration/mremap.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
int
main(void)
diff --git a/test/mremap.exp b/test/integration/mremap.exp
index 369a88d..369a88d 100644
--- a/test/mremap.exp
+++ b/test/integration/mremap.exp
diff --git a/test/posix_memalign.c b/test/integration/posix_memalign.c
index 2185bcf..dc5cd0e 100644
--- a/test/posix_memalign.c
+++ b/test/integration/posix_memalign.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
#define CHUNK 0x400000
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
@@ -92,10 +91,9 @@ main(void)
err = posix_memalign(&ps[i],
alignment, size);
if (err) {
- malloc_printf(
+ test_fail(
"Error for size %zu (%#zx): %s\n",
size, size, strerror(err));
- exit(1);
}
total += malloc_usable_size(ps[i]);
if (total >= (MAXALIGN << 1))
diff --git a/test/posix_memalign.exp b/test/integration/posix_memalign.exp
index b5061c7..b5061c7 100644
--- a/test/posix_memalign.exp
+++ b/test/integration/posix_memalign.exp
diff --git a/test/rallocm.c b/test/integration/rallocm.c
index c5dedf4..2c10dba 100644
--- a/test/rallocm.c
+++ b/test/integration/rallocm.c
@@ -1,5 +1,6 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include <unistd.h>
+
+#include "test/jemalloc_test.h"
int
main(void)
diff --git a/test/rallocm.exp b/test/integration/rallocm.exp
index 369a88d..369a88d 100644
--- a/test/rallocm.exp
+++ b/test/integration/rallocm.exp
diff --git a/test/thread_arena.c b/test/integration/thread_arena.c
index 6b9bc9c..eb5b098 100644
--- a/test/thread_arena.c
+++ b/test/integration/thread_arena.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
#define NTHREADS 10
diff --git a/test/thread_arena.exp b/test/integration/thread_arena.exp
index 369a88d..369a88d 100644
--- a/test/thread_arena.exp
+++ b/test/integration/thread_arena.exp
diff --git a/test/thread_tcache_enabled.c b/test/integration/thread_tcache_enabled.c
index 586b533..f9da052 100644
--- a/test/thread_tcache_enabled.c
+++ b/test/integration/thread_tcache_enabled.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
void *
je_thread_start(void *arg)
diff --git a/test/thread_tcache_enabled.exp b/test/integration/thread_tcache_enabled.exp
index 369a88d..369a88d 100644
--- a/test/thread_tcache_enabled.exp
+++ b/test/integration/thread_tcache_enabled.exp
diff --git a/test/src/test.c b/test/src/test.c
new file mode 100644
index 0000000..1bc34b4
--- /dev/null
+++ b/test/src/test.c
@@ -0,0 +1,28 @@
+#include "test/jemalloc_test.h"
+
+#define JEMALLOC_TEST_EXIT_FAIL 1
+#define JEMALLOC_TEST_EXIT_SKIP 2
+
+JEMALLOC_ATTR(format(printf, 1, 2))
+void
+test_fail(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ malloc_vcprintf(NULL, NULL, format, ap);
+ va_end(ap);
+ exit(JEMALLOC_TEST_EXIT_FAIL);
+}
+
+JEMALLOC_ATTR(format(printf, 1, 2))
+void
+test_skip(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ malloc_vcprintf(NULL, NULL, format, ap);
+ va_end(ap);
+ exit(JEMALLOC_TEST_EXIT_SKIP);
+}
diff --git a/test/src/thread.c b/test/src/thread.c
new file mode 100644
index 0000000..5a91e27
--- /dev/null
+++ b/test/src/thread.c
@@ -0,0 +1,35 @@
+#include "test/jemalloc_test.h"
+
+#ifdef _WIN32
+void
+je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
+{
+ LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
+ *thread = CreateThread(NULL, 0, routine, arg, 0, NULL);
+ if (*thread == NULL)
+ test_fail("Error in CreateThread()\n");
+}
+
+void
+je_thread_join(je_thread_t thread, void **ret)
+{
+
+ WaitForSingleObject(thread, INFINITE);
+}
+
+#else
+void
+je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
+{
+
+ if (pthread_create(thread, NULL, proc, arg) != 0)
+ test_fail("Error in pthread_create()\n");
+}
+
+void
+je_thread_join(je_thread_t thread, void **ret)
+{
+
+ pthread_join(thread, ret);
+}
+#endif
diff --git a/test/test.sh.in b/test/test.sh.in
new file mode 100644
index 0000000..726cd63
--- /dev/null
+++ b/test/test.sh.in
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+case @abi@ in
+ macho)
+ export DYLD_FALLBACK_LIBRARY_PATH="@objroot@lib"
+ ;;
+ pecoff)
+ export PATH="${PATH}:@objroot@lib"
+ ;;
+ *)
+ ;;
+esac
+
+total=0
+failures=0
+echo "========================================="
+for t in $@; do
+ total=`expr $total + 1`
+ /bin/echo -n "${t} ... "
+ ${t}@exe@ @abs_srcroot@ @abs_objroot@ > @objroot@${t}.out 2>&1
+ result=$?
+ if [ -e "@srcroot@${t}.exp" ] ; then
+ diff -w -u @srcroot@${t}.exp @objroot@${t}.out >/dev/null 2>&1
+ fail=$?
+ if [ "${fail}" -eq "1" ] ; then
+ failures=`expr ${failures} + 1`
+ echo "*** FAIL ***"
+ else
+ echo "pass"
+ fi
+ else
+ echo "*** FAIL *** (.exp file is missing)"
+ failures=`expr ${failures} + 1`
+ fi
+done
+echo "========================================="
+echo "Failures: ${failures}/${total}"
diff --git a/test/bitmap.c b/test/unit/bitmap.c
index b2cb630..37c3043 100644
--- a/test/bitmap.c
+++ b/test/unit/bitmap.c
@@ -1,5 +1,4 @@
-#define JEMALLOC_MANGLE
-#include "jemalloc_test.h"
+#include "test/jemalloc_test.h"
#if (LG_BITMAP_MAXBITS > 12)
# define MAXBITS 4500
@@ -37,7 +36,6 @@ test_bitmap_init(void)
for (j = 0; j < i; j++)
assert(bitmap_get(bitmap, &binfo, j) == false);
free(bitmap);
-
}
}
}
diff --git a/test/bitmap.exp b/test/unit/bitmap.exp
index 369a88d..369a88d 100644
--- a/test/bitmap.exp
+++ b/test/unit/bitmap.exp