Skip to content

Commit 1a404c5

Browse files
authored
Merge pull request #93 from Flamefire/more_tests
Add more tests, fix bug in add_to_ld_library_path and typos
2 parents 6ec89dd + fed67f1 commit 1a404c5

12 files changed

Lines changed: 128 additions & 84 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/__main__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def _err_exit(msg):
1111

1212

1313
def scorep_main(argv=None):
14-
# print(sys.flags)
1514
if argv is None:
1615
argv = sys.argv
1716

@@ -61,10 +60,9 @@ def scorep_main(argv=None):
6160
if len(prog_argv) == 0:
6261
_err_exit("Did not find a script to run")
6362

64-
if ("SCOREP_PYTHON_BINDINGS_INITALISED" not in os.environ) or (
65-
os.environ["SCOREP_PYTHON_BINDINGS_INITALISED"] != "true"):
63+
if os.environ.get("SCOREP_PYTHON_BINDINGS_INITIALISED") != "true":
6664
scorep.subsystem.init_environment(scorep_config, keep_files)
67-
os.environ["SCOREP_PYTHON_BINDINGS_INITALISED"] = "true"
65+
os.environ["SCOREP_PYTHON_BINDINGS_INITIALISED"] = "true"
6866
"""
6967
python -m starts the module as skript. i.e. sys.argv will loke like:
7068
['/home/gocht/Dokumente/code/scorep_python/scorep.py', '--mpi', 'mpi_test.py']
@@ -80,7 +78,7 @@ def scorep_main(argv=None):
8078

8179
os.execve(sys.executable, new_args, os.environ)
8280
else:
83-
scorep.subsystem.reset_pereload()
81+
scorep.subsystem.reset_preload()
8482

8583
# everything is ready
8684
sys.argv = prog_argv

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=[]):

scorep/instrumenter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def unregister():
4747
"""
4848
Disables the python-tracing.
4949
Disabling the python-tracing is more efficient than disable_recording,
50-
as python does not longer call the tracing module.
50+
as python does no longer call the tracing module.
5151
However, all the other things that are traced by Score-P will still be recorded.
5252
Please call register() to enable tracing again.
5353
"""
@@ -61,7 +61,7 @@ class enable():
6161
with enable(region_name=None):
6262
do stuff
6363
```
64-
This overides --no-instrumenter (--nopython leagacy)
64+
This overides --noinstrumenter (--nopython legacy)
6565
If a region name is given, the region the contextmanager is active will be marked in the trace or profile
6666
"""
6767

