test_build.py 1.7 KB

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