Commit | Line | Data |
---|---|---|
efdd48db JR |
1 | # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
2 | # | |
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: | |
9 | # | |
10 | # The above copyright notice and this permission notice shall be included in all | |
11 | # copies or substantial portions of the Software. | |
12 | # | |
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 | |
19 | # SOFTWARE. | |
20 | ||
ee0fecde JR |
21 | import pytest |
22 | import os | |
23 | import shutil | |
24 | import filecmp | |
25 | ||
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 | |
30 | ||
31 | ||
32 | from lttng_ivc.utils.skip import must_be_root | |
33 | from itertools import combinations | |
34 | """ | |
35 | ||
36 | FC: Fully Compatible | |
37 | BC: Feature of the smallest version number will works. | |
38 | ||
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 | +--------------------------+------------+------------+------------+------------+ | |
48 | ||
49 | """ | |
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"), | |
63 | ] | |
64 | ||
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"), | |
78 | ] | |
79 | ||
80 | test_matrix_lost_packet = [ | |
81 | ("babeltrace-1.3", False), | |
82 | ("babeltrace-1.4", True), | |
83 | ("babeltrace-1.5", True), | |
84 | ] | |
85 | ||
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"), | |
91 | ] | |
92 | ||
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"), | |
98 | ] | |
99 | ||
100 | ||
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 = [] | |
106 | ||
107 | ||
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 | |
114 | else: | |
115 | for tup in test_matrix_base_ust: | |
116 | if (tup[0] in Settings.test_only or tup[1] in | |
117 | Settings.test_only): | |
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 | |
121 | Settings.test_only): | |
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 | |
125 | Settings.test_only): | |
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 | |
129 | Settings.test_only): | |
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 | |
133 | Settings.test_only): | |
134 | runtime_matrix_same_trace_ust.append(tup) | |
135 | ||
136 | ||
137 | @pytest.mark.parametrize("babeltrace_l, tools_l", runtime_matrix_base_ust) | |
138 | def test_babeltrace_base_ust(tmpdir, babeltrace_l, tools_l): | |
139 | ||
140 | nb_events = 100 | |
141 | ||
142 | # Prepare environment | |
143 | babeltrace = ProjectFactory.get_precook(babeltrace_l) | |
144 | tools = ProjectFactory.get_precook(tools_l) | |
145 | ||
146 | runtime_path = os.path.join(str(tmpdir), "runtime") | |
147 | app_path = os.path.join(str(tmpdir), "app") | |
148 | ||
149 | with Run.get_runtime(runtime_path) as runtime: | |
150 | runtime.add_project(tools) | |
151 | runtime.add_project(babeltrace) | |
152 | ||
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) | |
156 | ||
157 | # Start lttng-sessiond | |
158 | sessiond = utils.sessiond_spawn(runtime) | |
159 | ||
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') | |
164 | ||
165 | # Run application | |
166 | cmd = './app {}'.format(nb_events) | |
167 | runtime.run(cmd, cwd=app_path) | |
168 | ||
169 | # Stop tracing | |
87e6d73a | 170 | runtime.run('lttng stop') |
ee0fecde JR |
171 | runtime.run('lttng destroy -a') |
172 | cp = runtime.subprocess_terminate(sessiond) | |
173 | if cp.returncode != 0: | |
174 | pytest.fail("Sessiond return code") | |
175 | ||
176 | # Do not validate the metadata only the return code of babeltrace | |
177 | cmd = 'babeltrace -o ctf-metadata {}'.format(runtime.lttng_home) | |
178 | runtime.run(cmd) | |
179 | ||
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) | |
183 | ||
184 | ||
185 | @must_be_root | |
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) | |
189 | if modules.skip: | |
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) | |
193 | ||
194 | nb_events = 100 | |
195 | ||
196 | with Run.get_runtime(str(tmpdir)) as runtime: | |
197 | runtime.add_project(modules) | |
198 | runtime.add_project(tools) | |
199 | runtime.add_project(babeltrace) | |
200 | ||
201 | sessiond = utils.sessiond_spawn(runtime) | |
202 | runtime.load_test_module() | |
203 | ||
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)) | |
209 | ||
210 | runtime.run("lttng stop") | |
211 | runtime.run("lttng destroy -a") | |
212 | ||
213 | sessiond = runtime.subprocess_terminate(sessiond) | |
214 | if sessiond.returncode != 0: | |
215 | pytest.fail("Return value of sessiond is not zero") | |
216 | return | |
217 | ||
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) | |
221 | ||
222 | ||
223 | @must_be_root | |
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) | |
227 | if modules.skip: | |
228 | pytest.skip("{} cannot be built on this kernel".format(modules.label)) | |
229 | tools = ProjectFactory.get_precook(tools_l) | |
230 | ||
231 | nb_events = 100 | |
232 | ||
233 | with Run.get_runtime(str(tmpdir)) as runtime: | |
234 | runtime.add_project(modules) | |
235 | runtime.add_project(tools) | |
236 | ||
237 | sessiond = utils.sessiond_spawn(runtime) | |
238 | runtime.load_test_module() | |
239 | ||
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)) | |
245 | ||
246 | runtime.run("lttng stop") | |
247 | runtime.run("lttng destroy -a") | |
248 | ||
249 | sessiond = runtime.subprocess_terminate(sessiond) | |
250 | if sessiond.returncode != 0: | |
251 | pytest.fail("Return value of sessiond is not zero") | |
252 | return | |
253 | ||
254 | # Actual testing | |
255 | processed_trace_files = {} | |
256 | # Gather text traces | |
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) | |
265 | ||
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) | |
271 | ||
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) | |
275 | ||
276 | nb_events = 100 | |
277 | ||
278 | app_path = os.path.join(str(tmpdir), "app") | |
279 | ||
280 | with Run.get_runtime(str(tmpdir)) as runtime: | |
281 | runtime.add_project(tools) | |
282 | ||
283 | shutil.copytree(Settings.apps_gen_events_folder, app_path) | |
284 | runtime.run("make V=1", cwd=app_path) | |
285 | ||
286 | sessiond = utils.sessiond_spawn(runtime) | |
287 | ||
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') | |
292 | ||
293 | # Run application | |
294 | cmd = './app {}'.format(nb_events) | |
295 | runtime.run(cmd, cwd=app_path) | |
296 | ||
297 | # Stop tracing | |
87e6d73a | 298 | runtime.run('lttng stop') |
ee0fecde JR |
299 | runtime.run('lttng destroy -a') |
300 | cp = runtime.subprocess_terminate(sessiond) | |
301 | if cp.returncode != 0: | |
302 | pytest.fail("Sessiond return code") | |
303 | ||
304 | # Actual testing | |
305 | processed_trace_files = {} | |
306 | # Gather text traces | |
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) | |
315 | ||
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) | |
321 | ||
322 | ||
323 | ||
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) | |
327 | ||
328 | trace_path = Settings.trace_lost_packet | |
329 | ||
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) | |
334 | if supported: | |
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")) | |
338 | else: | |
339 | os.path.getsize(cp_err) > 0 | |
340 | ||
341 | assert(utils.line_count(cp_out) == 8) |