@@ -103,7 +103,7 @@ class disable():
103103
with disable():
104104
do stuff
105105
```
106-
This overides --no-instrumenter (--nopython leagacy)
106+
This overides --noinstrumenter (--nopython legacy)
107107
If a region name is given, the region the contextmanager is active will be marked in the trace or profile
108108
"""
109109

scorep/subsystem.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def generate_subsystem_lib_name():
1818

1919
def generate_ld_preload(scorep_config):
2020
"""
21-
This functions generate a string that needs to be passed to $LD_PRELOAD.
22-
After this sting is passed, the tracing needs to be restarted with this $LD_PRELOAD in env.
21+
This functions generates a string that needs to be passed to $LD_PRELOAD.
22+
After this string is passed, the tracing needs to be restarted with this $LD_PRELOAD in env.
2323
2424
@return ld_preload string which needs to be passed to LD_PRELOAD
2525
"""
@@ -103,15 +103,12 @@ def init_environment(scorep_config=[], keep_files=False):
103103
"""
104104
Set the inital needed environmet variables, to get everythin up an running.
105105
As a few variables interact with LD env vars, the programms needs to be restarted after this.
106-
The function set the env var `SCOREP_PYTHON_BINDINGS_INITALISED` to true, once it is done with
107-
initalising.
108106
109107
@param scorep_config configuration flags for score-p
110108
@param keep_files whether to keep the generated files, or not.
111109
"""
112110

113-
if ("LD_PRELOAD" in os.environ) and (
114-
"libscorep" in os.environ["LD_PRELOAD"]):
111+
if "libscorep" in os.environ.get("LD_PRELOAD", ""):
115112
raise RuntimeError(
116113
"Score-P is already loaded. This should not happen at this point")
117114

@@ -132,7 +129,7 @@ def init_environment(scorep_config=[], keep_files=False):
132129
os.environ["LD_PRELOAD"] = preload_str
133130

134131

135-
def reset_pereload():
132+
def reset_preload():
136133
"""
137134
resets the environment variable `LD_PRELOAD` to the value before init_environment was called.
138135
"""
@@ -152,6 +149,5 @@ def clean_up(keep_files=True):
152149
if keep_files:
153150
return
154151
else:
155-
if ("SCOREP_PYTHON_BINDINGS_TEMP_DIR" in os.environ) and (
156-
os.environ["SCOREP_PYTHON_BINDINGS_TEMP_DIR"] != ""):
152+
if os.environ.get("SCOREP_PYTHON_BINDINGS_TEMP_DIR"):
157153
shutil.rmtree(os.environ["SCOREP_PYTHON_BINDINGS_TEMP_DIR"])

scorep/user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def region_begin(name, file_name=None, line_number=None):
99
"""
1010
Begin of an User region. If file_name or line_number is None, both will
11-
bet determined automatically
11+
be determined automatically
1212
@param name name of the user region
1313
@param file_name file name of the user region
1414
@param line_number line number of the user region
@@ -131,7 +131,7 @@ def __exit__(self, exc_type, exc_value, traceback):
131131
def rewind_begin(name, file_name=None, line_number=None):
132132
"""
133133
Begin of an User region. If file_name or line_number is None, both will
134-
bet determined automatically
134+
be determined automatically
135135
@param name name of the user region
136136
@param file_name file name of the user region
137137
@param line_number line number of the user region
@@ -162,7 +162,7 @@ def rewind_end(name, value):
162162
def oa_region_begin(name, file_name=None, line_number=None):
163163
"""
164164
Begin of an Online Access region. If file_name or line_number is None, both will
165-
bet determined automatically
165+
be determined automatically
166166
@param name name of the user region
167167
@param file_name file name of the user region
168168
@param line_number line number of the user region

src/methods.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extern "C"
151151
Py_RETURN_NONE;
152152
}
153153

154-
static PyObject* get_expiriment_dir_name(PyObject* self, PyObject* args)
154+
static PyObject* get_experiment_dir_name(PyObject* self, PyObject* args)
155155
{
156156

157157
return PyUnicode_FromString(SCOREP_GetExperimentDirName());
@@ -169,7 +169,7 @@ extern "C"
169169
{ "parameter_int", parameter_int, METH_VARARGS, "User parameter int." },
170170
{ "parameter_uint", parameter_uint, METH_VARARGS, "User parameter uint." },
171171
{ "parameter_string", parameter_string, METH_VARARGS, "User parameter string." },
172-
{ "get_expiriment_dir_name", get_expiriment_dir_name, METH_VARARGS,
172+
{ "get_experiment_dir_name", get_experiment_dir_name, METH_VARARGS,
173173
"Get the Score-P experiment dir." },
174174
{ NULL, NULL, 0, NULL } /* Sentinel */
175175
};

test/cases/mpi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env python
22

3+
import scorep
34
from mpi4py import MPI
45
import numpy as np
56
import mpi4py
7+
import instrumentation2
68
mpi4py.rc.thread_level = "funneled"
79

10+
scorep.instrumenter.register()
811

912
comm = mpi4py.MPI.COMM_WORLD
1013

@@ -14,7 +17,9 @@
1417
N = 5
1518
if comm.rank == 0:
1619
A = np.arange(N, dtype=np.float64) # rank 0 has proper data
20+
instrumentation2.baz()
1721
else:
22+
instrumentation2.bar()
1823
A = np.empty(N, dtype=np.float64) # all other just an empty array
1924

2025
# 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)