File: test_strstorage.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (53 lines) | stat: -rw-r--r-- 2,087 bytes parent folder | download
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
import py
import sys
import struct
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.strstorage import str_storage_getitem
from rpython.rlib.test.test_strstorage import BaseStrStorageTest
from rpython.jit.codewriter import longlong
from rpython.jit.metainterp.history import getkind
from rpython.jit.metainterp.test.support import LLJitMixin

class TestStrStorage(BaseStrStorageTest, LLJitMixin):

    # for the individual tests see
    # ====> ../../../rlib/test/test_strstorage.py

    def str_storage_getitem(self, TYPE, buf, offset):
        def f():
            return str_storage_getitem(TYPE, buf, offset)
        res = self.interp_operations(f, [], supports_singlefloats=True)
        #
        kind = getkind(TYPE)[0] # 'i' or 'f'
        self.check_operations_history({'gc_load_indexed_%s' % kind: 1,
                                       'finish': 1})
        #
        if TYPE == lltype.SingleFloat:
            # interp_operations returns the int version of r_singlefloat, but
            # our tests expects to receive an r_singlefloat: let's convert it
            # back!
            return longlong.int2singlefloat(res)
        return res

    #def str_storage_supported(self, TYPE):
    #    py.test.skip('this is not a JIT test')

    def test_force_virtual_str_storage(self):
        byteorder = sys.byteorder
        size = rffi.sizeof(lltype.Signed)
        def f(val):
            if byteorder == 'little':
                x = chr(val) + '\x00'*(size-1)
            else:
                x = '\x00'*(size-1) + chr(val)
            return str_storage_getitem(lltype.Signed, x, 0)
        res = self.interp_operations(f, [42], supports_singlefloats=True)
        assert res == 42
        self.check_operations_history({
            'newstr': 1,              # str forcing
            'strsetitem': 1,          # str forcing
            'call_pure_r': 1,         # str forcing (copystrcontent)
            'guard_no_exception': 1,  # str forcing
            'gc_load_indexed_i': 1,   # str_storage_getitem
            'finish': 1
            })