[pypy-svn] r65085 - in pypy/branch/pyjitpl5/pypy/jit/backend: minimal/test test

arigo at codespeak.net arigo at codespeak.net
Wed May 6 13:09:08 CEST 2009


Author: arigo
Date: Wed May  6 13:09:08 2009
New Revision: 65085

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
Log:
Really write test_ovf_operations_reversed, checking the case
of INT_xxx_OVF followed by a GUARD_EXCEPTION.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py	Wed May  6 13:09:08 2009
@@ -22,6 +22,7 @@
     test_passing_guard_class = _skip      # GUARD_CLASS
     test_failing_guards      = _skip      # GUARD_CLASS
     test_failing_guard_class = _skip      # GUARD_CLASS
+    test_ovf_operations_reversed = _skip  # exception
 
 class TestOOtype(OOJitMixin, MinimalTestMixin, OOtypeBackendTest):
     pass

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py	Wed May  6 13:09:08 2009
@@ -152,7 +152,7 @@
                                              'int')
                 assert res.value == y
 
-    def test_ovf_operations(self):
+    def test_ovf_operations(self, reversed=False):
         minint = -sys.maxint-1
         boom = 'boom'
         for opnum, testcases in [
@@ -192,15 +192,33 @@
             v1 = BoxInt(testcases[0][0])
             v2 = BoxInt(testcases[0][1])
             v_res = BoxInt()
-            ops = [
-                ResOperation(opnum, [v1, v2], v_res),
-                ResOperation(rop.GUARD_NO_EXCEPTION, [], None),
-                ResOperation(rop.FAIL, [v_res], None),
-                ]
+            #
+            if not reversed:
+                ops = [
+                    ResOperation(opnum, [v1, v2], v_res),
+                    ResOperation(rop.GUARD_NO_EXCEPTION, [], None),
+                    ResOperation(rop.FAIL, [v_res], None),
+                    ]
+                ops[1].suboperations = [ResOperation(rop.FAIL, [], None)]
+            else:
+                self.cpu.set_overflow_error()
+                ovferror = self.cpu.get_exception()
+                self.cpu.clear_exception()
+                if self.cpu.is_oo:
+                    v_exc = BoxPtr()
+                    c_ovferror = ConstObj(ovferror)
+                else:
+                    v_exc = BoxObj()
+                    c_ovferror = ConstInt(ovferror)
+                ops = [
+                    ResOperation(opnum, [v1, v2], v_res),
+                    ResOperation(rop.GUARD_EXCEPTION, [c_ovferror], v_exc),
+                    ResOperation(rop.FAIL, [], None),
+                    ]
+                ops[1].suboperations = [ResOperation(rop.FAIL, [v_res], None)]
+            #
             if opnum in (rop.INT_NEG_OVF, rop.INT_ABS_OVF):
                 del ops[0].args[1]
-            ops[1].suboperations = [ResOperation(rop.FAIL, [],
-                                                 None)]
             loop = TreeLoop('name')
             loop.operations = ops
             loop.inputargs = [v1, v2]
@@ -209,36 +227,15 @@
                 self.cpu.set_future_value_int(0, x)
                 self.cpu.set_future_value_int(1, y)
                 op = self.cpu.execute_operations(loop)
-                if z == boom:
+                if (z == boom) ^ reversed:
                     assert op is ops[1].suboperations[0]
                 else:
                     assert op is ops[-1]
+                if z != boom:
                     assert self.cpu.get_latest_value_int(0) == z
-            # ----------
-            # the same thing but with the exception path reversed
-##            v1 = BoxInt(testcases[0][0])
-##            v2 = BoxInt(testcases[0][1])
-##            v_res = BoxInt()
-##            v_exc = BoxPtr()
-##            self.cpu.set_overflow_error()
-##            ovferror = self.cpu.get_exception()
-##            self.cpu.clear_exception()
-##            ops = [
-##                ResOperation(opnum, [v1, v2], v_res),
-##                ResOperation(rop.GUARD_EXCEPTION, [ConstInt(ovferror)], v_exc),
-##                ResOperation(rop.FAIL, [ConstInt(boom)], None),
-##                ]
-##            if opnum in (rop.INT_NEG_OVF, rop.INT_ABS_OVF):
-##                del ops[0].args[1]
-##            ops[1].suboperations = [ResOperation(rop.FAIL, [ConstInt(v_res)],
-##                                                 None)]
-##            loop = TreeLoop('inverted')
-##            loop.operations = ops
-##            loop.inputargs = [v1, v2]
-##            self.cpu.compile_operations(loop)
-##            for x, y, z in testcases:
-##                op = self.cpu.execute_operations(loop, [BoxInt(x), BoxInt(y)])
-##                assert op.args[0].value == z
+
+    def test_ovf_operations_reversed(self):
+        self.test_ovf_operations(reversed=True)
 
 
     def test_passing_guards(self):



More information about the Pypy-commit mailing list