[pypy-commit] pypy vmprof: add a direct test

fijal noreply at buildbot.pypy.org
Mon Apr 6 18:20:56 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: vmprof
Changeset: r76727:7db06b25b25f
Date: 2015-04-06 18:20 +0200
http://bitbucket.org/pypy/pypy/changeset/7db06b25b25f/

Log:	add a direct test

diff --git a/pypy/module/_vmprof/src/get_custom_offset.c b/pypy/module/_vmprof/src/get_custom_offset.c
--- a/pypy/module/_vmprof/src/get_custom_offset.c
+++ b/pypy/module/_vmprof/src/get_custom_offset.c
@@ -16,7 +16,7 @@
     return !pypy_codemap_currently_invalid;
 }
 
-static ptrdiff_t vmprof_unw_get_custom_offset(void* ip, unw_cursor_t *cp) {
+static ptrdiff_t vmprof_unw_get_custom_offset(void* ip, void *cp) {
     intptr_t ip_l = (intptr_t)ip;
     return pypy_jit_stack_depth_at_loc(ip_l);
 }
diff --git a/pypy/module/_vmprof/test/test_direct.py b/pypy/module/_vmprof/test/test_direct.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_vmprof/test/test_direct.py
@@ -0,0 +1,66 @@
+
+import cffi, py
+
+srcdir = py.path.local(__file__).join("..", "..", "src")
+
+ffi = cffi.FFI()
+ffi.cdef("""
+long vmprof_write_header_for_jit_addr(void **, long, void*, int);
+void *pypy_find_codemap_at_addr(long addr, long *start_addr);
+long pypy_yield_codemap_at_addr(void *codemap_raw, long addr,
+                                long *current_pos_addr);
+long buffer[];
+""")
+
+lib = ffi.verify("""
+volatile int pypy_codemap_currently_invalid = 0;
+
+long buffer[] = {0, 0, 0, 0, 0};
+
+
+
+void *pypy_find_codemap_at_addr(long addr, long *start_addr)
+{
+    return (void*)buffer;
+}
+
+long pypy_yield_codemap_at_addr(void *codemap_raw, long addr,
+                                long *current_pos_addr)
+{
+    long c = *current_pos_addr;
+    if (c >= 5)
+        return 0;
+    *current_pos_addr = c + 1;
+    return *((long*)codemap_raw + c);
+}
+
+
+""" + open(str(srcdir.join("get_custom_offset.c"))).read())
+
+class TestDirect(object):
+    def test_infrastructure(self):
+        cont = ffi.new("long[1]", [0])
+        buf = lib.pypy_find_codemap_at_addr(0, cont)
+        assert buf
+        cont[0] = 0
+        next_addr = lib.pypy_yield_codemap_at_addr(buf, 0, cont)
+        assert cont[0] == 1
+        assert not next_addr
+        lib.buffer[0] = 13
+        cont[0] = 0
+        next_addr = lib.pypy_yield_codemap_at_addr(buf, 0, cont)
+        assert int(ffi.cast("long", next_addr)) == 13
+
+    def test_write_header_for_jit_addr(self):
+        lib.buffer[0] = 4
+        lib.buffer[1] = 8
+        lib.buffer[2] = 12
+        lib.buffer[3] = 16
+        lib.buffer[4] = 0
+        buf = ffi.new("long[5]", [0] * 5)
+        result = ffi.cast("void**", buf)
+        res = lib.vmprof_write_header_for_jit_addr(result, 0, ffi.NULL, 100)
+        assert res == 3
+        assert buf[0] == 16
+        assert buf[1] == 12
+        assert buf[2] == 8


More information about the pypy-commit mailing list