diff options
author | Dimitry Ivanov <dimitry@google.com> | 2016-01-21 10:55:40 -0800 |
---|---|---|
committer | Dimitry Ivanov <dimitry@google.com> | 2016-01-21 14:28:33 -0800 |
commit | 3edc5c41bbee7cf608a781e7056599f32ca1949c (patch) | |
tree | 88b26c5a450fb4548479c109a68253e7a41c07e8 /linker/tests/linker_memory_allocator_test.cpp | |
parent | 8d6e19408cfdbd73ba7e5c9e5b8716d9dad8dcf9 (diff) |
linker: align allocated blocks to 16 bytes
C/C++ requires the result of malloc/new to be
aligned for any primitive type.
Change-Id: I715b7679e738f34b3b409993fb3ef242e1321b7f
Diffstat (limited to 'linker/tests/linker_memory_allocator_test.cpp')
-rw-r--r-- | linker/tests/linker_memory_allocator_test.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/linker/tests/linker_memory_allocator_test.cpp b/linker/tests/linker_memory_allocator_test.cpp index defd4f3a8..5b8553675 100644 --- a/linker/tests/linker_memory_allocator_test.cpp +++ b/linker/tests/linker_memory_allocator_test.cpp @@ -96,6 +96,7 @@ TEST(linker_memory, test_realloc) { ASSERT_TRUE(reallocated_ptr != nullptr); ASSERT_TRUE(reallocated_ptr != array); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(reallocated_ptr) % 16); ASSERT_TRUE(memcmp(reallocated_ptr, model, array_size * 2) == 0); @@ -107,6 +108,7 @@ TEST(linker_memory, test_realloc) { ASSERT_TRUE(reallocated_ptr != nullptr); ASSERT_TRUE(reallocated_ptr != array); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(reallocated_ptr) % 16); ASSERT_TRUE(memcmp(reallocated_ptr, model, 4000) == 0); @@ -125,7 +127,10 @@ TEST(linker_memory, test_small_smoke) { reinterpret_cast<test_struct_small*>(allocator.alloc(sizeof(test_struct_small))); ASSERT_TRUE(ptr1 != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16); ASSERT_TRUE(ptr2 != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16); + ASSERT_EQ(reinterpret_cast<uintptr_t>(ptr1)+16, reinterpret_cast<uintptr_t>(ptr2)); ASSERT_TRUE(memcmp(ptr1, zeros, 16) == 0); @@ -143,7 +148,9 @@ TEST(linker_memory, test_huge_smoke) { reinterpret_cast<test_struct_huge*>(allocator.alloc(sizeof(test_struct_huge))); ASSERT_TRUE(ptr1 != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16); ASSERT_TRUE(ptr2 != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16); ASSERT_TRUE( reinterpret_cast<uintptr_t>(ptr1)/kPageSize != reinterpret_cast<uintptr_t>(ptr2)/kPageSize); @@ -160,7 +167,9 @@ TEST(linker_memory, test_large) { reinterpret_cast<test_struct_large*>(allocator.alloc(1024)); ASSERT_TRUE(ptr1 != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16); ASSERT_TRUE(ptr2 != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16); ASSERT_EQ(reinterpret_cast<uintptr_t>(ptr1) + 1024, reinterpret_cast<uintptr_t>(ptr2)); @@ -179,6 +188,7 @@ TEST(linker_memory, test_large) { reinterpret_cast<test_struct_large*>(allocator.alloc(sizeof(test_struct_large))); ASSERT_TRUE(ptr_to_free != nullptr); + ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr_to_free) % 16); allocator.free(ptr1); |