Skip to content

Commit

Permalink
Test alloc size with jemalloc only
Browse files Browse the repository at this point in the history
With other allocators we can't guarantee alloc field is correct.

Signed-off-by: Vadym Khoptynets <vadymkh@amazon.com>
  • Loading branch information
poiuj committed May 21, 2024
1 parent 4674128 commit a9b378b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/unit/test_sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9b378b

Please sign in to comment.