[pypy-commit] pypy precise-instantiate: rewrite these tests so they now pass
alex_gaynor
noreply at buildbot.pypy.org
Fri Jul 12 07:21:51 CEST 2013
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: precise-instantiate
Changeset: r65366:0facbce0dd89
Date: 2013-07-12 15:21 +1000
http://bitbucket.org/pypy/pypy/changeset/0facbce0dd89/
Log: rewrite these tests so they now pass
diff --git a/rpython/jit/codewriter/test/test_codewriter.py b/rpython/jit/codewriter/test/test_codewriter.py
--- a/rpython/jit/codewriter/test/test_codewriter.py
+++ b/rpython/jit/codewriter/test/test_codewriter.py
@@ -13,6 +13,7 @@
self.ARGS = ARGS
self.RESULT = RESULT
self.effectinfo = effectinfo
+
def get_extra_info(self):
return self.effectinfo
@@ -37,7 +38,7 @@
class tracker:
pass
-
+
calldescrof = FakeCallDescr
fielddescrof = FakeFieldDescr
sizeof = FakeSizeDescr
@@ -121,20 +122,32 @@
blackholeinterp.run()
assert blackholeinterp.get_tmpreg_i() == 100+6+5+4+3
+
def test_instantiate():
- class A1: id = 651
- class A2(A1): id = 652
- class B1: id = 661
- class B2(B1): id = 662
+ class A1:
+ id = 651
+
+ class A2(A1):
+ id = 652
+
+ class B1:
+ id = 661
+
+ class B2(B1):
+ id = 662
+
def dont_look(n):
return n + 1
+
+ classes = [
+ (A1, B1),
+ (A2, B2)
+ ]
+
def f(n):
- if n > 5:
- x, y = A1, B1
- else:
- x, y = A2, B2
+ x, y = classes[n]
return x().id + y().id + dont_look(n)
- rtyper = support.annotate(f, [35])
+ rtyper = support.annotate(f, [0])
maingraph = rtyper.annotator.translator.graphs[0]
cw = CodeWriter(FakeCPU(rtyper), [FakeJitDriverSD(maingraph)])
cw.find_all_graphs(FakePolicy())
@@ -149,16 +162,10 @@
else:
assert 0, "missing instantiate_*_%s in:\n%r" % (expected,
names)
- #
- print cw.assembler.list_of_addr2name
- names = dict.fromkeys([value
- for key, value in cw.assembler.list_of_addr2name])
- assert 'A1' in names
- assert 'B1' in names
- assert 'A2' in names
- assert 'B2' in names
+ names = set([value for key, value in cw.assembler.list_of_addr2name])
assert 'dont_look' in names
+
def test_instantiate_with_unreasonable_attr():
# It is possible to have in real code the instantiate() function for
# a class be dont-look-inside. This is caused by the code that
@@ -169,17 +176,19 @@
name = graph.name
return not (name.startswith('instantiate_') and
name.endswith('A2'))
+
class A1:
pass
+
class A2(A1):
pass
+
+ classes = [A1, A2]
+
def f(n):
- if n > 5:
- x = A1
- else:
- x = A2
+ x = classes[n]
x()
- rtyper = support.annotate(f, [35])
+ rtyper = support.annotate(f, [1])
maingraph = rtyper.annotator.translator.graphs[0]
cw = CodeWriter(FakeCPU(rtyper), [FakeJitDriverSD(maingraph)])
cw.find_all_graphs(MyFakePolicy())
@@ -188,12 +197,7 @@
names = [jitcode.name for jitcode in cw.assembler.indirectcalltargets]
assert len(names) == 1
assert names[0].startswith('instantiate_') and names[0].endswith('A1')
- #
- print cw.assembler.list_of_addr2name
- names = dict.fromkeys([value
- for key, value in cw.assembler.list_of_addr2name])
- assert 'A1' in names
- assert 'A2' in names
+
def test_int_abs():
def f(n):
@@ -209,7 +213,7 @@
def test_raw_malloc_and_access():
TP = rffi.CArray(lltype.Signed)
-
+
def f(n):
a = lltype.malloc(TP, n, flavor='raw')
a[0] = n
More information about the pypy-commit
mailing list