michael@0: #define JEMALLOC_MANGLE michael@0: #include "jemalloc_test.h" michael@0: michael@0: int michael@0: main(void) michael@0: { michael@0: size_t pagesize; michael@0: void *p, *q; michael@0: size_t sz, tsz; michael@0: int r; michael@0: michael@0: malloc_printf("Test begin\n"); michael@0: michael@0: /* Get page size. */ michael@0: { michael@0: #ifdef _WIN32 michael@0: SYSTEM_INFO si; michael@0: GetSystemInfo(&si); michael@0: pagesize = (size_t)si.dwPageSize; michael@0: #else michael@0: long result = sysconf(_SC_PAGESIZE); michael@0: assert(result != -1); michael@0: pagesize = (size_t)result; michael@0: #endif michael@0: } michael@0: michael@0: r = allocm(&p, &sz, 42, 0); michael@0: if (r != ALLOCM_SUCCESS) { michael@0: malloc_printf("Unexpected allocm() error\n"); michael@0: abort(); michael@0: } michael@0: michael@0: q = p; michael@0: r = rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (q != p) michael@0: malloc_printf("Unexpected object move\n"); michael@0: if (tsz != sz) { michael@0: malloc_printf("Unexpected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: michael@0: q = p; michael@0: r = rallocm(&q, &tsz, sz, 5, ALLOCM_NO_MOVE); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (q != p) michael@0: malloc_printf("Unexpected object move\n"); michael@0: if (tsz != sz) { michael@0: malloc_printf("Unexpected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: michael@0: q = p; michael@0: r = rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE); michael@0: if (r != ALLOCM_ERR_NOT_MOVED) michael@0: malloc_printf("Unexpected rallocm() result\n"); michael@0: if (q != p) michael@0: malloc_printf("Unexpected object move\n"); michael@0: if (tsz != sz) { michael@0: malloc_printf("Unexpected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: michael@0: q = p; michael@0: r = rallocm(&q, &tsz, sz + 5, 0, 0); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (q == p) michael@0: malloc_printf("Expected object move\n"); michael@0: if (tsz == sz) { michael@0: malloc_printf("Expected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: p = q; michael@0: sz = tsz; michael@0: michael@0: r = rallocm(&q, &tsz, pagesize*2, 0, 0); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (q == p) michael@0: malloc_printf("Expected object move\n"); michael@0: if (tsz == sz) { michael@0: malloc_printf("Expected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: p = q; michael@0: sz = tsz; michael@0: michael@0: r = rallocm(&q, &tsz, pagesize*4, 0, 0); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (tsz == sz) { michael@0: malloc_printf("Expected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: p = q; michael@0: sz = tsz; michael@0: michael@0: r = rallocm(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (q != p) michael@0: malloc_printf("Unexpected object move\n"); michael@0: if (tsz == sz) { michael@0: malloc_printf("Expected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: sz = tsz; michael@0: michael@0: r = rallocm(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE); michael@0: if (r != ALLOCM_SUCCESS) michael@0: malloc_printf("Unexpected rallocm() error\n"); michael@0: if (q != p) michael@0: malloc_printf("Unexpected object move\n"); michael@0: if (tsz == sz) { michael@0: malloc_printf("Expected size change: %zu --> %zu\n", michael@0: sz, tsz); michael@0: } michael@0: sz = tsz; michael@0: michael@0: dallocm(p, 0); michael@0: michael@0: malloc_printf("Test end\n"); michael@0: return (0); michael@0: }