1 # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 import lttng_ivc
.utils
.ProjectFactory
as ProjectFactory
28 import lttng_ivc
.utils
.utils
as utils
29 import lttng_ivc
.utils
.runtime
as Run
30 import lttng_ivc
.settings
as Settings
35 BC: Feature of the smallest version number will works.
36 TU: Tracing unavailable
38 NOTE: tracing between 2.7 and 2.8 should work but a problem with
39 _ustctl_basic_type prevent event registration. Hence consider in further test
40 that the event registration is expected to fail.
42 +------------------------------------------------------------------------------+
43 | LTTng UST control protocol compatibility matrix |
44 | (between applications and tools linked on LTTng UST and liblttng-ust-ctl) |
45 +--------------------------+------------+------------+------------+------------+
46 | LTTng UST / LTTng Tools | 2.7 (6.0) | 2.8 (6.1) | 2.9 (7.1) | 2.10 (7.2) |
47 +--------------------------+------------+------------+------------+------------+
48 | 2.7 (6.0) | FC | BC | TU | TU |
49 | 2.8 (6.1) | BC | FC | TU | TU |
50 | 2.9 (7.1) | TU | TU | FC | BC |
51 | 2.10 (7.2) | TU | TU | BC | FC |
52 +--------------------------+------------+------------+------------+------------+
54 Version number of this API is defined in include/lttng/ust-abi.h of lttng-ust project
59 First tuple member: lttng-ust label
60 Second tuple member: lttng-tool label
61 Third tuple member: expected scenario
64 event_registration_error
= "Error: UST app recv reg unsupported version"
66 test_matrix_tracing_available
= [
67 ("lttng-ust-2.7", "lttng-tools-2.7", "Success"),
68 ("lttng-ust-2.7", "lttng-tools-2.8", "Unsupported version"),
69 ("lttng-ust-2.7", "lttng-tools-2.9", "Unsupported"),
70 ("lttng-ust-2.7", "lttng-tools-2.10", "Unsupported"),
71 ("lttng-ust-2.8", "lttng-tools-2.7", "Unsupported version"),
72 ("lttng-ust-2.8", "lttng-tools-2.8", "Success"),
73 ("lttng-ust-2.8", "lttng-tools-2.9", "Unsupported"),
74 ("lttng-ust-2.8", "lttng-tools-2.10", "Unsupported"),
75 ("lttng-ust-2.9", "lttng-tools-2.7", "Unsupported"),
76 ("lttng-ust-2.9", "lttng-tools-2.8", "Unsupported"),
77 ("lttng-ust-2.9", "lttng-tools-2.9", "Success"),
78 ("lttng-ust-2.9", "lttng-tools-2.10", "Success"),
79 ("lttng-ust-2.10", "lttng-tools-2.7", "Unsupported"),
80 ("lttng-ust-2.10", "lttng-tools-2.8", "Unsupported"),
81 ("lttng-ust-2.10", "lttng-tools-2.9", "Success"),
82 ("lttng-ust-2.10", "lttng-tools-2.10", "Success"),
87 Statedump are supported starting at lttng-ust >= 2.9.
88 No need to test for prior lttng-ust givent that there is also a bump leading to
89 loss of tracing for application running under lttng-ust < 2.9.
91 test_matrix_regen_statedump
= [
92 ("lttng-ust-2.9", "lttng-tools-2.9", True),
93 ("lttng-ust-2.9", "lttng-tools-2.10", True),
94 ("lttng-ust-2.10", "lttng-tools-2.9", True),
95 ("lttng-ust-2.10", "lttng-tools-2.10", True),
98 test_matrix_starglobing_enabler
= [
99 ("lttng-ust-2.9", "lttng-tools-2.9", "Unsupported by tools"),
100 ("lttng-ust-2.9", "lttng-tools-2.10", "Unsupported by ust"),
101 ("lttng-ust-2.10", "lttng-tools-2.9", "Unsupported by tools"),
102 ("lttng-ust-2.10", "lttng-tools-2.10", "Supported"),
105 runtime_matrix_tracing_available
= []
106 runtime_matrix_regen_statedump
= []
107 runtime_matrix_starglobing_enabler
= []
109 if not Settings
.test_only
:
110 runtime_matrix_tracing_available
= test_matrix_tracing_available
111 runtime_matrix_regen_statedump
= test_matrix_regen_statedump
112 runtime_matrix_starglobing_enabler
= test_matrix_starglobing_enabler
114 for tup
in test_matrix_tracing_available
:
115 if (tup
[0] in Settings
.test_only
or tup
[1] in
117 runtime_matrix_tracing_available
.append(tup
)
118 for tup
in test_matrix_regen_statedump
:
119 if (tup
[0] in Settings
.test_only
or tup
[1] in
121 runtime_matrix_regen_statedump
.append(tup
)
122 for tup
in test_matrix_starglobing_enabler
:
123 if (tup
[0] in Settings
.test_only
or tup
[1] in
125 runtime_matrix_starglobing_enabler
.append(tup
)
128 @pytest.mark
.parametrize("ust_label,tools_label,outcome", runtime_matrix_tracing_available
)
129 def test_ust_app_tracing_available(tmpdir
, ust_label
, tools_label
, outcome
):
133 # Prepare environment
134 ust
= ProjectFactory
.get_precook(ust_label
)
135 tools
= ProjectFactory
.get_precook(tools_label
)
136 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
138 tools_runtime_path
= os
.path
.join(str(tmpdir
), "tools")
139 ust_runtime_path
= os
.path
.join(str(tmpdir
), "ust")
140 app_path
= os
.path
.join(str(tmpdir
), "app")
142 with Run
.get_runtime(ust_runtime_path
) as runtime_app
, Run
.get_runtime(tools_runtime_path
) as runtime_tools
:
143 runtime_tools
.add_project(tools
)
144 runtime_tools
.add_project(babeltrace
)
146 runtime_app
.add_project(ust
)
147 runtime_app
.lttng_home
= runtime_tools
.lttng_home
149 trace_path
= os
.path
.join(runtime_tools
.lttng_home
, 'trace')
151 # Make application using the ust runtime
152 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
153 runtime_app
.run("make V=1", cwd
=app_path
)
155 # Start lttng-sessiond
156 sessiond
= utils
.sessiond_spawn(runtime_tools
)
158 # Create session using mi to get path and session name
159 runtime_tools
.run('lttng create trace --output={}'.format(trace_path
))
161 runtime_tools
.run('lttng enable-event -u tp:tptest')
162 runtime_tools
.run('lttng start')
165 cmd
= './app {}'.format(nb_events
)
166 runtime_app
.run(cmd
, cwd
=app_path
)
169 runtime_tools
.run('lttng stop')
170 runtime_tools
.run('lttng destroy -a')
171 cp
= runtime_tools
.subprocess_terminate(sessiond
)
172 if cp
.returncode
!= 0:
173 pytest
.fail("Sessiond return code")
176 cmd
= 'babeltrace {}'.format(trace_path
)
177 if outcome
== "Success":
178 cp_process
, cp_out
, cp_err
= runtime_tools
.run(cmd
)
179 assert(utils
.line_count(cp_out
) == nb_events
)
181 with pytest
.raises(subprocess
.CalledProcessError
):
182 cp_process
, cp_out
, cp_err
= runtime_tools
.run(cmd
)
183 if outcome
== "Unsupported version":
184 assert(utils
.file_contains(runtime_tools
.get_subprocess_stderr_path(sessiond
),
185 [event_registration_error
]))
187 @pytest.mark
.parametrize("ust_label,tools_label, success", runtime_matrix_regen_statedump
)
188 def test_ust_app_regen_statedump(tmpdir
, ust_label
, tools_label
, success
):
196 ust
= ProjectFactory
.get_precook(ust_label
)
197 tools
= ProjectFactory
.get_precook(tools_label
)
198 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
200 tools_runtime_path
= os
.path
.join(str(tmpdir
), "tools")
201 ust_runtime_path
= os
.path
.join(str(tmpdir
), "ust")
202 app_path
= os
.path
.join(str(tmpdir
), "app")
205 app_sync_start
= os
.path
.join(app_path
, 'sync_start')
206 app_sync_end
= os
.path
.join(app_path
, 'sync_end')
208 with Run
.get_runtime(ust_runtime_path
) as runtime_app
, Run
.get_runtime(tools_runtime_path
) as runtime_tools
:
209 runtime_tools
.add_project(tools
)
210 runtime_tools
.add_project(babeltrace
)
212 runtime_app
.add_project(ust
)
213 runtime_app
.lttng_home
= runtime_tools
.lttng_home
215 trace_path
= os
.path
.join(runtime_tools
.lttng_home
, 'trace')
217 # Make application using the ust runtime
218 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
219 runtime_app
.run("make V=1", cwd
=app_path
)
221 # Start lttng-sessiond
222 sessiond
= utils
.sessiond_spawn(runtime_tools
)
224 # Create session using mi to get path and session name
225 runtime_tools
.run('lttng create trace --output={}'.format(trace_path
))
227 runtime_tools
.run('lttng enable-event -u lttng_ust_statedump:start,lttng_ust_statedump:end')
228 runtime_tools
.run('lttng start')
231 cmd
= './app {} 0 {} {}'.format(nb_events
, app_sync_start
, app_sync_end
)
232 runtime_app
.spawn_subprocess(cmd
, cwd
=app_path
)
234 utils
.wait_for_file(app_sync_start
)
237 with pytest
.raises(subprocess
.CalledProcessError
):
238 runtime_tools
.run('lttng regenerate statedump')
240 runtime_tools
.run('lttng regenerate statedump')
242 utils
.create_empty_file(app_sync_end
)
245 runtime_tools
.run('lttng stop')
246 runtime_tools
.run('lttng destroy -a')
247 cp
= runtime_tools
.subprocess_terminate(sessiond
)
248 if cp
.returncode
!= 0:
249 pytest
.fail("Sessiond return code")
251 # Read trace with babeltrace and check for event count via number of line
252 cmd
= 'babeltrace {}'.format(trace_path
)
253 cp_process
, cp_out
, cp_err
= runtime_tools
.run(cmd
)
254 assert(utils
.line_count(cp_out
) == expected_events
)
256 @pytest.mark
.parametrize("ust_label,tools_label, scenario", runtime_matrix_starglobing_enabler
)
257 def test_ust_app_starglobing_enabler(tmpdir
, ust_label
, tools_label
, scenario
):
261 if scenario
== "Unsupported by ust":
264 expected_events
= nb_events
266 # Prepare environment
267 ust
= ProjectFactory
.get_precook(ust_label
)
268 tools
= ProjectFactory
.get_precook(tools_label
)
269 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
271 tools_runtime_path
= os
.path
.join(str(tmpdir
), "tools")
272 ust_runtime_path
= os
.path
.join(str(tmpdir
), "ust")
273 app_path
= os
.path
.join(str(tmpdir
), "app")
275 with Run
.get_runtime(ust_runtime_path
) as runtime_app
, Run
.get_runtime(tools_runtime_path
) as runtime_tools
:
276 runtime_tools
.add_project(tools
)
277 runtime_tools
.add_project(babeltrace
)
279 runtime_app
.add_project(ust
)
280 runtime_app
.lttng_home
= runtime_tools
.lttng_home
282 trace_path
= os
.path
.join(runtime_tools
.lttng_home
, 'trace')
284 # Make application using the ust runtime
285 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
286 runtime_app
.run("make V=1", cwd
=app_path
)
288 # Start lttng-sessiond
289 sessiond
= utils
.sessiond_spawn(runtime_tools
)
291 # Create session using mi to get path and session name
292 runtime_tools
.run('lttng create trace --output={}'.format(trace_path
))
294 # If unsupported by tools simply finish early
295 if scenario
== "Unsupported by tools":
296 with pytest
.raises(subprocess
.CalledProcessError
):
297 runtime_tools
.run('lttng enable-event -u "tp:*te*"')
299 # TODO move this to internal runtime...
300 cp
= runtime_tools
.subprocess_terminate(sessiond
)
301 if cp
.returncode
!= 0:
302 pytest
.fail("Sessiond return code")
305 runtime_tools
.run('lttng enable-event -u "tp:*te*"')
307 runtime_tools
.run('lttng start')
310 cmd
= './app {}'.format(nb_events
)
311 runtime_app
.run(cmd
, cwd
=app_path
)
314 runtime_tools
.run('lttng stop')
315 runtime_tools
.run('lttng destroy -a')
316 cp
= runtime_tools
.subprocess_terminate(sessiond
)
317 if cp
.returncode
!= 0:
318 pytest
.fail("Sessiond return code")
320 # Read trace with babeltrace and check for event count via number of line
321 cmd
= 'babeltrace {}'.format(trace_path
)
322 cp_process
, cp_out
, cp_err
= runtime_tools
.run(cmd
)
323 assert(utils
.line_count(cp_out
) == expected_events
)