[compiler-rt] [scudo] Only init RingBuffer when needed. (PR #85994)
Christopher Ferris via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 20:10:33 PDT 2024
================
@@ -867,29 +867,83 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateInPlaceStress) {
}
}
+SCUDO_TYPED_TEST(ScudoCombinedTest, RingBufferDefaultDisabled) {
+ // The RingBuffer is not initialized until tracking is enabled for the
+ // first time.
+ auto *Allocator = this->Allocator.get();
+ ASSERT_EQ(0u, Allocator->getRingBufferSize());
+ ASSERT_EQ(nullptr, Allocator->getRingBufferAddress());
+}
+
+SCUDO_TYPED_TEST(ScudoCombinedTest, RingBufferInitOnce) {
+ auto *Allocator = this->Allocator.get();
+ Allocator->setTrackAllocationStacks(true);
+
+ auto Size = Allocator->getRingBufferSize();
+ ASSERT_GT(Size, 0u);
+ auto *Addr = Allocator->getRingBufferAddress();
+ EXPECT_NE(nullptr, Addr);
+
+ // Enable tracking again to verify that the initialization only happens once.
+ Allocator->setTrackAllocationStacks(true);
+ ASSERT_EQ(Size, Allocator->getRingBufferSize());
+ EXPECT_EQ(Addr, Allocator->getRingBufferAddress());
+}
+
SCUDO_TYPED_TEST(ScudoCombinedTest, RingBufferSize) {
auto *Allocator = this->Allocator.get();
+ Allocator->setTrackAllocationStacks(true);
+
auto Size = Allocator->getRingBufferSize();
ASSERT_GT(Size, 0u);
EXPECT_EQ(Allocator->getRingBufferAddress()[Size - 1], '\0');
}
SCUDO_TYPED_TEST(ScudoCombinedTest, RingBufferAddress) {
auto *Allocator = this->Allocator.get();
+ Allocator->setTrackAllocationStacks(true);
+
auto *Addr = Allocator->getRingBufferAddress();
EXPECT_NE(Addr, nullptr);
EXPECT_EQ(Addr, Allocator->getRingBufferAddress());
}
+SCUDO_TYPED_TEST(ScudoCombinedTest, StackDepotDefaultDisabled) {
+ // The StackDepot is not initialized until tracking is enabled for the
+ // first time.
+ auto *Allocator = this->Allocator.get();
+ ASSERT_EQ(0u, Allocator->getStackDepotSize());
+ ASSERT_EQ(nullptr, Allocator->getStackDepotAddress());
+}
+
+SCUDO_TYPED_TEST(ScudoCombinedTest, StackDepotInitOnce) {
+ auto *Allocator = this->Allocator.get();
+ Allocator->setTrackAllocationStacks(true);
+
+ auto Size = Allocator->getStackDepotSize();
+ ASSERT_GT(Size, 0u);
+ auto *Addr = Allocator->getStackDepotAddress();
----------------
cferris1000 wrote:
Done
https://github.com/llvm/llvm-project/pull/85994
More information about the llvm-commits
mailing list