File: test_rdynload.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 (38 lines) | stat: -rw-r--r-- 1,317 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
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 = 'xxxxxxxxxxxx'
        py.test.raises(DLOpenError, "dlopen(s)")
        #
        s = get_libc_name()
        assert dlopen(s)

    def test_dlsym(self):
        s = get_libc_name()
        lib = dlopen(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")
        assert "C object" in str(dlopen(fname))

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

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

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