Index: test/cctest/cctest.h |
diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h |
index 193126a0818e91a1aac21a900c0b0db476c7467d..0efcf066b7bb11dd2065b30329a8496ccf51a16a 100644 |
--- a/test/cctest/cctest.h |
+++ b/test/cctest/cctest.h |
@@ -71,6 +71,17 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags; |
EXTENSION_LIST(DEFINE_EXTENSION_FLAG) |
#undef DEFINE_EXTENSION_FLAG |
+void RunAndTrackAllocations(void (*test)()); |
+ |
+#ifndef TEST_TRACK_ALLOCATIONS |
+#define TEST_TRACK_ALLOCATIONS(Name) \ |
+ static void Test##Name(); \ |
+ TEST(Name##TrackAllocations) { \ |
+ RunAndTrackAllocations(&Test##Name); \ |
+ } \ |
+ TEST(Name) |
+#endif |
+ |
class CcTest { |
public: |
typedef void (TestFunction)(); |
@@ -300,4 +311,41 @@ static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { |
} |
+// Helper class for new allocations tracking and checking. |
+// To use checking of JS allocations tracking in a test, |
+// use TEST_TRACK_ALLOCATIONS macro or just create an instance |
+// of this class. |
+class HeapObjectsTracker { |
+ public: |
+ HeapObjectsTracker() { |
+ heap_profiler_ = i::Isolate::Current()->heap_profiler(); |
+ CHECK_NE(NULL, heap_profiler_); |
+ |
+ heap_profiler_->StartHeapAllocationsRecording(); |
+ |
+ HEAP->CollectAllAvailableGarbage(); |
+ HEAP->CollectAllAvailableGarbage(); |
+ HEAP->CollectAllAvailableGarbage(); |
+ untracked_on_start_ = heap_profiler_->FindUntrackedObjects(); |
+ } |
+ |
+ virtual ~HeapObjectsTracker() { |
+ CHECK_GE(0, CountUntrackedObjects()); |
+ heap_profiler_->StopHeapAllocationsRecording(); |
+ } |
+ |
+ private: |
+ int CountUntrackedObjects() { |
+ HEAP->CollectAllAvailableGarbage(); |
+ HEAP->CollectAllAvailableGarbage(); |
+ HEAP->CollectAllAvailableGarbage(); |
+ |
+ return heap_profiler_->FindUntrackedObjects() - untracked_on_start_; |
+ } |
+ |
+ i::HeapProfiler* heap_profiler_; |
+ int untracked_on_start_; |
+}; |
+ |
+ |
#endif // ifndef CCTEST_H_ |