[pypy-svn] r79630 - in pypy/trunk/pypy/rpython/memory/gc: . test

arigo at codespeak.net arigo at codespeak.net
Mon Nov 29 12:56:01 CET 2010


Author: arigo
Date: Mon Nov 29 12:55:58 2010
New Revision: 79630

Added:
   pypy/trunk/pypy/rpython/memory/gc/test/test_inspector.py
Modified:
   pypy/trunk/pypy/rpython/memory/gc/inspector.py
   pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py
Log:
Add a test.


Modified: pypy/trunk/pypy/rpython/memory/gc/inspector.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/inspector.py	(original)
+++ pypy/trunk/pypy/rpython/memory/gc/inspector.py	Mon Nov 29 12:55:58 2010
@@ -101,7 +101,7 @@
 
 AddressStack = get_address_stack()
 
-class HeapDumper:
+class HeapDumper(object):
     _alloc_flavor_ = "raw"
     BUFSIZE = 8192     # words
 

Modified: pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py	(original)
+++ pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py	Mon Nov 29 12:55:58 2010
@@ -60,7 +60,7 @@
         pass
 
 
-class DirectGCTest(object):
+class BaseDirectGCTest(object):
     GC_PARAMS = {}
 
     def setup_method(self, meth):
@@ -106,6 +106,9 @@
         addr = self.gc.malloc(self.get_type_id(TYPE), n, zero=True)
         return llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
 
+
+class DirectGCTest(BaseDirectGCTest):
+
     def test_simple(self):
         p = self.malloc(S)
         p.x = 5

Added: pypy/trunk/pypy/rpython/memory/gc/test/test_inspector.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/rpython/memory/gc/test/test_inspector.py	Mon Nov 29 12:55:58 2010
@@ -0,0 +1,48 @@
+import os
+from pypy.tool.udir import udir
+from pypy.rpython.memory.gc.test.test_direct import BaseDirectGCTest, S
+from pypy.rpython.memory.gc import inspector
+from pypy.rpython.lltypesystem import llmemory
+
+
+class InspectorTest(BaseDirectGCTest):
+
+    def test_dump_rpy_heap(self):
+        p = self.malloc(S)
+        p.x = 5
+        q = self.malloc(S)
+        q.x = 6
+        self.write(p, 'next', q)
+        self.stackroots.append(p)
+        #
+        saved = inspector.HeapDumper.flush.im_func
+        try:
+            seen = []
+            def my_flush(self):
+                for i in range(self.buf_count):
+                    seen.append(self.writebuffer[i])
+                self.buf_count = 0
+            inspector.HeapDumper.flush = my_flush
+            inspector.dump_rpy_heap(self.gc, -123456)
+        finally:
+            inspector.HeapDumper.flush = saved
+        #
+        class ASize(object):
+            def __eq__(self, other):
+                return isinstance(other, llmemory.AddressOffset)
+        adr_p = seen[0]
+        adr_q = seen[3]
+        expected = [adr_p, 1, ASize(), adr_q, -1,
+                    0, 0, 0, -1,
+                    adr_q, 1, ASize(), -1]
+        assert expected == seen
+
+
+class TestHybridGC(InspectorTest):
+    from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
+
+class TestMiniMarkGCSimple(InspectorTest):
+    from pypy.rpython.memory.gc.minimark import MiniMarkGC as GCClass
+    from pypy.rpython.memory.gc.minimark import SimpleArenaCollection
+    GC_PARAMS = {'ArenaCollectionClass': SimpleArenaCollection,
+                 "card_page_indices": 4}



More information about the Pypy-commit mailing list