Replace fprintf with malloc_printf in tests.

This commit is contained in:
Mike Hommey 2012-04-16 16:30:26 +02:00 committed by Jason Evans
parent fa08da752b
commit 45f208e112
12 changed files with 108 additions and 108 deletions

View File

@ -148,10 +148,12 @@ $(objroot)test/%.$(O): $(srcroot)test/%.c
$(CC) $(CFLAGS) -c $(CPPFLAGS) -I$(objroot)test -o $@ $< $(CC) $(CFLAGS) -c $(CPPFLAGS) -I$(objroot)test -o $@ $<
@$(CC) -MM $(CPPFLAGS) -I$(objroot)test -MT $@ -o $(@:%.$(O)=%.d) $< @$(CC) -MM $(CPPFLAGS) -I$(objroot)test -MT $@ -o $(@:%.$(O)=%.d) $<
$(objroot)test/%$(EXE): $(objroot)test/%.$(O) \ $(objroot)test/bitmap$(EXE): $(objroot)src/bitmap.$(O)
$(objroot)test/%$(EXE): $(objroot)test/%.$(O) $(objroot)src/util.$(O) \
$(objroot)lib/$(LIBJEMALLOC).$(SO) $(objroot)lib/$(LIBJEMALLOC).$(SO)
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) -o $@ $< $(call RPATH,$(objroot)lib) -L$(objroot)lib -ljemalloc$(install_suffix) $(LIBS) $(CC) -o $@ $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) -L$(objroot)lib -ljemalloc$(install_suffix) $(LIBS)
build_lib_shared: $(DSOS) build_lib_shared: $(DSOS)
build_lib_static: $(STATIC_LIBS) build_lib_static: $(STATIC_LIBS)

View File

