[pypy-commit] pypy vmprof-review: Test and fixes for enable()

arigo noreply at buildbot.pypy.org
Sun Aug 2 16:35:09 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: vmprof-review
Changeset: r78742:1d75a1bd5d77
Date: 2015-08-02 16:35 +0200
http://bitbucket.org/pypy/pypy/changeset/1d75a1bd5d77/

Log:	Test and fixes for enable()

diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -1,10 +1,11 @@
 import sys, os
 from rpython.rlib.objectmodel import specialize, we_are_translated
 from rpython.rlib.rstring import StringBuilder
-from rpython.rlib import jit, rgc
+from rpython.rlib import jit, rgc, rposix
 from rpython.rlib.rvmprof import cintf
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref
 from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
+from rpython.rtyper.lltypesystem import rffi
 
 MAX_CODES = 8000
 
@@ -126,7 +127,7 @@
         self._carefully_write(buf)
 
     def _carefully_write(self, buf):
-        fd = self._fileno
+        fd = self.fileno
         assert fd >= 0
         if not buf:
             return
diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py b/rpython/rlib/rvmprof/test/test_rvmprof.py
--- a/rpython/rlib/rvmprof/test/test_rvmprof.py
+++ b/rpython/rlib/rvmprof/test/test_rvmprof.py
@@ -1,4 +1,5 @@
-import py
+import py, os
+from rpython.tool.udir import udir
 from rpython.rlib.rvmprof import get_vmprof, vmprof_execute_code
 from rpython.translator.c.test.test_genc import compile
 from rpython.jit.backend import detect_cpu
@@ -73,3 +74,33 @@
     assert f() == 0
     fn = compile(f, [])
     assert fn() == 0
+
+
+def test_enable():
+
+    class MyCode:
+        pass
+    get_vmprof().register_code_object_class(MyCode, lambda code: 'some code')
+
+    @vmprof_execute_code("xcode1", lambda code, num: code)
+    def main(code, num):
+        print num
+        return 42
+
+    tmpfilename = str(udir.join('test_rvmprof'))
+
+    def f():
+        code = MyCode()
+        get_vmprof().register_code(code, 'some code')
+        fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
+        get_vmprof().enable(fd, 0.5)
+        res = main(code, 5)
+        assert res == 42
+        return 0
+
+    assert f() == 0
+    assert os.path.exists(tmpfilename)
+    fn = compile(f, [], gcpolicy="minimark")
+    os.unlink(tmpfilename)
+    assert fn() == 0
+    assert os.path.exists(tmpfilename)


More information about the pypy-commit mailing list