mirror of
https://github.com/fluencelabs/redis
synced 2025-08-01 00:41:56 +00:00
Jemalloc updated to 3.6.0.
Not a single bug in about 3 months, and our previous version was too old (3.2.0).
This commit is contained in:
58
deps/jemalloc/test/integration/MALLOCX_ARENA.c
vendored
Normal file
58
deps/jemalloc/test/integration/MALLOCX_ARENA.c
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define NTHREADS 10
|
||||
|
||||
void *
|
||||
thd_start(void *arg)
|
||||
{
|
||||
unsigned thread_ind = (unsigned)(uintptr_t)arg;
|
||||
unsigned arena_ind;
|
||||
void *p;
|
||||
size_t sz;
|
||||
|
||||
sz = sizeof(arena_ind);
|
||||
assert_d_eq(mallctl("arenas.extend", &arena_ind, &sz, NULL, 0), 0,
|
||||
"Error in arenas.extend");
|
||||
|
||||
if (thread_ind % 4 != 3) {
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
const char *dss_precs[] = {"disabled", "primary", "secondary"};
|
||||
const char *dss = dss_precs[thread_ind %
|
||||
(sizeof(dss_precs)/sizeof(char*))];
|
||||
assert_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0,
|
||||
"Error in mallctlnametomib()");
|
||||
mib[1] = arena_ind;
|
||||
assert_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss,
|
||||
sizeof(const char *)), 0, "Error in mallctlbymib()");
|
||||
}
|
||||
|
||||
p = mallocx(1, MALLOCX_ARENA(arena_ind));
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
dallocx(p, 0);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_ALLOCM_ARENA)
|
||||
{
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
thd_create(&thds[i], thd_start,
|
||||
(void *)(uintptr_t)i);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++)
|
||||
thd_join(thds[i], NULL);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_ALLOCM_ARENA));
|
||||
}
|
125
deps/jemalloc/test/integration/aligned_alloc.c
vendored
Normal file
125
deps/jemalloc/test/integration/aligned_alloc.c
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define CHUNK 0x400000
|
||||
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
|
||||
#define MAXALIGN ((size_t)0x2000000LU)
|
||||
#define NITER 4
|
||||
|
||||
TEST_BEGIN(test_alignment_errors)
|
||||
{
|
||||
size_t alignment;
|
||||
void *p;
|
||||
|
||||
alignment = 0;
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment, 1);
|
||||
assert_false(p != NULL || get_errno() != EINVAL,
|
||||
"Expected error for invalid alignment %zu", alignment);
|
||||
|
||||
for (alignment = sizeof(size_t); alignment < MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment + 1, 1);
|
||||
assert_false(p != NULL || get_errno() != EINVAL,
|
||||
"Expected error for invalid alignment %zu",
|
||||
alignment + 1);
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_oom_errors)
|
||||
{
|
||||
size_t alignment, size;
|
||||
void *p;
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x8000000000000000);
|
||||
size = UINT64_C(0x8000000000000000);
|
||||
#else
|
||||
alignment = 0x80000000LU;
|
||||
size = 0x80000000LU;
|
||||
#endif
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment, size);
|
||||
assert_false(p != NULL || get_errno() != ENOMEM,
|
||||
"Expected error for aligned_alloc(%zu, %zu)",
|
||||
alignment, size);
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x4000000000000000);
|
||||
size = UINT64_C(0xc000000000000001);
|
||||
#else
|
||||
alignment = 0x40000000LU;
|
||||
size = 0xc0000001LU;
|
||||
#endif
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment, size);
|
||||
assert_false(p != NULL || get_errno() != ENOMEM,
|
||||
"Expected error for aligned_alloc(%zu, %zu)",
|
||||
alignment, size);
|
||||
|
||||
alignment = 0x10LU;
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
size = UINT64_C(0xfffffffffffffff0);
|
||||
#else
|
||||
size = 0xfffffff0LU;
|
||||
#endif
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment, size);
|
||||
assert_false(p != NULL || get_errno() != ENOMEM,
|
||||
"Expected error for aligned_alloc(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size)
|
||||
{
|
||||
size_t alignment, size, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++)
|
||||
ps[i] = NULL;
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
total = 0;
|
||||
for (size = 1;
|
||||
size < 3 * alignment && size < (1U << 31);
|
||||
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = aligned_alloc(alignment, size);
|
||||
if (ps[i] == NULL) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(get_errno(), buf, sizeof(buf));
|
||||
test_fail(
|
||||
"Error for alignment=%zu, "
|
||||
"size=%zu (%#zx): %s",
|
||||
alignment, size, size, buf);
|
||||
}
|
||||
total += malloc_usable_size(ps[i]);
|
||||
if (total >= (MAXALIGN << 1))
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NITER; i++) {
|
||||
if (ps[i] != NULL) {
|
||||
free(ps[i]);
|
||||
ps[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_alignment_errors,
|
||||
test_oom_errors,
|
||||
test_alignment_and_size));
|
||||
}
|
125
deps/jemalloc/test/integration/allocated.c
vendored
Normal file
125
deps/jemalloc/test/integration/allocated.c
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
static const bool config_stats =
|
||||
#ifdef JEMALLOC_STATS
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
;
|
||||
|
||||
void *
|
||||
thd_start(void *arg)
|
||||
{
|
||||
int err;
|
||||
void *p;
|
||||
uint64_t a0, a1, d0, d1;
|
||||
uint64_t *ap0, *ap1, *dp0, *dp1;
|
||||
size_t sz, usize;
|
||||
|
||||
sz = sizeof(a0);
|
||||
if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT)
|
||||
goto label_ENOENT;
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
}
|
||||
sz = sizeof(ap0);
|
||||
if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT)
|
||||
goto label_ENOENT;
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
}
|
||||
assert_u64_eq(*ap0, a0,
|
||||
"\"thread.allocatedp\" should provide a pointer to internal "
|
||||
"storage");
|
||||
|
||||
sz = sizeof(d0);
|
||||
if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT)
|
||||
goto label_ENOENT;
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
}
|
||||
sz = sizeof(dp0);
|
||||
if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT)
|
||||
goto label_ENOENT;
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
}
|
||||
assert_u64_eq(*dp0, d0,
|
||||
"\"thread.deallocatedp\" should provide a pointer to internal "
|
||||
"storage");
|
||||
|
||||
p = malloc(1);
|
||||
assert_ptr_not_null(p, "Unexpected malloc() error");
|
||||
|
||||
sz = sizeof(a1);
|
||||
mallctl("thread.allocated", &a1, &sz, NULL, 0);
|
||||
sz = sizeof(ap1);
|
||||
mallctl("thread.allocatedp", &ap1, &sz, NULL, 0);
|
||||
assert_u64_eq(*ap1, a1,
|
||||
"Dereferenced \"thread.allocatedp\" value should equal "
|
||||
"\"thread.allocated\" value");
|
||||
assert_ptr_eq(ap0, ap1,
|
||||
"Pointer returned by \"thread.allocatedp\" should not change");
|
||||
|
||||
usize = malloc_usable_size(p);
|
||||
assert_u64_le(a0 + usize, a1,
|
||||
"Allocated memory counter should increase by at least the amount "
|
||||
"explicitly allocated");
|
||||
|
||||
free(p);
|
||||
|
||||
sz = sizeof(d1);
|
||||
mallctl("thread.deallocated", &d1, &sz, NULL, 0);
|
||||
sz = sizeof(dp1);
|
||||
mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0);
|
||||
assert_u64_eq(*dp1, d1,
|
||||
"Dereferenced \"thread.deallocatedp\" value should equal "
|
||||
"\"thread.deallocated\" value");
|
||||
assert_ptr_eq(dp0, dp1,
|
||||
"Pointer returned by \"thread.deallocatedp\" should not change");
|
||||
|
||||
assert_u64_le(d0 + usize, d1,
|
||||
"Deallocated memory counter should increase by at least the amount "
|
||||
"explicitly deallocated");
|
||||
|
||||
return (NULL);
|
||||
label_ENOENT:
|
||||
assert_false(config_stats,
|
||||
"ENOENT should only be returned if stats are disabled");
|
||||
test_skip("\"thread.allocated\" mallctl not available");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_main_thread)
|
||||
{
|
||||
|
||||
thd_start(NULL);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_subthread)
|
||||
{
|
||||
thd_t thd;
|
||||
|
||||
thd_create(&thd, thd_start, NULL);
|
||||
thd_join(thd, NULL);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
/* Run tests multiple times to check for bad interactions. */
|
||||
return (test(
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread));
|
||||
}
|
107
deps/jemalloc/test/integration/allocm.c
vendored
Normal file
107
deps/jemalloc/test/integration/allocm.c
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define CHUNK 0x400000
|
||||
#define MAXALIGN (((size_t)1) << 25)
|
||||
#define NITER 4
|
||||
|
||||
TEST_BEGIN(test_basic)
|
||||
{
|
||||
size_t nsz, rsz, sz;
|
||||
void *p;
|
||||
|
||||
sz = 42;
|
||||
nsz = 0;
|
||||
assert_d_eq(nallocm(&nsz, sz, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected nallocm() error");
|
||||
rsz = 0;
|
||||
assert_d_eq(allocm(&p, &rsz, sz, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
assert_zu_ge(rsz, sz, "Real size smaller than expected");
|
||||
assert_zu_eq(nsz, rsz, "nallocm()/allocm() rsize mismatch");
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
|
||||
assert_d_eq(allocm(&p, NULL, sz, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
|
||||
nsz = 0;
|
||||
assert_d_eq(nallocm(&nsz, sz, ALLOCM_ZERO), ALLOCM_SUCCESS,
|
||||
"Unexpected nallocm() error");
|
||||
rsz = 0;
|
||||
assert_d_eq(allocm(&p, &rsz, sz, ALLOCM_ZERO), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
assert_zu_eq(nsz, rsz, "nallocm()/allocm() rsize mismatch");
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size)
|
||||
{
|
||||
int r;
|
||||
size_t nsz, rsz, sz, alignment, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++)
|
||||
ps[i] = NULL;
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
total = 0;
|
||||
for (sz = 1;
|
||||
sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
nsz = 0;
|
||||
r = nallocm(&nsz, sz, ALLOCM_ALIGN(alignment) |
|
||||
ALLOCM_ZERO);
|
||||
assert_d_eq(r, ALLOCM_SUCCESS,
|
||||
"nallocm() error for alignment=%zu, "
|
||||
"size=%zu (%#zx): %d",
|
||||
alignment, sz, sz, r);
|
||||
rsz = 0;
|
||||
r = allocm(&ps[i], &rsz, sz,
|
||||
ALLOCM_ALIGN(alignment) | ALLOCM_ZERO);
|
||||
assert_d_eq(r, ALLOCM_SUCCESS,
|
||||
"allocm() error for alignment=%zu, "
|
||||
"size=%zu (%#zx): %d",
|
||||
alignment, sz, sz, r);
|
||||
assert_zu_ge(rsz, sz,
|
||||
"Real size smaller than expected for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
assert_zu_eq(nsz, rsz,
|
||||
"nallocm()/allocm() rsize mismatch for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
assert_ptr_null(
|
||||
(void *)((uintptr_t)ps[i] & (alignment-1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu", ps[i],
|
||||
alignment, sz);
|
||||
sallocm(ps[i], &rsz, 0);
|
||||
total += rsz;
|
||||
if (total >= (MAXALIGN << 1))
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NITER; i++) {
|
||||
if (ps[i] != NULL) {
|
||||
dallocm(ps[i], 0);
|
||||
ps[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_basic,
|
||||
test_alignment_and_size));
|
||||
}
|
97
deps/jemalloc/test/integration/mallocx.c
vendored
Normal file
97
deps/jemalloc/test/integration/mallocx.c
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define CHUNK 0x400000
|
||||
#define MAXALIGN (((size_t)1) << 25)
|
||||
#define NITER 4
|
||||
|
||||
TEST_BEGIN(test_basic)
|
||||
{
|
||||
size_t nsz, rsz, sz;
|
||||
void *p;
|
||||
|
||||
sz = 42;
|
||||
nsz = nallocx(sz, 0);
|
||||
assert_zu_ne(nsz, 0, "Unexpected nallocx() error");
|
||||
p = mallocx(sz, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
rsz = sallocx(p, 0);
|
||||
assert_zu_ge(rsz, sz, "Real size smaller than expected");
|
||||
assert_zu_eq(nsz, rsz, "nallocx()/sallocx() size mismatch");
|
||||
dallocx(p, 0);
|
||||
|
||||
p = mallocx(sz, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
dallocx(p, 0);
|
||||
|
||||
nsz = nallocx(sz, MALLOCX_ZERO);
|
||||
assert_zu_ne(nsz, 0, "Unexpected nallocx() error");
|
||||
p = mallocx(sz, MALLOCX_ZERO);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
rsz = sallocx(p, 0);
|
||||
assert_zu_eq(nsz, rsz, "nallocx()/sallocx() rsize mismatch");
|
||||
dallocx(p, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size)
|
||||
{
|
||||
size_t nsz, rsz, sz, alignment, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++)
|
||||
ps[i] = NULL;
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
total = 0;
|
||||
for (sz = 1;
|
||||
sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO);
|
||||
assert_zu_ne(nsz, 0,
|
||||
"nallocx() error for alignment=%zu, "
|
||||
"size=%zu (%#zx)", alignment, sz, sz);
|
||||
ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO);
|
||||
assert_ptr_not_null(ps[i],
|
||||
"mallocx() error for alignment=%zu, "
|
||||
"size=%zu (%#zx)", alignment, sz, sz);
|
||||
rsz = sallocx(ps[i], 0);
|
||||
assert_zu_ge(rsz, sz,
|
||||
"Real size smaller than expected for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
assert_zu_eq(nsz, rsz,
|
||||
"nallocx()/sallocx() size mismatch for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
assert_ptr_null(
|
||||
(void *)((uintptr_t)ps[i] & (alignment-1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu", ps[i],
|
||||
alignment, sz);
|
||||
total += rsz;
|
||||
if (total >= (MAXALIGN << 1))
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NITER; i++) {
|
||||
if (ps[i] != NULL) {
|
||||
dallocx(ps[i], 0);
|
||||
ps[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_basic,
|
||||
test_alignment_and_size));
|
||||
}
|
45
deps/jemalloc/test/integration/mremap.c
vendored
Normal file
45
deps/jemalloc/test/integration/mremap.c
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
TEST_BEGIN(test_mremap)
|
||||
{
|
||||
int err;
|
||||
size_t sz, lg_chunk, chunksize, i;
|
||||
char *p, *q;
|
||||
|
||||
sz = sizeof(lg_chunk);
|
||||
err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "Error in mallctl(): %s", strerror(err));
|
||||
chunksize = ((size_t)1U) << lg_chunk;
|
||||
|
||||
p = (char *)malloc(chunksize);
|
||||
assert_ptr_not_null(p, "malloc(%zu) --> %p", chunksize, p);
|
||||
memset(p, 'a', chunksize);
|
||||
|
||||
q = (char *)realloc(p, chunksize * 2);
|
||||
assert_ptr_not_null(q, "realloc(%p, %zu) --> %p", p, chunksize * 2,
|
||||
q);
|
||||
for (i = 0; i < chunksize; i++) {
|
||||
assert_c_eq(q[i], 'a',
|
||||
"realloc() should preserve existing bytes across copies");
|
||||
}
|
||||
|
||||
p = q;
|
||||
|
||||
q = (char *)realloc(p, chunksize);
|
||||
assert_ptr_not_null(q, "realloc(%p, %zu) --> %p", p, chunksize, q);
|
||||
for (i = 0; i < chunksize; i++) {
|
||||
assert_c_eq(q[i], 'a',
|
||||
"realloc() should preserve existing bytes across copies");
|
||||
}
|
||||
|
||||
free(q);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_mremap));
|
||||
}
|
119
deps/jemalloc/test/integration/posix_memalign.c
vendored
Normal file
119
deps/jemalloc/test/integration/posix_memalign.c
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define CHUNK 0x400000
|
||||
/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
|
||||
#define MAXALIGN ((size_t)0x2000000LU)
|
||||
#define NITER 4
|
||||
|
||||
TEST_BEGIN(test_alignment_errors)
|
||||
{
|
||||
size_t alignment;
|
||||
void *p;
|
||||
|
||||
for (alignment = 0; alignment < sizeof(void *); alignment++) {
|
||||
assert_d_eq(posix_memalign(&p, alignment, 1), EINVAL,
|
||||
"Expected error for invalid alignment %zu",
|
||||
alignment);
|
||||
}
|
||||
|
||||
for (alignment = sizeof(size_t); alignment < MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
assert_d_ne(posix_memalign(&p, alignment + 1, 1), 0,
|
||||
"Expected error for invalid alignment %zu",
|
||||
alignment + 1);
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_oom_errors)
|
||||
{
|
||||
size_t alignment, size;
|
||||
void *p;
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x8000000000000000);
|
||||
size = UINT64_C(0x8000000000000000);
|
||||
#else
|
||||
alignment = 0x80000000LU;
|
||||
size = 0x80000000LU;
|
||||
#endif
|
||||
assert_d_ne(posix_memalign(&p, alignment, size), 0,
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x4000000000000000);
|
||||
size = UINT64_C(0xc000000000000001);
|
||||
#else
|
||||
alignment = 0x40000000LU;
|
||||
size = 0xc0000001LU;
|
||||
#endif
|
||||
assert_d_ne(posix_memalign(&p, alignment, size), 0,
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
|
||||
alignment = 0x10LU;
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
size = UINT64_C(0xfffffffffffffff0);
|
||||
#else
|
||||
size = 0xfffffff0LU;
|
||||
#endif
|
||||
assert_d_ne(posix_memalign(&p, alignment, size), 0,
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size)
|
||||
{
|
||||
size_t alignment, size, total;
|
||||
unsigned i;
|
||||
int err;
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++)
|
||||
ps[i] = NULL;
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
total = 0;
|
||||
for (size = 1;
|
||||
size < 3 * alignment && size < (1U << 31);
|
||||
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
err = posix_memalign(&ps[i],
|
||||
alignment, size);
|
||||
if (err) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(get_errno(), buf, sizeof(buf));
|
||||
test_fail(
|
||||
"Error for alignment=%zu, "
|
||||
"size=%zu (%#zx): %s",
|
||||
alignment, size, size, buf);
|
||||
}
|
||||
total += malloc_usable_size(ps[i]);
|
||||
if (total >= (MAXALIGN << 1))
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NITER; i++) {
|
||||
if (ps[i] != NULL) {
|
||||
free(ps[i]);
|
||||
ps[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_alignment_errors,
|
||||
test_oom_errors,
|
||||
test_alignment_and_size));
|
||||
}
|
111
deps/jemalloc/test/integration/rallocm.c
vendored
Normal file
111
deps/jemalloc/test/integration/rallocm.c
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
TEST_BEGIN(test_same_size)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t sz, tsz;
|
||||
|
||||
assert_d_eq(allocm(&p, &sz, 42, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE), ALLOCM_SUCCESS,
|
||||
"Unexpected rallocm() error");
|
||||
assert_ptr_eq(q, p, "Unexpected object move");
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_extra_no_move)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t sz, tsz;
|
||||
|
||||
assert_d_eq(allocm(&p, &sz, 42, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, sz, sz-42, ALLOCM_NO_MOVE),
|
||||
ALLOCM_SUCCESS, "Unexpected rallocm() error");
|
||||
assert_ptr_eq(q, p, "Unexpected object move");
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_no_move_fail)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t sz, tsz;
|
||||
|
||||
assert_d_eq(allocm(&p, &sz, 42, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE),
|
||||
ALLOCM_ERR_NOT_MOVED, "Unexpected rallocm() result");
|
||||
assert_ptr_eq(q, p, "Unexpected object move");
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_grow_and_shrink)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t tsz;
|
||||
#define NCYCLES 3
|
||||
unsigned i, j;
|
||||
#define NSZS 2500
|
||||
size_t szs[NSZS];
|
||||
#define MAXSZ ZU(12 * 1024 * 1024)
|
||||
|
||||
assert_d_eq(allocm(&p, &szs[0], 1, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected allocm() error");
|
||||
|
||||
for (i = 0; i < NCYCLES; i++) {
|
||||
for (j = 1; j < NSZS && szs[j-1] < MAXSZ; j++) {
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &szs[j], szs[j-1]+1, 0, 0),
|
||||
ALLOCM_SUCCESS,
|
||||
"Unexpected rallocm() error for size=%zu-->%zu",
|
||||
szs[j-1], szs[j-1]+1);
|
||||
assert_zu_ne(szs[j], szs[j-1]+1,
|
||||
"Expected size to at least: %zu", szs[j-1]+1);
|
||||
p = q;
|
||||
}
|
||||
|
||||
for (j--; j > 0; j--) {
|
||||
q = p;
|
||||
assert_d_eq(rallocm(&q, &tsz, szs[j-1], 0, 0),
|
||||
ALLOCM_SUCCESS,
|
||||
"Unexpected rallocm() error for size=%zu-->%zu",
|
||||
szs[j], szs[j-1]);
|
||||
assert_zu_eq(tsz, szs[j-1],
|
||||
"Expected size=%zu, got size=%zu", szs[j-1], tsz);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
assert_d_eq(dallocm(p, 0), ALLOCM_SUCCESS,
|
||||
"Unexpected dallocm() error");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_same_size,
|
||||
test_extra_no_move,
|
||||
test_no_move_fail,
|
||||
test_grow_and_shrink));
|
||||
}
|
182
deps/jemalloc/test/integration/rallocx.c
vendored
Normal file
182
deps/jemalloc/test/integration/rallocx.c
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
TEST_BEGIN(test_grow_and_shrink)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t tsz;
|
||||
#define NCYCLES 3
|
||||
unsigned i, j;
|
||||
#define NSZS 2500
|
||||
size_t szs[NSZS];
|
||||
#define MAXSZ ZU(12 * 1024 * 1024)
|
||||
|
||||
p = mallocx(1, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
szs[0] = sallocx(p, 0);
|
||||
|
||||
for (i = 0; i < NCYCLES; i++) {
|
||||
for (j = 1; j < NSZS && szs[j-1] < MAXSZ; j++) {
|
||||
q = rallocx(p, szs[j-1]+1, 0);
|
||||
assert_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for size=%zu-->%zu",
|
||||
szs[j-1], szs[j-1]+1);
|
||||
szs[j] = sallocx(q, 0);
|
||||
assert_zu_ne(szs[j], szs[j-1]+1,
|
||||
"Expected size to at least: %zu", szs[j-1]+1);
|
||||
p = q;
|
||||
}
|
||||
|
||||
for (j--; j > 0; j--) {
|
||||
q = rallocx(p, szs[j-1], 0);
|
||||
assert_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for size=%zu-->%zu",
|
||||
szs[j], szs[j-1]);
|
||||
tsz = sallocx(q, 0);
|
||||
assert_zu_eq(tsz, szs[j-1],
|
||||
"Expected size=%zu, got size=%zu", szs[j-1], tsz);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
dallocx(p, 0);
|
||||
#undef MAXSZ
|
||||
#undef NSZS
|
||||
#undef NCYCLES
|
||||
}
|
||||
TEST_END
|
||||
|
||||
static bool
|
||||
validate_fill(const void *p, uint8_t c, size_t offset, size_t len)
|
||||
{
|
||||
bool ret = false;
|
||||
const uint8_t *buf = (const uint8_t *)p;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t b = buf[offset+i];
|
||||
if (b != c) {
|
||||
test_fail("Allocation at %p contains %#x rather than "
|
||||
"%#x at offset %zu", p, b, c, offset+i);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_zero)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t psz, qsz, i, j;
|
||||
size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024};
|
||||
#define FILL_BYTE 0xaaU
|
||||
#define RANGE 2048
|
||||
|
||||
for (i = 0; i < sizeof(start_sizes)/sizeof(size_t); i++) {
|
||||
size_t start_size = start_sizes[i];
|
||||
p = mallocx(start_size, MALLOCX_ZERO);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
psz = sallocx(p, 0);
|
||||
|
||||
assert_false(validate_fill(p, 0, 0, psz),
|
||||
"Expected zeroed memory");
|
||||
memset(p, FILL_BYTE, psz);
|
||||
assert_false(validate_fill(p, FILL_BYTE, 0, psz),
|
||||
"Expected filled memory");
|
||||
|
||||
for (j = 1; j < RANGE; j++) {
|
||||
q = rallocx(p, start_size+j, MALLOCX_ZERO);
|
||||
assert_ptr_not_null(q, "Unexpected rallocx() error");
|
||||
qsz = sallocx(q, 0);
|
||||
if (q != p || qsz != psz) {
|
||||
assert_false(validate_fill(q, FILL_BYTE, 0,
|
||||
psz), "Expected filled memory");
|
||||
assert_false(validate_fill(q, 0, psz, qsz-psz),
|
||||
"Expected zeroed memory");
|
||||
}
|
||||
if (psz != qsz) {
|
||||
memset(q+psz, FILL_BYTE, qsz-psz);
|
||||
psz = qsz;
|
||||
}
|
||||
p = q;
|
||||
}
|
||||
assert_false(validate_fill(p, FILL_BYTE, 0, psz),
|
||||
"Expected filled memory");
|
||||
dallocx(p, 0);
|
||||
}
|
||||
#undef FILL_BYTE
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_align)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t align;
|
||||
#define MAX_ALIGN (ZU(1) << 25)
|
||||
|
||||
align = ZU(1);
|
||||
p = mallocx(1, MALLOCX_ALIGN(align));
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
||||
for (align <<= 1; align <= MAX_ALIGN; align <<= 1) {
|
||||
q = rallocx(p, 1, MALLOCX_ALIGN(align));
|
||||
assert_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for align=%zu", align);
|
||||
assert_ptr_null(
|
||||
(void *)((uintptr_t)q & (align-1)),
|
||||
"%p inadequately aligned for align=%zu",
|
||||
q, align);
|
||||
p = q;
|
||||
}
|
||||
dallocx(p, 0);
|
||||
#undef MAX_ALIGN
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_lg_align_and_zero)
|
||||
{
|
||||
void *p, *q;
|
||||
size_t lg_align, sz;
|
||||
#define MAX_LG_ALIGN 25
|
||||
#define MAX_VALIDATE (ZU(1) << 22)
|
||||
|
||||
lg_align = ZU(0);
|
||||
p = mallocx(1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
||||
for (lg_align++; lg_align <= MAX_LG_ALIGN; lg_align++) {
|
||||
q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
|
||||
assert_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for lg_align=%zu", lg_align);
|
||||
assert_ptr_null(
|
||||
(void *)((uintptr_t)q & ((ZU(1) << lg_align)-1)),
|
||||
"%p inadequately aligned for lg_align=%zu",
|
||||
q, lg_align);
|
||||
sz = sallocx(q, 0);
|
||||
if ((sz << 1) <= MAX_VALIDATE) {
|
||||
assert_false(validate_fill(q, 0, 0, sz),
|
||||
"Expected zeroed memory");
|
||||
} else {
|
||||
assert_false(validate_fill(q, 0, 0, MAX_VALIDATE),
|
||||
"Expected zeroed memory");
|
||||
assert_false(validate_fill(q+sz-MAX_VALIDATE, 0, 0,
|
||||
MAX_VALIDATE), "Expected zeroed memory");
|
||||
}
|
||||
p = q;
|
||||
}
|
||||
dallocx(p, 0);
|
||||
#undef MAX_VALIDATE
|
||||
#undef MAX_LG_ALIGN
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_grow_and_shrink,
|
||||
test_zero,
|
||||
test_align,
|
||||
test_lg_align_and_zero));
|
||||
}
|
79
deps/jemalloc/test/integration/thread_arena.c
vendored
Normal file
79
deps/jemalloc/test/integration/thread_arena.c
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define NTHREADS 10
|
||||
|
||||
void *
|
||||
thd_start(void *arg)
|
||||
{
|
||||
unsigned main_arena_ind = *(unsigned *)arg;
|
||||
void *p;
|
||||
unsigned arena_ind;
|
||||
size_t size;
|
||||
int err;
|
||||
|
||||
p = malloc(1);
|
||||
assert_ptr_not_null(p, "Error in malloc()");
|
||||
free(p);
|
||||
|
||||
size = sizeof(arena_ind);
|
||||
if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind,
|
||||
sizeof(main_arena_ind)))) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(err, buf, sizeof(buf));
|
||||
test_fail("Error in mallctl(): %s", buf);
|
||||
}
|
||||
|
||||
size = sizeof(arena_ind);
|
||||
if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(err, buf, sizeof(buf));
|
||||
test_fail("Error in mallctl(): %s", buf);
|
||||
}
|
||||
assert_u_eq(arena_ind, main_arena_ind,
|
||||
"Arena index should be same as for main thread");
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_thread_arena)
|
||||
{
|
||||
void *p;
|
||||
unsigned arena_ind;
|
||||
size_t size;
|
||||
int err;
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned i;
|
||||
|
||||
p = malloc(1);
|
||||
assert_ptr_not_null(p, "Error in malloc()");
|
||||
|
||||
size = sizeof(arena_ind);
|
||||
if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(err, buf, sizeof(buf));
|
||||
test_fail("Error in mallctl(): %s", buf);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
thd_create(&thds[i], thd_start,
|
||||
(void *)&arena_ind);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
intptr_t join_ret;
|
||||
thd_join(thds[i], (void *)&join_ret);
|
||||
assert_zd_eq(join_ret, 0, "Unexpected thread join error");
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_thread_arena));
|
||||
}
|
113
deps/jemalloc/test/integration/thread_tcache_enabled.c
vendored
Normal file
113
deps/jemalloc/test/integration/thread_tcache_enabled.c
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
static const bool config_tcache =
|
||||
#ifdef JEMALLOC_TCACHE
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
;
|
||||
|
||||
void *
|
||||
thd_start(void *arg)
|
||||
{
|
||||
int err;
|
||||
size_t sz;
|
||||
bool e0, e1;
|
||||
|
||||
sz = sizeof(bool);
|
||||
if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT) {
|
||||
assert_false(config_tcache,
|
||||
"ENOENT should only be returned if tcache is "
|
||||
"disabled");
|
||||
}
|
||||
goto label_ENOENT;
|
||||
}
|
||||
|
||||
if (e0) {
|
||||
e1 = false;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
assert_true(e0, "tcache should be enabled");
|
||||
}
|
||||
|
||||
e1 = true;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_false(e0, "tcache should be disabled");
|
||||
|
||||
e1 = true;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_true(e0, "tcache should be enabled");
|
||||
|
||||
e1 = false;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_true(e0, "tcache should be enabled");
|
||||
|
||||
e1 = false;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_false(e0, "tcache should be disabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = true;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_false(e0, "tcache should be disabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = true;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_true(e0, "tcache should be enabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = false;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_true(e0, "tcache should be enabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = false;
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() error");
|
||||
assert_false(e0, "tcache should be disabled");
|
||||
|
||||
free(malloc(1));
|
||||
return (NULL);
|
||||
label_ENOENT:
|
||||
test_skip("\"thread.tcache.enabled\" mallctl not available");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_main_thread)
|
||||
{
|
||||
|
||||
thd_start(NULL);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_subthread)
|
||||
{
|
||||
thd_t thd;
|
||||
|
||||
thd_create(&thd, thd_start, NULL);
|
||||
thd_join(thd, NULL);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
/* Run tests multiple times to check for bad interactions. */
|
||||
return (test(
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread));
|
||||
}
|
59
deps/jemalloc/test/integration/xallocx.c
vendored
Normal file
59
deps/jemalloc/test/integration/xallocx.c
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
TEST_BEGIN(test_same_size)
|
||||
{
|
||||
void *p;
|
||||
size_t sz, tsz;
|
||||
|
||||
p = mallocx(42, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
sz = sallocx(p, 0);
|
||||
|
||||
tsz = xallocx(p, sz, 0, 0);
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
dallocx(p, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_extra_no_move)
|
||||
{
|
||||
void *p;
|
||||
size_t sz, tsz;
|
||||
|
||||
p = mallocx(42, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
sz = sallocx(p, 0);
|
||||
|
||||
tsz = xallocx(p, sz, sz-42, 0);
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
dallocx(p, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_no_move_fail)
|
||||
{
|
||||
void *p;
|
||||
size_t sz, tsz;
|
||||
|
||||
p = mallocx(42, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
sz = sallocx(p, 0);
|
||||
|
||||
tsz = xallocx(p, sz + 5, 0, 0);
|
||||
assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
dallocx(p, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_same_size,
|
||||
test_extra_no_move,
|
||||
test_no_move_fail));
|
||||
}
|
Reference in New Issue
Block a user