1 #include <ThreadedTestCaller.h>
2 #include <cppunit/Test.h>
3 #include <cppunit/TestCaller.h>
4 #include <cppunit/TestSuite.h>
10 #include "AllocatorTest.h"
12 #include "Allocator.h"
13 #include "PhysicalPartitionAllocator.h"
15 AllocatorTest::AllocatorTest(std::string name
)
21 AllocatorTest::Suite() {
22 CppUnit::TestSuite
*suite
= new CppUnit::TestSuite("Yo");
25 suite
->addTest(new CppUnit::TestCaller
<AllocatorTest
>("Allocator::BlockSize Test", &AllocatorTest::BlockSizeTest
));
26 suite
->addTest(new CppUnit::TestCaller
<AllocatorTest
>("Allocator::Partition Full Test", &AllocatorTest::PartitionFullTest
));
32 AllocatorTest::BlockSizeTest() {
34 Allocator
allocator(0);
35 CHK(allocator
.InitCheck() != B_OK
);
39 Allocator
allocator(1);
40 CHK(allocator
.InitCheck() == B_OK
);
44 Allocator
allocator(2);
45 CHK(allocator
.InitCheck() == B_OK
);
49 Allocator
allocator(3);
50 CHK(allocator
.InitCheck() != B_OK
);
54 Allocator
allocator(256);
55 CHK(allocator
.InitCheck() == B_OK
);
59 Allocator
allocator(512);
60 CHK(allocator
.InitCheck() == B_OK
);
64 Allocator
allocator(1024);
65 CHK(allocator
.InitCheck() == B_OK
);
69 Allocator
allocator(1025);
70 CHK(allocator
.InitCheck() != B_OK
);
74 Allocator
allocator(2048);
75 CHK(allocator
.InitCheck() == B_OK
);
79 Allocator
allocator(4096);
80 CHK(allocator
.InitCheck() == B_OK
);
86 AllocatorTest::PartitionFullTest() {
88 extent_address extent
;
89 const uint32 blockSize
= 2048;
90 Allocator
allocator(blockSize
);
91 CHK(allocator
.InitCheck() == B_OK
);
92 CHK(allocator
.GetNextExtent(blockSize
*12, true, extent
) == B_OK
); // 0-11
93 extent
.set_location(14);
95 CHK(allocator
.GetExtent(extent
) == B_OK
); // 14
96 CHK(allocator
.GetNextExtent(blockSize
*3, true, extent
) == B_OK
); // 15-17
97 CHK(allocator
.GetNextExtent(1, true, extent
) == B_OK
); // 12
98 CHK(allocator
.GetBlock(12) != B_OK
);
99 CHK(allocator
.GetBlock(13) == B_OK
);
103 extent_address extent
;
104 Allocator
allocator(2048);
105 CHK(allocator
.InitCheck() == B_OK
);
106 CHK(allocator
.GetNextExtent(ULONG_MAX
-1, true, extent
) == B_OK
);
107 CHK(allocator
.GetNextExtent(1, true, extent
) != B_OK
);
108 extent
.set_location(256);
109 extent
.set_length(1);
110 CHK(allocator
.GetExtent(extent
) != B_OK
);
111 CHK(allocator
.GetBlock(13) != B_OK
);
115 extent_address extent
;
116 const uint32 blockSize
= 2048;
117 Allocator
allocator(blockSize
);
118 CHK(allocator
.InitCheck() == B_OK
);
119 CHK(allocator
.GetNextExtent(ULONG_MAX
-blockSize
*2, true, extent
) == B_OK
);
120 CHK(allocator
.GetNextExtent(1, true, extent
) == B_OK
);
121 extent
.set_location(256);
122 extent
.set_length(1);
123 CHK(allocator
.GetExtent(extent
) != B_OK
);
124 CHK(allocator
.GetBlock(13) != B_OK
);
125 PhysicalPartitionAllocator
partition(0, 0, allocator
);
126 std::list
<long_address
> extents
;
127 std::list
<extent_address
> physicalExtents
;
128 CHK(partition
.GetNextExtents(1, extents
, physicalExtents
) == B_OK
);
132 extent_address extent
;
133 const uint32 blockSize
= 2048;
134 Allocator
allocator(blockSize
);
135 CHK(allocator
.InitCheck() == B_OK
);
136 CHK(allocator
.GetNextExtent(ULONG_MAX
, true, extent
) == B_OK
);
137 PhysicalPartitionAllocator
partition(0, 0, allocator
);
138 std::list
<long_address
> extents
;
139 std::list
<extent_address
> physicalExtents
;
140 CHK(partition
.GetNextExtents(1, extents
, physicalExtents
) != B_OK
);