1 //===- llvm/unittest/Support/AllocatorTest.cpp - BumpPtrAllocator tests ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/Allocator.h"
12 #include "gtest/gtest.h"
18 TEST(AllocatorTest, Basics) {
19 BumpPtrAllocator Alloc;
20 int *a = (int*)Alloc.Allocate(sizeof(int), 0);
21 int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 0);
22 int *c = (int*)Alloc.Allocate(sizeof(int), 0);
31 EXPECT_EQ(1U, Alloc.GetNumSlabs());
34 // Allocate enough bytes to create three slabs.
35 TEST(AllocatorTest, ThreeSlabs) {
36 BumpPtrAllocator Alloc(4096, 4096);
37 Alloc.Allocate(3000, 0);
38 EXPECT_EQ(1U, Alloc.GetNumSlabs());
39 Alloc.Allocate(3000, 0);
40 EXPECT_EQ(2U, Alloc.GetNumSlabs());
41 Alloc.Allocate(3000, 0);
42 EXPECT_EQ(3U, Alloc.GetNumSlabs());
45 // Allocate enough bytes to create two slabs, reset the allocator, and do it
47 TEST(AllocatorTest, TestReset) {
48 BumpPtrAllocator Alloc(4096, 4096);
49 Alloc.Allocate(3000, 0);
50 EXPECT_EQ(1U, Alloc.GetNumSlabs());
51 Alloc.Allocate(3000, 0);
52 EXPECT_EQ(2U, Alloc.GetNumSlabs());
54 EXPECT_EQ(1U, Alloc.GetNumSlabs());
55 Alloc.Allocate(3000, 0);
56 EXPECT_EQ(1U, Alloc.GetNumSlabs());
57 Alloc.Allocate(3000, 0);
58 EXPECT_EQ(2U, Alloc.GetNumSlabs());
61 } // anonymous namespace