summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-02-05 18:14:55 -0800
committerChristopher Ferris <cferris@google.com>2018-02-07 06:57:14 -0800
commitcae21a9b53a10f0cba79bf6783c4a5af16228fed (patch)
treec60c6622d2b80f9ad4ae5a990b7fb3439f16444b /libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
parentbe6fbae74fc3048647caadd58a9eaad81245e934 (diff)
Add aligned_alloc to libc.
Bug: 72969374 Test: Bionic unit tests pass. Test: Malloc debug unit tests pass. Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0 (cherry picked from commit d69ee59594088c0d92ba9273188ef53ea5e6cd6a)
Diffstat (limited to 'libc/malloc_debug/tests/malloc_debug_unit_tests.cpp')
-rw-r--r--libc/malloc_debug/tests/malloc_debug_unit_tests.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index 4e9066812..0e4a7d85f 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -54,6 +54,7 @@ void* debug_calloc(size_t, size_t);
void* debug_realloc(void*, size_t);
int debug_posix_memalign(void**, size_t, size_t);
void* debug_memalign(size_t, size_t);
+void* debug_aligned_alloc(size_t, size_t);
size_t debug_malloc_usable_size(void*);
void debug_get_malloc_leak_info(uint8_t**, size_t*, size_t*, size_t*, size_t*);
void debug_free_malloc_leak_info(uint8_t*);
@@ -136,6 +137,7 @@ MallocDispatch MallocDebugTest::dispatch = {
nullptr,
nullptr,
mallopt,
+ aligned_alloc,
};
void VerifyAllocCalls(bool backtrace_enabled) {
@@ -308,6 +310,11 @@ TEST_F(MallocDebugTest, expand_alloc) {
ASSERT_LE(1039U, debug_malloc_usable_size(pointer));
debug_free(pointer);
+ pointer = debug_aligned_alloc(128, 15);
+ ASSERT_TRUE(pointer != nullptr);
+ ASSERT_LE(1039U, debug_malloc_usable_size(pointer));
+ debug_free(pointer);
+
pointer = debug_realloc(nullptr, 30);
ASSERT_TRUE(pointer != nullptr);
ASSERT_LE(1054U, debug_malloc_usable_size(pointer));
@@ -1772,6 +1779,12 @@ void VerifyRecordAllocs() {
debug_free(pointer);
expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+ pointer = debug_aligned_alloc(32, 50);
+ ASSERT_TRUE(pointer != nullptr);
+ expected += android::base::StringPrintf("%d: memalign %p 32 50\n", getpid(), pointer);
+ debug_free(pointer);
+ expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
ASSERT_EQ(0, debug_posix_memalign(&pointer, 32, 50));
ASSERT_TRUE(pointer != nullptr);
expected += android::base::StringPrintf("%d: memalign %p 32 50\n", getpid(), pointer);