@ -1,3 +1,5 @@
#ifndef JEMALLOC_INTERNAL_H
#define JEMALLOC_INTERNAL_H
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/syscall.h> #include <sys/syscall.h>
@ -868,3 +870,4 @@ malloc_tsd_funcs(JEMALLOC_INLINE, thread_allocated, thread_allocated_t,
#undef JEMALLOC_H_INLINES #undef JEMALLOC_H_INLINES
/******************************************************************************/ /******************************************************************************/
#endif /* JEMALLOC_INTERNAL_H */

View File

@ -20,14 +20,14 @@ main(void)
unsigned i; unsigned i;
void *p, *ps[NITER]; void *p, *ps[NITER];
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
/* Test error conditions. */ /* Test error conditions. */
alignment = 0; alignment = 0;
errno = 0; errno = 0;
p = aligned_alloc(alignment, 1); p = aligned_alloc(alignment, 1);
if (p != NULL || errno != EINVAL) { if (p != NULL || errno != EINVAL) {
fprintf(stderr, malloc_printf(
"Expected error for invalid alignment %zu\n", alignment); "Expected error for invalid alignment %zu\n", alignment);
} }
@ -36,7 +36,7 @@ main(void)
errno = 0; errno = 0;
p = aligned_alloc(alignment + 1, 1); p = aligned_alloc(alignment + 1, 1);
if (p != NULL || errno != EINVAL) { if (p != NULL || errno != EINVAL) {
fprintf(stderr, malloc_printf(
"Expected error for invalid alignment %zu\n", "Expected error for invalid alignment %zu\n",
alignment + 1); alignment + 1);
} }
@ -52,7 +52,7 @@ main(void)
errno = 0; errno = 0;
p = aligned_alloc(alignment, size); p = aligned_alloc(alignment, size);
if (p != NULL || errno != ENOMEM) { if (p != NULL || errno != ENOMEM) {
fprintf(stderr, malloc_printf(
"Expected error for aligned_alloc(%zu, %zu)\n", "Expected error for aligned_alloc(%zu, %zu)\n",
alignment, size); alignment, size);
} }
@ -67,7 +67,7 @@ main(void)
errno = 0; errno = 0;
p = aligned_alloc(alignment, size); p = aligned_alloc(alignment, size);
if (p != NULL || errno != ENOMEM) { if (p != NULL || errno != ENOMEM) {
fprintf(stderr, malloc_printf(
"Expected error for aligned_alloc(%zu, %zu)\n", "Expected error for aligned_alloc(%zu, %zu)\n",
alignment, size); alignment, size);
} }
@ -81,7 +81,7 @@ main(void)
errno = 0; errno = 0;
p = aligned_alloc(alignment, size); p = aligned_alloc(alignment, size);
if (p != NULL || errno != ENOMEM) { if (p != NULL || errno != ENOMEM) {
fprintf(stderr, malloc_printf(
"Expected error for aligned_alloc(&p, %zu, %zu)\n", "Expected error for aligned_alloc(&p, %zu, %zu)\n",
alignment, size); alignment, size);
} }
@ -93,14 +93,14 @@ main(void)
alignment <= MAXALIGN; alignment <= MAXALIGN;
alignment <<= 1) { alignment <<= 1) {
total = 0; total = 0;
fprintf(stderr, "Alignment: %zu\n", alignment); malloc_printf("Alignment: %zu\n", alignment);
for (size = 1; for (size = 1;
size < 3 * alignment && size < (1U << 31); size < 3 * alignment && size < (1U << 31);
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
for (i = 0; i < NITER; i++) { for (i = 0; i < NITER; i++) {
ps[i] = aligned_alloc(alignment, size); ps[i] = aligned_alloc(alignment, size);
if (ps[i] == NULL) { if (ps[i] == NULL) {
fprintf(stderr, malloc_printf(
"Error for size %zu (%#zx): %s\n", "Error for size %zu (%#zx): %s\n",
size, size, strerror(errno)); size, size, strerror(errno));
exit(1); exit(1);
@ -118,6 +118,6 @@ main(void)
} }
} }
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (0); return (0);
} }

View File

@ -27,7 +27,7 @@ thread_start(void *arg)
#endif #endif
goto label_return; goto label_return;
} }
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
exit(1); exit(1);
} }
@ -39,7 +39,7 @@ thread_start(void *arg)
#endif #endif
goto label_return; goto label_return;
} }
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
exit(1); exit(1);
} }
@ -53,7 +53,7 @@ thread_start(void *arg)
#endif #endif
goto label_return; goto label_return;
} }
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
exit(1); exit(1);
} }
@ -65,7 +65,7 @@ thread_start(void *arg)
#endif #endif
goto label_return; goto label_return;
} }
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
exit(1); exit(1);
} }
@ -73,7 +73,7 @@ thread_start(void *arg)
p = malloc(1); p = malloc(1);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "%s(): Error in malloc()\n", __func__); malloc_printf("%s(): Error in malloc()\n", __func__);
exit(1); exit(1);
} }
@ -108,13 +108,13 @@ main(void)
int ret = 0; int ret = 0;
pthread_t thread; pthread_t thread;
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
thread_start(NULL); thread_start(NULL);
if (pthread_create(&thread, NULL, thread_start, NULL) if (pthread_create(&thread, NULL, thread_start, NULL)
!= 0) { != 0) {
fprintf(stderr, "%s(): Error in pthread_create()\n", __func__); malloc_printf("%s(): Error in pthread_create()\n", __func__);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
@ -124,7 +124,7 @@ main(void)
if (pthread_create(&thread, NULL, thread_start, NULL) if (pthread_create(&thread, NULL, thread_start, NULL)
!= 0) { != 0) {
fprintf(stderr, "%s(): Error in pthread_create()\n", __func__); malloc_printf("%s(): Error in pthread_create()\n", __func__);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
@ -133,6 +133,6 @@ main(void)
thread_start(NULL); thread_start(NULL);
label_return: label_return:
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (ret); return (ret);
} }

View File

@ -19,52 +19,52 @@ main(void)
unsigned i; unsigned i;
void *ps[NITER]; void *ps[NITER];
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
sz = 42; sz = 42;
nsz = 0; nsz = 0;
r = nallocm(&nsz, sz, 0); r = nallocm(&nsz, sz, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected nallocm() error\n"); malloc_printf("Unexpected nallocm() error\n");
abort(); abort();
} }
rsz = 0; rsz = 0;
r = allocm(&p, &rsz, sz, 0); r = allocm(&p, &rsz, sz, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); malloc_printf("Unexpected allocm() error\n");
abort(); abort();
} }
if (rsz < sz) if (rsz < sz)
fprintf(stderr, "Real size smaller than expected\n"); malloc_printf("Real size smaller than expected\n");
if (nsz != rsz) if (nsz != rsz)
fprintf(stderr, "nallocm()/allocm() rsize mismatch\n"); malloc_printf("nallocm()/allocm() rsize mismatch\n");
if (dallocm(p, 0) != ALLOCM_SUCCESS) if (dallocm(p, 0) != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected dallocm() error\n"); malloc_printf("Unexpected dallocm() error\n");
r = allocm(&p, NULL, sz, 0); r = allocm(&p, NULL, sz, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); malloc_printf("Unexpected allocm() error\n");
abort(); abort();
} }
if (dallocm(p, 0) != ALLOCM_SUCCESS) if (dallocm(p, 0) != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected dallocm() error\n"); malloc_printf("Unexpected dallocm() error\n");
nsz = 0; nsz = 0;
r = nallocm(&nsz, sz, ALLOCM_ZERO); r = nallocm(&nsz, sz, ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected nallocm() error\n"); malloc_printf("Unexpected nallocm() error\n");
abort(); abort();
} }
rsz = 0; rsz = 0;
r = allocm(&p, &rsz, sz, ALLOCM_ZERO); r = allocm(&p, &rsz, sz, ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); malloc_printf("Unexpected allocm() error\n");
abort(); abort();
} }
if (nsz != rsz) if (nsz != rsz)
fprintf(stderr, "nallocm()/allocm() rsize mismatch\n"); malloc_printf("nallocm()/allocm() rsize mismatch\n");
if (dallocm(p, 0) != ALLOCM_SUCCESS) if (dallocm(p, 0) != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected dallocm() error\n"); malloc_printf("Unexpected dallocm() error\n");
#if LG_SIZEOF_PTR == 3 #if LG_SIZEOF_PTR == 3
alignment = UINT64_C(0x8000000000000000); alignment = UINT64_C(0x8000000000000000);
@ -76,19 +76,19 @@ main(void)
nsz = 0; nsz = 0;
r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment)); r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"Expected error for nallocm(&nsz, %zu, %#x)\n", "Expected error for nallocm(&nsz, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
rsz = 0; rsz = 0;
r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)); r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"Expected error for allocm(&p, %zu, %#x)\n", "Expected error for allocm(&p, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
if (nsz != rsz) if (nsz != rsz)
fprintf(stderr, "nallocm()/allocm() rsize mismatch\n"); malloc_printf("nallocm()/allocm() rsize mismatch\n");
#if LG_SIZEOF_PTR == 3 #if LG_SIZEOF_PTR == 3
alignment = UINT64_C(0x4000000000000000); alignment = UINT64_C(0x4000000000000000);
@ -100,11 +100,11 @@ main(void)
nsz = 0; nsz = 0;
r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment)); r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected nallocm() error\n"); malloc_printf("Unexpected nallocm() error\n");
rsz = 0; rsz = 0;
r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)); r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"Expected error for allocm(&p, %zu, %#x)\n", "Expected error for allocm(&p, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
@ -118,19 +118,19 @@ main(void)
nsz = 0; nsz = 0;
r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment)); r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"Expected error for nallocm(&nsz, %zu, %#x)\n", "Expected error for nallocm(&nsz, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
rsz = 0; rsz = 0;
r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)); r = allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment));
if (r == ALLOCM_SUCCESS) { if (r == ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"Expected error for allocm(&p, %zu, %#x)\n", "Expected error for allocm(&p, %zu, %#x)\n",
sz, ALLOCM_ALIGN(alignment)); sz, ALLOCM_ALIGN(alignment));
} }
if (nsz != rsz) if (nsz != rsz)
fprintf(stderr, "nallocm()/allocm() rsize mismatch\n"); malloc_printf("nallocm()/allocm() rsize mismatch\n");
for (i = 0; i < NITER; i++) for (i = 0; i < NITER; i++)
ps[i] = NULL; ps[i] = NULL;
@ -139,7 +139,7 @@ main(void)
alignment <= MAXALIGN; alignment <= MAXALIGN;
alignment <<= 1) { alignment <<= 1) {
total = 0; total = 0;
fprintf(stderr, "Alignment: %zu\n", alignment); malloc_printf("Alignment: %zu\n", alignment);
for (sz = 1; for (sz = 1;
sz < 3 * alignment && sz < (1U << 31); sz < 3 * alignment && sz < (1U << 31);
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
@ -148,7 +148,7 @@ main(void)
r = nallocm(&nsz, sz, r = nallocm(&nsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO); ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"nallocm() error for size %zu" "nallocm() error for size %zu"
" (%#zx): %d\n", " (%#zx): %d\n",
sz, sz, r); sz, sz, r);
@ -158,24 +158,24 @@ main(void)
r = allocm(&ps[i], &rsz, sz, r = allocm(&ps[i], &rsz, sz,
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO); ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, malloc_printf(
"allocm() error for size %zu" "allocm() error for size %zu"
" (%#zx): %d\n", " (%#zx): %d\n",
sz, sz, r); sz, sz, r);
exit(1); exit(1);
} }
if (rsz < sz) { if (rsz < sz) {
fprintf(stderr, malloc_printf(
"Real size smaller than" "Real size smaller than"
" expected\n"); " expected\n");
} }
if (nsz != rsz) { if (nsz != rsz) {
fprintf(stderr, malloc_printf(
"nallocm()/allocm() rsize" "nallocm()/allocm() rsize"
" mismatch\n"); " mismatch\n");
} }
if ((uintptr_t)p & (alignment-1)) { if ((uintptr_t)p & (alignment-1)) {
fprintf(stderr, malloc_printf(
"%p inadequately aligned for" "%p inadequately aligned for"
" alignment: %zu\n", p, alignment); " alignment: %zu\n", p, alignment);
} }
@ -193,6 +193,6 @@ main(void)
} }
} }
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (0); return (0);
} }

