[pypy-commit] pypy stm-gc: Fix tests
arigo
noreply at buildbot.pypy.org
Mon Apr 30 15:52:49 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54828:69f7007806f7
Date: 2012-04-30 15:48 +0200
http://bitbucket.org/pypy/pypy/changeset/69f7007806f7/
Log: Fix tests
diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py
--- a/pypy/rpython/llinterp.py
+++ b/pypy/rpython/llinterp.py
@@ -61,6 +61,19 @@
if tracing:
self.tracer = Tracer()
+ def eval_entry_point(self, graph, args=()):
+ from pypy.rpython.lltypesystem import lltype, rffi
+ ARGV = graph.startblock.inputargs[1].concretetype
+ args = [''] + list(args)
+ ll_args = lltype.malloc(ARGV.TO, len(args), flavor='raw')
+ for i in range(len(args)):
+ ll_args[i] = rffi.str2charp(args[i])
+ res = self.eval_graph(graph, [len(args), ll_args])
+ for arg in ll_args:
+ rffi.free_charp(arg)
+ lltype.free(ll_args, flavor='raw')
+ return res
+
def eval_graph(self, graph, args=(), recursive=False):
llframe = self.frame_class(graph, args, self)
if self.tracer and not recursive:
diff --git a/pypy/rpython/memory/gctransform/test/test_transform.py b/pypy/rpython/memory/gctransform/test/test_transform.py
--- a/pypy/rpython/memory/gctransform/test/test_transform.py
+++ b/pypy/rpython/memory/gctransform/test/test_transform.py
@@ -12,21 +12,17 @@
class LLInterpedTranformerTests:
- def llinterpreter_for_transformed_graph(self, f, args_s):
+ def llinterpreter_for_transformed_graph(self, f):
from pypy.rpython.llinterp import LLInterpreter
from pypy.translator.c.genc import CStandaloneBuilder
from pypy.translator.c import gc
+ from pypy.annotation.listdef import s_list_of_strings
- t = rtype(f, args_s)
+ t = rtype(f, [s_list_of_strings])
# XXX we shouldn't need an actual gcpolicy here.
cbuild = CStandaloneBuilder(t, f, t.config, gcpolicy=self.gcpolicy)
db = cbuild.generate_graphs_for_llinterp()
graph = cbuild.getentrypointptr()._obj.graph
- # arguments cannot be GC objects because nobody would put a
- # proper header on them
- for v in graph.getargs():
- if isinstance(v.concretetype, lltype.Ptr):
- assert v.concretetype.TO._gckind != 'gc', "fix the test!"
llinterp = LLInterpreter(t.rtyper)
if conftest.option.view:
t.view()
@@ -47,20 +43,22 @@
d = C()
d.x = 2
return d
- def f(x):
+ def f(argv):
+ x = int(argv[1])
return g(x).x
- llinterp, graph = self.llinterpreter_for_transformed_graph(f, [SomeInteger()])
+ llinterp, graph = self.llinterpreter_for_transformed_graph(f)
- res = llinterp.eval_graph(graph, [0])
- assert res == f(0)
- res = llinterp.eval_graph(graph, [1])
- assert res == f(1)
+ res = llinterp.eval_entry_point(graph, ["0"])
+ assert res == f(["", "0"])
+ res = llinterp.eval_entry_point(graph, ["1"])
+ assert res == f(["", "1"])
def test_simple_varsize(self):
from pypy.annotation.model import SomeInteger
- def f(x):
+ def f(argv):
+ x = int(argv[1])
r = []
for i in range(x):
if i % 2:
@@ -68,17 +66,18 @@
return len(r)
- llinterp, graph = self.llinterpreter_for_transformed_graph(f, [SomeInteger()])
+ llinterp, graph = self.llinterpreter_for_transformed_graph(f)
- res = llinterp.eval_graph(graph, [0])
- assert res == f(0)
- res = llinterp.eval_graph(graph, [10])
- assert res == f(10)
+ res = llinterp.eval_entry_point(graph, ["0"])
+ assert res == f(["", "0"])
+ res = llinterp.eval_entry_point(graph, ["10"])
+ assert res == f(["", "10"])
def test_str(self):
from pypy.annotation.model import SomeBool
- def f(flag):
+ def f(argv):
+ flag = int(argv[1])
if flag:
x = 'a'
else:
@@ -86,12 +85,12 @@
return len(x + 'a')
- llinterp, graph = self.llinterpreter_for_transformed_graph(f, [SomeBool()])
+ llinterp, graph = self.llinterpreter_for_transformed_graph(f)
- res = llinterp.eval_graph(graph, [True])
- assert res == f(True)
- res = llinterp.eval_graph(graph, [False])
- assert res == f(False)
+ res = llinterp.eval_entry_point(graph, ["1"])
+ assert res == f(["", "1"])
+ res = llinterp.eval_entry_point(graph, ["0"])
+ assert res == f(["", "0"])
class _TestGCTransformer(BaseGCTransformer):
More information about the pypy-commit
mailing list