From a9b378b08e5393cd733ae6847094bce0aa1a8cd0 Mon Sep 17 00:00:00 2001 From: Vadym Khoptynets Date: Tue, 21 May 2024 14:56:34 +0000 Subject: [PATCH] Test alloc size with jemalloc only With other allocators we can't guarantee alloc field is correct. Signed-off-by: Vadym Khoptynets --- src/unit/test_sds.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/unit/test_sds.c b/src/unit/test_sds.c index abf6b98e0f..3afbdc035f 100644 --- a/src/unit/test_sds.c +++ b/src/unit/test_sds.c @@ -274,44 +274,60 @@ int test_typesAndAllocSize(int argc, char **argv, int flags) { sds x = sdsnewlen(NULL, 30); TEST_ASSERT_MESSAGE("len 30 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_5); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 30 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); x = sdsnewlen(NULL, 31); TEST_ASSERT_MESSAGE("len 31 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_8); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 31 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); x = sdsnewlen(NULL, 252); TEST_ASSERT_MESSAGE("len 252 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_8); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 252 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); x = sdsnewlen(NULL, 253); TEST_ASSERT_MESSAGE("len 253 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_16); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 253 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); x = sdsnewlen(NULL, 65530); TEST_ASSERT_MESSAGE("len 65530 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_16); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 65530 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); x = sdsnewlen(NULL, 65531); TEST_ASSERT_MESSAGE("len 65531 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_32); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 65531 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); #if (LONG_MAX == LLONG_MAX) if (flags & UNIT_TEST_LARGE_MEMORY) { x = sdsnewlen(NULL, 4294967286); TEST_ASSERT_MESSAGE("len 4294967286 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_32); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 4294967286 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); x = sdsnewlen(NULL, 4294967287); TEST_ASSERT_MESSAGE("len 4294967287 type", (x[-1] & SDS_TYPE_MASK) == SDS_TYPE_64); +#ifdef USE_JEMALLOC TEST_ASSERT_MESSAGE("len 4294967287 sdsAllocSize", sdsAllocSize(x) == s_malloc_size(sdsAllocPtr(x))); +#endif sdsfree(x); } #endif