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
.utils
as utils
28 import lttng_ivc
.utils
.runtime
as Run
29 import lttng_ivc
.settings
as Settings
32 from lttng_ivc
.utils
.skip
import must_be_root
33 from itertools
import combinations
37 BC: Feature of the smallest version number will works.
39 +------------------------------------------------------------------------------+
40 | Babeltrace vs UST/Tools/Metadata |
41 +--------------------------+------------+------------+------------+------------+
42 | Babeltrace / LTTng | 2.7 | 2.8 | 2.9 | 2.10 |
43 +--------------------------+------------+------------+------------+------------+
44 | 1.3 | FC | BC | BC | BC |
45 | 1.4 | FC | FC | FC | FC |
46 | 1.5 | FC | FC | FC | FC |
47 +--------------------------+------------+------------+------------+------------+
50 test_matrix_base_ust
= [
51 ("babeltrace-1.3", "lttng-tools-2.7"),
52 ("babeltrace-1.3", "lttng-tools-2.8"),
53 ("babeltrace-1.3", "lttng-tools-2.9"),
54 ("babeltrace-1.3", "lttng-tools-2.10"),
55 ("babeltrace-1.4", "lttng-tools-2.7"),
56 ("babeltrace-1.4", "lttng-tools-2.8"),
57 ("babeltrace-1.4", "lttng-tools-2.9"),
58 ("babeltrace-1.4", "lttng-tools-2.10"),
59 ("babeltrace-1.5", "lttng-tools-2.7"),
60 ("babeltrace-1.5", "lttng-tools-2.8"),
61 ("babeltrace-1.5", "lttng-tools-2.9"),
62 ("babeltrace-1.5", "lttng-tools-2.10"),
65 test_matrix_base_modules
= [
66 ("babeltrace-1.3", "lttng-modules-2.7", "lttng-tools-2.7"),
67 ("babeltrace-1.3", "lttng-modules-2.8", "lttng-tools-2.8"),
68 ("babeltrace-1.3", "lttng-modules-2.9", "lttng-tools-2.9"),
69 ("babeltrace-1.3", "lttng-modules-2.10", "lttng-tools-2.10"),
70 ("babeltrace-1.4", "lttng-modules-2.7", "lttng-tools-2.7"),
71 ("babeltrace-1.4", "lttng-modules-2.8", "lttng-tools-2.8"),
72 ("babeltrace-1.4", "lttng-modules-2.9", "lttng-tools-2.9"),
73 ("babeltrace-1.4", "lttng-modules-2.10", "lttng-tools-2.10"),
74 ("babeltrace-1.5", "lttng-modules-2.7", "lttng-tools-2.7"),
75 ("babeltrace-1.5", "lttng-modules-2.8", "lttng-tools-2.8"),
76 ("babeltrace-1.5", "lttng-modules-2.9", "lttng-tools-2.9"),
77 ("babeltrace-1.5", "lttng-modules-2.10", "lttng-tools-2.10"),
80 test_matrix_lost_packet
= [
81 ("babeltrace-1.3", False),
82 ("babeltrace-1.4", True),
83 ("babeltrace-1.5", True),
86 test_matrix_same_trace_modules
= [
87 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.7", "lttng-tools-2.7"),
88 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.8", "lttng-tools-2.8"),
89 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.9", "lttng-tools-2.9"),
90 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.10", "lttng-tools-2.10"),
93 test_matrix_same_trace_ust
= [
94 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.7"),
95 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.8"),
96 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.9"),
97 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.10"),
101 runtime_matrix_base_ust
= []
102 runtime_matrix_lost_packet
= []
103 runtime_matrix_base_modules
= []
104 runtime_matrix_same_trace_modules
= []
105 runtime_matrix_same_trace_ust
= []
108 if not Settings
.test_only
:
109 runtime_matrix_base_ust
= test_matrix_base_ust
110 runtime_matrix_base_modules
= test_matrix_base_modules
111 runtime_matrix_lost_packet
= test_matrix_lost_packet
112 runtime_matrix_same_trace_modules
= test_matrix_same_trace_modules
113 runtime_matrix_same_trace_ust
= test_matrix_same_trace_ust
115 for tup
in test_matrix_base_ust
:
116 if (tup
[0] in Settings
.test_only
or tup
[1] in
118 runtime_matrix_base_ust
.append(tup
)
119 for tup
in test_matrix_base_modules
:
120 if (tup
[0] in Settings
.test_only
or tup
[1] in
122 runtime_matrix_base_modules
.append(tup
)
123 for tup
in test_matrix_lost_packet
:
124 if (tup
[0] in Settings
.test_only
or tup
[1] in
126 test_matrix_lost_packet
.append(tup
)
127 for tup
in test_matrix_same_trace_modules
:
128 if (tup
[0] in Settings
.test_only
or tup
[1] in
130 runtime_matrix_same_trace_modules
.append(tup
)
131 for tup
in test_matrix_same_trace_ust
:
132 if (tup
[0] in Settings
.test_only
or tup
[1] in
134 runtime_matrix_same_trace_ust
.append(tup
)
137 @pytest.mark
.parametrize("babeltrace_l, tools_l", runtime_matrix_base_ust
)
138 def test_babeltrace_base_ust(tmpdir
, babeltrace_l
, tools_l
):
142 # Prepare environment
143 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
144 tools
= ProjectFactory
.get_precook(tools_l
)
146 runtime_path
= os
.path
.join(str(tmpdir
), "runtime")
147 app_path
= os
.path
.join(str(tmpdir
), "app")
149 with Run
.get_runtime(runtime_path
) as runtime
:
150 runtime
.add_project(tools
)
151 runtime
.add_project(babeltrace
)
153 # Make application using the runtime
154 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
155 runtime
.run("make V=1", cwd
=app_path
)
157 # Start lttng-sessiond
158 sessiond
= utils
.sessiond_spawn(runtime
)
160 # Create session using mi to get path and session name
161 runtime
.run('lttng create trace')
162 runtime
.run('lttng enable-event -u tp:tptest')
163 runtime
.run('lttng start')
166 cmd
= './app {}'.format(nb_events
)
167 runtime
.run(cmd
, cwd
=app_path
)
170 runtime
.run('lttng stop')
171 runtime
.run('lttng destroy -a')
172 cp
= runtime
.subprocess_terminate(sessiond
)
173 if cp
.returncode
!= 0:
174 pytest
.fail("Sessiond return code")
176 # Do not validate the metadata only the return code of babeltrace
177 cmd
= 'babeltrace -o ctf-metadata {}'.format(runtime
.lttng_home
)
180 cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
181 cp_process
, cp_out
, cp_err
= runtime
.run(cmd
)
182 assert(utils
.line_count(cp_out
) == nb_events
)
186 @pytest.mark
.parametrize("babeltrace_l,modules_l,tools_l", runtime_matrix_base_modules
)
187 def test_babeltrace_base_modules(tmpdir
, babeltrace_l
, modules_l
, tools_l
):
188 modules
= ProjectFactory
.get_precook(modules_l
)
190 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
191 tools
= ProjectFactory
.get_precook(tools_l
)
192 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
196 with Run
.get_runtime(str(tmpdir
)) as runtime
:
197 runtime
.add_project(modules
)
198 runtime
.add_project(tools
)
199 runtime
.add_project(babeltrace
)
201 sessiond
= utils
.sessiond_spawn(runtime
)
202 runtime
.load_test_module()
204 runtime
.run("lttng create trace")
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 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
219 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
220 assert(utils
.line_count(cp_out
) == nb_events
)
224 @pytest.mark
.parametrize("babeltrace_list,modules_l,tools_l", runtime_matrix_same_trace_modules
)
225 def test_babeltrace_same_trace_modules(tmpdir
, babeltrace_list
, modules_l
, tools_l
):
226 modules
= ProjectFactory
.get_precook(modules_l
)
228 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
229 tools
= ProjectFactory
.get_precook(tools_l
)
233 with Run
.get_runtime(str(tmpdir
)) as runtime
:
234 runtime
.add_project(modules
)
235 runtime
.add_project(tools
)
237 sessiond
= utils
.sessiond_spawn(runtime
)
238 runtime
.load_test_module()
240 runtime
.run("lttng create trace")
241 runtime
.run("lttng enable-event -k lttng_test_filter_event")
242 runtime
.run("lttng start")
243 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
244 procfile
.write("{}".format(nb_events
))
246 runtime
.run("lttng stop")
247 runtime
.run("lttng destroy -a")
249 sessiond
= runtime
.subprocess_terminate(sessiond
)
250 if sessiond
.returncode
!= 0:
251 pytest
.fail("Return value of sessiond is not zero")
255 processed_trace_files
= {}
257 for label
in babeltrace_list
:
258 babeltrace
= ProjectFactory
.get_precook(label
)
259 runtime
.add_project(babeltrace
)
260 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
261 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
262 assert (utils
.line_count(cp_out
) == nb_events
)
263 processed_trace_files
[label
] = cp_out
264 runtime
.remove_project(babeltrace
)
266 # Perform combinations and validate that traces match
267 for a
, b
in combinations(processed_trace_files
, 2):
268 version_a
= processed_trace_files
[a
]
269 version_b
= processed_trace_files
[b
]
270 assert (filecmp
.cmp(version_a
, version_b
)), "Processed trace from {} and {} differ.".format(a
,b
)
272 @pytest.mark
.parametrize("babeltrace_list,tools_l", runtime_matrix_same_trace_ust
)
273 def test_babeltrace_same_trace_ust(tmpdir
, babeltrace_list
, tools_l
):
274 tools
= ProjectFactory
.get_precook(tools_l
)
278 app_path
= os
.path
.join(str(tmpdir
), "app")
280 with Run
.get_runtime(str(tmpdir
)) as runtime
:
281 runtime
.add_project(tools
)
283 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
284 runtime
.run("make V=1", cwd
=app_path
)
286 sessiond
= utils
.sessiond_spawn(runtime
)
288 # Create session using mi to get path and session name
289 runtime
.run('lttng create trace')
290 runtime
.run('lttng enable-event -u tp:tptest')
291 runtime
.run('lttng start')
294 cmd
= './app {}'.format(nb_events
)
295 runtime
.run(cmd
, cwd
=app_path
)
298 runtime
.run('lttng stop')
299 runtime
.run('lttng destroy -a')
300 cp
= runtime
.subprocess_terminate(sessiond
)
301 if cp
.returncode
!= 0:
302 pytest
.fail("Sessiond return code")
305 processed_trace_files
= {}
307 for label
in babeltrace_list
:
308 babeltrace
= ProjectFactory
.get_precook(label
)
309 runtime
.add_project(babeltrace
)
310 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
311 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
312 assert (utils
.line_count(cp_out
) == nb_events
)
313 processed_trace_files
[label
] = cp_out
314 runtime
.remove_project(babeltrace
)
316 # Perform combinations and validate that traces match
317 for a
, b
in combinations(processed_trace_files
, 2):
318 version_a
= processed_trace_files
[a
]
319 version_b
= processed_trace_files
[b
]
320 assert (filecmp
.cmp(version_a
, version_b
)), "Processed trace from {} and {} differ.".format(a
, b
)
324 @pytest.mark
.parametrize("babeltrace_l,supported", runtime_matrix_lost_packet
)
325 def test_babeltrace_lost_patcket(tmpdir
, babeltrace_l
, supported
):
326 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
328 trace_path
= Settings
.trace_lost_packet
330 with Run
.get_runtime(str(tmpdir
)) as runtime
:
331 runtime
.add_project(babeltrace
)
332 cmd
= "babeltrace {}".format(trace_path
)
333 cp
, cp_out
, cp_err
= runtime
.run(cmd
)
335 assert(utils
.file_contains(cp_err
, "Tracer lost 3 trace packets"))
336 assert(utils
.file_contains(cp_err
, "Tracer lost 2 trace packets"))
337 assert(utils
.file_contains(cp_err
, "Tracer lost 1 trace packets"))
339 os
.path
.getsize(cp_err
) > 0
341 assert(utils
.line_count(cp_out
) == 8)