View File

@ -7,12 +7,6 @@
* */ * */
#include <assert.h> #include <assert.h>
/*
* Directly include the bitmap code, since it isn't exposed outside
* libjemalloc.
*/
#include "../src/bitmap.c"
#if (LG_BITMAP_MAXBITS > 12) #if (LG_BITMAP_MAXBITS > 12)
# define MAXBITS 4500 # define MAXBITS 4500
#else #else
@ -144,7 +138,7 @@ test_bitmap_sfu(void)
int int
main(void) main(void)
{ {
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
test_bitmap_size(); test_bitmap_size();
test_bitmap_init(); test_bitmap_init();
@ -152,6 +146,6 @@ main(void)
test_bitmap_unset(); test_bitmap_unset();
test_bitmap_sfu(); test_bitmap_sfu();
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (0); return (0);
} }

View File

@ -4,3 +4,4 @@
* have a different name. * have a different name.
*/ */
#include "jemalloc/jemalloc@install_suffix@.h" #include "jemalloc/jemalloc@install_suffix@.h"
#include "jemalloc/internal/jemalloc_internal.h"

View File

@ -14,12 +14,12 @@ main(void)
size_t sz, lg_chunk, chunksize, i; size_t sz, lg_chunk, chunksize, i;
char *p, *q; char *p, *q;
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
sz = sizeof(lg_chunk); sz = sizeof(lg_chunk);
if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) { if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) {
assert(err != ENOENT); assert(err != ENOENT);
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
ret = 1; ret = 1;
goto label_return; goto label_return;
@ -28,7 +28,7 @@ main(void)
p = (char *)malloc(chunksize); p = (char *)malloc(chunksize);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "malloc(%zu) --> %p\n", chunksize, p); malloc_printf("malloc(%zu) --> %p\n", chunksize, p);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
@ -36,7 +36,7 @@ main(void)
q = (char *)realloc(p, chunksize * 2); q = (char *)realloc(p, chunksize * 2);
if (q == NULL) { if (q == NULL) {
fprintf(stderr, "realloc(%p, %zu) --> %p\n", p, chunksize * 2, malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize * 2,
q); q);
ret = 1; ret = 1;
goto label_return; goto label_return;
@ -49,7 +49,7 @@ main(void)
q = (char *)realloc(p, chunksize); q = (char *)realloc(p, chunksize);
if (q == NULL) { if (q == NULL) {
fprintf(stderr, "realloc(%p, %zu) --> %p\n", p, chunksize, q); malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize, q);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
@ -61,6 +61,6 @@ main(void)
ret = 0; ret = 0;
label_return: label_return:
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (ret); return (ret);
} }

