1 #include <gtest/gtest.h> 14 TEST(TestWeakPointer, WeakPointerGetsInvalidated) {
15 Tensor a = at::ones({2, 2});
18 ASSERT_FALSE(b.lock().defined());
22 TEST(TestWeakPointer, WeakPointerLock) {
23 Tensor a = at::ones({2, 2});
26 ASSERT_TRUE(c.defined());
29 ASSERT_TRUE(b.lock().defined());
31 ASSERT_FALSE(b.lock().defined());
35 TEST(TestWeakPointer, WeakUpdatesRefcountsTest) {
36 Tensor a = at::ones({2, 2});
37 ASSERT_EQ(a.use_count(), 1);
38 ASSERT_EQ(a.weak_use_count(), 1);
41 ASSERT_EQ(a.use_count(), 1);
42 ASSERT_EQ(a.weak_use_count(), 2);
44 ASSERT_EQ(a.use_count(), 1);
45 ASSERT_EQ(a.weak_use_count(), 1);
48 ASSERT_EQ(a.use_count(), 1);
49 auto locked = b.lock();
50 ASSERT_TRUE(locked.defined());
51 ASSERT_EQ(a.use_count(), 2);
53 ASSERT_EQ(a.use_count(), 1);
54 ASSERT_EQ(a.weak_use_count(), 1);
57 ASSERT_EQ(a.use_count(), 1);
58 ASSERT_EQ(a.weak_use_count(), 2);
60 ASSERT_EQ(b.use_count(), 0);
61 ASSERT_EQ(b.weak_use_count(), 1);