[pypy-svn] r51673 - in pypy/branch/gc_hash/pypy: rpython/memory/test translator/c/test

arigo at codespeak.net arigo at codespeak.net
Wed Feb 20 10:21:18 CET 2008


Author: arigo
Date: Wed Feb 20 10:21:18 2008
New Revision: 51673

Modified:
   pypy/branch/gc_hash/pypy/rpython/memory/test/snippet.py
   pypy/branch/gc_hash/pypy/rpython/memory/test/test_gc.py
   pypy/branch/gc_hash/pypy/translator/c/test/test_boehm.py
   pypy/branch/gc_hash/pypy/translator/c/test/test_newgc.py
   pypy/branch/gc_hash/pypy/translator/c/test/test_typed.py
Log:
Intermediate check-in: add hash test.


Modified: pypy/branch/gc_hash/pypy/rpython/memory/test/snippet.py
==============================================================================
--- pypy/branch/gc_hash/pypy/rpython/memory/test/snippet.py	(original)
+++ pypy/branch/gc_hash/pypy/rpython/memory/test/snippet.py	Wed Feb 20 10:21:18 2008
@@ -1,7 +1,44 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.lltypesystem.lloperation import llop
 
-class SemiSpaceGCTests:
+class AnyGCTests(object):
+
+    def test_hash(self):
+        class A(object):
+            pass
+        class B(A):
+            pass
+        class C(B):
+            pass
+        c1 = C()
+        hashc1 = hash(c1)
+        def gethash(x):     # indirection to prevent constant-folding
+            return hash(x)
+        def f():
+            error = 0
+            b1 = B()
+            c2 = C()
+            hashb1 = hash(b1)
+            hashc2 = hash(c2)
+            if hashb1 != hash(b1): error += 1
+            if hashc1 != hash(c1): error += 2
+            if hashc2 != hash(c2): error += 4
+            if hashb1 != gethash(b1): error += 10
+            if hashc1 != gethash(c1): error += 20
+            if hashc2 != gethash(c2): error += 40
+            llop.gc__collect(lltype.Void)
+            if hashb1 != hash(b1): error += 100
+            if hashc1 != hash(c1): error += 200
+            if hashc2 != hash(c2): error += 400
+            if hashb1 != gethash(b1): error += 1000
+            if hashc1 != gethash(c1): error += 2000
+            if hashc2 != gethash(c2): error += 4000
+            return error
+        res = self.run(f)
+        assert res == 0
+
+
+class SemiSpaceGCTests(AnyGCTests):
     large_tests_ok = False
 
     def test_finalizer_order(self):

Modified: pypy/branch/gc_hash/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/gc_hash/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/branch/gc_hash/pypy/rpython/memory/test/test_gc.py	Wed Feb 20 10:21:18 2008
@@ -19,7 +19,7 @@
     print >>sys.stdout, strmsg
 
 
-class GCTest(object):
+class GCTest(snippet.AnyGCTests):
     GC_PARAMS = {}
 
     def setup_class(cls):

Modified: pypy/branch/gc_hash/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/branch/gc_hash/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/branch/gc_hash/pypy/translator/c/test/test_boehm.py	Wed Feb 20 10:21:18 2008
@@ -1,6 +1,7 @@
 import py
 from pypy.translator.translator import TranslationContext
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.memory.test import snippet
 from pypy.translator.tool.cbuild import check_boehm_presence
 from pypy.translator.c.genc import CExtModuleBuilder
 from pypy import conftest
@@ -9,7 +10,7 @@
     if not check_boehm_presence():
         py.test.skip("Boehm GC not present")
 
-class AbstractGCTestClass(object):
+class AbstractGCTestClass(snippet.AnyGCTests):
     gcpolicy = "boehm"
     stacklessgc = False
    
@@ -46,6 +47,12 @@
             return cbuilder.get_entry_point(isolated=True)
         return compile()
 
+    # interface for snippet.py
+    large_tests_ok = True
+    def run(self, func):
+        fn = self.getcompiled(func)
+        return fn()
+
 
 class TestUsingBoehm(AbstractGCTestClass):
     gcpolicy = "boehm"

Modified: pypy/branch/gc_hash/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/gc_hash/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/gc_hash/pypy/translator/c/test/test_newgc.py	Wed Feb 20 10:21:18 2008
@@ -282,12 +282,6 @@
     gcpolicy = "marksweep"
     should_be_moving = False
 
-    # interface for snippet.py
-    large_tests_ok = True
-    def run(self, func):
-        fn = self.getcompiled(func)
-        return fn()
-
     def test_empty_collect(self):
         def f():
             llop.gc__collect(lltype.Void)

Modified: pypy/branch/gc_hash/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/branch/gc_hash/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/branch/gc_hash/pypy/translator/c/test/test_typed.py	Wed Feb 20 10:21:18 2008
@@ -589,7 +589,7 @@
         res = f()
 
         # xxx this is too precise, checking the exact implementation
-        assert res[0] == ~res[1]
+        assert res[0] == res[1]
         assert res[2] == hash(c)
         assert res[3] == hash(d)
 



More information about the Pypy-commit mailing list