View File

@ -21,13 +21,13 @@ main(void)
int err; int err;
void *p, *ps[NITER]; void *p, *ps[NITER];
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
/* Test error conditions. */ /* Test error conditions. */
for (alignment = 0; alignment < sizeof(void *); alignment++) { for (alignment = 0; alignment < sizeof(void *); alignment++) {
err = posix_memalign(&p, alignment, 1); err = posix_memalign(&p, alignment, 1);
if (err != EINVAL) { if (err != EINVAL) {
fprintf(stderr, malloc_printf(
"Expected error for invalid alignment %zu\n", "Expected error for invalid alignment %zu\n",
alignment); alignment);
} }
@ -37,7 +37,7 @@ main(void)
alignment <<= 1) { alignment <<= 1) {
err = posix_memalign(&p, alignment + 1, 1); err = posix_memalign(&p, alignment + 1, 1);
if (err == 0) { if (err == 0) {
fprintf(stderr, malloc_printf(
"Expected error for invalid alignment %zu\n", "Expected error for invalid alignment %zu\n",
alignment + 1); alignment + 1);
} }
@ -52,7 +52,7 @@ main(void)
#endif #endif
err = posix_memalign(&p, alignment, size); err = posix_memalign(&p, alignment, size);
if (err == 0) { if (err == 0) {
fprintf(stderr, malloc_printf(
"Expected error for posix_memalign(&p, %zu, %zu)\n", "Expected error for posix_memalign(&p, %zu, %zu)\n",
alignment, size); alignment, size);
} }
@ -66,7 +66,7 @@ main(void)
#endif #endif
err = posix_memalign(&p, alignment, size); err = posix_memalign(&p, alignment, size);
if (err == 0) { if (err == 0) {
fprintf(stderr, malloc_printf(
"Expected error for posix_memalign(&p, %zu, %zu)\n", "Expected error for posix_memalign(&p, %zu, %zu)\n",
alignment, size); alignment, size);
} }
@ -79,7 +79,7 @@ main(void)
#endif #endif
err = posix_memalign(&p, alignment, size); err = posix_memalign(&p, alignment, size);
if (err == 0) { if (err == 0) {
fprintf(stderr, malloc_printf(
"Expected error for posix_memalign(&p, %zu, %zu)\n", "Expected error for posix_memalign(&p, %zu, %zu)\n",
alignment, size); alignment, size);
} }
@ -91,7 +91,7 @@ main(void)
alignment <= MAXALIGN; alignment <= MAXALIGN;
alignment <<= 1) { alignment <<= 1) {
total = 0; total = 0;
fprintf(stderr, "Alignment: %zu\n", alignment); malloc_printf("Alignment: %zu\n", alignment);
for (size = 1; for (size = 1;
size < 3 * alignment && size < (1U << 31); size < 3 * alignment && size < (1U << 31);
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
@ -99,7 +99,7 @@ main(void)
err = posix_memalign(&ps[i], err = posix_memalign(&ps[i],
alignment, size); alignment, size);
if (err) { if (err) {
fprintf(stderr, malloc_printf(
"Error for size %zu (%#zx): %s\n", "Error for size %zu (%#zx): %s\n",
size, size, strerror(err)); size, size, strerror(err));
exit(1); exit(1);
@ -117,6 +117,6 @@ main(void)
} }
} }
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (0); return (0);
} }

