test_build.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from subprocess import PIPE, Popen
  2. import sys
  3. import re
  4. import pytest
  5. from numpy.linalg import lapack_lite
  6. from numpy.testing import assert_
  7. class FindDependenciesLdd:
  8. def __init__(self):
  9. self.cmd = ['ldd']
  10. try:
  11. p = Popen(self.cmd, stdout=PIPE, stderr=PIPE)
  12. stdout, stderr = p.communicate()
  13. except OSError:
  14. raise RuntimeError(f'command {self.cmd} cannot be run')
  15. def get_dependencies(self, lfile):
  16. p = Popen(self.cmd + [lfile], stdout=PIPE, stderr=PIPE)
  17. stdout, stderr = p.communicate()
  18. if not (p.returncode == 0):
  19. raise RuntimeError(f'failed dependencies check for {lfile}')
  20. return stdout
  21. def grep_dependencies(self, lfile, deps):
  22. stdout = self.get_dependencies(lfile)
  23. rdeps = dict([(dep, re.compile(dep)) for dep in deps])
  24. founds = []
  25. for l in stdout.splitlines():
  26. for k, v in rdeps.items():
  27. if v.search(l):
  28. founds.append(k)
  29. return founds
  30. class TestF77Mismatch:
  31. @pytest.mark.skipif(not(sys.platform[:5] == 'linux'),
  32. reason="no fortran compiler on non-Linux platform")
  33. def test_lapack(self):
  34. f = FindDependenciesLdd()
  35. deps = f.grep_dependencies(lapack_lite.__file__,
  36. [b'libg2c', b'libgfortran'])
  37. assert_(len(deps) <= 1,
  38. """Both g77 and gfortran runtimes linked in lapack_lite ! This is likely to
  39. cause random crashes and wrong results. See numpy INSTALL.txt for more
  40. information.""")