File: test__jitlog.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: 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 (54 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (3)
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
import sys
import platform
import pytest
from rpython.tool.udir import udir
from rpython.rlib.rjitlog import rjitlog as jl
from rpython.jit.metainterp.resoperation import opname

win32_untranslated ="not config.option.runappdirect and sys.platform == 'win32'"
win32_reason = "fileno may come from different runtimes depending on current compiler"

class AppTestJitLog(object):
    spaceconfig = {'usemodules': ['_jitlog', 'struct']}

    def setup_class(cls):
        cls.w_tmpfilename = cls.space.wrap(str(udir.join('test__jitlog.1')))
        cls.w_mark_header = cls.space.newbytes(jl.MARK_JITLOG_HEADER)
        cls.w_version = cls.space.newbytes(jl.JITLOG_VERSION_16BIT_LE)
        cls.w_is_32bit = cls.space.wrap(sys.maxint == 2**31-1)
        cls.w_machine = cls.space.newbytes(platform.machine())
        cls.w_resops = cls.space.newdict()
        space = cls.space
        for key, value in opname.items():
            space.setitem(cls.w_resops, space.wrap(key), space.wrap(value))

    @pytest.mark.skipif(win32_untranslated, reason=win32_reason)
    def test_enable(self):
        import _jitlog, struct
        tmpfile = open(self.tmpfilename, 'wb')
        fileno = tmpfile.fileno()
        _jitlog.enable(fileno)
        _jitlog.disable()
        # no need to clsoe tmpfile, it is done by jitlog

        with open(self.tmpfilename, 'rb') as fd:
            assert fd.read(1) == self.mark_header
            assert fd.read(2) == self.version
            assert bool(ord(fd.read(1))) == self.is_32bit
            strcount, = struct.unpack('<i', fd.read(4))
            machine = fd.read(strcount)
            assert machine == self.machine
            # resoperations
            count, = struct.unpack('<h', fd.read(2))
            opnames = set()
            for i in range(count):
                opnum = struct.unpack('<h', fd.read(2))
                strcount, = struct.unpack('<i', fd.read(4))
                opname = fd.read(strcount)
                opnames.append((opnum, opname))

            for opnum, opname in opnames:
                # must be known resoperation
                assert opnum in self.resops
                # the name must equal
                assert self.resops[opnum] == opname