add test for zero-sized alloc and aligned alloc

This commit is contained in:
Dave Watson 2018-10-09 08:41:36 -07:00
parent 01e2a38e5a
commit 2b112ea593
3 changed files with 28 additions and 1 deletions

View File

@ -226,6 +226,7 @@ endif
TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \ TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
$(srcroot)test/integration/allocated.c \ $(srcroot)test/integration/allocated.c \
$(srcroot)test/integration/extent.c \ $(srcroot)test/integration/extent.c \
$(srcroot)test/integration/malloc.c \
$(srcroot)test/integration/mallocx.c \ $(srcroot)test/integration/mallocx.c \
$(srcroot)test/integration/MALLOCX_ARENA.c \ $(srcroot)test/integration/MALLOCX_ARENA.c \
$(srcroot)test/integration/overflow.c \ $(srcroot)test/integration/overflow.c \

View File

@ -138,10 +138,20 @@ TEST_BEGIN(test_alignment_and_size) {
} }
TEST_END TEST_END
TEST_BEGIN(test_zero_alloc) {
void *res = aligned_alloc(8, 0);
assert(res);
size_t usable = malloc_usable_size(res);
assert(usable > 0);
free(res);
}
TEST_END
int int
main(void) { main(void) {
return test( return test(
test_alignment_errors, test_alignment_errors,
test_oom_errors, test_oom_errors,
test_alignment_and_size); test_alignment_and_size,
test_zero_alloc);
} }

16
test/integration/malloc.c Normal file
View File

@ -0,0 +1,16 @@
#include "test/jemalloc_test.h"
TEST_BEGIN(test_zero_alloc) {
void *res = malloc(0);
assert(res);
size_t usable = malloc_usable_size(res);
assert(usable > 0);
free(res);
}
TEST_END
int
main(void) {
return test(
test_zero_alloc);
}