obj2yaml: Use the correct relocation type for different machine types
[oota-llvm.git] / unittests / Support / AllocatorTest.cpp
index 2a01f3a9c484e69d6d53bc9b40f0b16901a9e278..bcf6bf1c71dd0267380b0e97f7311be0642f6440 100644 (file)
@@ -8,7 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/Allocator.h"
-
 #include "gtest/gtest.h"
 #include <cstdlib>
 
@@ -34,7 +33,7 @@ TEST(AllocatorTest, Basics) {
 
 // Allocate enough bytes to create three slabs.
 TEST(AllocatorTest, ThreeSlabs) {
-  BumpPtrAllocator Alloc(4096, 4096);
+  BumpPtrAllocator Alloc;
   Alloc.Allocate(3000, 0);
   EXPECT_EQ(1U, Alloc.GetNumSlabs());
   Alloc.Allocate(3000, 0);
@@ -46,7 +45,7 @@ TEST(AllocatorTest, ThreeSlabs) {
 // Allocate enough bytes to create two slabs, reset the allocator, and do it
 // again.
 TEST(AllocatorTest, TestReset) {
-  BumpPtrAllocator Alloc(4096, 4096);
+  BumpPtrAllocator Alloc;
   Alloc.Allocate(3000, 0);
   EXPECT_EQ(1U, Alloc.GetNumSlabs());
   Alloc.Allocate(3000, 0);
@@ -82,17 +81,25 @@ TEST(AllocatorTest, TestAlignment) {
 // Test allocating just over the slab size.  This tests a bug where before the
 // allocator incorrectly calculated the buffer end pointer.
 TEST(AllocatorTest, TestOverflow) {
-  BumpPtrAllocator Alloc(4096, 4096);
+  BumpPtrAllocator Alloc;
 
   // Fill the slab right up until the end pointer.
   Alloc.Allocate(4096 - sizeof(MemSlab), 0);
   EXPECT_EQ(1U, Alloc.GetNumSlabs());
 
-  // If we dont't allocate a new slab, then we will have overflowed.
+  // If we don't allocate a new slab, then we will have overflowed.
   Alloc.Allocate(1, 0);
   EXPECT_EQ(2U, Alloc.GetNumSlabs());
 }
 
+// Test allocating with a size larger than the initial slab size.
+TEST(AllocatorTest, TestSmallSlabSize) {
+  BumpPtrAllocator Alloc;
+
+  Alloc.Allocate(8000, 0);
+  EXPECT_EQ(2U, Alloc.GetNumSlabs());
+}
+
 // Mock slab allocator that returns slabs aligned on 4096 bytes.  There is no
 // easy portable way to do this, so this is kind of a hack.
 class MockSlabAllocator : public SlabAllocator {
@@ -134,7 +141,7 @@ public:
 // will not.
 TEST(AllocatorTest, TestBigAlignment) {
   MockSlabAllocator SlabAlloc;
-  BumpPtrAllocator Alloc(4096, 4096, SlabAlloc);
+  BumpPtrAllocator Alloc(SlabAlloc);
   uintptr_t Ptr = (uintptr_t)Alloc.Allocate(3000, 2048);
   MemSlab *Slab = SlabAlloc.GetLastSlab();
   EXPECT_LE(Ptr + 3000, ((uintptr_t)Slab) + Slab->Size);