[pypy-svn] r32058 - in pypy/dist/pypy: jit/codegen/i386/test jit/hintannotator jit/timeshifter/test translator translator/c
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 7 16:49:37 CEST 2006
Author: arigo
Date: Thu Sep 7 16:49:33 2006
New Revision: 32058
Modified:
pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py
pypy/dist/pypy/jit/hintannotator/annotator.py
pypy/dist/pypy/jit/timeshifter/test/test_exception.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
pypy/dist/pypy/translator/c/database.py
pypy/dist/pypy/translator/translator.py
Log:
(pedronis, arigo)
Ported the test_exception to the asm back-end. This needed a way to
test for exception-raising examples, and unification of the
exceptiontransformer used by the JIT and by GenC.
Modified: pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_genc_ts.py Thu Sep 7 16:49:33 2006
@@ -80,7 +80,11 @@
os.write(1, SEPLINE)
bench = Benchmark()
while 1:
- res = generated(*residualargs)
+ try:
+ res = generated(*residualargs)
+ except Exception, e:
+ os.write(1, 'EXCEPTION: %s\n' % (e,))
+ return 0
if bench.stop():
break
os.write(1, convert_result(res) + '\n')
@@ -122,6 +126,11 @@
os.write(2, '{%s: %s\n' % (testname, lines.pop(1)[1:]))
assert len(lines) == 2
lastline = lines[1]
+ if 'check_raises' in kwds:
+ exc_name = kwds['check_raises'].__name__
+ assert lastline.startswith('EXCEPTION: ') # else DID NOT RAISE
+ assert exc_name in lastline
+ return True
if hasattr(ll_function, 'convert_result'):
return lastline
else:
Modified: pypy/dist/pypy/jit/hintannotator/annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/annotator.py Thu Sep 7 16:49:33 2006
@@ -3,19 +3,17 @@
from pypy.jit.hintannotator.bookkeeper import HintBookkeeper
from pypy.rpython.lltypesystem import lltype
-from pypy.translator.c.exceptiontransform import ExceptionTransformer
-
class HintAnnotator(RPythonAnnotator):
- def __init__(self, translator=None, base_translator=None, policy=None):
+ def __init__(self, translator=None, base_translator=None, policy=None):
bookkeeper = HintBookkeeper(self)
RPythonAnnotator.__init__(self, translator, policy=policy,
bookkeeper=bookkeeper)
self.base_translator = base_translator
assert base_translator is not None # None not supported any more
- self.exceptiontransformer = ExceptionTransformer(base_translator)
+ self.exceptiontransformer = base_translator.getexceptiontransformer()
def build_types(self, origgraph, input_args_hs):
desc = self.bookkeeper.getdesc(origgraph)
Modified: pypy/dist/pypy/jit/timeshifter/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_exception.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_exception.py Thu Sep 7 16:49:33 2006
@@ -1,6 +1,5 @@
import py
from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.llinterp import LLException
from pypy.jit.timeshifter.test.test_timeshift import TimeshiftingTests
from pypy.jit.timeshifter.test.test_timeshift import P_NOVIRTUAL
from pypy.jit.timeshifter.test.test_vlist import P_OOPSPEC
@@ -33,19 +32,20 @@
return res
s.flag = 0
- res = self.timeshift(ll_function, [0], [], policy=P_NOVIRTUAL)
- assert res == -1
+ self.timeshift_raises(ValueError,
+ ll_function, [0], [], policy=P_NOVIRTUAL)
assert s.flag == 0
s.flag = 0
- res = self.timeshift(ll_function, [0], [0], policy=P_NOVIRTUAL)
- assert res == -1
+ self.timeshift_raises(ValueError,
+ ll_function, [0], [0], policy=P_NOVIRTUAL)
assert s.flag == 0
s.flag = 0
res = self.timeshift(ll_function, [17], [0], policy=P_NOVIRTUAL)
assert res == 24
- assert s.flag == 1
+ if self.__class__ is TestException: # no chance to work with genc
+ assert s.flag == 1
self.check_insns({'setfield': 1})
def test_catch(self):
@@ -117,8 +117,8 @@
res = self.timeshift(ll_function, [2], [], policy=P_OOPSPEC)
assert res == 6
- py.test.raises(LLException,
- "self.timeshift(ll_function, [-3], [], policy=P_OOPSPEC)")
+ self.timeshift_raises(ValueError,
+ ll_function, [-3], [], policy=P_OOPSPEC)
- py.test.raises(LLException,
- "self.timeshift(ll_function, [-3], [0], policy=P_OOPSPEC)")
+ self.timeshift_raises(ValueError,
+ ll_function, [-3], [0], policy=P_OOPSPEC)
Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Thu Sep 7 16:49:33 2006
@@ -12,7 +12,7 @@
from pypy.rpython.annlowlevel import PseudoHighLevelCallable
from pypy.rpython.module.support import LLSupport
from pypy.annotation import model as annmodel
-from pypy.rpython.llinterp import LLInterpreter
+from pypy.rpython.llinterp import LLInterpreter, LLException
from pypy.objspace.flow.model import checkgraph
from pypy.annotation.policy import AnnotatorPolicy
from pypy.translator.backendopt.inline import auto_inlining
@@ -65,7 +65,8 @@
del cls._cache
del cls._cache_order
- def timeshift_cached(self, ll_function, values, inline=None, policy=None):
+ def timeshift_cached(self, ll_function, values, inline=None, policy=None,
+ check_raises='ignored anyway'):
# decode the 'values' if they are specified as strings
if hasattr(ll_function, 'convert_arguments'):
assert len(ll_function.convert_arguments) == len(values)
@@ -268,7 +269,20 @@
if conftest.option.view:
residual_graph.show()
self.insns = summary(residual_graph)
- res = llinterp.eval_graph(residual_graph, residualargs)
+
+ if 'check_raises' not in kwds:
+ res = llinterp.eval_graph(residual_graph, residualargs)
+ else:
+ try:
+ llinterp.eval_graph(residual_graph, residualargs)
+ except LLException, e:
+ exc = kwds['check_raises']
+ assert llinterp.find_exception(e) is exc, (
+ "wrong exception type")
+ else:
+ raise AssertionError("DID NOT RAISE")
+ return True
+
if hasattr(ll_function, 'convert_result'):
res = ll_function.convert_result(res)
@@ -288,6 +302,11 @@
main()
return res
+ def timeshift_raises(self, ExcCls, ll_function, values, opt_consts=[],
+ *args, **kwds):
+ kwds['check_raises'] = ExcCls
+ return self.timeshift(ll_function, values, opt_consts, *args, **kwds)
+
def check_insns(self, expected=None, **counts):
if expected is not None:
assert self.insns == expected
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Thu Sep 7 16:49:33 2006
@@ -14,7 +14,6 @@
from pypy.translator.c.support import cdecl, CNameManager, ErrorValue
from pypy.translator.c.support import log
from pypy.translator.c.extfunc import do_the_getting
-from pypy.translator.c.exceptiontransform import ExceptionTransformer
from pypy import conftest
# ____________________________________________________________
@@ -68,7 +67,7 @@
if translator is None or translator.rtyper is None:
self.exctransformer = None
else:
- self.exctransformer = ExceptionTransformer(translator)
+ self.exctransformer = translator.getexceptiontransformer()
self.gcpolicy = gcpolicy(self, thread_enabled)
if translator is not None:
self.gctransformer = gcpolicy.transformerclass(translator)
Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py (original)
+++ pypy/dist/pypy/translator/translator.py Thu Sep 7 16:49:33 2006
@@ -31,6 +31,7 @@
raise TypeError("unexpected keyword argument")
self.annotator = None
self.rtyper = None
+ self.exceptiontransformer = None
self.graphs = [] # [graph]
self.callgraph = {} # {opaque_tag: (caller-graph, callee-graph)}
self._prebuilt_graphs = {} # only used by the pygame viewer
@@ -84,6 +85,15 @@
type_system = type_system)
return self.rtyper
+ def getexceptiontransformer(self):
+ if self.rtyper is None:
+ raise ValueError("no rtyper")
+ if self.exceptiontransformer is not None:
+ return self.exceptiontransformer
+ from pypy.translator.c.exceptiontransform import ExceptionTransformer
+ self.exceptiontransformer = ExceptionTransformer(self)
+ return self.exceptiontransformer
+
def checkgraphs(self):
for graph in self.graphs:
checkgraph(graph)
More information about the Pypy-commit
mailing list