test_dl.py 806 Bytes
Newer Older
1 2
#! /usr/bin/env python
"""Test dlmodule.c
3
   Roger E. Masse  revised strategy by Barry Warsaw
4 5
"""

6
import dl
7
from test.test_support import verbose,TestSkipped
8

9
sharedlibs = [
10
    ('/usr/lib/libc.so', 'getpid'),
11
    ('/lib/libc.so.6', 'getpid'),
12
    ('/usr/bin/cygwin1.dll', 'getpid'),
13
    ('/usr/lib/libc.dylib', 'getpid'),
14
    ]
15

16 17
for s, func in sharedlibs:
    try:
18
        if verbose:
19
            print('trying to open:', s, end=' ')
20
        l = dl.open(s)
21
    except dl.error as err:
22
        if verbose:
23
            print('failed', repr(str(err)))
24
        pass
25
    else:
26
        if verbose:
27
            print('succeeded...', end=' ')
28 29 30
        l.call(func)
        l.close()
        if verbose:
31
            print('worked!')
32
        break
33
else:
34
    raise TestSkipped('Could not open any shared libraries')