Skip to content

Commit bcd58e3

Browse files
committed
Run each test for all instrumenters
1 parent 6ec89dd commit bcd58e3

1 file changed

Lines changed: 45 additions & 46 deletions

File tree

test/test_scorep.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import sys
88
import pytest
99

10+
# All instrumenters (except dummy which isn't a real one)
11+
ALL_INSTRUMENTERS = ['profile', 'trace']
12+
if sys.version_info.major >= 3:
13+
ALL_INSTRUMENTERS.extend(['cProfile', 'cTrace'])
14+
1015

1116
def call(arguments, expected_returncode=0, env=None):
1217
"""
@@ -53,6 +58,7 @@ def requires_package(name):
5358

5459

5560
requires_python3 = pytest.mark.skipif(sys.version_info.major < 3, reason="not tested for python 2")
61+
foreach_instrumenter = pytest.mark.parametrize('instrumenter', ALL_INSTRUMENTERS)
5662

5763

5864
@pytest.fixture
@@ -76,11 +82,12 @@ def test_has_version():
7682
assert scorep.__version__ is not None
7783

7884

79-
def test_user_regions(scorep_env):
85+
@foreach_instrumenter
86+
def test_user_regions(scorep_env, instrumenter):
8087
trace_path = get_trace_path(scorep_env)
8188

8289
std_out, std_err = call_with_scorep("cases/user_regions.py",
83-
["--nopython"],
90+
["--nopython", "--instrumenter-type=" + instrumenter],
8491
env=scorep_env)
8592

8693
assert std_err == ""
@@ -98,11 +105,12 @@ def test_user_regions(scorep_env):
98105
assert re.search('LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "user:test_region_4"', std_out)
99106

100107

101-
def test_context(scorep_env):
108+
@foreach_instrumenter
109+
def test_context(scorep_env, instrumenter):
102110
trace_path = get_trace_path(scorep_env)
103111

104112
std_out, std_err = call_with_scorep("cases/context.py",
105-
["--noinstrumenter"],
113+
["--noinstrumenter", "--instrumenter-type=" + instrumenter],
106114
env=scorep_env)
107115

108116
assert std_err == ""
@@ -116,19 +124,19 @@ def test_context(scorep_env):
116124
assert re.search('LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "__main__:foo"', std_out)
117125

118126

119-
def test_user_regions_no_scorep(scorep_env):
127+
def test_user_regions_no_scorep():
120128
std_out, std_err = call([sys.executable,
121-
"cases/user_regions.py"],
122-
env=scorep_env)
129+
"cases/user_regions.py"])
123130

124131
assert std_err == ""
125132
assert std_out == "hello world\nhello world\nhello world3\nhello world4\n"
126133

127134

128-
def test_user_rewind(scorep_env):
135+
@foreach_instrumenter
136+
def test_user_rewind(scorep_env, instrumenter):
129137
trace_path = get_trace_path(scorep_env)
130138

131-
std_out, std_err = call_with_scorep("cases/user_rewind.py", env=scorep_env)
139+
std_out, std_err = call_with_scorep("cases/user_rewind.py", ["--instrumenter-type=" + instrumenter], env=scorep_env)
132140

133141
assert std_err == ""
134142
assert std_out == "hello world\nhello world\n"
@@ -139,11 +147,12 @@ def test_user_rewind(scorep_env):
139147
assert re.search('MEASUREMENT_ON_OFF[ ]*[0-9 ]*[0-9 ]*Mode: ON', std_out)
140148

141149

142-
def test_oa_regions(scorep_env):
150+
@foreach_instrumenter
151+
def test_oa_regions(scorep_env, instrumenter):
143152
trace_path = get_trace_path(scorep_env)
144153

145154
std_out, std_err = call_with_scorep("cases/oa_regions.py",
146-
["--nopython"],
155+
["--nopython", "--instrumenter-type=" + instrumenter],
147156
env=scorep_env)
148157

149158
assert std_err == ""
@@ -156,11 +165,14 @@ def test_oa_regions(scorep_env):
156165
assert re.search('LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "test_region"', std_out)
157166

158167

159-
def test_instrumentation(scorep_env):
168+
@pytest.mark.parametrize('instrumenter', ALL_INSTRUMENTERS + [None])
169+
def test_instrumentation(scorep_env, instrumenter):
160170
trace_path = get_trace_path(scorep_env)
161171

172+
# Also test when no instrumenter is given
173+
instrumenter_type = ["--instrumenter-type=" + instrumenter] if instrumenter else []
162174
std_out, std_err = call_with_scorep("cases/instrumentation.py",
163-
["--nocompiler"],
175+
["--nocompiler"] + instrumenter_type,
164176
env=scorep_env)
165177

166178
assert std_err == ""
@@ -169,15 +181,17 @@ def test_instrumentation(scorep_env):
169181
std_out, std_err = call(["otf2-print", trace_path])
170182

171183
assert std_err == ""
172-
assert re.search('ENTER[ ]*[0-9 ]*[0-9 ]*Region: "__main__:foo"', std_out)
173-
assert re.search('LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "__main__:foo"', std_out)
184+
for func in ('__main__:foo', 'instrumentation2:bar', 'instrumentation2:baz'):
185+
for event in ('ENTER', 'LEAVE'):
186+
assert re.search('%s[ ]*[0-9 ]*[0-9 ]*Region: "%s"' % (event, func), std_out)
174187

175188

176-
def test_user_instrumentation(scorep_env):
189+
@foreach_instrumenter
190+
def test_user_instrumentation(scorep_env, instrumenter):
177191
trace_path = get_trace_path(scorep_env)
178192

179193
std_out, std_err = call_with_scorep("cases/user_instrumentation.py",
180-
["--nocompiler", "--noinstrumenter"],
194+
["--nocompiler", "--noinstrumenter", "--instrumenter-type=" + instrumenter],
181195
env=scorep_env)
182196

183197
assert std_err == ""
@@ -190,11 +204,12 @@ def test_user_instrumentation(scorep_env):
190204
assert re.search('LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "__main__:foo"', std_out)
191205

192206

193-
def test_error_region(scorep_env):
207+
@foreach_instrumenter
208+
def test_error_region(scorep_env, instrumenter):
194209
trace_path = get_trace_path(scorep_env)
195210

196211
std_out, std_err = call_with_scorep("cases/error_region.py",
197-
["--nocompiler", "--noinstrumenter"],
212+
["--nocompiler", "--noinstrumenter", "--instrumenter-type=" + instrumenter],
198213
env=scorep_env)
199214

200215
assert std_err == \
@@ -215,7 +230,8 @@ def test_error_region(scorep_env):
215230

216231
@requires_package('mpi4py')
217232
@requires_package('numpy')
218-
def test_mpi(scorep_env):
233+
@foreach_instrumenter
234+
def test_mpi(scorep_env, instrumenter):
219235
std_out, std_err = call(["mpirun",
220236
"-n",
221237
"2",
@@ -227,6 +243,7 @@ def test_mpi(scorep_env):
227243
"scorep",
228244
"--mpp=mpi",
229245
"--nocompiler",
246+
"--instrumenter-type=" + instrumenter,
230247
"cases/mpi.py"],
231248
env=scorep_env)
232249

@@ -236,9 +253,10 @@ def test_mpi(scorep_env):
236253
assert re.search(expected_std_out, std_out)
237254

238255

239-
def test_call_main(scorep_env):
256+
@foreach_instrumenter
257+
def test_call_main(scorep_env, instrumenter):
240258
std_out, std_err = call_with_scorep("cases/call_main.py",
241-
["--nocompiler"],
259+
["--nocompiler", "--instrumenter-type=" + instrumenter],
242260
expected_returncode=1,
243261
env=scorep_env)
244262

@@ -259,11 +277,12 @@ def test_dummy(scorep_env):
259277

260278

261279
@requires_python3
262-
def test_numpy_dot(scorep_env):
280+
@foreach_instrumenter
281+
def test_numpy_dot(scorep_env, instrumenter):
263282
trace_path = get_trace_path(scorep_env)
264283

265284
std_out, std_err = call_with_scorep("cases/numpy_dot.py",
266-
["--nocompiler", "--noinstrumenter"],
285+
["--nocompiler", "--noinstrumenter", "--instrumenter-type=" + instrumenter],
267286
env=scorep_env)
268287

269288
assert std_out == "[[ 7 10]\n [15 22]]\n"
@@ -276,32 +295,12 @@ def test_numpy_dot(scorep_env):
276295
assert re.search('LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "numpy.__array_function__:dot"', std_out)
277296

278297

279-
@requires_python3
280-
@pytest.mark.parametrize('instrumenter', ['cProfile', 'cTrace'])
281-
def test_instrumentation_ctracing(scorep_env, instrumenter):
282-
trace_path = scorep_env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2"
283-
284-
std_out, std_err = call_with_scorep("cases/instrumentation.py",
285-
["--nocompiler", "--instrumenter-type=" + instrumenter],
286-
env=scorep_env)
287-
288-
assert std_err == ""
289-
assert std_out == "hello world\nbaz\nbar\n"
290-
291-
std_out, std_err = call(["otf2-print", trace_path])
292-
293-
assert std_err == ""
294-
for func in ('__main__:foo', 'instrumentation2:bar', 'instrumentation2:baz'):
295-
for event in ('ENTER', 'LEAVE'):
296-
assert re.search('%s[ ]*[0-9 ]*[0-9 ]*Region: "%s"' % (event, func), std_out)
297-
298-
299-
@pytest.mark.parametrize('instrumenter', ['profile', 'trace', 'cProfile', 'cTrace'])
298+
@foreach_instrumenter
300299
def test_threads(scorep_env, instrumenter):
301300
if instrumenter[0] == 'c' and sys.version_info.major < 3:
302301
pytest.skip("C extension class only implemented for Python3")
303302

304-
trace_path = scorep_env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2"
303+
trace_path = get_trace_path(scorep_env)
305304

306305
std_out, std_err = call_with_scorep("cases/use_threads.py",
307306
["--nocompiler", "--instrumenter-type=" + instrumenter],

0 commit comments

Comments
 (0)