@@ -867,32 +867,86 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateInPlaceStress) {
867
867
}
868
868
}
869
869
870
+ SCUDO_TYPED_TEST (ScudoCombinedTest, RingBufferDefaultDisabled) {
871
+ // The RingBuffer is not initialized until tracking is enabled for the
872
+ // first time.
873
+ auto *Allocator = this ->Allocator .get ();
874
+ EXPECT_EQ (0u , Allocator->getRingBufferSize ());
875
+ EXPECT_EQ (nullptr , Allocator->getRingBufferAddress ());
876
+ }
877
+
878
+ SCUDO_TYPED_TEST (ScudoCombinedTest, RingBufferInitOnce) {
879
+ auto *Allocator = this ->Allocator .get ();
880
+ Allocator->setTrackAllocationStacks (true );
881
+
882
+ auto RingBufferSize = Allocator->getRingBufferSize ();
883
+ ASSERT_GT (RingBufferSize, 0u );
884
+ auto *RingBufferAddress = Allocator->getRingBufferAddress ();
885
+ EXPECT_NE (nullptr , RingBufferAddress);
886
+
887
+ // Enable tracking again to verify that the initialization only happens once.
888
+ Allocator->setTrackAllocationStacks (true );
889
+ ASSERT_EQ (RingBufferSize, Allocator->getRingBufferSize ());
890
+ EXPECT_EQ (RingBufferAddress, Allocator->getRingBufferAddress ());
891
+ }
892
+
870
893
SCUDO_TYPED_TEST (ScudoCombinedTest, RingBufferSize) {
871
894
auto *Allocator = this ->Allocator .get ();
872
- auto Size = Allocator->getRingBufferSize ();
873
- ASSERT_GT (Size, 0u );
874
- EXPECT_EQ (Allocator->getRingBufferAddress ()[Size - 1 ], ' \0 ' );
895
+ Allocator->setTrackAllocationStacks (true );
896
+
897
+ auto RingBufferSize = Allocator->getRingBufferSize ();
898
+ ASSERT_GT (RingBufferSize, 0u );
899
+ EXPECT_EQ (Allocator->getRingBufferAddress ()[RingBufferSize - 1 ], ' \0 ' );
875
900
}
876
901
877
902
SCUDO_TYPED_TEST (ScudoCombinedTest, RingBufferAddress) {
878
903
auto *Allocator = this ->Allocator .get ();
879
- auto *Addr = Allocator->getRingBufferAddress ();
880
- EXPECT_NE (Addr, nullptr );
881
- EXPECT_EQ (Addr, Allocator->getRingBufferAddress ());
904
+ Allocator->setTrackAllocationStacks (true );
905
+
906
+ auto *RingBufferAddress = Allocator->getRingBufferAddress ();
907
+ EXPECT_NE (RingBufferAddress, nullptr );
908
+ EXPECT_EQ (RingBufferAddress, Allocator->getRingBufferAddress ());
909
+ }
910
+
911
+ SCUDO_TYPED_TEST (ScudoCombinedTest, StackDepotDefaultDisabled) {
912
+ // The StackDepot is not initialized until tracking is enabled for the
913
+ // first time.
914
+ auto *Allocator = this ->Allocator .get ();
915
+ EXPECT_EQ (0u , Allocator->getStackDepotSize ());
916
+ EXPECT_EQ (nullptr , Allocator->getStackDepotAddress ());
917
+ }
918
+
919
+ SCUDO_TYPED_TEST (ScudoCombinedTest, StackDepotInitOnce) {
920
+ auto *Allocator = this ->Allocator .get ();
921
+ Allocator->setTrackAllocationStacks (true );
922
+
923
+ auto StackDepotSize = Allocator->getStackDepotSize ();
924
+ EXPECT_GT (StackDepotSize, 0u );
925
+ auto *StackDepotAddress = Allocator->getStackDepotAddress ();
926
+ EXPECT_NE (nullptr , StackDepotAddress);
927
+
928
+ // Enable tracking again to verify that the initialization only happens once.
929
+ Allocator->setTrackAllocationStacks (true );
930
+ EXPECT_EQ (StackDepotSize, Allocator->getStackDepotSize ());
931
+ EXPECT_EQ (StackDepotAddress, Allocator->getStackDepotAddress ());
882
932
}
883
933
884
934
SCUDO_TYPED_TEST (ScudoCombinedTest, StackDepotSize) {
885
935
auto *Allocator = this ->Allocator .get ();
886
- auto Size = Allocator->getStackDepotSize ();
887
- ASSERT_GT (Size, 0u );
888
- EXPECT_EQ (Allocator->getStackDepotAddress ()[Size - 1 ], ' \0 ' );
936
+ Allocator->setTrackAllocationStacks (true );
937
+
938
+ auto StackDepotSize = Allocator->getStackDepotSize ();
939
+ EXPECT_GT (StackDepotSize, 0u );
940
+ EXPECT_EQ (Allocator->getStackDepotAddress ()[StackDepotSize - 1 ], ' \0 ' );
889
941
}
890
942
891
943
SCUDO_TYPED_TEST (ScudoCombinedTest, StackDepotAddress) {
892
944
auto *Allocator = this ->Allocator .get ();
893
- auto *Addr = Allocator->getStackDepotAddress ();
894
- EXPECT_NE (Addr, nullptr );
895
- EXPECT_EQ (Addr, Allocator->getStackDepotAddress ());
945
+ Allocator->setTrackAllocationStacks (true );
946
+
947
+ auto *StackDepotAddress = Allocator->getStackDepotAddress ();
948
+ EXPECT_NE (StackDepotAddress, nullptr );
949
+ EXPECT_EQ (StackDepotAddress, Allocator->getStackDepotAddress ());
896
950
}
897
951
898
952
SCUDO_TYPED_TEST (ScudoCombinedTest, StackDepot) {
0 commit comments