Skip to content

Commit 9369c42

Browse files
committed
Add test for and fix add_to_ld_library_path
If the path to add is a substring of an existing path it was silently ignored. This is now handled by properly splitting and joining that path into an array and checking that
1 parent bcd58e3 commit 9369c42

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_custom_target(ScorepModule ALL
3131

3232
enable_testing()
3333
add_test(NAME ScorepPythonTests
34-
COMMAND Python::Interpreter -m pytest test_scorep.py
34+
COMMAND Python::Interpreter -m pytest
3535
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/test
3636
)
3737
set(pythonPath ${CMAKE_CURRENT_BINARY_DIR}/site-packages)

DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Although, we do not actively maintain the CMake build system, and will not help
2222

2323
You might find this build system helpful for development, especially if you are doing C/C++ things:
2424
* Include paths for C++ are correctly searched for and set up for use by IDEs or other tools. For example Visual Studio Code works out of the box, given the appropriate extensions (C++, Python, CMake) are installed.
25-
* A folder `site-packages` is created in the build folder where the C/C++ extension module and the scorep module are copied to on each build (e.g. `make`-call). Hence it is possible to add that folder to the PYTHONPATH environment variable, build the project and start debugging or execute the tests in test/test_scorep.py.
25+
* A folder `site-packages` is created in the build folder where the C/C++ extension module and the scorep module are copied to on each build (e.g. `make`-call). Hence it is possible to add that folder to the PYTHONPATH environment variable, build the project and start debugging or execute the tests in test.
2626
* A `test` target exists which can be run to execute all tests.
2727

2828
Please note, that changes to the Python source files are not reflected in the build folder unless a build is executed.

scorep/helper.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,10 @@ def add_to_ld_library_path(path):
6868
adds the path to the LD_LIBRARY_PATH.
6969
@param path path to be added
7070
"""
71-
if ("LD_LIBRARY_PATH" not in os.environ):
72-
os.environ["LD_LIBRARY_PATH"] = ""
73-
74-
if (path not in os.environ["LD_LIBRARY_PATH"]):
75-
if os.environ["LD_LIBRARY_PATH"] == "":
76-
os.environ["LD_LIBRARY_PATH"] = path
77-
else:
78-
os.environ["LD_LIBRARY_PATH"] = path + \
79-
":" + os.environ["LD_LIBRARY_PATH"]
71+
library_path = os.environ.get("LD_LIBRARY_PATH", "")
72+
library_paths = library_path.split(":") if library_path else []
73+
if path not in library_paths:
74+
os.environ["LD_LIBRARY_PATH"] = ':'.join([path] + library_paths)
8075

8176

8277
def generate_compile_deps(config=[]):

test/cases/mpi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mpi4py import MPI
44
import numpy as np
55
import mpi4py
6+
import instrumentation2
67
mpi4py.rc.thread_level = "funneled"
78

89

@@ -14,7 +15,9 @@
1415
N = 5
1516
if comm.rank == 0:
1617
A = np.arange(N, dtype=np.float64) # rank 0 has proper data
18+
instrumentation2.baz()
1719
else:
20+
instrumentation2.bar()
1821
A = np.empty(N, dtype=np.float64) # all other just an empty array
1922

2023
# Broadcast A from rank 0 to everybody

test/test_helper.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import scorep.helper
3+
4+
5+
def test_add_to_ld_library_path(monkeypatch):
6+
# Previous value: Empty
7+
monkeypatch.setenv('LD_LIBRARY_PATH', '')
8+
scorep.helper.add_to_ld_library_path('/my/path')
9+
assert os.environ['LD_LIBRARY_PATH'] == '/my/path'
10+
# Don't add duplicates
11+
scorep.helper.add_to_ld_library_path('/my/path')
12+
assert os.environ['LD_LIBRARY_PATH'] == '/my/path'
13+
# Prepend
14+
scorep.helper.add_to_ld_library_path('/new/folder')
15+
assert os.environ['LD_LIBRARY_PATH'] == '/new/folder:/my/path'
16+
# also no duplicates:
17+
for p in ('/my/path', '/new/folder'):
18+
scorep.helper.add_to_ld_library_path(p)
19+
assert os.environ['LD_LIBRARY_PATH'] == '/new/folder:/my/path'
20+
21+
# Add parent folder of existing one
22+
monkeypatch.setenv('LD_LIBRARY_PATH', '/some/folder:/parent/sub')
23+
scorep.helper.add_to_ld_library_path('/parent')
24+
assert os.environ['LD_LIBRARY_PATH'] == '/parent:/some/folder:/parent/sub'

0 commit comments

Comments
 (0)