diff options
Diffstat (limited to 'base/lazy_instance_unittest.cc')
-rw-r--r-- | base/lazy_instance_unittest.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/base/lazy_instance_unittest.cc b/base/lazy_instance_unittest.cc index 1bd3ab4..01ce8e5 100644 --- a/base/lazy_instance_unittest.cc +++ b/base/lazy_instance_unittest.cc @@ -5,6 +5,7 @@ #include "base/at_exit.h" #include "base/atomic_sequence_num.h" #include "base/lazy_instance.h" +#include "base/memory/aligned_memory.h" #include "base/threading/simple_thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -139,3 +140,33 @@ TEST(LazyInstanceTest, LeakyLazyInstance) { } EXPECT_FALSE(deleted2); } + +namespace { + +template <size_t alignment> +class AlignedData { + public: + AlignedData() {} + ~AlignedData() {} + base::AlignedMemory<alignment, alignment> data_; +}; + +} // anonymous namespace + +#define EXPECT_ALIGNED(ptr, align) \ + EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) + +TEST(LazyInstanceTest, Alignment) { + using base::LazyInstance; + + // Create some static instances with increasing sizes and alignment + // requirements. By ordering this way, the linker will need to do some work to + // ensure proper alignment of the static data. + static LazyInstance<AlignedData<4> > align4 = LAZY_INSTANCE_INITIALIZER; + static LazyInstance<AlignedData<32> > align32 = LAZY_INSTANCE_INITIALIZER; + static LazyInstance<AlignedData<4096> > align4096 = LAZY_INSTANCE_INITIALIZER; + + EXPECT_ALIGNED(align4.Pointer(), 4); + EXPECT_ALIGNED(align32.Pointer(), 32); + EXPECT_ALIGNED(align4096.Pointer(), 4096); +} |