diff options
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_allocator.h | 1 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc | 53 |
2 files changed, 36 insertions, 18 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h index 77ea6242f6e..23952f6eb3c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h @@ -102,6 +102,7 @@ typedef IntrusiveList<AllocatorListNode> AllocatorFreeList; // is has to be POD. template<const uptr kNumClasses, class SizeClassAllocator> struct SizeClassAllocatorLocalCache { + typedef SizeClassAllocator Allocator; // Don't need to call Init if the object is a global (i.e. zero-initialized). void Init() { internal_memset(this, 0, sizeof(*this)); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc index de6491dd7dd..57e4045b848 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc @@ -19,9 +19,7 @@ static const uptr kAllocatorSize = 0x010000000000ULL; // 1T. typedef DefaultSizeClassMap SCMap; typedef - SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 16, SCMap> Allocator; -typedef SizeClassAllocatorLocalCache<Allocator::kNumClasses, Allocator> - AllocatorCache; + SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 16, SCMap> Allocator64; template <class SizeClassMap> void TestSizeClassMap() { @@ -61,7 +59,8 @@ TEST(SanitizerCommon, CompactSizeClassMap) { TestSizeClassMap<CompactSizeClassMap>(); } -TEST(SanitizerCommon, SizeClassAllocator64) { +template <class Allocator> +void TestSizeClassAllocator() { Allocator a; a.Init(); @@ -107,8 +106,12 @@ TEST(SanitizerCommon, SizeClassAllocator64) { a.TestOnlyUnmap(); } +TEST(SanitizerCommon, SizeClassAllocator64) { + TestSizeClassAllocator<Allocator64>(); +} -TEST(SanitizerCommon, SizeClassAllocator64MetadataStress) { +template <class Allocator> +void SizeClassAllocator64MetadataStress() { Allocator a; a.Init(); static volatile void *sink; @@ -132,6 +135,11 @@ TEST(SanitizerCommon, SizeClassAllocator64MetadataStress) { (void)sink; } +TEST(SanitizerCommon, SizeClassAllocator64MetadataStress) { + SizeClassAllocator64MetadataStress<Allocator64>(); +} + +template<class Allocator> void FailInAssertionOnOOM() { Allocator a; a.Init(); @@ -144,8 +152,7 @@ void FailInAssertionOnOOM() { } TEST(SanitizerCommon, SizeClassAllocator64Overflow) { - EXPECT_DEATH(FailInAssertionOnOOM(), - "Out of memory"); + EXPECT_DEATH(FailInAssertionOnOOM<Allocator64>(), "Out of memory"); } TEST(SanitizerCommon, LargeMmapAllocator) { @@ -203,15 +210,13 @@ TEST(SanitizerCommon, LargeMmapAllocator) { } } -TEST(SanitizerCommon, CombinedAllocator) { - typedef Allocator PrimaryAllocator; - typedef LargeMmapAllocator SecondaryAllocator; - typedef CombinedAllocator<PrimaryAllocator, AllocatorCache, - SecondaryAllocator> Allocator; +template +<class PrimaryAllocator, class SecondaryAllocator, class AllocatorCache> +void TestCombinedAllocator() { + CombinedAllocator<PrimaryAllocator, AllocatorCache, SecondaryAllocator> a; + a.Init(); AllocatorCache cache; - Allocator a; - a.Init(); cache.Init(); EXPECT_EQ(a.Allocate(&cache, -1, 1), (void*)0); @@ -251,13 +256,19 @@ TEST(SanitizerCommon, CombinedAllocator) { a.TestOnlyUnmap(); } -static THREADLOCAL AllocatorCache static_allocator_cache; -TEST(SanitizerCommon, SizeClassAllocatorLocalCache) { - static_allocator_cache.Init(); +TEST(SanitizerCommon, CombinedAllocator) { + TestCombinedAllocator<Allocator64, + LargeMmapAllocator, + SizeClassAllocatorLocalCache<Allocator64::kNumClasses, Allocator64> > (); +} - Allocator a; +template <class AllocatorCache> +void TestSizeClassAllocatorLocalCache() { + static THREADLOCAL AllocatorCache static_allocator_cache; + static_allocator_cache.Init(); AllocatorCache cache; + typename AllocatorCache::Allocator a; a.Init(); cache.Init(); @@ -282,3 +293,9 @@ TEST(SanitizerCommon, SizeClassAllocatorLocalCache) { a.TestOnlyUnmap(); } + +TEST(SanitizerCommon, SizeClassAllocator64LocalCache) { + typedef SizeClassAllocatorLocalCache<Allocator64::kNumClasses, Allocator64> + AllocatorCache; + TestSizeClassAllocatorLocalCache<AllocatorCache> (); +} |