| 1 |
import os |
| 2 |
from rpython.tool.udir import udir |
| 3 |
from rpython.memory.gc.test.test_direct import BaseDirectGCTest, S |
| 4 |
from rpython.memory.gc import inspector |
| 5 |
from rpython.rtyper.lltypesystem import llmemory |
| 6 |
|
| 7 |
|
| 8 |
class InspectorTest(BaseDirectGCTest): |
| 9 |
|
| 10 |
def test_dump_rpy_heap(self): |
| 11 |
p = self.malloc(S) |
| 12 |
p.x = 5 |
| 13 |
q = self.malloc(S) |
| 14 |
q.x = 6 |
| 15 |
self.write(p, 'next', q) |
| 16 |
self.stackroots.append(p) |
| 17 |
|
| 18 |
saved = inspector.HeapDumper.flush.im_func |
| 19 |
try: |
| 20 |
seen = [] |
| 21 |
def my_flush(self): |
| 22 |
for i in range(self.buf_count): |
| 23 |
seen.append(self.writebuffer[i]) |
| 24 |
self.buf_count = 0 |
| 25 |
inspector.HeapDumper.flush = my_flush |
| 26 |
inspector.dump_rpy_heap(self.gc, -123456) |
| 27 |
finally: |
| 28 |
inspector.HeapDumper.flush = saved |
| 29 |
|
| 30 |
class ASize(object): |
| 31 |
def __eq__(self, other): |
| 32 |
return isinstance(other, llmemory.AddressOffset) |
| 33 |
adr_p = seen[0] |
| 34 |
adr_q = seen[3] |
| 35 |
expected = [adr_p, 1, ASize(), adr_q, -1, |
| 36 |
0, 0, 0, -1, |
| 37 |
adr_q, 1, ASize(), -1] |
| 38 |
assert expected == seen |
| 39 |
|
| 40 |
|
| 41 |
class TestHybridGC(InspectorTest): |
| 42 |
from rpython.memory.gc.hybrid import HybridGC as GCClass |
| 43 |
|
| 44 |
class TestMiniMarkGCSimple(InspectorTest): |
| 45 |
from rpython.memory.gc.minimark import MiniMarkGC as GCClass |
| 46 |
from rpython.memory.gc.minimarktest import SimpleArenaCollection |
| 47 |
GC_PARAMS = {'ArenaCollectionClass': SimpleArenaCollection, |
| 48 |
"card_page_indices": 4} |