File: test_rdynload.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 (49 lines) | stat: -rw-r--r-- 1,674 bytes parent folder | download | duplicates (6)
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
from rpython.rlib.rdynload import *
from rpython.rlib.clibffi import get_libc_name
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.translator.platform import platform
import py

class TestDLOperations:
    def test_dlopen(self):
        s = rffi.str2charp('xxxxxxxxxxxx')
        py.test.raises(DLOpenError, "dlopen(s)")
        rffi.free_charp(s)
        #
        s = rffi.str2charp(get_libc_name())
        assert dlopen(s)
        rffi.free_charp(s)

    def test_dlsym(self):
        s = rffi.str2charp(get_libc_name())
        lib = dlopen(s)
        rffi.free_charp(s)
        handle = rffi.cast(lltype.Ptr(lltype.FuncType([lltype.Signed],
                           lltype.Signed)), dlsym(lib, 'abs'))
        assert 1 == handle(1)
        assert 1 == handle(-1)

    def test_ldscripts(self):
        # this test only makes sense on linux
        if platform.name != "linux":
            return

        fname = os.path.join(os.path.dirname(__file__), "ldscript_working1.so")
        s = rffi.str2charp(fname)
        assert "C object" in str(dlopen(s))
        rffi.free_charp(s)

        fname = os.path.join(os.path.dirname(__file__), "ldscript_working2.so")
        s = rffi.str2charp(fname)
        assert "C object" in str(dlopen(s))
        rffi.free_charp(s)

        fname = os.path.join(os.path.dirname(__file__), "ldscript_broken1.so")
        s = rffi.str2charp(fname)
        py.test.raises(DLOpenError, 'dlopen(s)')
        rffi.free_charp(s)

        fname = os.path.join(os.path.dirname(__file__), "ldscript_broken2.so")
        s = rffi.str2charp(fname)
        py.test.raises(DLOpenError, 'dlopen(s)')
        rffi.free_charp(s)