Revised strategy for testing recomended by bwarsaw

This commit is contained in:
Roger E. Masse 1996-12-16 20:25:44 +00:00
parent 14ed5fb1ec
commit 2362b58952
1 changed files with 28 additions and 26 deletions

View File

@ -1,32 +1,34 @@
#! /usr/bin/env python #! /usr/bin/env python
"""Test dlmodule.c """Test dlmodule.c
Roger E. Masse Roger E. Masse revised strategy by Barry Warsaw
""" """
filename = '/usr/lib/libresolv.so' verbose = 0
try: if __name__ == '__main__':
import dl verbose = 1
except ImportError:
# No test if no library
raise SystemExit
try: import dl
import os
n = os.popen('/bin/uname','r')
if n.readlines()[0][:-1] != 'SunOS':
raise SystemExit
l = dl.open('/usr/lib/libresolv.so')
except:
# No test if not SunOS (or Solaris)
raise SystemExit
# Try to open a shared library that should be available sharedlibs = [
# on SunOS and Solaris in a default place # SunOS/Solaris
try: ('/usr/lib/libresolv.so', 'gethostent'),
open(filename,'r') ]
except IOError:
# No test if I can't even open the test file with builtin open
raise SystemExit
l = dl.open(filename) for s, func in sharedlibs:
a = l.call('gethostent') try:
l.close() if verbose:
print 'trying to open:', s,
l = dl.open(s)
except dl.error:
if verbose:
print 'failed'
pass
else:
if verbose:
print 'succeeded...',
l.call(func)
l.close()
if verbose:
print 'worked!'
break
else:
print 'Could not open any shared libraries'