diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-23 17:52:20 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-23 17:52:20 +0000 |
commit | cd924d6e5efdf80f66283ac66987f2b339c381cf (patch) | |
tree | 89d2ccd8588e12669b93eb98117e8d76a766fbf2 /base/lazy_instance_unittest.cc | |
parent | 2e8bb832c7b3867b3a10b81621830add0dd5bfb5 (diff) | |
download | chromium_src-cd924d6e5efdf80f66283ac66987f2b339c381cf.zip chromium_src-cd924d6e5efdf80f66283ac66987f2b339c381cf.tar.gz chromium_src-cd924d6e5efdf80f66283ac66987f2b339c381cf.tar.bz2 |
Add ALIGNAS and ALIGNOF macros to ensure proper alignment of StaticMemorySingletonTraits
BUG=95006
Review URL: https://chromiumcodereview.appspot.com/9186057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123270 0039d316-1c4b-4281-b951-d872f2087c98
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); +} |