summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/tests
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-11-20 03:56:04 +0000
committerDean Michael Berris <dberris@google.com>2018-11-20 03:56:04 +0000
commit388af45f18298cb6684dfb61ebeca2070468c8d7 (patch)
tree5ccd892abf09dc5226671bc8f06812179c10d640 /compiler-rt/lib/xray/tests
parent25e44e7c33a639b3c5266901ba109fefa39ca8c4 (diff)
downloadbcm5719-llvm-388af45f18298cb6684dfb61ebeca2070468c8d7.tar.gz
bcm5719-llvm-388af45f18298cb6684dfb61ebeca2070468c8d7.zip
[XRay] Add a test for allocator exhaustion
Use a more representative test of allocating small chunks for oddly-sized (small) objects from an allocator that has a page's worth of memory. llvm-svn: 347286
Diffstat (limited to 'compiler-rt/lib/xray/tests')
-rw-r--r--compiler-rt/lib/xray/tests/unit/allocator_test.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler-rt/lib/xray/tests/unit/allocator_test.cc b/compiler-rt/lib/xray/tests/unit/allocator_test.cc
index be404160e41..0177798b069 100644
--- a/compiler-rt/lib/xray/tests/unit/allocator_test.cc
+++ b/compiler-rt/lib/xray/tests/unit/allocator_test.cc
@@ -33,10 +33,28 @@ TEST(AllocatorTest, Allocate) {
TEST(AllocatorTest, OverAllocate) {
Allocator<sizeof(TestData)> A(sizeof(TestData));
auto B1 = A.Allocate();
- (void)B1;
+ ASSERT_NE(B1.Data, nullptr);
auto B2 = A.Allocate();
ASSERT_EQ(B2.Data, nullptr);
}
+struct OddSizedData {
+ s64 A;
+ s32 B;
+};
+
+TEST(AllocatorTest, AllocateBoundaries) {
+ Allocator<sizeof(OddSizedData)> A(GetPageSizeCached());
+
+ // Keep allocating until we hit a nullptr block.
+ unsigned C = 0;
+ auto Expected =
+ GetPageSizeCached() / RoundUpTo(sizeof(OddSizedData), kCacheLineSize);
+ for (auto B = A.Allocate(); B.Data != nullptr; B = A.Allocate(), ++C)
+ ;
+
+ ASSERT_EQ(C, Expected);
+}
+
} // namespace
} // namespace __xray
OpenPOWER on IntegriCloud