OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/aligned_memory.h" | 5 #include "base/memory/aligned_memory.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 #define EXPECT_ALIGNED(ptr, align) \ | 9 #define EXPECT_ALIGNED(ptr, align) \ |
10 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) | 10 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) |
11 | 11 |
(...skipping 15 matching lines...) Expand all Loading... |
27 EXPECT_ALIGNED(raw8.void_data(), 8); | 27 EXPECT_ALIGNED(raw8.void_data(), 8); |
28 EXPECT_ALIGNED(raw16.void_data(), 16); | 28 EXPECT_ALIGNED(raw16.void_data(), 16); |
29 EXPECT_ALIGNED(raw256.void_data(), 256); | 29 EXPECT_ALIGNED(raw256.void_data(), 256); |
30 EXPECT_ALIGNED(raw4096.void_data(), 4096); | 30 EXPECT_ALIGNED(raw4096.void_data(), 4096); |
31 } | 31 } |
32 | 32 |
33 TEST(AlignedMemoryTest, StackAlignment) { | 33 TEST(AlignedMemoryTest, StackAlignment) { |
34 AlignedMemory<8, 8> raw8; | 34 AlignedMemory<8, 8> raw8; |
35 AlignedMemory<8, 16> raw16; | 35 AlignedMemory<8, 16> raw16; |
36 AlignedMemory<8, 256> raw256; | 36 AlignedMemory<8, 256> raw256; |
37 AlignedMemory<8, 4096> raw4096; | |
38 | 37 |
39 EXPECT_EQ(8u, ALIGNOF(raw8)); | 38 EXPECT_EQ(8u, ALIGNOF(raw8)); |
40 EXPECT_EQ(16u, ALIGNOF(raw16)); | 39 EXPECT_EQ(16u, ALIGNOF(raw16)); |
41 EXPECT_EQ(256u, ALIGNOF(raw256)); | 40 EXPECT_EQ(256u, ALIGNOF(raw256)); |
42 EXPECT_EQ(4096u, ALIGNOF(raw4096)); | |
43 | 41 |
44 EXPECT_ALIGNED(raw8.void_data(), 8); | 42 EXPECT_ALIGNED(raw8.void_data(), 8); |
45 EXPECT_ALIGNED(raw16.void_data(), 16); | 43 EXPECT_ALIGNED(raw16.void_data(), 16); |
46 EXPECT_ALIGNED(raw256.void_data(), 256); | 44 EXPECT_ALIGNED(raw256.void_data(), 256); |
| 45 |
| 46 // TODO(ios): This test hits an armv7 bug in clang. crbug.com/138066 |
| 47 #if !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY)) |
| 48 AlignedMemory<8, 4096> raw4096; |
| 49 EXPECT_EQ(4096u, ALIGNOF(raw4096)); |
47 EXPECT_ALIGNED(raw4096.void_data(), 4096); | 50 EXPECT_ALIGNED(raw4096.void_data(), 4096); |
| 51 #endif // !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY)) |
48 } | 52 } |
49 | 53 |
50 } // namespace | 54 } // namespace |
OLD | NEW |