diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-23 23:25:16 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-23 23:33:53 +0300 |
commit | f377199cf3b6a29f5eee520a969ef7ba243f61a9 (patch) | |
tree | 031f0cb06a299a748929751ed85240e5e91fe910 | |
parent | 0919657ac067bec39e9d05dbc3f00a1a40ce2040 (diff) | |
download | ydb-f377199cf3b6a29f5eee520a969ef7ba243f61a9.tar.gz |
Intermediate changes
commit_hash:9da3eb91ac1626625fafab7ae80b22f3f3b75821
-rw-r--r-- | library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp | 91 |
1 files changed, 53 insertions, 38 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 e43dca33c6..47db5325e1 100644 --- a/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp +++ b/library/cpp/yt/memory/unittests/atomic_intrusive_ptr_ut.cpp @@ -5,11 +5,15 @@ #include <library/cpp/yt/memory/atomic_intrusive_ptr.h> #include <library/cpp/yt/memory/leaky_singleton.h> +#include <util/system/compiler.h> + namespace NYT { namespace { //////////////////////////////////////////////////////////////////////////////// +#ifndef _lsan_enabled_ + using ::testing::IsNull; using ::testing::NotNull; using ::testing::InSequence; @@ -175,8 +179,17 @@ TEST(TIntrusiveAtomicPtrTest, Empty) EXPECT_EQ(nullptr, emptyPointer.Get()); } -// Reserved ref count. -constexpr int RRC = 65535; +constexpr int ReservedRefCount = 65535; + +TEST(TIntrusiveAtomicPtrTest, Reset) +{ + TIntricateObject object; + TIntricateObjectPtr owningPointer(&object); + TAtomicIntrusivePtr<TIntricateObject> atomicPointer(owningPointer); + atomicPointer.Reset(); + EXPECT_EQ(nullptr, atomicPointer.Get()); + EXPECT_THAT(object, HasRefCounts(1 + ReservedRefCount, ReservedRefCount, 0)); +} TEST(TIntrusiveAtomicPtrTest, Basic) { @@ -197,24 +210,24 @@ TEST(TIntrusiveAtomicPtrTest, Basic) TIntricateObjectPtr owningPointer(&object); TAtomicIntrusivePtr<TIntricateObject> atomicPointer(owningPointer); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 1, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 1, 1)); EXPECT_EQ(&object, owningPointer.Get()); auto p1 = atomicPointer.Acquire(); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 1, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 1, 1)); p1.Reset(); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 2, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 2, 1)); owningPointer.Reset(); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 3, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 3, 1)); } - EXPECT_THAT(object, HasRefCounts(2 + RRC, 2 + RRC, 2)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 2 + ReservedRefCount, 2)); } TEST(TIntrusiveAtomicPtrTest, BasicConst) @@ -236,24 +249,24 @@ TEST(TIntrusiveAtomicPtrTest, BasicConst) TConstIntricateObjectPtr owningPointer(&object); TAtomicIntrusivePtr<const TIntricateObject> atomicPointer(owningPointer); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 1, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 1, 1)); EXPECT_EQ(&object, owningPointer.Get()); auto p1 = atomicPointer.Acquire(); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 1, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 1, 1)); p1.Reset(); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 2, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 2, 1)); owningPointer.Reset(); - EXPECT_THAT(object, HasRefCounts(2 + RRC, 3, 1)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 3, 1)); } - EXPECT_THAT(object, HasRefCounts(2 + RRC, 2 + RRC, 2)); + EXPECT_THAT(object, HasRefCounts(2 + ReservedRefCount, 2 + ReservedRefCount, 2)); } TEST(TIntrusiveAtomicPtrTest, Acquire) @@ -261,25 +274,25 @@ TEST(TIntrusiveAtomicPtrTest, Acquire) TIntricateObject object; { TAtomicIntrusivePtr<TIntricateObject> atomicPtr{TIntricateObjectPtr(&object)}; - EXPECT_THAT(object, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount, 0, 0)); - for (int i = 0; i < RRC / 2; ++i) { + for (int i = 0; i < ReservedRefCount / 2; ++i) { { auto tmp = atomicPtr.Acquire(); - EXPECT_THAT(object, HasRefCounts(RRC, i, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount, i, 0)); } - EXPECT_THAT(object, HasRefCounts(RRC, i + 1, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount, i + 1, 0)); } { auto tmp = atomicPtr.Acquire(); - EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC / 2, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount + ReservedRefCount / 2, ReservedRefCount / 2, 0)); } - EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC / 2 + 1, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount + ReservedRefCount / 2, ReservedRefCount / 2 + 1, 0)); } - EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC + RRC / 2, 1)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount + ReservedRefCount / 2, ReservedRefCount + ReservedRefCount / 2, 1)); } TEST(TIntrusiveAtomicPtrTest, AcquireConst) @@ -287,25 +300,25 @@ TEST(TIntrusiveAtomicPtrTest, AcquireConst) const TIntricateObject object; { TAtomicIntrusivePtr<const TIntricateObject> atomicPtr{TConstIntricateObjectPtr(&object)}; - EXPECT_THAT(object, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount, 0, 0)); - for (int i = 0; i < RRC / 2; ++i) { + for (int i = 0; i < ReservedRefCount / 2; ++i) { { auto tmp = atomicPtr.Acquire(); - EXPECT_THAT(object, HasRefCounts(RRC, i, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount, i, 0)); } - EXPECT_THAT(object, HasRefCounts(RRC, i + 1, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount, i + 1, 0)); } { auto tmp = atomicPtr.Acquire(); - EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC / 2, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount + ReservedRefCount / 2, ReservedRefCount / 2, 0)); } - EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC / 2 + 1, 0)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount + ReservedRefCount / 2, ReservedRefCount / 2 + 1, 0)); } - EXPECT_THAT(object, HasRefCounts(RRC + RRC / 2, RRC + RRC / 2, 1)); + EXPECT_THAT(object, HasRefCounts(ReservedRefCount + ReservedRefCount / 2, ReservedRefCount + ReservedRefCount / 2, 1)); } TEST(TIntrusiveAtomicPtrTest, CAS) @@ -315,7 +328,7 @@ TEST(TIntrusiveAtomicPtrTest, CAS) { TAtomicIntrusivePtr<TIntricateObject> atomicPtr{TIntricateObjectPtr(&o1)}; - EXPECT_THAT(o1, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(o1, HasRefCounts(ReservedRefCount, 0, 0)); TIntricateObjectPtr p2(&o2); EXPECT_THAT(o2, HasRefCounts(1, 0, 0)); @@ -324,18 +337,18 @@ TEST(TIntrusiveAtomicPtrTest, CAS) EXPECT_TRUE(atomicPtr.CompareAndSwap(rawPtr, std::move(p2))); EXPECT_EQ(rawPtr, &o1); - EXPECT_THAT(o1, HasRefCounts(RRC, RRC, 1)); - EXPECT_THAT(o2, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(o1, HasRefCounts(ReservedRefCount, ReservedRefCount, 1)); + EXPECT_THAT(o2, HasRefCounts(ReservedRefCount, 0, 0)); rawPtr = nullptr; EXPECT_FALSE(atomicPtr.CompareAndSwap(rawPtr, TIntricateObjectPtr(&o1))); EXPECT_EQ(rawPtr, &o2); - EXPECT_THAT(o1, HasRefCounts(2 * RRC, 2 * RRC, 2)); - EXPECT_THAT(o2, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(o1, HasRefCounts(2 * ReservedRefCount, 2 * ReservedRefCount, 2)); + EXPECT_THAT(o2, HasRefCounts(ReservedRefCount, 0, 0)); } - EXPECT_THAT(o2, HasRefCounts(RRC, RRC, 1)); + EXPECT_THAT(o2, HasRefCounts(ReservedRefCount, ReservedRefCount, 1)); } TEST(TIntrusiveAtomicPtrTest, CASConst) @@ -345,7 +358,7 @@ TEST(TIntrusiveAtomicPtrTest, CASConst) { TAtomicIntrusivePtr<const TIntricateObject> atomicPtr{TConstIntricateObjectPtr(&o1)}; - EXPECT_THAT(o1, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(o1, HasRefCounts(ReservedRefCount, 0, 0)); TConstIntricateObjectPtr p2(&o2); EXPECT_THAT(o2, HasRefCounts(1, 0, 0)); @@ -354,18 +367,18 @@ TEST(TIntrusiveAtomicPtrTest, CASConst) EXPECT_TRUE(atomicPtr.CompareAndSwap(rawPtr, std::move(p2))); EXPECT_EQ(rawPtr, &o1); - EXPECT_THAT(o1, HasRefCounts(RRC, RRC, 1)); - EXPECT_THAT(o2, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(o1, HasRefCounts(ReservedRefCount, ReservedRefCount, 1)); + EXPECT_THAT(o2, HasRefCounts(ReservedRefCount, 0, 0)); rawPtr = nullptr; EXPECT_FALSE(atomicPtr.CompareAndSwap(rawPtr, TConstIntricateObjectPtr(&o1))); EXPECT_EQ(rawPtr, &o2); - EXPECT_THAT(o1, HasRefCounts(2 * RRC, 2 * RRC, 2)); - EXPECT_THAT(o2, HasRefCounts(RRC, 0, 0)); + EXPECT_THAT(o1, HasRefCounts(2 * ReservedRefCount, 2 * ReservedRefCount, 2)); + EXPECT_THAT(o2, HasRefCounts(ReservedRefCount, 0, 0)); } - EXPECT_THAT(o2, HasRefCounts(RRC, RRC, 1)); + EXPECT_THAT(o2, HasRefCounts(ReservedRefCount, ReservedRefCount, 1)); } TEST(TIntrusiveAtomicPtrTest, LSan) @@ -391,6 +404,8 @@ TEST(TIntrusiveAtomicPtrTest, LSan) LeakySingleton<TSingleton>(); } +#endif + //////////////////////////////////////////////////////////////////////////////// } // namespace |