aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-09-23 13:52:42 +0300
committerbabenko <babenko@yandex-team.com>2024-09-23 14:05:30 +0300
commitd1ac45800ff24c19bf59707918ecfaf0b8324437 (patch)
tree94be73c9ea0757ff8824749c8523a2d220d7e653 /library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp
parent6f99122df4c7263d855c65d02e4ade278aaeed03 (diff)
downloadydb-d1ac45800ff24c19bf59707918ecfaf0b8324437.tar.gz
Make TAtomicIntrusivePtr lsan-friendly
commit_hash:c4a4db14dd6f9b82fb65377014112bf0a131d3e0
Diffstat (limited to 'library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp')
-rw-r--r--library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp b/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp
index 68489fcdf7..e43dca33c6 100644
--- a/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp
+++ b/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp
@@ -3,6 +3,7 @@
#include <library/cpp/yt/memory/new.h>
#include <library/cpp/yt/memory/ref_counted.h>
#include <library/cpp/yt/memory/atomic_intrusive_ptr.h>
+#include <library/cpp/yt/memory/leaky_singleton.h>
namespace NYT {
namespace {
@@ -168,7 +169,7 @@ private:
////////////////////////////////////////////////////////////////////////////////
-TEST(TAtomicPtrTest, Empty)
+TEST(TIntrusiveAtomicPtrTest, Empty)
{
TIntricateObjectPtr emptyPointer;
EXPECT_EQ(nullptr, emptyPointer.Get());
@@ -177,7 +178,7 @@ TEST(TAtomicPtrTest, Empty)
// Reserved ref count.
constexpr int RRC = 65535;
-TEST(TAtomicPtrTest, Basic)
+TEST(TIntrusiveAtomicPtrTest, Basic)
{
TIntricateObject object;
@@ -216,7 +217,7 @@ TEST(TAtomicPtrTest, Basic)
EXPECT_THAT(object, HasRefCounts(2 + RRC, 2 + RRC, 2));
}
-TEST(TAtomicPtrTest, BasicConst)
+TEST(TIntrusiveAtomicPtrTest, BasicConst)
{
const TIntricateObject object;
@@ -255,7 +256,7 @@ TEST(TAtomicPtrTest, BasicConst)
EXPECT_THAT(object, HasRefCounts(2 + RRC, 2 + RRC, 2));
}
-TEST(TAtomicPtrTest, Acquire)
+TEST(TIntrusiveAtomicPtrTest, Acquire)
{
TIntricateObject object;
{
@@ -281,7 +282,7 @@ TEST(TAtomicPtrTest, Acquire)
EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC + RRC / 2, 1));
}
-TEST(TAtomicPtrTest, AcquireConst)
+TEST(TIntrusiveAtomicPtrTest, AcquireConst)
{
const TIntricateObject object;
{
@@ -307,7 +308,7 @@ TEST(TAtomicPtrTest, AcquireConst)
EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC + RRC / 2, 1));
}
-TEST(TAtomicPtrTest, CAS)
+TEST(TIntrusiveAtomicPtrTest, CAS)
{
TIntricateObject o1;
TIntricateObject o2;
@@ -337,7 +338,7 @@ TEST(TAtomicPtrTest, CAS)
EXPECT_THAT(o2, HasRefCounts(RRC, RRC, 1));
}
-TEST(TAtomicPtrTest, CASConst)
+TEST(TIntrusiveAtomicPtrTest, CASConst)
{
const TIntricateObject o1;
const TIntricateObject o2;
@@ -367,6 +368,29 @@ TEST(TAtomicPtrTest, CASConst)
EXPECT_THAT(o2, HasRefCounts(RRC, RRC, 1));
}
+TEST(TIntrusiveAtomicPtrTest, LSan)
+{
+ struct S final
+ { };
+
+ struct TSingleton
+ {
+ TSingleton()
+ {
+ for (auto& ptr : Ptrs) {
+ ptr.Store(New<S>());
+ // Clobber pointer bits to prevent LSan from tracing the pointer.
+ ptr.Acquire();
+ }
+ }
+
+ // LSan has some issues detecting leaks when just one allocation is made.
+ std::array<TAtomicIntrusivePtr<S>, 100> Ptrs;
+ };
+
+ LeakySingleton<TSingleton>();
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace