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
26 import lttng_ivc
.utils
.ProjectFactory
as ProjectFactory
27 import lttng_ivc
.utils
.runtime
as Run
28 import lttng_ivc
.settings
as Settings
29 from lttng_ivc
.utils
.skip
import must_be_root
30 from lttng_ivc
.utils
.utils
import sessiond_spawn
31 from lttng_ivc
.utils
.utils
import line_count
32 from lttng_ivc
.utils
.utils
import file_contains
36 NOTE: Kernel version is left to the Lttng-modules object on building. We assume
37 that a failing lttng-modules build is caused only by version validation. This
38 project is not dedicated to finding build problem but inter version problem.
40 NOTE: The command for regenerate metadata changed between 2.8 and 2.9 from
41 "metadata regenerate" to "regenerate metadata" breaking the cli ....bad
44 TODO:Packet sequence number. 5b3cf4f924befda843a7736daf84f8ecae5e86a4
45 LTTNG_RING_BUFFER_GET_SEQ_NUM
46 TODO:Stream instance id. 5594698f9c8ad13e0964c67946d1867df7757dae
47 LTTNG_RING_BUFFER_INSTANCE_ID
51 BC: Feature of the smallest version number will works.
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 +------------------+------+------+------+---------------+
67 First tuple member: lttng-ust label
68 Second tuple member: lttng-tool label
69 Third tuple member: expected scenario
71 test_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"),
90 test_matrix_regen_metadata
= [
91 ("lttng-modules-2.7", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"),
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"),
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"),
109 test_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"),
112 ("lttng-modules-2.7", "lttng-tools-2.9", "Unsupported by modules"),
113 ("lttng-modules-2.7", "lttng-tools-2.10", "Unsupported by modules"),
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"),
128 test_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"),
144 ("lttng-modules-2.10", "lttng-tools-2.10", "Supported"),
148 def get_metadata_file_path(base_trace_path
):
149 metadata
= os
.path
.join(base_trace_path
, 'kernel', 'metadata')
153 runtime_matrix_base_tracing
= []
154 runtime_matrix_regen_metadata
= []
155 runtime_matrix_statedump
= []
156 runtime_matrix_starglobing_enabler
= []
158 if not Settings
.test_only
:
159 runtime_matrix_base_tracing
= test_matrix_base_tracing
160 runtime_matrix_regen_metadata
= test_matrix_regen_metadata
161 runtime_matrix_statedump
= test_matrix_statedump
162 runtime_matrix_starglobing_enabler
= test_matrix_starglobing_enabler
164 for tup
in test_matrix_base_tracing
:
165 if (tup
[0] in Settings
.test_only
or tup
[1] in
167 runtime_matrix_base_tracing
.append(tup
)
168 for tup
in test_matrix_regen_metadata
:
169 if (tup
[0] in Settings
.test_only
or tup
[1] in
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
175 runtime_matrix_statedump
.append(tup
)
176 for tup
in test_matrix_starglobing_enabler
:
177 if (tup
[0] in Settings
.test_only
or tup
[1] in
179 runtime_matrix_starglobing_enabler
.append(tup
)
183 @pytest.mark
.parametrize("modules_label,tools_label", runtime_matrix_base_tracing
)
184 def test_modules_base_tracing(tmpdir
, modules_label
, tools_label
):
185 modules
= ProjectFactory
.get_precook(modules_label
)
187 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
188 tools
= ProjectFactory
.get_precook(tools_label
)
189 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
193 with Run
.get_runtime(str(tmpdir
)) as runtime
:
194 runtime
.add_project(modules
)
195 runtime
.add_project(tools
)
196 runtime
.add_project(babeltrace
)
198 trace_path
= os
.path
.join(runtime
.lttng_home
, 'trace')
199 babeltrace_cmd
= 'babeltrace {}'.format(trace_path
)
201 sessiond
= sessiond_spawn(runtime
)
202 runtime
.load_test_module()
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
))
210 runtime
.run("lttng stop")
211 runtime
.run("lttng destroy -a")
213 sessiond
= runtime
.subprocess_terminate(sessiond
)
214 if sessiond
.returncode
!= 0:
215 pytest
.fail("Return value of sessiond is not zero")
218 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
219 assert(line_count(cp_out
) == nb_events
)
223 @pytest.mark
.parametrize("modules_label,tools_label,command,scenario", runtime_matrix_regen_metadata
)
224 def test_modules_regen_metadata(tmpdir
, modules_label
, tools_label
, command
, scenario
):
225 modules
= ProjectFactory
.get_precook(modules_label
)
227 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
228 tools
= ProjectFactory
.get_precook(tools_label
)
229 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
233 with Run
.get_runtime(str(tmpdir
)) as runtime
:
234 runtime
.add_project(modules
)
235 runtime
.add_project(tools
)
236 runtime
.add_project(babeltrace
)
238 trace_path
= os
.path
.join(runtime
.lttng_home
, 'trace')
239 babeltrace_cmd
= 'babeltrace {}'.format(trace_path
)
241 sessiond
= sessiond_spawn(runtime
)
242 runtime
.load_test_module()
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
))
250 runtime
.run("lttng stop")
252 # Validate that we have all event base on the current metadata
253 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
254 assert line_count(cp_out
) == nb_events
256 # Empty the metadata file
257 open(get_metadata_file_path(trace_path
), 'w').close()
259 # Babeltrace should never be able to parse the trace
260 with pytest
.raises(subprocess
.CalledProcessError
):
261 runtime
.run(babeltrace_cmd
)
263 runtime
.run("lttng start")
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":
268 if modules_label
== "lttng-modules-2.7":
269 pytest
.xfail("failing configuration (but should work)")
270 # Error from lttng-modules-2.7 is not reported correctly by
271 # sessiond. But it is reported on the sessiond side.
272 # For now, run the command, validate that the error exist on
273 # sessiond side and mark as xfail.
274 runtime
.run("lttng {}".format(command
))
275 with pytest
.raises(subprocess
.CalledProcessError
):
276 runtime
.run("lttng {}".format(command
))
278 # Make sure everything looks good on this side
279 stderr_path
= runtime
.get_subprocess_stderr_path(sessiond
)
280 sessiond
= runtime
.subprocess_terminate(sessiond
)
281 if scenario
== "Unsupported by modules":
282 error_msg
= "Error: Failed to regenerate the kernel metadata"
283 assert file_contains(stderr_path
, [error_msg
]), "Error message missing"
284 if modules_label
== "lttng-modules-2.7":
285 pytest
.xfail("Lttng-tools does not bubble up error from unsupported metadata regeneration")
289 runtime
.run("lttng {}".format(command
))
290 runtime
.run("lttng stop")
291 runtime
.run("lttng destroy -a")
293 sessiond
= runtime
.subprocess_terminate(sessiond
)
294 if sessiond
.returncode
!= 0:
295 pytest
.fail("Return value of sessiond is not zero")
297 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
298 assert line_count(cp_out
) == nb_events
302 @pytest.mark
.parametrize("modules_label,tools_label,scenario", runtime_matrix_statedump
)
303 def test_modules_statedump(tmpdir
, modules_label
, tools_label
, scenario
):
304 modules
= ProjectFactory
.get_precook(modules_label
)
306 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
307 tools
= ProjectFactory
.get_precook(tools_label
)
308 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
311 if scenario
== "Unsupported by tools" or scenario
== "Unsupported by modules":
316 with Run
.get_runtime(str(tmpdir
)) as runtime
:
317 runtime
.add_project(modules
)
318 runtime
.add_project(tools
)
319 runtime
.add_project(babeltrace
)
321 trace_path
= os
.path
.join(runtime
.lttng_home
, 'trace')
322 babeltrace_cmd
= 'babeltrace {}'.format(trace_path
)
324 sessiond
= sessiond_spawn(runtime
)
325 runtime
.load_test_module()
327 runtime
.run("lttng create trace -o {}".format(trace_path
))
328 runtime
.run("lttng enable-event -k lttng_statedump_start,lttng_statedump_end")
329 runtime
.run("lttng start")
331 # Generate some event
332 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
333 procfile
.write("{}".format(nb_events
))
335 if scenario
== "Unsupported by tools" or scenario
== "Unsupported by modules":
336 with pytest
.raises(subprocess
.CalledProcessError
):
337 runtime
.run("lttng regenerate statedump")
339 runtime
.run("lttng regenerate statedump")
341 runtime
.run("lttng stop")
342 runtime
.run("lttng destroy -a")
344 sessiond
= runtime
.subprocess_terminate(sessiond
)
345 if sessiond
.returncode
!= 0:
346 pytest
.fail("Return value of sessiond is not zero")
348 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
349 assert(line_count(cp_out
) == expected_event
)
353 @pytest.mark
.parametrize("modules_label,tools_label, scenario", runtime_matrix_starglobing_enabler
)
354 def test_modules_starglobing_enabler(tmpdir
, modules_label
, tools_label
, scenario
):
355 modules
= ProjectFactory
.get_precook(modules_label
)
357 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
358 tools
= ProjectFactory
.get_precook(tools_label
)
359 babeltrace
= ProjectFactory
.get_precook(Settings
.default_babeltrace
)
363 if scenario
== "Unsupported by modules":
366 expected_events
= nb_events
368 with Run
.get_runtime(str(tmpdir
)) as runtime
:
369 runtime
.add_project(modules
)
370 runtime
.add_project(tools
)
371 runtime
.add_project(babeltrace
)
373 trace_path
= os
.path
.join(runtime
.lttng_home
, 'trace')
374 babeltrace_cmd
= 'babeltrace {}'.format(trace_path
)
376 sessiond
= sessiond_spawn(runtime
)
377 runtime
.load_test_module()
379 runtime
.run("lttng create trace -o {}".format(trace_path
))
381 if scenario
== "Unsupported by tools":
382 with pytest
.raises(subprocess
.CalledProcessError
):
383 runtime
.run("lttng enable-event -k 'lttng_test_*_even*'")
384 sessiond
= runtime
.subprocess_terminate(sessiond
)
385 if sessiond
.returncode
!= 0:
386 pytest
.fail("Return value of sessiond is not zero")
389 runtime
.run("lttng enable-event -k 'lttng_test_*_even*'")
390 runtime
.run("lttng start")
392 # Generate some event
393 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
394 procfile
.write("{}".format(nb_events
))
396 runtime
.run("lttng stop")
397 runtime
.run("lttng destroy -a")
399 sessiond
= runtime
.subprocess_terminate(sessiond
)
400 if sessiond
.returncode
!= 0:
401 pytest
.fail("Return value of sessiond is not zero")
403 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
404 assert(line_count(cp_out
) == expected_events
)