Ejemplo n.º 1
0
 def get_libpath(mainlib, dependency):
     if environment.is_linux():
         cmd = 'ldd %s | grep %s' % (mainlib, dependency)
         subp = subprocess.Popen(cmd,stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,shell=True)
         out = subp.communicate()[0]
         # ldd produces a string that always has 4 columns. The full path
         # is in the 3rd column
         libpath = out.split()[2]
     else:
         libpath = os.path.join(_bin, dependency + '.dylib')
     return libpath
Ejemplo n.º 2
0
def run_tests():
    logfile = open('meson-test-run.txt', 'w')
    commontests = gather_tests('test cases/common')
    failtests = gather_tests('test cases/failing')
    objtests = gather_tests('test cases/prebuilt object')
    if environment.is_linux():
        cpuid = platform.machine()
        if cpuid != 'x86_64' and cpuid != 'i386' and cpuid != 'i686':
            # Don't have a prebuilt object file for those so skip.
            objtests = []
    if environment.is_osx():
        platformtests = gather_tests('test cases/osx')
    elif environment.is_windows():
        platformtests = gather_tests('test cases/windows')
    else:
        platformtests = gather_tests('test cases/linuxlike')
    if not environment.is_osx() and not environment.is_windows():
        frameworktests = gather_tests('test cases/frameworks')
    else:
        frameworktests = []
    if not environment.is_osx() and shutil.which('javac'):
        javatests = gather_tests('test cases/java')
    else:
        javatests = []
    if shutil.which('mcs'):
        cstests = gather_tests('test cases/csharp')
    else:
        cstests = []
    if shutil.which('valac'):
        valatests = gather_tests('test cases/vala')
    else:
        valatests = []
    if shutil.which('rustc'):
        rusttests = gather_tests('test cases/rust')
    else:
        rusttests = []
    if not environment.is_windows():
        objctests = gather_tests('test cases/objc')
    else:
        objctests = []
    if shutil.which('gfortran'):
        fortrantests = gather_tests('test cases/fortran')
    else:
        fortrantests = []
    try:
        os.mkdir(test_build_dir)
    except OSError:
        pass
    try:
        os.mkdir(install_dir)
    except OSError:
        pass
    print('\nRunning common tests.\n')
    [run_and_log(logfile, t) for t in commontests]
    print('\nRunning failing tests.\n')
    [run_and_log(logfile, t, False) for t in failtests]
    if len(objtests) > 0:
        print('\nRunning object inclusion tests.\n')
        [run_and_log(logfile, t) for t in objtests]
    else:
        print('\nNo object inclusion tests.\n')
    if len(platformtests) > 0:
        print('\nRunning platform dependent tests.\n')
        [run_and_log(logfile, t) for t in platformtests]
    else:
        print('\nNo platform specific tests.\n')
    if len(frameworktests) > 0:
        print('\nRunning framework tests.\n')
        [run_and_log(logfile, t) for t in frameworktests]
    else:
        print('\nNo framework tests on this platform.\n')
    if len(javatests) > 0:
        print('\nRunning java tests.\n')
        [run_and_log(logfile, t) for t in javatests]
    else:
        print('\nNot running Java tests.\n')
    if len(cstests) > 0:
        print('\nRunning C# tests.\n')
        [run_and_log(logfile, t) for t in cstests]
    else:
        print('\nNot running C# tests.\n')
    if len(valatests) > 0:
        print('\nRunning Vala tests.\n')
        [run_and_log(logfile, t) for t in valatests]
    else:
        print('\nNot running Vala tests.\n')
    if len(rusttests) > 0:
        print('\nRunning Rust tests.\n')
        [run_and_log(logfile, t) for t in rusttests]
    else:
        print('\nNot running Rust tests.\n')
    if len(objctests) > 0:
        print('\nRunning Objective C tests.\n')
        [run_and_log(logfile, t) for t in objctests]
    else:
        print('\nNo Objective C tests on this platform.\n')
    if len(fortrantests) > 0:
        print('\nRunning Fortran tests.\n')
        [run_and_log(logfile, t) for t in fortrantests]
    else:
        print('\nNo Fortran tests on this platform.\n')
Ejemplo n.º 3
0
def setup_dlopen(library, depends=[]):
    """Set the flags for a call to import a shared library
    such that all symbols are imported.
    
    On Linux this sets the flags for dlopen so that 
    all symbols from the library are imported in to
    the global symbol table.
    
    Without this each shared library gets its own
    copy of any singleton, which is not the correct
    behaviour
    
    Args:
      library - The path to the library we are opening
      depends - A list of dependents to open (default=[])
    
    Returns the original flags
    """
    if environment.is_windows():
      return None
    old_flags = sys.getdlopenflags()

    import _dlopen
    dlloader = _dlopen.loadlibrary
    import subprocess

    _bin = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../../')
    
    def get_libpath(mainlib, dependency):
        if environment.is_linux():
            cmd = 'ldd %s | grep %s' % (mainlib, dependency)
            subp = subprocess.Popen(cmd,stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,shell=True)
            out = subp.communicate()[0]
            # ldd produces a string that always has 4 columns. The full path
            # is in the 3rd column
            libpath = out.split()[2]
        else:
            libpath = os.path.join(_bin, dependency + '.dylib')
        return libpath

    library_var = "LD_LIBRARY_PATH"
    if environment.is_mac():
        library_var = 'DY' + library_var
    ldpath = os.environ.get(library_var, "")
    ldpath += ":" + _bin
    os.environ[library_var] = ldpath

    pythonlib = library
    if environment.is_linux():
        # stdc++ has to be loaded first or exceptions don't get translated 
        # properly across bounadries
        # NeXus has to be loaded as well as there seems to be an issue with
        # the thread-local storage not being initialized properly unles
        # it is loaded before other libraries.
        dlloader(get_libpath(pythonlib, 'stdc++'))
        dlloader(get_libpath(pythonlib, 'libNeXus.so'))
    # Load the dependencies
    for dep in depends:
        dlloader(get_libpath(pythonlib, dep))

    oldflags = sys.getdlopenflags()
    if environment.is_mac():
        try:
            import dl
            RTLD_LOCAL = dl.RTLD_LOCAL
            RTLD_NOW = dl.RTLD_NOW
        except ImportError:
            RTLD_LOCAL = 0x4
            RTLD_NOW = 0x2
        sys.setdlopenflags(RTLD_LOCAL|RTLD_NOW)
    
    return old_flags
Ejemplo n.º 4
0
For Mantid this ensures the singleton symbols are wired up correctly
"""
import sys
import os
import environment

#######################################################################
# Ensure the correct Mantid shared libaries are found when loading the
# python shared libraries
#######################################################################
if environment.is_windows():
    _var = 'PATH'
    _sep = ';'
else:
    _sep = ':'
    if environment.is_linux():
        _var = 'LD_LIBRARY_PATH'
    elif environment.is_mac():
        _var = 'DYLD_LIBRARY_PATH'
    else: # Give it a go how it is
        _var = ''
        _sep = ''
try:
    _oldpath = os.environ[_var]
except:
    _oldpath = ''
    _sep = ''
os.environ[_var] = os.environ['MANTIDPATH'] + _sep + _oldpath       

#######################################################################
# Public api