Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: Source/platform/heap/HeapTest.cpp

Issue 452723002: Oilpan: blink_heap_unittests: Test case have memory leak checked by Lsan (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 4134 matching lines...) Expand 10 before | Expand all | Expand 10 after
4145 EXPECT_EQ(4u, map1->size()); 4145 EXPECT_EQ(4u, map1->size());
4146 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 4146 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
4147 EXPECT_EQ(2, OffHeapInt::s_destructorCalls); 4147 EXPECT_EQ(2, OffHeapInt::s_destructorCalls);
4148 EXPECT_EQ(2u, map1->size()); 4148 EXPECT_EQ(2u, map1->size());
4149 Iterator i1 = map1->begin(); 4149 Iterator i1 = map1->begin();
4150 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); 4150 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt);
4151 EXPECT_EQ(livingInt, i1->key.second); 4151 EXPECT_EQ(livingInt, i1->key.second);
4152 ++i1; 4152 ++i1;
4153 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); 4153 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt);
4154 EXPECT_EQ(livingInt, i1->key.second); 4154 EXPECT_EQ(livingInt, i1->key.second);
4155
4156 map1.clear();
4157 livingInt.clear();
haraken 2014/08/11 02:00:07 Hmm, I don't fully understand why we need to call
Daniel Chow 2014/08/11 02:44:21 it's a good idea, I will make a try today On 2014
4158 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
4155 } 4159 }
4156 4160
4157 TEST(HeapTest, MapWithCustomWeaknessHandling2) 4161 TEST(HeapTest, MapWithCustomWeaknessHandling2)
4158 { 4162 {
4159 typedef HeapHashMap<RefPtr<OffHeapInt>, PairWithWeakHandling> Map; 4163 typedef HeapHashMap<RefPtr<OffHeapInt>, PairWithWeakHandling> Map;
4160 typedef Map::iterator Iterator; 4164 typedef Map::iterator Iterator;
4161 HeapStats initialHeapSize; 4165 HeapStats initialHeapSize;
4162 clearOutOldGarbage(&initialHeapSize); 4166 clearOutOldGarbage(&initialHeapSize);
4163 OffHeapInt::s_destructorCalls = 0; 4167 OffHeapInt::s_destructorCalls = 0;
4164 4168
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4216 EXPECT_EQ(4u, map1->size()); 4220 EXPECT_EQ(4u, map1->size());
4217 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 4221 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
4218 EXPECT_EQ(2, OffHeapInt::s_destructorCalls); 4222 EXPECT_EQ(2, OffHeapInt::s_destructorCalls);
4219 EXPECT_EQ(2u, map1->size()); 4223 EXPECT_EQ(2u, map1->size());
4220 Iterator i1 = map1->begin(); 4224 Iterator i1 = map1->begin();
4221 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt) ; 4225 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt) ;
4222 EXPECT_EQ(livingInt, i1->value.second); 4226 EXPECT_EQ(livingInt, i1->value.second);
4223 ++i1; 4227 ++i1;
4224 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt) ; 4228 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt) ;
4225 EXPECT_EQ(livingInt, i1->value.second); 4229 EXPECT_EQ(livingInt, i1->value.second);
4230
4231 map1.clear();
4232 livingInt.clear();
4233 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
4226 } 4234 }
4227 4235
4228 TEST(HeapTest, Bind) 4236 TEST(HeapTest, Bind)
4229 { 4237 {
4230 Closure closure = bind(&Bar::trace, Bar::create(), static_cast<Visitor*>(0)) ; 4238 Closure closure = bind(&Bar::trace, Bar::create(), static_cast<Visitor*>(0)) ;
4231 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 4239 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
4232 // The closure should have a persistent handle to the Bar. 4240 // The closure should have a persistent handle to the Bar.
4233 EXPECT_EQ(1u, Bar::s_live); 4241 EXPECT_EQ(1u, Bar::s_live);
4234 4242
4235 Closure closure2 = bind(&Bar::trace, RawPtr<Bar>(Bar::create()), static_cast <Visitor*>(0)); 4243 Closure closure2 = bind(&Bar::trace, RawPtr<Bar>(Bar::create()), static_cast <Visitor*>(0));
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
4968 4976
4969 static volatile IntWrapper* s_workerObjectPointer; 4977 static volatile IntWrapper* s_workerObjectPointer;
4970 }; 4978 };
4971 4979
4972 TEST(HeapTest, RecursiveMutex) 4980 TEST(HeapTest, RecursiveMutex)
4973 { 4981 {
4974 RecursiveLockingTester::test(); 4982 RecursiveLockingTester::test();
4975 } 4983 }
4976 4984
4977 template<typename T> 4985 template<typename T>
4978 class TraceIfNeededTester : public GarbageCollected<TraceIfNeededTester<T> > { 4986 class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester <T> > {
haraken 2014/08/11 02:00:07 This change looks correct. Ian: It would be great
4979 public: 4987 public:
4980 static TraceIfNeededTester<T>* create() { return new TraceIfNeededTester<T>( ); } 4988 static TraceIfNeededTester<T>* create() { return new TraceIfNeededTester<T>( ); }
4981 static TraceIfNeededTester<T>* create(const T& obj) { return new TraceIfNeed edTester<T>(obj); } 4989 static TraceIfNeededTester<T>* create(const T& obj) { return new TraceIfNeed edTester<T>(obj); }
4982 void trace(Visitor* visitor) { TraceIfNeeded<T>::trace(visitor, &m_obj); } 4990 void trace(Visitor* visitor) { TraceIfNeeded<T>::trace(visitor, &m_obj); }
4983 T& obj() { return m_obj; } 4991 T& obj() { return m_obj; }
4992 ~TraceIfNeededTester() { }
4984 private: 4993 private:
4985 TraceIfNeededTester() { } 4994 TraceIfNeededTester() { }
4986 explicit TraceIfNeededTester(const T& obj) : m_obj(obj) { } 4995 explicit TraceIfNeededTester(const T& obj) : m_obj(obj) { }
4987 T m_obj; 4996 T m_obj;
4988 }; 4997 };
4989 4998
4990 class PartObject { 4999 class PartObject {
4991 DISALLOW_ALLOCATION(); 5000 DISALLOW_ALLOCATION();
4992 public: 5001 public:
4993 PartObject() : m_obj(SimpleObject::create()) { } 5002 PartObject() : m_obj(SimpleObject::create()) { }
(...skipping 27 matching lines...) Expand all
5021 EXPECT_EQ(1u, visitor.count()); 5030 EXPECT_EQ(1u, visitor.count());
5022 } 5031 }
5023 5032
5024 { 5033 {
5025 TraceIfNeededTester<HeapVector<Member<SimpleObject> > >* m_vec = TraceIf NeededTester<HeapVector<Member<SimpleObject> > >::create(); 5034 TraceIfNeededTester<HeapVector<Member<SimpleObject> > >* m_vec = TraceIf NeededTester<HeapVector<Member<SimpleObject> > >::create();
5026 m_vec->obj().append(SimpleObject::create()); 5035 m_vec->obj().append(SimpleObject::create());
5027 visitor.reset(); 5036 visitor.reset();
5028 m_vec->trace(&visitor); 5037 m_vec->trace(&visitor);
5029 EXPECT_EQ(2u, visitor.count()); 5038 EXPECT_EQ(2u, visitor.count());
5030 } 5039 }
5040
5041 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
5031 } 5042 }
5032 5043
5033 } // namespace blink 5044 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698