Always issues lttng stop before destroy
[deliverable/lttng-ivc.git] / lttng_ivc / tests / ust_app_vs_ust_tools / test_ust_app_vs_ust_tools.py
1 import pytest
2 import os
3 import shutil
4 import signal
5 import subprocess
6
7 import lttng_ivc.utils.ProjectFactory as ProjectFactory
8 import lttng_ivc.utils.utils as utils
9 import lttng_ivc.utils.runtime as Run
10 import lttng_ivc.settings as Settings
11
12 """
13
14 FC: Fully Compatible
15 BC: Feature of the smallest version number will works.
16 TU: Tracing unavailable
17
18 NOTE: tracing between 2.7 and 2.8 should work but a problem with
19 _ustctl_basic_type prevent event registration. Hence consider in further test
20 that the event registration is expected to fail.
21
22 +------------------------------------------------------------------------------+
23 | LTTng UST control protocol compatibility matrix |
24 | (between applications and tools linked on LTTng UST and liblttng-ust-ctl) |
25 +--------------------------+------------+------------+------------+------------+
26 | LTTng UST / LTTng Tools | 2.7 (6.0) | 2.8 (6.1) | 2.9 (7.1) | 2.10 (7.2) |
27 +--------------------------+------------+------------+------------+------------+
28 | 2.7 (6.0) | FC | BC | TU | TU |
29 | 2.8 (6.1) | BC | FC | TU | TU |
30 | 2.9 (7.1) | TU | TU | FC | BC |
31 | 2.10 (7.2) | TU | TU | BC | FC |
32 +--------------------------+------------+------------+------------+------------+
33
34 Version number of this API is defined in include/lttng/ust-abi.h of lttng-ust project
35
36 """
37
38 """
39 First tuple member: lttng-ust label
40 Second tuple member: lttng-tool label
41 Third tuple member: expected scenario
42 """
43
44 event_registration_error = "Error: UST app recv reg unsupported version"
45
46 test_matrix_tracing_available = [
47 ("lttng-ust-2.7", "lttng-tools-2.7", "Success"),
48 ("lttng-ust-2.7", "lttng-tools-2.8", "Unsupported version"),
49 ("lttng-ust-2.7", "lttng-tools-2.9", "Unsupported"),
50 ("lttng-ust-2.7", "lttng-tools-2.10", "Unsupported"),
51 ("lttng-ust-2.8", "lttng-tools-2.7", "Unsupported version"),
52 ("lttng-ust-2.8", "lttng-tools-2.8", "Success"),
53 ("lttng-ust-2.8", "lttng-tools-2.9", "Unsupported"),
54 ("lttng-ust-2.8", "lttng-tools-2.10", "Unsupported"),
55 ("lttng-ust-2.9", "lttng-tools-2.7", "Unsupported"),
56 ("lttng-ust-2.9", "lttng-tools-2.8", "Unsupported"),
57 ("lttng-ust-2.9", "lttng-tools-2.9", "Success"),
58 ("lttng-ust-2.9", "lttng-tools-2.10", "Success"),
59 ("lttng-ust-2.10", "lttng-tools-2.7", "Unsupported"),
60 ("lttng-ust-2.10", "lttng-tools-2.8", "Unsupported"),
61 ("lttng-ust-2.10", "lttng-tools-2.9", "Success"),
62 ("lttng-ust-2.10", "lttng-tools-2.10", "Success"),
63 ]
64
65 # Only consider test case for which tracing is valid
66 test_matrix_app_context = [
67 ("lttng-ust-2.7", "lttng-tools-2.7", ""),
68 ("lttng-ust-2.7", "lttng-tools-2.8", ""),
69 ("lttng-ust-2.7", "lttng-tools-2.9", ""),
70 ("lttng-ust-2.7", "lttng-tools-2.10", ""),
71 ("lttng-ust-2.8", "lttng-tools-2.7", ""),
72 ("lttng-ust-2.8", "lttng-tools-2.8", ""),
73 ("lttng-ust-2.8", "lttng-tools-2.9", ""),
74 ("lttng-ust-2.8", "lttng-tools-2.10", ""),
75 ("lttng-ust-2.9", "lttng-tools-2.7", ""),
76 ("lttng-ust-2.9", "lttng-tools-2.8", ""),
77 ("lttng-ust-2.9", "lttng-tools-2.9", ""),
78 ("lttng-ust-2.9", "lttng-tools-2.10", ""),
79 ("lttng-ust-2.10", "lttng-tools-2.7", ""),
80 ("lttng-ust-2.10", "lttng-tools-2.8", ""),
81 ("lttng-ust-2.10", "lttng-tools-2.9", ""),
82 ("lttng-ust-2.10", "lttng-tools-2.10", ""),
83 ]
84
85 """
86 Statedump are supported starting at lttng-ust >= 2.9.
87 No need to test for prior lttng-ust givent that there is also a bump leading to
88 loss of tracing for application running under lttng-ust < 2.9.
89 """
90 test_matrix_regen_statedump = [
91 ("lttng-ust-2.9", "lttng-tools-2.9", True),
92 ("lttng-ust-2.9", "lttng-tools-2.10", True),
93 ("lttng-ust-2.10", "lttng-tools-2.9", True),
94 ("lttng-ust-2.10", "lttng-tools-2.10", True),
95 ]
96
97 test_matrix_starglobing_enabler = [
98 ("lttng-ust-2.9", "lttng-tools-2.9", "Unsupported by tools"),
99 ("lttng-ust-2.9", "lttng-tools-2.10", "Unsupported by ust"),
100 ("lttng-ust-2.10", "lttng-tools-2.9", "Unsupported by tools"),
101 ("lttng-ust-2.10", "lttng-tools-2.10", "Supported"),
102 ]
103
104 runtime_matrix_tracing_available = []
105 runtime_matrix_regen_statedump = []
106 runtime_rix_starglobing_enabler = []
107
108 if not Settings.test_only:
109 runtime_matrix_tracing_available = test_matrix_tracing_available
110 runtime_matrix_regen_statedump = test_matrix_regen_statedump
111 runtime_matrix_starglobing_enabler = test_matrix_starglobing_enabler
112 else:
113 for tup in test_matrix_tracing_available:
114 if (tup[0] in Settings.test_only or tup[1] in
115 Settings.test_only):
116 runtime_matrix_tracing_available.append(tup)
117 for tup in test_matrix_regen_statedump:
118 if (tup[0] in Settings.test_only or tup[1] in
119 Settings.test_only):
120 runtime_matrix_regen_statedump.append(tup)
121 for tup in test_matrix_starglobing_enabler:
122 if (tup[0] in Settings.test_only or tup[1] in
123 Settings.test_only):
124 runtime_matrix_starglobing_enabler.append(tup)
125
126
127 @pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_tracing_available)
128 def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, outcome):
129
130 nb_events = 100
131
132 # Prepare environment
133 ust = ProjectFactory.get_precook(ust_label)
134 tools = ProjectFactory.get_precook(tools_label)
135 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
136
137 tools_runtime_path = os.path.join(str(tmpdir), "tools")
138 ust_runtime_path = os.path.join(str(tmpdir), "ust")
139 app_path = os.path.join(str(tmpdir), "app")
140
141 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
142 runtime_tools.add_project(tools)
143 runtime_tools.add_project(babeltrace)
144
145 runtime_app.add_project(ust)
146 runtime_app.lttng_home = runtime_tools.lttng_home
147
148 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
149
150 # Make application using the ust runtime
151 shutil.copytree(Settings.apps_gen_events_folder, app_path)
152 runtime_app.run("make V=1", cwd=app_path)
153
154 # Start lttng-sessiond
155 sessiond = utils.sessiond_spawn(runtime_tools)
156
157 # Create session using mi to get path and session name
158 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
159
160 runtime_tools.run('lttng enable-event -u tp:tptest')
161 runtime_tools.run('lttng start')
162
163 # Run application
164 cmd = './app {}'.format(nb_events)
165 runtime_app.run(cmd, cwd=app_path)
166
167 # Stop tracing
168 runtime_tools.run('lttng stop')
169 runtime_tools.run('lttng destroy -a')
170 cp = runtime_tools.subprocess_terminate(sessiond)
171 if cp.returncode != 0:
172 pytest.fail("Sessiond return code")
173
174
175 cmd = 'babeltrace {}'.format(trace_path)
176 if outcome == "Success":
177 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
178 assert(utils.line_count(cp_out) == nb_events)
179 else:
180 with pytest.raises(subprocess.CalledProcessError):
181 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
182 if outcome == "Unsupported version":
183 assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),
184 [event_registration_error]))
185
186 @pytest.mark.parametrize("ust_label,tools_label, success", runtime_matrix_regen_statedump)
187 def test_ust_app_regen_statedump(tmpdir, ust_label, tools_label, success):
188 nb_events = 100
189
190 if success:
191 expected_events = 4
192 else:
193 expected_events = 2
194
195 ust = ProjectFactory.get_precook(ust_label)
196 tools = ProjectFactory.get_precook(tools_label)
197 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
198
199 tools_runtime_path = os.path.join(str(tmpdir), "tools")
200 ust_runtime_path = os.path.join(str(tmpdir), "ust")
201 app_path = os.path.join(str(tmpdir), "app")
202
203
204 app_sync_start = os.path.join(app_path, 'sync_start')
205 app_sync_end = os.path.join(app_path, 'sync_end')
206
207 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
208 runtime_tools.add_project(tools)
209 runtime_tools.add_project(babeltrace)
210
211 runtime_app.add_project(ust)
212 runtime_app.lttng_home = runtime_tools.lttng_home
213
214 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
215
216 # Make application using the ust runtime
217 shutil.copytree(Settings.apps_gen_events_folder, app_path)
218 runtime_app.run("make V=1", cwd=app_path)
219
220 # Start lttng-sessiond
221 sessiond = utils.sessiond_spawn(runtime_tools)
222
223 # Create session using mi to get path and session name
224 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
225
226 runtime_tools.run('lttng enable-event -u lttng_ust_statedump:start,lttng_ust_statedump:end')
227 runtime_tools.run('lttng start')
228
229 # Run application
230 cmd = './app {} 0 {} {}'.format(nb_events, app_sync_start, app_sync_end)
231 runtime_app.spawn_subprocess(cmd, cwd=app_path)
232
233 utils.wait_for_file(app_sync_start)
234
235 if not success:
236 with pytest.raises(subprocess.CalledProcessError):
237 runtime_tools.run('lttng regenerate statedump')
238 else:
239 runtime_tools.run('lttng regenerate statedump')
240
241 utils.create_empty_file(app_sync_end)
242
243 # Stop tracing
244 runtime_tools.run('lttng stop')
245 runtime_tools.run('lttng destroy -a')
246 cp = runtime_tools.subprocess_terminate(sessiond)
247 if cp.returncode != 0:
248 pytest.fail("Sessiond return code")
249
250 # Read trace with babeltrace and check for event count via number of line
251 cmd = 'babeltrace {}'.format(trace_path)
252 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
253 assert(utils.line_count(cp_out) == expected_events)
254
255 @pytest.mark.parametrize("ust_label,tools_label, scenario", runtime_matrix_starglobing_enabler)
256 def test_ust_app_starglobing_enabler(tmpdir, ust_label, tools_label, scenario):
257
258 nb_events = 100
259
260 if scenario == "Unsupported by ust":
261 expected_events = 0
262 else:
263 expected_events = nb_events
264
265 # Prepare environment
266 ust = ProjectFactory.get_precook(ust_label)
267 tools = ProjectFactory.get_precook(tools_label)
268 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
269
270 tools_runtime_path = os.path.join(str(tmpdir), "tools")
271 ust_runtime_path = os.path.join(str(tmpdir), "ust")
272 app_path = os.path.join(str(tmpdir), "app")
273
274 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
275 runtime_tools.add_project(tools)
276 runtime_tools.add_project(babeltrace)
277
278 runtime_app.add_project(ust)
279 runtime_app.lttng_home = runtime_tools.lttng_home
280
281 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
282
283 # Make application using the ust runtime
284 shutil.copytree(Settings.apps_gen_events_folder, app_path)
285 runtime_app.run("make V=1", cwd=app_path)
286
287 # Start lttng-sessiond
288 sessiond = utils.sessiond_spawn(runtime_tools)
289
290 # Create session using mi to get path and session name
291 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
292
293 # If unsupported by tools simply finish early
294 if scenario == "Unsupported by tools":
295 with pytest.raises(subprocess.CalledProcessError):
296 runtime_tools.run('lttng enable-event -u "tp:*te*"')
297
298 # TODO move this to internal runtime...
299 cp = runtime_tools.subprocess_terminate(sessiond)
300 if cp.returncode != 0:
301 pytest.fail("Sessiond return code")
302 return
303 else:
304 runtime_tools.run('lttng enable-event -u "tp:*te*"')
305
306 runtime_tools.run('lttng start')
307
308 # Run application
309 cmd = './app {}'.format(nb_events)
310 runtime_app.run(cmd, cwd=app_path)
311
312 # Stop tracing
313 runtime_tools.run('lttng stop')
314 runtime_tools.run('lttng destroy -a')
315 cp = runtime_tools.subprocess_terminate(sessiond)
316 if cp.returncode != 0:
317 pytest.fail("Sessiond return code")
318
319 # Read trace with babeltrace and check for event count via number of line
320 cmd = 'babeltrace {}'.format(trace_path)
321 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
322 assert(utils.line_count(cp_out) == expected_events)
This page took 0.037873 seconds and 5 git commands to generate.