1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright 2011 Google Inc. All Rights Reserved.
#include "space.h"
#include "common_test.h"
#include "globals.h"
#include "UniquePtr.h"
namespace art {
class SpaceTest : public CommonTest {};
TEST_F(SpaceTest, Init) {
{
// Init < max == growth
UniquePtr<Space> space(Space::Create("test", 16 * MB, 32 * MB, 32 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Init == max == growth
UniquePtr<Space> space(Space::Create("test", 16 * MB, 16 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Init > max == growth
UniquePtr<Space> space(Space::Create("test", 32 * MB, 16 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() == NULL);
}
{
// Growth == init < max
UniquePtr<Space> space(Space::Create("test", 16 * MB, 32 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Growth < init < max
UniquePtr<Space> space(Space::Create("test", 16 * MB, 32 * MB, 8 * MB, NULL));
EXPECT_TRUE(space.get() == NULL);
}
{
// Init < growth < max
UniquePtr<Space> space(Space::Create("test", 8 * MB, 32 * MB, 16 * MB, NULL));
EXPECT_TRUE(space.get() != NULL);
}
{
// Init < max < growth
UniquePtr<Space> space(Space::Create("test", 8 * MB, 16 * MB, 32 * MB, NULL));
EXPECT_TRUE(space.get() == NULL);
}
}
TEST_F(SpaceTest, AllocAndFree) {
UniquePtr<Space> space(Space::Create("test", 4 * MB, 16 * MB, 16 * MB, NULL));
ASSERT_TRUE(space.get() != NULL);
// Succeeds, fits without adjusting the max allowed footprint.
void* ptr1 = space->AllocWithoutGrowth(1 * MB);
EXPECT_TRUE(ptr1 != NULL);
// Fails, requires a higher allowed footprint.
void* ptr2 = space->AllocWithoutGrowth(8 * MB);
EXPECT_TRUE(ptr2 == NULL);
// Succeeds, adjusts the footprint.
void* ptr3 = space->AllocWithGrowth(8 * MB);
EXPECT_TRUE(ptr3 != NULL);
// Fails, requires a higher allowed footprint.
void* ptr4 = space->AllocWithoutGrowth(8 * MB);
EXPECT_FALSE(ptr4 != NULL);
// Also fails, requires a higher allowed footprint.
void* ptr5 = space->AllocWithGrowth(8 * MB);
EXPECT_FALSE(ptr5 != NULL);
// Release some memory.
size_t free3 = space->Free(ptr3);
EXPECT_LE(8U * MB, free3);
// Succeeds, now that memory has been freed.
void* ptr6 = space->AllocWithGrowth(9 * MB);
EXPECT_TRUE(ptr6 != NULL);
// Final clean up.
size_t free1 = space->Free(ptr1);
EXPECT_LE(1U * MB, free1);
}
} // namespace art
|