summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/relocate.py
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-04-27 12:17:32 +0200
committerGitHub <noreply@github.com>2020-04-27 12:17:32 +0200
commit6b648c6e89a92f8220464a2807f42a45acd6b8e9 (patch)
treedd28f6b930b7e4781f5dcbe1c9f479e92a074540 /lib/spack/spack/test/relocate.py
parentca4de491bafbda92af7b15c442b33a2d84db969a (diff)
downloadspack-6b648c6e89a92f8220464a2807f42a45acd6b8e9.tar.gz
spack-6b648c6e89a92f8220464a2807f42a45acd6b8e9.tar.bz2
spack-6b648c6e89a92f8220464a2807f42a45acd6b8e9.tar.xz
spack-6b648c6e89a92f8220464a2807f42a45acd6b8e9.zip
Improve the coverage of spack.relocate (#15654)
This PR introduces trivial refactoring in: - `get_existing_elf_rpaths` - `get_relative_elf_rpaths` - `get_normalized_elf_rpaths` - `set_placeholder` mainly to be more consistent with practices used in other parts of the code and to simplify functions locally. It also adds or reworks unit tests for these functions and extends their docstrings. Co-authored-by: Patrick Gartung <gartung@fnal.gov> Co-authored-by: Peter J. Scheibel <scheibel1@llnl.gov>
Diffstat (limited to 'lib/spack/spack/test/relocate.py')
-rw-r--r--lib/spack/spack/test/relocate.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/spack/spack/test/relocate.py b/lib/spack/spack/test/relocate.py
index 0a9e9f7f0a..a2bba52f40 100644
--- a/lib/spack/spack/test/relocate.py
+++ b/lib/spack/spack/test/relocate.py
@@ -89,6 +89,20 @@ def expected_patchelf_path(request, mutable_database, monkeypatch):
return expected_path
+@pytest.fixture()
+def mock_patchelf(tmpdir):
+ import jinja2
+
+ def _factory(output):
+ f = tmpdir.mkdir('bin').join('patchelf')
+ t = jinja2.Template('#!/bin/bash\n{{ output }}\n')
+ f.write(t.render(output=output))
+ f.chmod(0o755)
+ return str(f)
+
+ return _factory
+
+
@pytest.mark.requires_executables(
'/usr/bin/gcc', 'patchelf', 'strings', 'file'
)
@@ -140,3 +154,43 @@ def test_file_is_relocatable_errors(tmpdir):
def test_search_patchelf(expected_patchelf_path):
current = spack.relocate._patchelf()
assert current == expected_patchelf_path
+
+
+@pytest.mark.parametrize('patchelf_behavior,expected', [
+ ('echo ', []),
+ ('echo /opt/foo/lib:/opt/foo/lib64', ['/opt/foo/lib', '/opt/foo/lib64']),
+ ('exit 1', [])
+])
+def test_existing_rpaths(patchelf_behavior, expected, mock_patchelf):
+ # Here we are mocking an executable that is always called "patchelf"
+ # because that will skip the part where we try to build patchelf
+ # by ourselves. The executable will output some rpaths like
+ # `patchelf --print-rpath` would.
+ path = mock_patchelf(patchelf_behavior)
+ rpaths = spack.relocate._elf_rpaths_for(path)
+ assert rpaths == expected
+
+
+@pytest.mark.parametrize('start_path,path_root,paths,expected', [
+ ('/usr/bin/test', '/usr', ['/usr/lib', '/usr/lib64', '/opt/local/lib'],
+ ['$ORIGIN/../lib', '$ORIGIN/../lib64', '/opt/local/lib'])
+])
+def test_make_relative_paths(start_path, path_root, paths, expected):
+ relatives = spack.relocate._make_relative(start_path, path_root, paths)
+ assert relatives == expected
+
+
+@pytest.mark.parametrize('start_path,relative_paths,expected', [
+ # $ORIGIN will be replaced with os.path.dirname('usr/bin/test')
+ # and then normalized
+ ('/usr/bin/test',
+ ['$ORIGIN/../lib', '$ORIGIN/../lib64', '/opt/local/lib'],
+ ['/usr/lib', '/usr/lib64', '/opt/local/lib']),
+ # Relative path without $ORIGIN
+ ('/usr/bin/test', ['../local/lib'], ['../local/lib']),
+])
+def test_normalize_relative_paths(start_path, relative_paths, expected):
+ normalized = spack.relocate._normalize_relative_paths(
+ start_path, relative_paths
+ )
+ assert normalized == expected