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