Debian Codegraph @

pypy/module/_vmprof/test/test_direct.py

raw symbols SCIP
1 import sys
2 import py
3 try:
4 import cffi
5 except ImportError:
6 py.test.skip('cffi required')
7
8 from rpython.rlib import rvmprof
9 srcdir = py.path.local(rvmprof.__file__).join("..", "src")
10 shareddir = srcdir.join('shared')
11
12 ffi = cffi.FFI()
13 ffi.cdef("""
14 long vmprof_write_header_for_jit_addr(void **, long, intptr_t , int);
15 void *pypy_find_codemap_at_addr(long addr, long *start_addr);
16 long pypy_yield_codemap_at_addr(void *codemap_raw, long addr,
17 long *current_pos_addr);
18 long buffer[];
19 """)
20
21 lib = ffi.verify("""
22 #define PYPY_JIT_CODEMAP
23 #include "vmprof_stack.h"
24
25 volatile int pypy_codemap_currently_invalid = 0;
26
27 long buffer[] = {0, 0, 0, 0, 0};
28
29
30
31 void *pypy_find_codemap_at_addr(long addr, long *start_addr)
32 {
33 return (void*)buffer;
34 }
35
36 long pypy_yield_codemap_at_addr(void *codemap_raw, long addr,
37 long *current_pos_addr)
38 {
39 long c = *current_pos_addr;
40 if (c >= 5)
41 return -1;
42 *current_pos_addr = c + 1;
43 return *((long*)codemap_raw + c);
44 }
45
46
47 """ + open(str(srcdir.join("shared/vmprof_get_custom_offset.h"))).read(), include_dirs=[str(srcdir), str(shareddir)])
48
49 class TestDirect(object):
50 def test_infrastructure(self):
51 cont = ffi.new("long[1]", [0])
52 buf = lib.pypy_find_codemap_at_addr(0, cont)
53 assert buf
54 cont[0] = 0
55 next_addr = lib.pypy_yield_codemap_at_addr(buf, 0, cont)
56 assert cont[0] == 1
57 assert not next_addr
58 lib.buffer[0] = 13
59 cont[0] = 0
60 next_addr = lib.pypy_yield_codemap_at_addr(buf, 0, cont)
61 assert int(ffi.cast("long", next_addr)) == 13
62
63 def test_write_header_for_jit_addr(self):
64 lib.buffer[0] = 4
65 lib.buffer[1] = 8
66 lib.buffer[2] = 12
67 lib.buffer[3] = 16
68 lib.buffer[4] = 0
69 buf = ffi.new("long[10]", [0] * 10)
70 result = ffi.cast("void**", buf)
71 res = lib.vmprof_write_header_for_jit_addr(result, 0, 0, 100)
72 assert res == 10
73 assert [x for x in buf] == [6, 0, 3, 16, 3, 12, 3, 8, 3, 4]