File: test_direct.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (73 lines) | stat: -rw-r--r-- 2,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import py
try:
    import cffi
except ImportError:
    py.test.skip('cffi required')

from rpython.rlib import rvmprof
srcdir = py.path.local(rvmprof.__file__).join("..", "src")
shareddir = srcdir.join('shared')

ffi = cffi.FFI()
ffi.cdef("""
long vmprof_write_header_for_jit_addr(void **, long, intptr_t , 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("""
#define PYPY_JIT_CODEMAP
#include "vmprof_stack.h"

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 -1;
    *current_pos_addr = c + 1;
    return *((long*)codemap_raw + c);
}


""" + open(str(srcdir.join("shared/vmprof_get_custom_offset.h"))).read(), include_dirs=[str(srcdir), str(shareddir)])

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[10]", [0] * 10)
        result = ffi.cast("void**", buf)
        res = lib.vmprof_write_header_for_jit_addr(result, 0, 0, 100)
        assert res == 10
        assert [x for x in buf] == [6, 0, 3, 16, 3, 12, 3, 8, 3, 4]