Fix: perform regenerate command on success path
[deliverable/lttng-ivc.git] / lttng_ivc / tests / modules_abi_vs_tools / test_modules_abi_vs_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
01c2cc05 21import pytest
ab63b97e
JR
22import os
23import glob
24import subprocess
01c2cc05
JR
25
26import lttng_ivc.utils.ProjectFactory as ProjectFactory
27import lttng_ivc.utils.runtime as Run
28import lttng_ivc.settings as Settings
ab63b97e
JR
29from lttng_ivc.utils.skip import must_be_root
30from lttng_ivc.utils.utils import sessiond_spawn
31from lttng_ivc.utils.utils import line_count
d0d95343 32from lttng_ivc.utils.utils import file_contains
01c2cc05
JR
33
34"""
35
ab63b97e
JR
36NOTE: Kernel version is left to the Lttng-modules object on building. We assume
37that a failing lttng-modules build is caused only by version validation. This
38project is not dedicated to finding build problem but inter version problem.
39
40NOTE: The command for regenerate metadata changed between 2.8 and 2.9 from
41"metadata regenerate" to "regenerate metadata" breaking the cli ....bad
42jdesfossez :P
01c2cc05
JR
43
44TODO:Packet sequence number. 5b3cf4f924befda843a7736daf84f8ecae5e86a4
45 LTTNG_RING_BUFFER_GET_SEQ_NUM
46TODO:Stream instance id. 5594698f9c8ad13e0964c67946d1867df7757dae
47 LTTNG_RING_BUFFER_INSTANCE_ID
48
49
50FC: Fully Compatible
51BC: Feature of the smallest version number will works.
52
53+-------------------------------------------------------+
54| LTTng Modules ABI vs LTTng Tools compatibility matrix |
55+-------------------------------------------------------+
56| Modules / Tools | 2.7 | 2.8 | 2.9 | 2.10 |
57+------------------+------+------+------+---------------+
58| 2.7 | FC | BC | BC | BC |
59| 2.8 | BC | FC | BC | BC |
60| 2.9 | BC | BC | FC | BC |
61| 2.10 | BC | BC | BC | FC |
62+------------------+------+------+------+---------------+
63
64"""
65
66"""
67First tuple member: lttng-ust label
68Second tuple member: lttng-tool label
69Third tuple member: expected scenario
70"""
ab63b97e
JR
71test_matrix_base_tracing = [
72 ("lttng-modules-2.7", "lttng-tools-2.7"),
73 ("lttng-modules-2.7", "lttng-tools-2.8"),
74 ("lttng-modules-2.7", "lttng-tools-2.9"),
75 ("lttng-modules-2.7", "lttng-tools-2.10"),
76 ("lttng-modules-2.8", "lttng-tools-2.7"),
77 ("lttng-modules-2.8", "lttng-tools-2.8"),
78 ("lttng-modules-2.8", "lttng-tools-2.9"),
79 ("lttng-modules-2.8", "lttng-tools-2.10"),
80 ("lttng-modules-2.9", "lttng-tools-2.7"),
81 ("lttng-modules-2.9", "lttng-tools-2.8"),
82 ("lttng-modules-2.9", "lttng-tools-2.9"),
83 ("lttng-modules-2.9", "lttng-tools-2.10"),
84 ("lttng-modules-2.10", "lttng-tools-2.7"),
85 ("lttng-modules-2.10", "lttng-tools-2.8"),
86 ("lttng-modules-2.10", "lttng-tools-2.9"),
87 ("lttng-modules-2.10", "lttng-tools-2.10"),
88]
01c2cc05
JR
89
90test_matrix_regen_metadata = [
ab63b97e 91 ("lttng-modules-2.7", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"),
328eecd4
JR
92 ("lttng-modules-2.7", "lttng-tools-2.8", "metadata regenerate", "Unsupported by modules"),
93 ("lttng-modules-2.7", "lttng-tools-2.9", "regenerate metadata", "Unsupported by modules"),
94 ("lttng-modules-2.7", "lttng-tools-2.10", "regenerate metadata", "Unsupported by modules"),
ab63b97e
JR
95 ("lttng-modules-2.8", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"),
96 ("lttng-modules-2.8", "lttng-tools-2.8", "metadata regenerate", "Supported"),
97 ("lttng-modules-2.8", "lttng-tools-2.9", "regenerate metadata", "Supported"),
98 ("lttng-modules-2.8", "lttng-tools-2.10", "regenerate metadata", "Supported"),
99 ("lttng-modules-2.9", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"),
100 ("lttng-modules-2.9", "lttng-tools-2.8", "metadata regenerate", "Supported"),
101 ("lttng-modules-2.9", "lttng-tools-2.9", "regenerate metadata", "Supported"),
102 ("lttng-modules-2.9", "lttng-tools-2.10", "regenerate metadata", "Supported"),
103 ("lttng-modules-2.10", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"),
104 ("lttng-modules-2.10", "lttng-tools-2.8", "metadata regenerate", "Supported"),
105 ("lttng-modules-2.10", "lttng-tools-2.9", "regenerate metadata", "Supported"),
106 ("lttng-modules-2.10", "lttng-tools-2.10","regenerate metadata", "Supported"),
01c2cc05
JR
107]
108
109test_matrix_statedump = [
110 ("lttng-modules-2.7", "lttng-tools-2.7", "Unsupported by tools"),
111 ("lttng-modules-2.7", "lttng-tools-2.8", "Unsupported by tools"),
328eecd4
JR
112 ("lttng-modules-2.7", "lttng-tools-2.9", "Unsupported by modules"),
113 ("lttng-modules-2.7", "lttng-tools-2.10", "Unsupported by modules"),
01c2cc05
JR
114 ("lttng-modules-2.8", "lttng-tools-2.7", "Unsupported by tools"),
115 ("lttng-modules-2.8", "lttng-tools-2.8", "Unsupported by tools"),
116 ("lttng-modules-2.8", "lttng-tools-2.9", "Unsupported by modules"),
117 ("lttng-modules-2.8", "lttng-tools-2.10", "Unsupported by modules"),
118 ("lttng-modules-2.9", "lttng-tools-2.7", "Unsupported by tools"),
119 ("lttng-modules-2.9", "lttng-tools-2.8", "Unsupported by tools"),
120 ("lttng-modules-2.9", "lttng-tools-2.9", "Supported"),
121 ("lttng-modules-2.9", "lttng-tools-2.10", "Supported"),
122 ("lttng-modules-2.10", "lttng-tools-2.7", "Unsupported by tools"),
123 ("lttng-modules-2.10", "lttng-tools-2.8", "Unsupported by tools"),
124 ("lttng-modules-2.10", "lttng-tools-2.9", "Supported"),
125 ("lttng-modules-2.10", "lttng-tools-2.10", "Supported"),
126]
127
ab63b97e
JR
128test_matrix_starglobing_enabler = [
129 ("lttng-modules-2.7", "lttng-tools-2.7", "Unsupported by tools"),
130 ("lttng-modules-2.7", "lttng-tools-2.8", "Unsupported by tools"),
131 ("lttng-modules-2.7", "lttng-tools-2.9", "Unsupported by tools"),
132 ("lttng-modules-2.7", "lttng-tools-2.10", "Unsupported by modules"),
133 ("lttng-modules-2.8", "lttng-tools-2.7", "Unsupported by tools"),
134 ("lttng-modules-2.8", "lttng-tools-2.8", "Unsupported by tools"),
135 ("lttng-modules-2.8", "lttng-tools-2.9", "Unsupported by tools"),
136 ("lttng-modules-2.8", "lttng-tools-2.10", "Unsupported by modules"),
137 ("lttng-modules-2.9", "lttng-tools-2.7", "Unsupported by tools"),
138 ("lttng-modules-2.9", "lttng-tools-2.8", "Unsupported by tools"),
139 ("lttng-modules-2.9", "lttng-tools-2.9", "Unsupported by tools"),
140 ("lttng-modules-2.9", "lttng-tools-2.10", "Unsupported by modules"),
141 ("lttng-modules-2.10", "lttng-tools-2.7", "Unsupported by tools"),
142 ("lttng-modules-2.10", "lttng-tools-2.8", "Unsupported by tools"),
143 ("lttng-modules-2.10", "lttng-tools-2.9", "Unsupported by tools"),
01c2cc05
JR
144 ("lttng-modules-2.10", "lttng-tools-2.10", "Supported"),
145]
146
147
ab63b97e
JR
148def get_metadata_file_path(base_trace_path):
149 metadata = os.path.join(base_trace_path, 'kernel', 'metadata')
150 return metadata
151
152
153runtime_matrix_base_tracing = []
01c2cc05
JR
154runtime_matrix_regen_metadata = []
155runtime_matrix_statedump = []
ab63b97e 156runtime_matrix_starglobing_enabler = []
01c2cc05
JR
157
158if not Settings.test_only:
ab63b97e 159 runtime_matrix_base_tracing = test_matrix_base_tracing
01c2cc05
JR
160 runtime_matrix_regen_metadata = test_matrix_regen_metadata
161 runtime_matrix_statedump = test_matrix_statedump
ab63b97e 162 runtime_matrix_starglobing_enabler = test_matrix_starglobing_enabler
01c2cc05 163else:
ab63b97e
JR
164 for tup in test_matrix_base_tracing:
165 if (tup[0] in Settings.test_only or tup[1] in
166 Settings.test_only):
167 runtime_matrix_base_tracing.append(tup)
01c2cc05
JR
168 for tup in test_matrix_regen_metadata:
169 if (tup[0] in Settings.test_only or tup[1] in
170 Settings.test_only):
171 runtime_matrix_regen_metadata.append(tup)
172 for tup in test_matrix_statedump:
173 if (tup[0] in Settings.test_only or tup[1] in
174 Settings.test_only):
175 runtime_matrix_statedump.append(tup)
ab63b97e 176 for tup in test_matrix_starglobing_enabler:
01c2cc05
JR
177 if (tup[0] in Settings.test_only or tup[1] in
178 Settings.test_only):
ab63b97e 179 runtime_matrix_starglobing_enabler.append(tup)
01c2cc05
JR
180
181
ab63b97e
JR
182@must_be_root
183@pytest.mark.parametrize("modules_label,tools_label", runtime_matrix_base_tracing)
184def test_modules_base_tracing(tmpdir, modules_label, tools_label):
01c2cc05 185 modules = ProjectFactory.get_precook(modules_label)
ab63b97e
JR
186 if modules.skip:
187 pytest.skip("{} cannot be built on this kernel".format(modules.label))
01c2cc05 188 tools = ProjectFactory.get_precook(tools_label)
ab63b97e
JR
189 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
190
191 nb_events = 100
192
193 with Run.get_runtime(str(tmpdir)) as runtime:
194 runtime.add_project(modules)
195 runtime.add_project(tools)
196 runtime.add_project(babeltrace)
197
198 trace_path = os.path.join(runtime.lttng_home, 'trace')
199 babeltrace_cmd = 'babeltrace {}'.format(trace_path)
01c2cc05 200
ab63b97e
JR
201 sessiond = sessiond_spawn(runtime)
202 runtime.load_test_module()
01c2cc05 203
ab63b97e
JR
204 runtime.run("lttng create trace -o {}".format(trace_path))
205 runtime.run("lttng enable-event -k lttng_test_filter_event")
206 runtime.run("lttng start")
207 with open(Settings.lttng_test_procfile, 'w') as procfile:
208 procfile.write("{}".format(nb_events))
209
210 runtime.run("lttng stop")
211 runtime.run("lttng destroy -a")
212
213 sessiond = runtime.subprocess_terminate(sessiond)
214 if sessiond.returncode != 0:
5676c7e7 215 pytest.fail("Return value of sessiond is not zero")
ab63b97e
JR
216 return
217
218 cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
219 assert(line_count(cp_out) == nb_events)
220
221
222@must_be_root
223@pytest.mark.parametrize("modules_label,tools_label,command,scenario", runtime_matrix_regen_metadata)
224def test_modules_regen_metadata(tmpdir, modules_label, tools_label, command, scenario):
01c2cc05 225 modules = ProjectFactory.get_precook(modules_label)
ab63b97e
JR
226 if modules.skip:
227 pytest.skip("{} cannot be built on this kernel".format(modules.label))
01c2cc05 228 tools = ProjectFactory.get_precook(tools_label)
ab63b97e
JR
229 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
230
231 nb_events = 10
232
233 with Run.get_runtime(str(tmpdir)) as runtime:
234 runtime.add_project(modules)
235 runtime.add_project(tools)
236 runtime.add_project(babeltrace)
237
238 trace_path = os.path.join(runtime.lttng_home, 'trace')
239 babeltrace_cmd = 'babeltrace {}'.format(trace_path)
240
241 sessiond = sessiond_spawn(runtime)
242 runtime.load_test_module()
01c2cc05 243
ab63b97e
JR
244 runtime.run("lttng create trace -o {}".format(trace_path))
245 runtime.run("lttng enable-event -k lttng_test_filter_event")
246 runtime.run("lttng start")
247 with open(Settings.lttng_test_procfile, 'w') as procfile:
248 procfile.write("{}".format(nb_events))
01c2cc05 249
ab63b97e
JR
250 runtime.run("lttng stop")
251
252 # Validate that we have all event base on the current metadata
253 cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
d0d95343 254 assert line_count(cp_out) == nb_events
ab63b97e
JR
255
256 # Empty the metadata file
257 open(get_metadata_file_path(trace_path), 'w').close()
258
259 # Babeltrace should never be able to parse the trace
260 with pytest.raises(subprocess.CalledProcessError):
261 runtime.run(babeltrace_cmd)
262
263 runtime.run("lttng start")
264
265 # TODO: rework this a bit to differentiate each errors and rework how
266 # the condition are meet
267 if scenario == "Unsupported by tools" or scenario == "Unsupported by modules":
d0d95343 268 if modules_label == "lttng-modules-2.7":
d0d95343
JR
269 # Error from lttng-modules-2.7 is not reported correctly by
270 # sessiond. But it is reported on the sessiond side.
271 # For now, run the command, validate that the error exist on
272 # sessiond side and mark as xfail.
273 runtime.run("lttng {}".format(command))
ab63b97e
JR
274 with pytest.raises(subprocess.CalledProcessError):
275 runtime.run("lttng {}".format(command))
276
277 # Make sure everything looks good on this side
66ef2fa5
JR
278 runtime.run("lttng stop")
279 runtime.run("lttng destroy -a")
d0d95343 280 stderr_path = runtime.get_subprocess_stderr_path(sessiond)
ab63b97e 281 sessiond = runtime.subprocess_terminate(sessiond)
d0d95343
JR
282 if scenario == "Unsupported by modules":
283 error_msg = "Error: Failed to regenerate the kernel metadata"
284 assert file_contains(stderr_path, [error_msg]), "Error message missing"
285 if modules_label == "lttng-modules-2.7":
286 pytest.xfail("Lttng-tools does not bubble up error from unsupported metadata regeneration")
287
ab63b97e
JR
288 return
289
b145173a 290 runtime.run("lttng {}".format(command))
ab63b97e
JR
291 runtime.run("lttng stop")
292 runtime.run("lttng destroy -a")
293
294 sessiond = runtime.subprocess_terminate(sessiond)
295 if sessiond.returncode != 0:
5676c7e7 296 pytest.fail("Return value of sessiond is not zero")
ab63b97e
JR
297
298 cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
d0d95343 299 assert line_count(cp_out) == nb_events
ab63b97e
JR
300
301
302@must_be_root
303@pytest.mark.parametrize("modules_label,tools_label,scenario", runtime_matrix_statedump)
304def test_modules_statedump(tmpdir, modules_label, tools_label, scenario):
01c2cc05 305 modules = ProjectFactory.get_precook(modules_label)
ab63b97e
JR
306 if modules.skip:
307 pytest.skip("{} cannot be built on this kernel".format(modules.label))
01c2cc05 308 tools = ProjectFactory.get_precook(tools_label)
ab63b97e
JR
309 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
310
311 nb_events = 100
312 if scenario == "Unsupported by tools" or scenario == "Unsupported by modules":
313 expected_event = 2
314 else:
315 expected_event = 4
316
317 with Run.get_runtime(str(tmpdir)) as runtime:
318 runtime.add_project(modules)
319 runtime.add_project(tools)
320 runtime.add_project(babeltrace)
321
322 trace_path = os.path.join(runtime.lttng_home, 'trace')
323 babeltrace_cmd = 'babeltrace {}'.format(trace_path)
324
325 sessiond = sessiond_spawn(runtime)
326 runtime.load_test_module()
327
328 runtime.run("lttng create trace -o {}".format(trace_path))
329 runtime.run("lttng enable-event -k lttng_statedump_start,lttng_statedump_end")
330 runtime.run("lttng start")
331
332 # Generate some event
333 with open(Settings.lttng_test_procfile, 'w') as procfile:
334 procfile.write("{}".format(nb_events))
335
336 if scenario == "Unsupported by tools" or scenario == "Unsupported by modules":
337 with pytest.raises(subprocess.CalledProcessError):
338 runtime.run("lttng regenerate statedump")
339 else:
340 runtime.run("lttng regenerate statedump")
341
342 runtime.run("lttng stop")
343 runtime.run("lttng destroy -a")
344
345 sessiond = runtime.subprocess_terminate(sessiond)
346 if sessiond.returncode != 0:
5676c7e7 347 pytest.fail("Return value of sessiond is not zero")
ab63b97e
JR
348
349 cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
350 assert(line_count(cp_out) == expected_event)
351
352
353@must_be_root
354@pytest.mark.parametrize("modules_label,tools_label, scenario", runtime_matrix_starglobing_enabler)
355def test_modules_starglobing_enabler(tmpdir, modules_label, tools_label, scenario):
356 modules = ProjectFactory.get_precook(modules_label)
357 if modules.skip:
358 pytest.skip("{} cannot be built on this kernel".format(modules.label))
359 tools = ProjectFactory.get_precook(tools_label)
360 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
361
362 nb_events = 100
363
364 if scenario == "Unsupported by modules":
365 expected_events = 0
366 else:
367 expected_events = nb_events
368
369 with Run.get_runtime(str(tmpdir)) as runtime:
370 runtime.add_project(modules)
371 runtime.add_project(tools)
372 runtime.add_project(babeltrace)
373
374 trace_path = os.path.join(runtime.lttng_home, 'trace')
375 babeltrace_cmd = 'babeltrace {}'.format(trace_path)
376
377 sessiond = sessiond_spawn(runtime)
378 runtime.load_test_module()
379
380 runtime.run("lttng create trace -o {}".format(trace_path))
381
382 if scenario == "Unsupported by tools":
383 with pytest.raises(subprocess.CalledProcessError):
384 runtime.run("lttng enable-event -k 'lttng_test_*_even*'")
385 sessiond = runtime.subprocess_terminate(sessiond)
386 if sessiond.returncode != 0:
5676c7e7 387 pytest.fail("Return value of sessiond is not zero")
ab63b97e
JR
388 return
389
390 runtime.run("lttng enable-event -k 'lttng_test_*_even*'")
391 runtime.run("lttng start")
392
393 # Generate some event
394 with open(Settings.lttng_test_procfile, 'w') as procfile:
395 procfile.write("{}".format(nb_events))
396
397 runtime.run("lttng stop")
398 runtime.run("lttng destroy -a")
399
400 sessiond = runtime.subprocess_terminate(sessiond)
401 if sessiond.returncode != 0:
5676c7e7 402 pytest.fail("Return value of sessiond is not zero")
ab63b97e
JR
403
404 cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
405 assert(line_count(cp_out) == expected_events)
This page took 0.043075 seconds and 5 git commands to generate.