Introduce basic babeltrace testing
[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 destroy -a')
151 cp = runtime.subprocess_terminate(sessiond)
152 if cp.returncode != 0:
153 pytest.fail("Sessiond return code")
154
155 # Do not validate the metadata only the return code of babeltrace
156 cmd = 'babeltrace -o ctf-metadata {}'.format(runtime.lttng_home)
157 runtime.run(cmd)
158
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)
162
163
164 @must_be_root
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)
168 if modules.skip:
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)
172
173 nb_events = 100
174
175 with Run.get_runtime(str(tmpdir)) as runtime:
176 runtime.add_project(modules)
177 runtime.add_project(tools)
178 runtime.add_project(babeltrace)
179
180 sessiond = utils.sessiond_spawn(runtime)
181 runtime.load_test_module()
182
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))
188
189 runtime.run("lttng stop")
190 runtime.run("lttng destroy -a")
191
192 sessiond = runtime.subprocess_terminate(sessiond)
193 if sessiond.returncode != 0:
194 pytest.fail("Return value of sessiond is not zero")
195 return
196
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)
200
201
202 @must_be_root
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)
206 if modules.skip:
207 pytest.skip("{} cannot be built on this kernel".format(modules.label))
208 tools = ProjectFactory.get_precook(tools_l)
209
210 nb_events = 100
211
212 with Run.get_runtime(str(tmpdir)) as runtime:
213 runtime.add_project(modules)
214 runtime.add_project(tools)
215
216 sessiond = utils.sessiond_spawn(runtime)
217 runtime.load_test_module()
218
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))
224
225 runtime.run("lttng stop")
226 runtime.run("lttng destroy -a")
227
228 sessiond = runtime.subprocess_terminate(sessiond)
229 if sessiond.returncode != 0:
230 pytest.fail("Return value of sessiond is not zero")
231 return
232
233 # Actual testing
234 processed_trace_files = {}
235 # Gather text traces
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)
244
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)
250
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)
254
255 nb_events = 100
256
257 app_path = os.path.join(str(tmpdir), "app")
258
259 with Run.get_runtime(str(tmpdir)) as runtime:
260 runtime.add_project(tools)
261
262 shutil.copytree(Settings.apps_gen_events_folder, app_path)
263 runtime.run("make V=1", cwd=app_path)
264
265 sessiond = utils.sessiond_spawn(runtime)
266
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')
271
272 # Run application
273 cmd = './app {}'.format(nb_events)
274 runtime.run(cmd, cwd=app_path)
275
276 # Stop tracing
277 runtime.run('lttng destroy -a')
278 cp = runtime.subprocess_terminate(sessiond)
279 if cp.returncode != 0:
280 pytest.fail("Sessiond return code")
281
282 # Actual testing
283 processed_trace_files = {}
284 # Gather text traces
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)
293
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)
299
300
301
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)
305
306 trace_path = Settings.trace_lost_packet
307
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)
312 if supported:
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"))
316 else:
317 os.path.getsize(cp_err) > 0
318
319 assert(utils.line_count(cp_out) == 8)
This page took 0.039234 seconds and 5 git commands to generate.