f9534d51110f425565dc0cd21b27c4ca5aa4320d
[deliverable/lttng-ivc.git] / lttng_ivc / tests / babeltrace / base / test_babeltrace_base.py
1 import pytest
2 import os
3 import shutil
4 import filecmp
5
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
10
11
12 from lttng_ivc.utils.skip import must_be_root
13 from itertools import combinations
14 """
15
16 FC: Fully Compatible
17 BC: Feature of the smallest version number will works.
18
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 +--------------------------+------------+------------+------------+------------+
28
29 """
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"),
43 ]
44
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"),
58 ]
59
60 test_matrix_lost_packet = [
61 ("babeltrace-1.3", False),
62 ("babeltrace-1.4", True),
63 ("babeltrace-1.5", True),
64 ]
65
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"),
71 ]
72
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"),
78 ]
79
80
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 = []
86
87
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
94 else:
95 for tup in test_matrix_base_ust:
96 if (tup[0] in Settings.test_only or tup[1] in
97 Settings.test_only):
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
101 Settings.test_only):
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
105 Settings.test_only):
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
109 Settings.test_only):
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
113 Settings.test_only):
114 runtime_matrix_same_trace_ust.append(tup)
115
116
117 @pytest.mark.parametrize("babeltrace_l, tools_l", runtime_matrix_base_ust)
118 def test_babeltrace_base_ust(tmpdir, babeltrace_l, tools_l):
119
120 nb_events = 100
121
122 # Prepare environment
123 babeltrace = ProjectFactory.get_precook(babeltrace_l)
124 tools = ProjectFactory.get_precook(tools_l)
125
126 runtime_path = os.path.join(str(tmpdir), "runtime")
127 app_path = os.path.join(str(tmpdir), "app")
128
129 with Run.get_runtime(runtime_path) as runtime:
130 runtime.add_project(tools)
131 runtime.add_project(babeltrace)
132
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)
136
137 # Start lttng-sessiond
138 sessiond = utils.sessiond_spawn(runtime)
139
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')
144
145 # Run application
146 cmd = './app {}'.format(nb_events)
147 runtime.run(cmd, cwd=app_path)
148
149 # Stop tracing
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")
155
156 # Do not validate the metadata only the return code of babeltrace
157 cmd = 'babeltrace -o ctf-metadata {}'.format(runtime.lttng_home)
158 runtime.run(cmd)
159
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)
163
164
165 @must_be_root
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)
169 if modules.skip:
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)
173
174 nb_events = 100
175
176 with Run.get_runtime(str(tmpdir)) as runtime:
177 runtime.add_project(modules)
178 runtime.add_project(tools)
179 runtime.add_project(babeltrace)
180
181 sessiond = utils.sessiond_spawn(runtime)
182 runtime.load_test_module()
183
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))
189
190 runtime.run("lttng stop")
191 runtime.run("lttng destroy -a")
192
193 sessiond = runtime.subprocess_terminate(sessiond)
194 if sessiond.returncode != 0:
195 pytest.fail("Return value of sessiond is not zero")
196 return
197
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)
201
202
203 @must_be_root
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)
207 if modules.skip:
208 pytest.skip("{} cannot be built on this kernel".format(modules.label))
209 tools = ProjectFactory.get_precook(tools_l)
210
211 nb_events = 100
212
213 with Run.get_runtime(str(tmpdir)) as runtime:
214 runtime.add_project(modules)
215 runtime.add_project(tools)
216
217 sessiond = utils.sessiond_spawn(runtime)
218 runtime.load_test_module()
219
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))
225
226 runtime.run("lttng stop")
227 runtime.run("lttng destroy -a")
228
229 sessiond = runtime.subprocess_terminate(sessiond)
230 if sessiond.returncode != 0:
231 pytest.fail("Return value of sessiond is not zero")
232 return
233
234 # Actual testing
235 processed_trace_files = {}
236 # Gather text traces
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)
245
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)
251
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)
255
256 nb_events = 100
257
258 app_path = os.path.join(str(tmpdir), "app")
259
260 with Run.get_runtime(str(tmpdir)) as runtime:
261 runtime.add_project(tools)
262
263 shutil.copytree(Settings.apps_gen_events_folder, app_path)
264 runtime.run("make V=1", cwd=app_path)
265
266 sessiond = utils.sessiond_spawn(runtime)
267
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')
272
273 # Run application
274 cmd = './app {}'.format(nb_events)
275 runtime.run(cmd, cwd=app_path)
276
277 # Stop tracing
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")
283
284 # Actual testing
285 processed_trace_files = {}
286 # Gather text traces
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)
295
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)
301
302
303
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)
307
308 trace_path = Settings.trace_lost_packet
309
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)
314 if supported:
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"))
318 else:
319 os.path.getsize(cp_err) > 0
320
321 assert(utils.line_count(cp_out) == 8)
This page took 0.037468 seconds and 4 git commands to generate.