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 destroy -a')
151 cp
= runtime
.subprocess_terminate(sessiond
)
152 if cp
.returncode
!= 0:
153 pytest
.fail("Sessiond return code")
155 # Do not validate the metadata only the return code of babeltrace
156 cmd
= 'babeltrace -o ctf-metadata {}'.format(runtime
.lttng_home
)
159 cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
160 cp_process
, cp_out
, cp_err
= runtime
.run(cmd
)
161 assert(utils
.line_count(cp_out
) == nb_events
)
165 @pytest.mark
.parametrize("babeltrace_l,modules_l,tools_l", runtime_matrix_base_modules
)
166 def test_babeltrace_base_modules(tmpdir
, babeltrace_l
, modules_l
, tools_l
):
167 modules
= ProjectFactory
.get_precook(modules_l
)
169 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
170 tools
= ProjectFactory
.get_precook(tools_l
)
171 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
175 with Run
.get_runtime(str(tmpdir
)) as runtime
:
176 runtime
.add_project(modules
)
177 runtime
.add_project(tools
)
178 runtime
.add_project(babeltrace
)
180 sessiond
= utils
.sessiond_spawn(runtime
)
181 runtime
.load_test_module()
183 runtime
.run("lttng create trace")
184 runtime
.run("lttng enable-event -k lttng_test_filter_event")
185 runtime
.run("lttng start")
186 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
187 procfile
.write("{}".format(nb_events
))
189 runtime
.run("lttng stop")
190 runtime
.run("lttng destroy -a")
192 sessiond
= runtime
.subprocess_terminate(sessiond
)
193 if sessiond
.returncode
!= 0:
194 pytest
.fail("Return value of sessiond is not zero")
197 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
198 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
199 assert(utils
.line_count(cp_out
) == nb_events
)
203 @pytest.mark
.parametrize("babeltrace_list,modules_l,tools_l", runtime_matrix_same_trace_modules
)
204 def test_babeltrace_same_trace_modules(tmpdir
, babeltrace_list
, modules_l
, tools_l
):
205 modules
= ProjectFactory
.get_precook(modules_l
)
207 pytest
.skip("{} cannot be built on this kernel".format(modules
.label
))
208 tools
= ProjectFactory
.get_precook(tools_l
)
212 with Run
.get_runtime(str(tmpdir
)) as runtime
:
213 runtime
.add_project(modules
)
214 runtime
.add_project(tools
)
216 sessiond
= utils
.sessiond_spawn(runtime
)
217 runtime
.load_test_module()
219 runtime
.run("lttng create trace")
220 runtime
.run("lttng enable-event -k lttng_test_filter_event")
221 runtime
.run("lttng start")
222 with
open(Settings
.lttng_test_procfile
, 'w') as procfile
:
223 procfile
.write("{}".format(nb_events
))
225 runtime
.run("lttng stop")
226 runtime
.run("lttng destroy -a")
228 sessiond
= runtime
.subprocess_terminate(sessiond
)
229 if sessiond
.returncode
!= 0:
230 pytest
.fail("Return value of sessiond is not zero")
234 processed_trace_files
= {}
236 for label
in babeltrace_list
:
237 babeltrace
= ProjectFactory
.get_precook(label
)
238 runtime
.add_project(babeltrace
)
239 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
240 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
241 assert (utils
.line_count(cp_out
) == nb_events
)
242 processed_trace_files
[label
] = cp_out
243 runtime
.remove_project(babeltrace
)
245 # Perform combinations and validate that traces match
246 for a
, b
in combinations(processed_trace_files
, 2):
247 version_a
= processed_trace_files
[a
]
248 version_b
= processed_trace_files
[b
]
249 assert (filecmp
.cmp(version_a
, version_b
)), "Processed trace from {} and {} differ.".format(a
,b
)
251 @pytest.mark
.parametrize("babeltrace_list,tools_l", runtime_matrix_same_trace_ust
)
252 def test_babeltrace_same_trace_ust(tmpdir
, babeltrace_list
, tools_l
):
253 tools
= ProjectFactory
.get_precook(tools_l
)
257 app_path
= os
.path
.join(str(tmpdir
), "app")
259 with Run
.get_runtime(str(tmpdir
)) as runtime
:
260 runtime
.add_project(tools
)
262 shutil
.copytree(Settings
.apps_gen_events_folder
, app_path
)
263 runtime
.run("make V=1", cwd
=app_path
)
265 sessiond
= utils
.sessiond_spawn(runtime
)
267 # Create session using mi to get path and session name
268 runtime
.run('lttng create trace')
269 runtime
.run('lttng enable-event -u tp:tptest')
270 runtime
.run('lttng start')
273 cmd
= './app {}'.format(nb_events
)
274 runtime
.run(cmd
, cwd
=app_path
)
277 runtime
.run('lttng destroy -a')
278 cp
= runtime
.subprocess_terminate(sessiond
)
279 if cp
.returncode
!= 0:
280 pytest
.fail("Sessiond return code")
283 processed_trace_files
= {}
285 for label
in babeltrace_list
:
286 babeltrace
= ProjectFactory
.get_precook(label
)
287 runtime
.add_project(babeltrace
)
288 babeltrace_cmd
= 'babeltrace {}'.format(runtime
.lttng_home
)
289 cp_process
, cp_out
, cp_err
= runtime
.run(babeltrace_cmd
)
290 assert (utils
.line_count(cp_out
) == nb_events
)
291 processed_trace_files
[label
] = cp_out
292 runtime
.remove_project(babeltrace
)
294 # Perform combinations and validate that traces match
295 for a
, b
in combinations(processed_trace_files
, 2):
296 version_a
= processed_trace_files
[a
]
297 version_b
= processed_trace_files
[b
]
298 assert (filecmp
.cmp(version_a
, version_b
)), "Processed trace from {} and {} differ.".format(a
, b
)
302 @pytest.mark
.parametrize("babeltrace_l,supported", runtime_matrix_lost_packet
)
303 def test_babeltrace_lost_patcket(tmpdir
, babeltrace_l
, supported
):
304 babeltrace
= ProjectFactory
.get_precook(babeltrace_l
)
306 trace_path
= Settings
.trace_lost_packet
308 with Run
.get_runtime(str(tmpdir
)) as runtime
:
309 runtime
.add_project(babeltrace
)
310 cmd
= "babeltrace {}".format(trace_path
)
311 cp
, cp_out
, cp_err
= runtime
.run(cmd
)
313 assert(utils
.file_contains(cp_err
, "Tracer lost 3 trace packets"))
314 assert(utils
.file_contains(cp_err
, "Tracer lost 2 trace packets"))
315 assert(utils
.file_contains(cp_err
, "Tracer lost 1 trace packets"))
317 os
.path
.getsize(cp_err
) > 0
319 assert(utils
.line_count(cp_out
) == 8)