summaryrefslogtreecommitdiff
path: root/linker/tests/linker_block_allocator_test.cpp
diff options
context:
space:
mode:
authorDimitry Ivanov <dimitry@google.com>2016-01-21 10:55:40 -0800
committerDimitry Ivanov <dimitry@google.com>2016-01-21 14:28:33 -0800
commit3edc5c41bbee7cf608a781e7056599f32ca1949c (patch)
tree88b26c5a450fb4548479c109a68253e7a41c07e8 /linker/tests/linker_block_allocator_test.cpp
parent8d6e19408cfdbd73ba7e5c9e5b8716d9dad8dcf9 (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_block_allocator_test.cpp')
-rw-r--r--linker/tests/linker_block_allocator_test.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/linker/tests/linker_block_allocator_test.cpp b/linker/tests/linker_block_allocator_test.cpp
index 3ef0f36f8..5adc4253e 100644
--- a/linker/tests/linker_block_allocator_test.cpp
+++ b/linker/tests/linker_block_allocator_test.cpp
@@ -53,10 +53,12 @@ TEST(linker_allocator, test_nominal) {
test_struct_nominal* ptr1 = allocator.alloc();
ASSERT_TRUE(ptr1 != nullptr);
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16);
test_struct_nominal* ptr2 = allocator.alloc();
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16);
ASSERT_TRUE(ptr2 != nullptr);
// they should be next to each other.
- ASSERT_EQ(ptr1+1, ptr2);
+ ASSERT_EQ(reinterpret_cast<uint8_t*>(ptr1)+16, reinterpret_cast<uint8_t*>(ptr2));
ptr1->value = 42;
@@ -71,8 +73,10 @@ TEST(linker_allocator, test_small) {
char* ptr2 = reinterpret_cast<char*>(allocator.alloc());
ASSERT_TRUE(ptr1 != nullptr);
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16);
ASSERT_TRUE(ptr2 != nullptr);
- ASSERT_EQ(ptr1+2*sizeof(void*), ptr2);
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16);
+ ASSERT_EQ(ptr1+16, ptr2); // aligned to 16
}
TEST(linker_allocator, test_larger) {
@@ -82,9 +86,11 @@ TEST(linker_allocator, test_larger) {
test_struct_larger* ptr2 = allocator.alloc();
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(ptr1+1, ptr2);
+ ASSERT_EQ(reinterpret_cast<uint8_t*>(ptr1) + 1024, reinterpret_cast<uint8_t*>(ptr2));
// lets allocate until we reach next page.
size_t n = kPageSize/sizeof(test_struct_larger) + 1 - 2;