| 1 |
from rpython.rlib.rdynload import * |
| 2 |
from rpython.rlib.clibffi import get_libc_name |
| 3 |
from rpython.rtyper.lltypesystem import rffi, lltype |
| 4 |
from rpython.translator.platform import platform |
| 5 |
import py |
| 6 |
|
| 7 |
class TestDLOperations: |
| 8 |
def test_dlopen(self): |
| 9 |
s = 'xxxxxxxxxxxx' |
| 10 |
py.test.raises(DLOpenError, "dlopen(s)") |
| 11 |
|
| 12 |
s = get_libc_name() |
| 13 |
assert dlopen(s) |
| 14 |
|
| 15 |
def test_dlsym(self): |
| 16 |
s = get_libc_name() |
| 17 |
lib = dlopen(s) |
| 18 |
handle = rffi.cast(lltype.Ptr(lltype.FuncType([lltype.Signed], |
| 19 |
lltype.Signed)), dlsym(lib, 'abs')) |
| 20 |
assert 1 == handle(1) |
| 21 |
assert 1 == handle(-1) |
| 22 |
|
| 23 |
def test_ldscripts(self): |
| 24 |
|
| 25 |
if platform.name != "linux": |
| 26 |
return |
| 27 |
|
| 28 |
fname = os.path.join(os.path.dirname(__file__), "ldscript_working1.so") |
| 29 |
assert "C object" in str(dlopen(fname)) |
| 30 |
|
| 31 |
fname = os.path.join(os.path.dirname(__file__), "ldscript_working2.so") |
| 32 |
assert "C object" in str(dlopen(fname)) |
| 33 |
|
| 34 |
fname = os.path.join(os.path.dirname(__file__), "ldscript_broken1.so") |
| 35 |
py.test.raises(DLOpenError, 'dlopen(fname)') |
| 36 |
|
| 37 |
fname = os.path.join(os.path.dirname(__file__), "ldscript_broken2.so") |
| 38 |
py.test.raises(DLOpenError, 'dlopen(fname)') |