[pypy-commit] pypy gc_no_cleanup_nursery: add tests
wenzhuman
noreply at buildbot.pypy.org
Wed Aug 13 00:39:47 CEST 2014
Author: wenzhuman <manwenzhu at gmail.com>
Branch: gc_no_cleanup_nursery
Changeset: r72779:21a70c2f9848
Date: 2014-08-11 18:42 -0700
http://bitbucket.org/pypy/pypy/changeset/21a70c2f9848/
Log: add tests
diff --git a/rpython/memory/gc/test/test_direct.py b/rpython/memory/gc/test/test_direct.py
--- a/rpython/memory/gc/test/test_direct.py
+++ b/rpython/memory/gc/test/test_direct.py
@@ -107,7 +107,7 @@
def malloc(self, TYPE, n=None):
addr = self.gc.malloc(self.get_type_id(TYPE), n, zero=True)
obj_ptr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
- #TODO: only zero fields if there is gc filed add something like has_gc_ptr()
+
if not self.gc.malloc_zero_filled:
zero_gc_pointers_inside(obj_ptr, TYPE)
return obj_ptr
@@ -667,9 +667,25 @@
class TestIncrementalMiniMarkGCFull(DirectGCTest):
from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
- def test_no_cleanup(self):
+ def test_malloc_fixedsize_no_cleanup(self):
p = self.malloc(S)
import pytest
with pytest.raises(lltype.UninitializedMemoryAccess):
x1 = p.x
-
\ No newline at end of file
+ assert p.prev == lltype.nullptr(S)
+ assert p.next == lltype.nullptr(S)
+
+ def test_malloc_varsize_no_cleanup(self):
+ x = lltype.Signed
+ VAR1 = lltype.GcArray(x)
+ p = self.malloc(VAR1,5)
+ import pytest
+ with pytest.raises(lltype.UninitializedMemoryAccess):
+ x1 = p[0]
+
+ def test_malloc_varsize_no_cleanup2(self):
+ p = self.malloc(VAR,100)
+ for i in range(100):
+ assert p[0] == lltype.nullptr(S)
+ assert False
+
diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py
--- a/rpython/memory/test/test_transformed_gc.py
+++ b/rpython/memory/test/test_transformed_gc.py
@@ -1,6 +1,7 @@
import py
import inspect
+from rpython.rlib.objectmodel import compute_hash, compute_identity_hash
from rpython.translator.c import gc
from rpython.annotator import model as annmodel
from rpython.rtyper.llannotation import SomePtr
@@ -13,6 +14,7 @@
from rpython.conftest import option
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rarithmetic import LONG_BIT
+import pdb
WORD = LONG_BIT // 8
@@ -154,7 +156,6 @@
class GenericGCTests(GCTest):
GC_CAN_SHRINK_ARRAY = False
-
def define_instances(cls):
class A(object):
pass
@@ -709,7 +710,6 @@
GC_CAN_MOVE = True
GC_CAN_MALLOC_NONMOVABLE = False
GC_CAN_TEST_ID = False
-
def define_many_ids(cls):
class A(object):
pass
@@ -1118,6 +1118,7 @@
def test_adr_of_nursery(self):
run = self.runner("adr_of_nursery")
res = run([])
+
class TestGenerationalNoFullCollectGC(GCTest):
# test that nursery is doing its job and that no full collection
@@ -1178,7 +1179,7 @@
'large_object': 8*WORD,
'translated_to_c': False}
root_stack_depth = 200
-
+
def define_ref_from_rawmalloced_to_regular(cls):
import gc
S = lltype.GcStruct('S', ('x', lltype.Signed))
@@ -1232,8 +1233,7 @@
def test_malloc_nonmovable_fixsize(self):
py.test.skip("not supported")
-
-
+
class TestMiniMarkGC(TestHybridGC):
gcname = "minimark"
GC_CAN_TEST_ID = True
@@ -1250,7 +1250,7 @@
'translated_to_c': False,
}
root_stack_depth = 200
-
+
def define_no_clean_setarrayitems(cls):
# The optimization find_clean_setarrayitems() in
# gctransformer/framework.py does not work with card marking.
@@ -1275,6 +1275,29 @@
run = self.runner("no_clean_setarrayitems")
res = run([])
assert res == 123
+
+ def define_nursery_hash_base(cls):
+ class A:
+ pass
+ def fn():
+ objects = []
+ hashes = []
+ for i in range(200):
+ rgc.collect(0) # nursery-only collection, if possible
+ obj = A()
+ objects.append(obj)
+ hashes.append(compute_identity_hash(obj))
+ unique = {}
+ for i in range(len(objects)):
+ assert compute_identity_hash(objects[i]) == hashes[i]
+ unique[hashes[i]] = None
+ return len(unique)
+ return fn
+
+ def test_nursery_hash_base(self):
+ res = self.runner('nursery_hash_base')
+ assert res >= 195
+ assert False
class TestIncrementalMiniMarkGC(TestMiniMarkGC):
gcname = "incminimark"
@@ -1292,8 +1315,58 @@
'translated_to_c': False,
}
root_stack_depth = 200
+
+ def define_malloc_array_of_gcptr(self):
+ S = lltype.GcStruct('S', ('x', lltype.Signed))
+ A = lltype.GcArray(lltype.Ptr(S))
+ def f():
+ lst = lltype.malloc(A, 5, zero= False)
+ return (lst[0] == lltype.nullptr(S)
+ and lst[1] == lltype.nullptr(S)
+ and lst[2] == lltype.nullptr(S)
+ and lst[3] == lltype.nullptr(S)
+ and lst[4] == lltype.nullptr(S))
+ return f
+
+ def test_malloc_array_of_gcptr(self):
+ run = self.runner('malloc_array_of_gcptr')
+ res = run([])
+ assert not res
+ '''
+ def define_malloc_struct_of_gcptr(cls):
+ S1 = lltype.GcStruct('S', ('x', lltype.Signed))
+ S = lltype.GcStruct('S',
+ ('x', lltype.Signed),
+ ('filed1', lltype.Ptr(S1)),
+ ('filed2', lltype.Ptr(S1)))
+ s0 = lltype.malloc(S)
+ def f():
+ return (s0.filed1 == lltype.nullptr(S1) and s0.filed2 == lltype.nullptr(S1))
+ return f
+ def test_malloc_struct_of_gcptr(self):
+ run = self.runner("malloc_struct_of_gcptr")
+ res = run([])
+ assert res
+ '''
+ '''
+ def define_malloc_struct_of_gcptr(cls):
+ S = lltype.GcForwardReference()
+ S.become(lltype.GcStruct('S',
+ ('x', lltype.Signed),
+ ('prev', lltype.Ptr(S)),
+ ('next', lltype.Ptr(S))))
+ s0 = lltype.malloc(S,zero = False)
+ def f():
+ return s0.next == lltype.nullptr(S)
+ return f
+ def test_malloc_struct_of_gcptr(self):
+ run = self.runner("malloc_struct_of_gcptr")
+ pdb.set_trace()
+ res = run([])
+ assert res
+ '''
# ________________________________________________________________
# tagged pointers
More information about the pypy-commit
mailing list