[llvm-commits] [compiler-rt] r169264 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_allocator.h tests/sanitizer_allocator64_test.cc

Kostya Serebryany kcc at google.com
Tue Dec 4 05:59:23 PST 2012


Author: kcc
Date: Tue Dec  4 07:59:22 2012
New Revision: 169264

URL: http://llvm.org/viewvc/llvm-project?rev=169264&view=rev
Log:
[tsan] refactor the allocator tests to allow testing other flavours of the allocator (add templates)

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=169264&r1=169263&r2=169264&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Tue Dec  4 07:59:22 2012
@@ -102,6 +102,7 @@
 // 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));

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc?rev=169264&r1=169263&r2=169264&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc Tue Dec  4 07:59:22 2012
@@ -19,9 +19,7 @@
 
 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 @@
   TestSizeClassMap<CompactSizeClassMap>();
 }
 
-TEST(SanitizerCommon, SizeClassAllocator64) {
+template <class Allocator>
+void TestSizeClassAllocator() {
   Allocator a;
   a.Init();
 
@@ -107,8 +106,12 @@
   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 @@
   (void)sink;
 }
 
+TEST(SanitizerCommon, SizeClassAllocator64MetadataStress) {
+  SizeClassAllocator64MetadataStress<Allocator64>();
+}
+
+template<class Allocator>
 void FailInAssertionOnOOM() {
   Allocator a;
   a.Init();
@@ -144,8 +152,7 @@
 }
 
 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, 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 @@
   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 @@
 
   a.TestOnlyUnmap();
 }
+
+TEST(SanitizerCommon, SizeClassAllocator64LocalCache) {
+  typedef SizeClassAllocatorLocalCache<Allocator64::kNumClasses, Allocator64>
+      AllocatorCache;
+  TestSizeClassAllocatorLocalCache<AllocatorCache> ();
+}





More information about the llvm-commits mailing list