[pypy-svn] pypy default: move test_pypy_c_new to its own directory, because the file is getting too big

antocuni commits-noreply at bitbucket.org
Fri Feb 18 13:54:36 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r42154:41f62bfd60c1
Date: 2011-02-18 10:09 +0100
http://bitbucket.org/pypy/pypy/changeset/41f62bfd60c1/

Log:	move test_pypy_c_new to its own directory, because the file is
	getting too big

diff --git a/pypy/module/pypyjit/test/test_pypy_c_new.py b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
copy from pypy/module/pypyjit/test/test_pypy_c_new.py
copy to pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -3,9 +3,18 @@
 from lib_pypy import disassembler
 from pypy.tool.udir import udir
 from pypy.tool import logparser
+from pypy.jit.tool import oparser
+
+class Log(object):
+    def __init__(self, func, rawtraces):
+        traces = map(Trace, rawtraces)
 
 class Trace(object):
-    pass
+    def __init__(self, rawtrace):
+        # "low level trace", i.e. an instance of history.TreeLoop
+        self.lltrace = oparser.parse(rawtrace, no_namespace=True)
+        
+
 
 class BaseTestPyPyC(object):
     def setup_class(cls):
@@ -19,15 +28,6 @@
     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 find_chunks_range(self, func):
         """
         Parse the given function and return a dictionary mapping "chunk
@@ -61,25 +61,33 @@
             chunks[name] = opcodes
         return chunks
     
-    def run(self, func):
+    def run(self, func, threshold=1000):
+        # write the snippet
         with self.filepath.open("w") as f:
             f.write(str(py.code.Source(func)) + "\n")
-            f.write("print %s()\n" % func.func_name)
+            f.write("%s()\n" % func.func_name)
+        #
+        # run a child pypy-c with logging enabled
         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)})
+        env={'PYPYLOG': 'jit-log-opt,jit-summary:' + str(logfile)}
+        cmdline = [sys.executable,
+                   '--jit', 'threshold=%d' % threshold,
+                   str(self.filepath)]
+        pipe = subprocess.Popen(cmdline,
+                                env=env,
+                                stdout=subprocess.PIPE,
+                                stderr=subprocess.PIPE)
         pipe.wait()
         stderr = pipe.stderr.read()
+        stdout = pipe.stdout.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-')
-        import pdb;pdb.set_trace()
-        log.xxx
-        return Trace()
+        #
+        # parse the JIT log
+        chunks = self.find_chunks(func)
+        rawlog = logparser.parse_log_file(str(logfile))
+        rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
+        log = Log(func, rawtraces)
+        return log
 
 class TestInfrastructure(BaseTestPyPyC):
 
@@ -107,6 +115,16 @@
         opcodes_names = [opcode.__class__.__name__ for opcode in myline]
         assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST']
 
+    def test_parse_jitlog(self):
+        def f():
+            i = 0
+            while i < 1003: # default threshold is 10
+                i += 1 # ID: increment
+            return i
+        #
+        trace = self.run(f)
+
+
     def test_full(self):
         py.test.skip('in-progress')
         def f():

diff --git a/pypy/module/pypyjit/test_pypy_c/__init__.py b/pypy/module/pypyjit/test_pypy_c/__init__.py
new file mode 100644

diff --git a/pypy/module/pypyjit/test/test_pypy_c_new.py b/pypy/module/pypyjit/test/test_pypy_c_new.py
deleted file mode 100644
--- a/pypy/module/pypyjit/test/test_pypy_c_new.py
+++ /dev/null
@@ -1,134 +0,0 @@
-import py, sys, re
-import subprocess
-from lib_pypy import disassembler
-from pypy.tool.udir import udir
-from pypy.tool import logparser
-
-class Trace(object):
-    pass
-
-class BaseTestPyPyC(object):
-    def setup_class(cls):
-        if '__pypy__' not in sys.builtin_module_names:
-            py.test.skip("must run this test with pypy")
-        if not sys.pypy_translation_info['translation.jit']:
-            py.test.skip("must give a pypy-c with the jit enabled")
-        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 find_chunks_range(self, func):
-        """
-        Parse the given function and return a dictionary mapping "chunk
-        names" to "line ranges".  Chunks are identified by comments with a
-        special syntax::
-
-            # the chunk "myid" corresponds to the whole line
-            print 'foo' # ID: myid
-        """
-        result = {}
-        start_lineno = func.func_code.co_firstlineno
-        for i, line in enumerate(py.code.Source(func)):
-            m = re.search('# ID: (\w+)', line)
-            if m:
-                name = m.group(1)
-                lineno = start_lineno+i
-                result[name] = xrange(lineno, lineno+1)
-        return result
-
-    def find_chunks(self, func):
-        """
-        Parse the given function and return a dictionary mapping "chunk names"
-        to "opcodes".
-        """
-        chunks = {}
-        code = disassembler.dis(func)
-        ranges = self.find_chunks_range(func)
-        for name, linerange in ranges.iteritems():
-            opcodes = [opcode for opcode in code.opcodes
-                       if opcode.lineno in linerange]
-            chunks[name] = opcodes
-        return chunks
-    
-    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-')
-        import pdb;pdb.set_trace()
-        log.xxx
-        return Trace()
-
-class TestInfrastructure(BaseTestPyPyC):
-
-    def test_find_chunks_range(self):
-        def f():
-            a = 0 # ID: myline
-            return a
-        #
-        start_lineno = f.func_code.co_firstlineno
-        ids = self.find_chunks_range(f)
-        assert len(ids) == 1
-        myline_range = ids['myline']
-        assert list(myline_range) == range(start_lineno+1, start_lineno+2)
-
-    def test_find_chunks(self):
-        def f():
-            i = 0
-            x = 0
-            z = x + 3 # ID: myline
-            return z
-        #
-        chunks = self.find_chunks(f)
-        assert len(chunks) == 1
-        myline = chunks['myline']
-        opcodes_names = [opcode.__class__.__name__ for opcode in myline]
-        assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST']
-
-    def test_full(self):
-        py.test.skip('in-progress')
-        def f():
-            i = 0
-            while i < 1003:
-                # LOOP one
-                i += 1
-
-        trace = self.run(f)
-        loop = trace.get_loops('one')
-        loop.get_bytecode(3, 'LOAD_FAST').match('''
-        int_add
-        guard_true
-        ''')
-        loop.get_bytecode(4, 'LOAD_CONST').match_stats(
-            guard='3', call='1-2', call_may_force='0'
-        )
-        # this would make operations that are "costly" obligatory to pass
-        # like new
-        loo.get_bytecode(5, 'INPLACE_ADD').match_stats(
-            allocs='5-10'
-            )
-
-class TestPyPyCNew(BaseTestPyPyC):
-    pass


More information about the Pypy-commit mailing list