[pypy-svn] pypy default: I don't want to, but hg is making me commit this work in progress

fijal commits-noreply at bitbucket.org
Tue Feb 1 08:28:11 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r41514:2f12f4b023ab
Date: 2011-02-01 09:27 +0200
http://bitbucket.org/pypy/pypy/changeset/2f12f4b023ab/

Log:	I don't want to, but hg is making me commit this work in progress

diff --git a/pypy/module/pypyjit/test/test_pypy_c_new.py b/pypy/module/pypyjit/test/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test/test_pypy_c_new.py
@@ -1,16 +1,85 @@
 
-import py
-py.test.skip("DEMO")
+import py, sys, re
+import subprocess
+import disassembler
+from pypy.tool.udir import udir
+from pypy.tool import logparser
 
-class TestPyPyCNew(object):
-    def test_one(self):
+class Trace(object):
+    pass
+
+class BaseTestPyPyC(object):
+    def setup_class(cls):
+        cls.tmpdir = udir.join('test-pypy-jit')
+        cls.tmpdir.ensure(dir=True)
+
+    def setup_method(self, meth):
+        self.filepath = self.tmpdir.join(meth.im_func.func_name + '.py')
+
+    def parse_out(self, out):
+        out = out.strip("\n")
+        if out == 'None':
+            return None
+        try:
+            return int(out)
+        except ValueError:
+            return out
+
+    def parse_func(self, func):
+        # find lines such as # LOOP <name> is in a line
+        code = disassembler.dis(func)
+        result = {}
+        for i, line in enumerate(py.code.Source(func)):
+            m = re.search('# LOOP (\w+)', line)
+            if m:
+                name = m.group(1)
+                result[name] = []
+                for opcode in code.opcodes:
+                    no = opcode.lineno - func.func_code.co_firstlineno
+                    if i - 1 <= no <= i + 1:
+                        result[name].append(opcode)
+        return result
+    
+    def run(self, func):
+        with self.filepath.open("w") as f:
+            f.write(str(py.code.Source(func)) + "\n")
+            f.write("print %s()\n" % func.func_name)
+        logfile = self.filepath.new(ext='.log')
+        pipe = subprocess.Popen([sys.executable, str(self.filepath)],
+                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                                env={'PYPYLOG': "jit-log-opt,jit-summary:" + str(logfile)})
+        pipe.wait()
+        stderr = pipe.stderr.read()
+        assert not stderr
+        res = self.parse_out(pipe.stdout.read())
+        bytecodes = self.parse_func(func)
+        assert res == func()
+        log = logparser.parse_log_file(str(logfile))
+        parts = logparser.extract_category(log, 'jit-log-opt-')
+        log.xxx
+        return Trace()
+
+class TestInfrastructure(BaseTestPyPyC):
+    def test_parse_func(self):
+        def f():
+            i = 0
+            x = 0
+            # LOOP name
+            z = x + 3
+            return z
+
+        res = self.parse_func(f)
+        assert len(res) == 1
+        assert len(res['name']) == 6
+
+    def test_full(self):
         def f():
             i = 0
             while i < 1003:
                 # LOOP one
                 i += 1
 
-        trace = self.run(f, [])
+        trace = self.run(f)
         loop = trace.get_loops('one')
         loop.get_bytecode(3, 'LOAD_FAST').match('''
         int_add
@@ -24,3 +93,6 @@
         loo.get_bytecode(5, 'INPLACE_ADD').match_stats(
             allocs='5-10'
             )
+
+class TestPyPyCNew(BaseTestPyPyC):
+    pass


More information about the Pypy-commit mailing list