View File

@ -15,7 +15,7 @@ main(void)
size_t sz, tsz; size_t sz, tsz;
int r; int r;
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
/* Get page size. */ /* Get page size. */
{ {
@ -26,51 +26,51 @@ main(void)
r = allocm(&p, &sz, 42, 0); r = allocm(&p, &sz, 42, 0);
if (r != ALLOCM_SUCCESS) { if (r != ALLOCM_SUCCESS) {
fprintf(stderr, "Unexpected allocm() error\n"); malloc_printf("Unexpected allocm() error\n");
abort(); abort();
} }
q = p; q = p;
r = rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (q != p) if (q != p)
fprintf(stderr, "Unexpected object move\n"); malloc_printf("Unexpected object move\n");
if (tsz != sz) { if (tsz != sz) {
fprintf(stderr, "Unexpected size change: %zu --> %zu\n", malloc_printf("Unexpected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
q = p; q = p;
r = rallocm(&q, &tsz, sz, 5, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, sz, 5, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (q != p) if (q != p)
fprintf(stderr, "Unexpected object move\n"); malloc_printf("Unexpected object move\n");
if (tsz != sz) { if (tsz != sz) {
fprintf(stderr, "Unexpected size change: %zu --> %zu\n", malloc_printf("Unexpected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
q = p; q = p;
r = rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_ERR_NOT_MOVED) if (r != ALLOCM_ERR_NOT_MOVED)
fprintf(stderr, "Unexpected rallocm() result\n"); malloc_printf("Unexpected rallocm() result\n");
if (q != p) if (q != p)
fprintf(stderr, "Unexpected object move\n"); malloc_printf("Unexpected object move\n");
if (tsz != sz) { if (tsz != sz) {
fprintf(stderr, "Unexpected size change: %zu --> %zu\n", malloc_printf("Unexpected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
q = p; q = p;
r = rallocm(&q, &tsz, sz + 5, 0, 0); r = rallocm(&q, &tsz, sz + 5, 0, 0);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (q == p) if (q == p)
fprintf(stderr, "Expected object move\n"); malloc_printf("Expected object move\n");
if (tsz == sz) { if (tsz == sz) {
fprintf(stderr, "Expected size change: %zu --> %zu\n", malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
p = q; p = q;
@ -78,11 +78,11 @@ main(void)
r = rallocm(&q, &tsz, pagesize*2, 0, 0); r = rallocm(&q, &tsz, pagesize*2, 0, 0);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (q == p) if (q == p)
fprintf(stderr, "Expected object move\n"); malloc_printf("Expected object move\n");
if (tsz == sz) { if (tsz == sz) {
fprintf(stderr, "Expected size change: %zu --> %zu\n", malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
p = q; p = q;
@ -90,9 +90,9 @@ main(void)
r = rallocm(&q, &tsz, pagesize*4, 0, 0); r = rallocm(&q, &tsz, pagesize*4, 0, 0);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (tsz == sz) { if (tsz == sz) {
fprintf(stderr, "Expected size change: %zu --> %zu\n", malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
p = q; p = q;
@ -100,28 +100,28 @@ main(void)
r = rallocm(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (q != p) if (q != p)
fprintf(stderr, "Unexpected object move\n"); malloc_printf("Unexpected object move\n");
if (tsz == sz) { if (tsz == sz) {
fprintf(stderr, "Expected size change: %zu --> %zu\n", malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
sz = tsz; sz = tsz;
r = rallocm(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE); r = rallocm(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE);
if (r != ALLOCM_SUCCESS) if (r != ALLOCM_SUCCESS)
fprintf(stderr, "Unexpected rallocm() error\n"); malloc_printf("Unexpected rallocm() error\n");
if (q != p) if (q != p)
fprintf(stderr, "Unexpected object move\n"); malloc_printf("Unexpected object move\n");
if (tsz == sz) { if (tsz == sz) {
fprintf(stderr, "Expected size change: %zu --> %zu\n", malloc_printf("Expected size change: %zu --> %zu\n",
sz, tsz); sz, tsz);
} }
sz = tsz; sz = tsz;
dallocm(p, 0); dallocm(p, 0);
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (0); return (0);
} }

View File

@ -20,14 +20,14 @@ thread_start(void *arg)
p = malloc(1); p = malloc(1);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "%s(): Error in malloc()\n", __func__); malloc_printf("%s(): Error in malloc()\n", __func__);
return (void *)1; return (void *)1;
} }
size = sizeof(arena_ind); size = sizeof(arena_ind);
if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind, if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind,
sizeof(main_arena_ind)))) { sizeof(main_arena_ind)))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
return (void *)1; return (void *)1;
} }
@ -35,7 +35,7 @@ thread_start(void *arg)
size = sizeof(arena_ind); size = sizeof(arena_ind);
if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, if ((err = mallctl("thread.arena", &arena_ind, &size, NULL,
0))) { 0))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
return (void *)1; return (void *)1;
} }
@ -55,18 +55,18 @@ main(void)
pthread_t threads[NTHREADS]; pthread_t threads[NTHREADS];
unsigned i; unsigned i;
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
p = malloc(1); p = malloc(1);
if (p == NULL) { if (p == NULL) {
fprintf(stderr, "%s(): Error in malloc()\n", __func__); malloc_printf("%s(): Error in malloc()\n", __func__);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
size = sizeof(arena_ind); size = sizeof(arena_ind);
if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
strerror(err)); strerror(err));
ret = 1; ret = 1;
goto label_return; goto label_return;
@ -75,7 +75,7 @@ main(void)
for (i = 0; i < NTHREADS; i++) { for (i = 0; i < NTHREADS; i++) {
if (pthread_create(&threads[i], NULL, thread_start, if (pthread_create(&threads[i], NULL, thread_start,
(void *)&arena_ind) != 0) { (void *)&arena_ind) != 0) {
fprintf(stderr, "%s(): Error in pthread_create()\n", malloc_printf("%s(): Error in pthread_create()\n",
__func__); __func__);
ret = 1; ret = 1;
goto label_return; goto label_return;
@ -86,6 +86,6 @@ main(void)
pthread_join(threads[i], (void *)&ret); pthread_join(threads[i], (void *)&ret);
label_return: label_return:
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (ret); return (ret);
} }

View File

@ -79,13 +79,13 @@ main(void)
int ret = 0; int ret = 0;
pthread_t thread; pthread_t thread;
fprintf(stderr, "Test begin\n"); malloc_printf("Test begin\n");
thread_start(NULL); thread_start(NULL);
if (pthread_create(&thread, NULL, thread_start, NULL) if (pthread_create(&thread, NULL, thread_start, NULL)
!= 0) { != 0) {
fprintf(stderr, "%s(): Error in pthread_create()\n", __func__); malloc_printf("%s(): Error in pthread_create()\n", __func__);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
@ -95,7 +95,7 @@ main(void)
if (pthread_create(&thread, NULL, thread_start, NULL) if (pthread_create(&thread, NULL, thread_start, NULL)
!= 0) { != 0) {
fprintf(stderr, "%s(): Error in pthread_create()\n", __func__); malloc_printf("%s(): Error in pthread_create()\n", __func__);
ret = 1; ret = 1;
goto label_return; goto label_return;
} }
@ -104,6 +104,6 @@ main(void)
thread_start(NULL); thread_start(NULL);
label_return: label_return:
fprintf(stderr, "Test end\n"); malloc_printf("Test end\n");
return (ret); return (ret);
} }