6 import lttng_ivc
.utils
.ProjectFactory
as ProjectFactory
7 import lttng_ivc
.utils
.utils
as utils
8 import lttng_ivc
.utils
.runtime
as Run
9 import lttng_ivc
.settings
as Settings
12 from lttng_ivc
.utils
.skip
import must_be_root
13 from itertools
import combinations
17 BC: Feature of the smallest version number will works.
19 +------------------------------------------------------------------------------+
20 | Babeltrace vs UST/Tools/Metadata |
21 +--------------------------+------------+------------+------------+------------+
22 | Babeltrace / LTTng | 2.7 | 2.8 | 2.9 | 2.10 |
23 +--------------------------+------------+------------+------------+------------+
24 | 1.3 | FC | BC | BC | BC |
25 | 1.4 | FC | FC | FC | FC |
26 | 1.5 | FC | FC | FC | FC |
27 +--------------------------+------------+------------+------------+------------+
30 test_matrix_base_ust
= [
31 ("babeltrace-1.3", "lttng-tools-2.7"),
32 ("babeltrace-1.3", "lttng-tools-2.8"),
33 ("babeltrace-1.3", "lttng-tools-2.9"),
34 ("babeltrace-1.3", "lttng-tools-2.10"),
35 ("babeltrace-1.4", "lttng-tools-2.7"),
36 ("babeltrace-1.4", "lttng-tools-2.8"),
37 ("babeltrace-1.4", "lttng-tools-2.9"),
38 ("babeltrace-1.4", "lttng-tools-2.10"),
39 ("babeltrace-1.5", "lttng-tools-2.7"),
40 ("babeltrace-1.5", "lttng-tools-2.8"),
41 ("babeltrace-1.5", "lttng-tools-2.9"),
42 ("babeltrace-1.5", "lttng-tools-2.10"),
45 test_matrix_base_modules
= [
46 ("babeltrace-1.3", "lttng-modules-2.7", "lttng-tools-2.7"),
47 ("babeltrace-1.3", "lttng-modules-2.8", "lttng-tools-2.8"),
48 ("babeltrace-1.3", "lttng-modules-2.9", "lttng-tools-2.9"),
49 ("babeltrace-1.3", "lttng-modules-2.10", "lttng-tools-2.10"),
50 ("babeltrace-1.4", "lttng-modules-2.7", "lttng-tools-2.7"),
51 ("babeltrace-1.4", "lttng-modules-2.8", "lttng-tools-2.8"),
52 ("babeltrace-1.4", "lttng-modules-2.9", "lttng-tools-2.9"),
53 ("babeltrace-1.4", "lttng-modules-2.10", "lttng-tools-2.10"),
54 ("babeltrace-1.5", "lttng-modules-2.7", "lttng-tools-2.7"),
55 ("babeltrace-1.5", "lttng-modules-2.8", "lttng-tools-2.8"),
56 ("babeltrace-1.5", "lttng-modules-2.9", "lttng-tools-2.9"),
57 ("babeltrace-1.5", "lttng-modules-2.10", "lttng-tools-2.10"),
60 test_matrix_lost_packet
= [
61 ("babeltrace-1.3", False),
62 ("babeltrace-1.4", True),
63 ("babeltrace-1.5", True),
66 test_matrix_same_trace_modules
= [
67 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.7", "lttng-tools-2.7"),
68 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.8", "lttng-tools-2.8"),
69 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.9", "lttng-tools-2.9"),
70 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-modules-2.10", "lttng-tools-2.10"),
73 test_matrix_same_trace_ust
= [
74 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.7"),
75 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.8"),
76 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.9"),
77 (["babeltrace-1.3", "babeltrace-1.4", "babeltrace-1.5"], "lttng-tools-2.10"),
81 runtime_matrix_base_ust
= []
82 runtime_matrix_lost_packet
= []
83 runtime_matrix_base_modules
= []
84 runtime_matrix_same_trace_modules
= []
85 runtime_matrix_same_trace_ust
= []
88 if not Settings
.test_only
:
89 runtime_matrix_base_ust
= test_matrix_base_ust
90 runtime_matrix_base_modules
= test_matrix_base_modules
91 runtime_matrix_lost_packet
= test_matrix_lost_packet
92 runtime_matrix_same_trace_modules
= test_matrix_same_trace_modules
93 runtime_matrix_same_trace_ust
= test_matrix_same_trace_ust
95 for tup
in test_matrix_base_ust
:
96 if (tup
[0] in Settings
.test_only
or tup
[1] in
98 runtime_matrix_base_ust
.append(tup
)
99 for tup
in test_matrix_base_modules
:
100 if (tup
[0] in Settings
.test_only
or tup
[1] in
102 runtime_matrix_base_modules
.append(tup
)
103 for tup
in test_matrix_lost_packet
:
104 if (tup
[0] in Settings
.test_only
or tup
[1] in
106 test_matrix_lost_packet
.append(tup
)
107 for tup
in test_matrix_same_trace_modules
:
108 if (tup
[0] in Settings
.test_only
or tup
[1] in
110 runtime_matrix_same_trace_modules
.append(tup
)
111 for tup
in test_matrix_same_trace_ust
:
112 if (tup
[0] in Settings
.test_only
or tup
[1] in
114 runtime_matrix_same_trace_ust
.append(tup
)
117 @pytest.mark
.parametrize("babeltrace_l, tools_l", runtime_matrix_base_ust
)
118 def test_babeltrace_base_ust(tmpdir
, babeltrace_l
, tools_l
):
122 # Prepare environment
123 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
124 tools
= ProjectFactory
.get_precook(tools_l
)
126 runtime_path
= os
.path
.join(str(tmpdir
), "runtime")
127 app_path
= os
.path
.join(str(tmpdir
), "app")
129 with Run
.get_runtime(runtime_path
) as runtime
:
130 runtime
.add_project(tools
)
131 runtime
.add_project(babeltrace
)
133 # Make application using the runtime
134 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
135 runtime
.run("make V=1", cwd
=app_path
)
137 # Start lttng-sessiond
138 sessiond
= utils
.sessiond_spawn(runtime
)
140 # Create session using mi to get path and session name
141 runtime
.run('lttng create trace')
142 runtime
.run('lttng enable-event -u tp:tptest')
143 runtime
.run('lttng start')
146 cmd
= './app {}'.format(nb_events
)
147 runtime
.run(cmd
, cwd
=app_path
)
150 runtime
.run('lttng stop')
151 runtime
.run('lttng destroy -a')
152 cp
= runtime
.subprocess_terminate(sessiond
)
153 if cp
.returncode
!= 0:
154 pytest
.fail("Sessiond return code")
156 # Do not validate the metadata only the return code of babeltrace
157 cmd
= 'babeltrace -o ctf-metadata {}'.format(runtime
.lttng_home
)
160 cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
161 cp_process
, cp_out
, cp_err
= runtime
.run(cmd
)
162 assert(utils
.line_count(cp_out
) == nb_events
)
166 @pytest.mark
.parametrize("babeltrace_l,modules_l,tools_l", runtime_matrix_base_modules
)
167 def test_babeltrace_base_modules(tmpdir
, babeltrace_l
, modules_l
, tools_l
):
168 modules
= ProjectFactory
.get_precook(modules_l
)
170 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
171 tools
= ProjectFactory
.get_precook(tools_l
)
172 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
176 with Run
.get_runtime(str(tmpdir
)) as runtime
:
177 runtime
.add_project(modules
)
178 runtime
.add_project(tools
)
179 runtime
.add_project(babeltrace
)
181 sessiond
= utils
.sessiond_spawn(runtime
)
182 runtime
.load_test_module()
184 runtime
.run("lttng create trace")
185 runtime
.run("lttng enable-event -k lttng_test_filter_event")
186 runtime
.run("lttng start")
187 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
188 procfile
.write("{}".format(nb_events
))
190 runtime
.run("lttng stop")
191 runtime
.run("lttng destroy -a")
193 sessiond
= runtime
.subprocess_terminate(sessiond
)
194 if sessiond
.returncode
!= 0:
195 pytest
.fail("Return value of sessiond is not zero")
198 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
199 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
200 assert(utils
.line_count(cp_out
) == nb_events
)
204 @pytest.mark
.parametrize("babeltrace_list,modules_l,tools_l", runtime_matrix_same_trace_modules
)
205 def test_babeltrace_same_trace_modules(tmpdir
, babeltrace_list
, modules_l
, tools_l
):
206 modules
= ProjectFactory
.get_precook(modules_l
)
208 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
209 tools
= ProjectFactory
.get_precook(tools_l
)
213 with Run
.get_runtime(str(tmpdir
)) as runtime
:
214 runtime
.add_project(modules
)
215 runtime
.add_project(tools
)
217 sessiond
= utils
.sessiond_spawn(runtime
)
218 runtime
.load_test_module()
220 runtime
.run("lttng create trace")
221 runtime
.run("lttng enable-event -k lttng_test_filter_event")
222 runtime
.run("lttng start")
223 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
224 procfile
.write("{}".format(nb_events
))
226 runtime
.run("lttng stop")
227 runtime
.run("lttng destroy -a")
229 sessiond
= runtime
.subprocess_terminate(sessiond
)
230 if sessiond
.returncode
!= 0:
231 pytest
.fail("Return value of sessiond is not zero")
235 processed_trace_files
= {}
237 for label
in babeltrace_list
:
238 babeltrace
= ProjectFactory
.get_precook(label
)
239 runtime
.add_project(babeltrace
)
240 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
241 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
242 assert (utils
.line_count(cp_out
) == nb_events
)
243 processed_trace_files
[label
] = cp_out
244 runtime
.remove_project(babeltrace
)
246 # Perform combinations and validate that traces match
247 for a
, b
in combinations(processed_trace_files
, 2):
248 version_a
= processed_trace_files
[a
]
249 version_b
= processed_trace_files
[b
]
250 assert (filecmp
.cmp(version_a
, version_b
)), "Processed trace from {} and {} differ.".format(a
,b
)
252 @pytest.mark
.parametrize("babeltrace_list,tools_l", runtime_matrix_same_trace_ust
)
253 def test_babeltrace_same_trace_ust(tmpdir
, babeltrace_list
, tools_l
):
254 tools
= ProjectFactory
.get_precook(tools_l
)
258 app_path
= os
.path
.join(str(tmpdir
), "app")
260 with Run
.get_runtime(str(tmpdir
)) as runtime
:
261 runtime
.add_project(tools
)
263 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
264 runtime
.run("make V=1", cwd
=app_path
)
266 sessiond
= utils
.sessiond_spawn(runtime
)
268 # Create session using mi to get path and session name
269 runtime
.run('lttng create trace')
270 runtime
.run('lttng enable-event -u tp:tptest')
271 runtime
.run('lttng start')
274 cmd
= './app {}'.format(nb_events
)
275 runtime
.run(cmd
, cwd
=app_path
)
278 runtime
.run('lttng stop')
279 runtime
.run('lttng destroy -a')
280 cp
= runtime
.subprocess_terminate(sessiond
)
281 if cp
.returncode
!= 0:
282 pytest
.fail("Sessiond return code")
285 processed_trace_files
= {}
287 for label
in babeltrace_list
:
288 babeltrace
= ProjectFactory
.get_precook(label
)
289 runtime
.add_project(babeltrace
)
290 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
291 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
292 assert (utils
.line_count(cp_out
) == nb_events
)
293 processed_trace_files
[label
] = cp_out
294 runtime
.remove_project(babeltrace
)
296 # Perform combinations and validate that traces match
297 for a
, b
in combinations(processed_trace_files
, 2):
298 version_a
= processed_trace_files
[a
]
299 version_b
= processed_trace_files
[b
]
300 assert (filecmp
.cmp(version_a
, version_b
)), "Processed trace from {} and {} differ.".format(a
, b
)
304 @pytest.mark
.parametrize("babeltrace_l,supported", runtime_matrix_lost_packet
)
305 def test_babeltrace_lost_patcket(tmpdir
, babeltrace_l
, supported
):
306 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
308 trace_path
= Settings
.trace_lost_packet
310 with Run
.get_runtime(str(tmpdir
)) as runtime
:
311 runtime
.add_project(babeltrace
)
312 cmd
= "babeltrace {}".format(trace_path
)
313 cp
, cp_out
, cp_err
= runtime
.run(cmd
)
315 assert(utils
.file_contains(cp_err
, "Tracer lost 3 trace packets"))
316 assert(utils
.file_contains(cp_err
, "Tracer lost 2 trace packets"))
317 assert(utils
.file_contains(cp_err
, "Tracer lost 1 trace packets"))
319 os
.path
.getsize(cp_err
) > 0
321 assert(utils
.line_count(cp_out
) == 8)