[pypy-commit] pypy gc-incminimark-pinning: another test rewrite...
groggi
noreply at buildbot.pypy.org
Mon Jun 2 17:24:02 CEST 2014
Author: Gregor Wegberg <code at gregorwegberg.com>
Branch: gc-incminimark-pinning
Changeset: r71822:1d6f4c0637ba
Date: 2014-05-14 16:15 +0200
http://bitbucket.org/pypy/pypy/changeset/1d6f4c0637ba/
Log: another test rewrite...
diff --git a/rpython/memory/gc/test/test_object_pinning.py b/rpython/memory/gc/test/test_object_pinning.py
--- a/rpython/memory/gc/test/test_object_pinning.py
+++ b/rpython/memory/gc/test/test_object_pinning.py
@@ -1,5 +1,5 @@
import py
-from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper.lltypesystem import lltype, llmemory, llarena
from rpython.memory.gc.incminimark import IncrementalMiniMarkGC
from test_direct import BaseDirectGCTest
@@ -10,6 +10,32 @@
class PinningGCTest(BaseDirectGCTest):
+ def test_pin_can_move(self):
+ # even a pinned object is considered to be movable. Only the caller
+ # of pin() knows if it is currently movable or not.
+ ptr = self.malloc(S)
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ assert self.gc.can_move(adr)
+ assert self.gc.pin(adr)
+ assert self.gc.can_move(adr)
+
+ def test_pin_twice(self):
+ ptr = self.malloc(S)
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ assert self.gc.pin(adr)
+ assert not self.gc.pin(adr)
+
+ def test_unpin_not_pinned(self):
+ # this test checks a requirement of the unpin() interface
+ ptr = self.malloc(S)
+ py.test.raises(Exception,
+ self.gc.unpin, llmemory.cast_ptr_to_adr(ptr))
+
+ # XXX test with multiple mallocs, and only part of them is pinned
+
+class TestIncminimark(PinningGCTest):
+ from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
+
def test_simple_pin(self):
ptr = self.malloc(S)
ptr.someInt = 100
@@ -23,7 +49,24 @@
assert self.gc.is_in_nursery(adr)
assert ptr.someInt == 100
- # XXX not implemented yet
+ def test_simple_pin_unpin(self):
+ ptr = self.malloc(S)
+ ptr.someInt = 100
+ self.stackroots.append(ptr)
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ # check if pin worked
+ assert self.gc.pin(adr)
+ self.gc.collect()
+ assert self.gc.is_in_nursery(adr)
+ assert ptr.someInt == 100
+ # unpin and check if object is gone from nursery
+ self.gc.unpin(adr)
+ self.gc.collect()
+ py.test.raises(RuntimeError, 'ptr.someInt')
+ ptr_old = self.stackroots[0]
+ assert ptr_old.someInt == 100
+
+ @py.test.mark.xfail(reason="Not implemented yet", run=False)
def test_pin_referenced_from_stackroot(self):
root_ptr = self.malloc(S)
next_ptr = self.malloc(S)
@@ -40,29 +83,6 @@
assert next_ptr.someInt == 100
root_ptr = self.stackroots[0]
assert root_ptr.next == next_ptr
-
-
- def test_pin_can_move(self):
- # even a pinned object is considered to be movable. Only the caller
- # of pin() knows if it is currently movable or not.
- ptr = self.malloc(S)
- adr = llmemory.cast_ptr_to_adr(ptr)
- assert self.gc.can_move(adr)
- assert self.gc.pin(adr)
- assert self.gc.can_move(adr)
-
- def test_pin_twice(self):
- ptr = self.malloc(S)
- adr = llmemory.cast_ptr_to_adr(ptr)
- assert self.gc.pin(adr)
- assert not self.gc.pin(adr)
-
- # XXX test with multiple mallocs, and only part of them is pinned
- # XXX test unpin()
-
-
-class TestIncminimark(PinningGCTest):
- from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
def test_pin_old(self):
ptr = self.malloc(S)
More information about the pypy-commit
mailing list