Licensing information
[deliverable/lttng-ivc.git] / lttng_ivc / tests / ust_app_vs_ust_tools / test_ust_app_vs_ust_tools.py
CommitLineData
efdd48db
JR
1# Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
2#
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:
9#
10# The above copyright notice and this permission notice shall be included in all
11# copies or substantial portions of the Software.
12#
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
19# SOFTWARE.
20
e93e3f39
JR
21import pytest
22import os
23import shutil
24import signal
25import subprocess
26
27import lttng_ivc.utils.ProjectFactory as ProjectFactory
28import lttng_ivc.utils.utils as utils
29import lttng_ivc.utils.runtime as Run
30import lttng_ivc.settings as Settings
31
32"""
33
34FC: Fully Compatible
35BC: Feature of the smallest version number will works.
36TU: Tracing unavailable
37
f4711e68
JR
38NOTE: 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
40that the event registration is expected to fail.
41
e93e3f39
JR
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+--------------------------+------------+------------+------------+------------+
53
54Version number of this API is defined in include/lttng/ust-abi.h of lttng-ust project
55
56"""
57
58"""
59First tuple member: lttng-ust label
60Second tuple member: lttng-tool label
61Third tuple member: expected scenario
62"""
63
f4711e68
JR
64event_registration_error = "Error: UST app recv reg unsupported version"
65
e93e3f39 66test_matrix_tracing_available = [
f4711e68
JR
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"),
e93e3f39
JR
83]
84
e93e3f39 85
bde0c540
JR
86"""
87Statedump are supported starting at lttng-ust >= 2.9.
88No need to test for prior lttng-ust givent that there is also a bump leading to
89loss of tracing for application running under lttng-ust < 2.9.
90"""
91test_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),
96]
97
98test_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"),
103]
104
e93e3f39 105runtime_matrix_tracing_available = []
bde0c540 106runtime_matrix_regen_statedump = []
c73fc582 107runtime_matrix_starglobing_enabler = []
e93e3f39
JR
108
109if not Settings.test_only:
110 runtime_matrix_tracing_available = test_matrix_tracing_available
bde0c540
JR
111 runtime_matrix_regen_statedump = test_matrix_regen_statedump
112 runtime_matrix_starglobing_enabler = test_matrix_starglobing_enabler
e93e3f39
JR
113else:
114 for tup in test_matrix_tracing_available:
115 if (tup[0] in Settings.test_only or tup[1] in
116 Settings.test_only):
117 runtime_matrix_tracing_available.append(tup)
bde0c540
JR
118 for tup in test_matrix_regen_statedump:
119 if (tup[0] in Settings.test_only or tup[1] in
120 Settings.test_only):
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
124 Settings.test_only):
125 runtime_matrix_starglobing_enabler.append(tup)
e93e3f39
JR
126
127
f4711e68
JR
128@pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_tracing_available)
129def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, outcome):
581ef8bb 130
e93e3f39
JR
131 nb_events = 100
132
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)
137
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")
141
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)
145
146 runtime_app.add_project(ust)
147 runtime_app.lttng_home = runtime_tools.lttng_home
148
149 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
150
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)
154
155 # Start lttng-sessiond
36df6d36 156 sessiond = utils.sessiond_spawn(runtime_tools)
e93e3f39
JR
157
158 # Create session using mi to get path and session name
159 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
160
e93e3f39
JR
161 runtime_tools.run('lttng enable-event -u tp:tptest')
162 runtime_tools.run('lttng start')
163
164 # Run application
165 cmd = './app {}'.format(nb_events)
166 runtime_app.run(cmd, cwd=app_path)
167
168 # Stop tracing
87e6d73a 169 runtime_tools.run('lttng stop')
e93e3f39 170 runtime_tools.run('lttng destroy -a')
bde0c540
JR
171 cp = runtime_tools.subprocess_terminate(sessiond)
172 if cp.returncode != 0:
173 pytest.fail("Sessiond return code")
e93e3f39 174
f4711e68
JR
175
176 cmd = 'babeltrace {}'.format(trace_path)
177 if outcome == "Success":
e93e3f39
JR
178 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
179 assert(utils.line_count(cp_out) == nb_events)
f4711e68
JR
180 else:
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]))
bde0c540
JR
186
187@pytest.mark.parametrize("ust_label,tools_label, success", runtime_matrix_regen_statedump)
188def test_ust_app_regen_statedump(tmpdir, ust_label, tools_label, success):
189 nb_events = 100
190
191 if success:
192 expected_events = 4
193 else:
194 expected_events = 2
195
196 ust = ProjectFactory.get_precook(ust_label)
197 tools = ProjectFactory.get_precook(tools_label)
198 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
199
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")
203
204
205 app_sync_start = os.path.join(app_path, 'sync_start')
206 app_sync_end = os.path.join(app_path, 'sync_end')
207
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)
211
212 runtime_app.add_project(ust)
213 runtime_app.lttng_home = runtime_tools.lttng_home
214
215 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
216
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)
220
221 # Start lttng-sessiond
222 sessiond = utils.sessiond_spawn(runtime_tools)
223
224 # Create session using mi to get path and session name
225 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
226
227 runtime_tools.run('lttng enable-event -u lttng_ust_statedump:start,lttng_ust_statedump:end')
228 runtime_tools.run('lttng start')
229
230 # Run application
231 cmd = './app {} 0 {} {}'.format(nb_events, app_sync_start, app_sync_end)
232 runtime_app.spawn_subprocess(cmd, cwd=app_path)
233
234 utils.wait_for_file(app_sync_start)
235
236 if not success:
237 with pytest.raises(subprocess.CalledProcessError):
238 runtime_tools.run('lttng regenerate statedump')
239 else:
240 runtime_tools.run('lttng regenerate statedump')
241
242 utils.create_empty_file(app_sync_end)
243
244 # Stop tracing
87e6d73a 245 runtime_tools.run('lttng stop')
bde0c540
JR
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")
250
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)
255
256@pytest.mark.parametrize("ust_label,tools_label, scenario", runtime_matrix_starglobing_enabler)
257def test_ust_app_starglobing_enabler(tmpdir, ust_label, tools_label, scenario):
258
259 nb_events = 100
260
261 if scenario == "Unsupported by ust":
262 expected_events = 0
263 else:
264 expected_events = nb_events
265
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)
270
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")
274
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)
278
279 runtime_app.add_project(ust)
280 runtime_app.lttng_home = runtime_tools.lttng_home
281
282 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
283
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)
287
288 # Start lttng-sessiond
289 sessiond = utils.sessiond_spawn(runtime_tools)
290
291 # Create session using mi to get path and session name
292 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
293
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*"')
298
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")
303 return
304 else:
305 runtime_tools.run('lttng enable-event -u "tp:*te*"')
306
307 runtime_tools.run('lttng start')
308
309 # Run application
310 cmd = './app {}'.format(nb_events)
311 runtime_app.run(cmd, cwd=app_path)
312
313 # Stop tracing
87e6d73a 314 runtime_tools.run('lttng stop')
bde0c540
JR
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")
319
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)
This page took 0.035858 seconds and 5 git commands to generate.