Commit | Line | Data |
---|---|---|
e93e3f39 JR |
1 | import pytest |
2 | import os | |
3 | import shutil | |
4 | import signal | |
5 | import subprocess | |
6 | ||
7 | import lttng_ivc.utils.ProjectFactory as ProjectFactory | |
8 | import lttng_ivc.utils.utils as utils | |
9 | import lttng_ivc.utils.runtime as Run | |
10 | import lttng_ivc.settings as Settings | |
11 | ||
12 | """ | |
13 | ||
14 | FC: Fully Compatible | |
15 | BC: Feature of the smallest version number will works. | |
16 | TU: Tracing unavailable | |
17 | ||
f4711e68 JR |
18 | NOTE: tracing between 2.7 and 2.8 should work but a problem with |
19 | _ustctl_basic_type prevent event registration. Hence consider in further test | |
20 | that the event registration is expected to fail. | |
21 | ||
e93e3f39 JR |
22 | +------------------------------------------------------------------------------+ |
23 | | LTTng UST control protocol compatibility matrix | | |
24 | | (between applications and tools linked on LTTng UST and liblttng-ust-ctl) | | |
25 | +--------------------------+------------+------------+------------+------------+ | |
26 | | LTTng UST / LTTng Tools | 2.7 (6.0) | 2.8 (6.1) | 2.9 (7.1) | 2.10 (7.2) | | |
27 | +--------------------------+------------+------------+------------+------------+ | |
28 | | 2.7 (6.0) | FC | BC | TU | TU | | |
29 | | 2.8 (6.1) | BC | FC | TU | TU | | |
30 | | 2.9 (7.1) | TU | TU | FC | BC | | |
31 | | 2.10 (7.2) | TU | TU | BC | FC | | |
32 | +--------------------------+------------+------------+------------+------------+ | |
33 | ||
34 | Version number of this API is defined in include/lttng/ust-abi.h of lttng-ust project | |
35 | ||
36 | """ | |
37 | ||
38 | """ | |
39 | First tuple member: lttng-ust label | |
40 | Second tuple member: lttng-tool label | |
41 | Third tuple member: expected scenario | |
42 | """ | |
43 | ||
f4711e68 JR |
44 | event_registration_error = "Error: UST app recv reg unsupported version" |
45 | ||
e93e3f39 | 46 | test_matrix_tracing_available = [ |
f4711e68 JR |
47 | ("lttng-ust-2.7", "lttng-tools-2.7", "Success"), |
48 | ("lttng-ust-2.7", "lttng-tools-2.8", "Unsupported version"), | |
49 | ("lttng-ust-2.7", "lttng-tools-2.9", "Unsupported"), | |
50 | ("lttng-ust-2.7", "lttng-tools-2.10", "Unsupported"), | |
51 | ("lttng-ust-2.8", "lttng-tools-2.7", "Unsupported version"), | |
52 | ("lttng-ust-2.8", "lttng-tools-2.8", "Success"), | |
53 | ("lttng-ust-2.8", "lttng-tools-2.9", "Unsupported"), | |
54 | ("lttng-ust-2.8", "lttng-tools-2.10", "Unsupported"), | |
55 | ("lttng-ust-2.9", "lttng-tools-2.7", "Unsupported"), | |
56 | ("lttng-ust-2.9", "lttng-tools-2.8", "Unsupported"), | |
57 | ("lttng-ust-2.9", "lttng-tools-2.9", "Success"), | |
58 | ("lttng-ust-2.9", "lttng-tools-2.10", "Success"), | |
59 | ("lttng-ust-2.10", "lttng-tools-2.7", "Unsupported"), | |
60 | ("lttng-ust-2.10", "lttng-tools-2.8", "Unsupported"), | |
61 | ("lttng-ust-2.10", "lttng-tools-2.9", "Success"), | |
62 | ("lttng-ust-2.10", "lttng-tools-2.10", "Success"), | |
e93e3f39 JR |
63 | ] |
64 | ||
e93e3f39 | 65 | |
bde0c540 JR |
66 | """ |
67 | Statedump are supported starting at lttng-ust >= 2.9. | |
68 | No need to test for prior lttng-ust givent that there is also a bump leading to | |
69 | loss of tracing for application running under lttng-ust < 2.9. | |
70 | """ | |
71 | test_matrix_regen_statedump = [ | |
72 | ("lttng-ust-2.9", "lttng-tools-2.9", True), | |
73 | ("lttng-ust-2.9", "lttng-tools-2.10", True), | |
74 | ("lttng-ust-2.10", "lttng-tools-2.9", True), | |
75 | ("lttng-ust-2.10", "lttng-tools-2.10", True), | |
76 | ] | |
77 | ||
78 | test_matrix_starglobing_enabler = [ | |
79 | ("lttng-ust-2.9", "lttng-tools-2.9", "Unsupported by tools"), | |
80 | ("lttng-ust-2.9", "lttng-tools-2.10", "Unsupported by ust"), | |
81 | ("lttng-ust-2.10", "lttng-tools-2.9", "Unsupported by tools"), | |
82 | ("lttng-ust-2.10", "lttng-tools-2.10", "Supported"), | |
83 | ] | |
84 | ||
e93e3f39 | 85 | runtime_matrix_tracing_available = [] |
bde0c540 JR |
86 | runtime_matrix_regen_statedump = [] |
87 | runtime_rix_starglobing_enabler = [] | |
e93e3f39 JR |
88 | |
89 | if not Settings.test_only: | |
90 | runtime_matrix_tracing_available = test_matrix_tracing_available | |
bde0c540 JR |
91 | runtime_matrix_regen_statedump = test_matrix_regen_statedump |
92 | runtime_matrix_starglobing_enabler = test_matrix_starglobing_enabler | |
e93e3f39 JR |
93 | else: |
94 | for tup in test_matrix_tracing_available: | |
95 | if (tup[0] in Settings.test_only or tup[1] in | |
96 | Settings.test_only): | |
97 | runtime_matrix_tracing_available.append(tup) | |
bde0c540 JR |
98 | for tup in test_matrix_regen_statedump: |
99 | if (tup[0] in Settings.test_only or tup[1] in | |
100 | Settings.test_only): | |
101 | runtime_matrix_regen_statedump.append(tup) | |
102 | for tup in test_matrix_starglobing_enabler: | |
103 | if (tup[0] in Settings.test_only or tup[1] in | |
104 | Settings.test_only): | |
105 | runtime_matrix_starglobing_enabler.append(tup) | |
e93e3f39 JR |
106 | |
107 | ||
f4711e68 JR |
108 | @pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_tracing_available) |
109 | def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, outcome): | |
581ef8bb | 110 | |
e93e3f39 JR |
111 | nb_events = 100 |
112 | ||
113 | # Prepare environment | |
114 | ust = ProjectFactory.get_precook(ust_label) | |
115 | tools = ProjectFactory.get_precook(tools_label) | |
116 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
117 | ||
118 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
119 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
120 | app_path = os.path.join(str(tmpdir), "app") | |
121 | ||
122 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
123 | runtime_tools.add_project(tools) | |
124 | runtime_tools.add_project(babeltrace) | |
125 | ||
126 | runtime_app.add_project(ust) | |
127 | runtime_app.lttng_home = runtime_tools.lttng_home | |
128 | ||
129 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
130 | ||
131 | # Make application using the ust runtime | |
132 | shutil.copytree(Settings.apps_gen_events_folder, app_path) | |
133 | runtime_app.run("make V=1", cwd=app_path) | |
134 | ||
135 | # Start lttng-sessiond | |
36df6d36 | 136 | sessiond = utils.sessiond_spawn(runtime_tools) |
e93e3f39 JR |
137 | |
138 | # Create session using mi to get path and session name | |
139 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
140 | ||
e93e3f39 JR |
141 | runtime_tools.run('lttng enable-event -u tp:tptest') |
142 | runtime_tools.run('lttng start') | |
143 | ||
144 | # Run application | |
145 | cmd = './app {}'.format(nb_events) | |
146 | runtime_app.run(cmd, cwd=app_path) | |
147 | ||
148 | # Stop tracing | |
87e6d73a | 149 | runtime_tools.run('lttng stop') |
e93e3f39 | 150 | runtime_tools.run('lttng destroy -a') |
bde0c540 JR |
151 | cp = runtime_tools.subprocess_terminate(sessiond) |
152 | if cp.returncode != 0: | |
153 | pytest.fail("Sessiond return code") | |
e93e3f39 | 154 | |
f4711e68 JR |
155 | |
156 | cmd = 'babeltrace {}'.format(trace_path) | |
157 | if outcome == "Success": | |
e93e3f39 JR |
158 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) |
159 | assert(utils.line_count(cp_out) == nb_events) | |
f4711e68 JR |
160 | else: |
161 | with pytest.raises(subprocess.CalledProcessError): | |
162 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
163 | if outcome == "Unsupported version": | |
164 | assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond), | |
165 | [event_registration_error])) | |
bde0c540 JR |
166 | |
167 | @pytest.mark.parametrize("ust_label,tools_label, success", runtime_matrix_regen_statedump) | |
168 | def test_ust_app_regen_statedump(tmpdir, ust_label, tools_label, success): | |
169 | nb_events = 100 | |
170 | ||
171 | if success: | |
172 | expected_events = 4 | |
173 | else: | |
174 | expected_events = 2 | |
175 | ||
176 | ust = ProjectFactory.get_precook(ust_label) | |
177 | tools = ProjectFactory.get_precook(tools_label) | |
178 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
179 | ||
180 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
181 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
182 | app_path = os.path.join(str(tmpdir), "app") | |
183 | ||
184 | ||
185 | app_sync_start = os.path.join(app_path, 'sync_start') | |
186 | app_sync_end = os.path.join(app_path, 'sync_end') | |
187 | ||
188 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
189 | runtime_tools.add_project(tools) | |
190 | runtime_tools.add_project(babeltrace) | |
191 | ||
192 | runtime_app.add_project(ust) | |
193 | runtime_app.lttng_home = runtime_tools.lttng_home | |
194 | ||
195 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
196 | ||
197 | # Make application using the ust runtime | |
198 | shutil.copytree(Settings.apps_gen_events_folder, app_path) | |
199 | runtime_app.run("make V=1", cwd=app_path) | |
200 | ||
201 | # Start lttng-sessiond | |
202 | sessiond = utils.sessiond_spawn(runtime_tools) | |
203 | ||
204 | # Create session using mi to get path and session name | |
205 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
206 | ||
207 | runtime_tools.run('lttng enable-event -u lttng_ust_statedump:start,lttng_ust_statedump:end') | |
208 | runtime_tools.run('lttng start') | |
209 | ||
210 | # Run application | |
211 | cmd = './app {} 0 {} {}'.format(nb_events, app_sync_start, app_sync_end) | |
212 | runtime_app.spawn_subprocess(cmd, cwd=app_path) | |
213 | ||
214 | utils.wait_for_file(app_sync_start) | |
215 | ||
216 | if not success: | |
217 | with pytest.raises(subprocess.CalledProcessError): | |
218 | runtime_tools.run('lttng regenerate statedump') | |
219 | else: | |
220 | runtime_tools.run('lttng regenerate statedump') | |
221 | ||
222 | utils.create_empty_file(app_sync_end) | |
223 | ||
224 | # Stop tracing | |
87e6d73a | 225 | runtime_tools.run('lttng stop') |
bde0c540 JR |
226 | runtime_tools.run('lttng destroy -a') |
227 | cp = runtime_tools.subprocess_terminate(sessiond) | |
228 | if cp.returncode != 0: | |
229 | pytest.fail("Sessiond return code") | |
230 | ||
231 | # Read trace with babeltrace and check for event count via number of line | |
232 | cmd = 'babeltrace {}'.format(trace_path) | |
233 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
234 | assert(utils.line_count(cp_out) == expected_events) | |
235 | ||
236 | @pytest.mark.parametrize("ust_label,tools_label, scenario", runtime_matrix_starglobing_enabler) | |
237 | def test_ust_app_starglobing_enabler(tmpdir, ust_label, tools_label, scenario): | |
238 | ||
239 | nb_events = 100 | |
240 | ||
241 | if scenario == "Unsupported by ust": | |
242 | expected_events = 0 | |
243 | else: | |
244 | expected_events = nb_events | |
245 | ||
246 | # Prepare environment | |
247 | ust = ProjectFactory.get_precook(ust_label) | |
248 | tools = ProjectFactory.get_precook(tools_label) | |
249 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
250 | ||
251 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
252 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
253 | app_path = os.path.join(str(tmpdir), "app") | |
254 | ||
255 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
256 | runtime_tools.add_project(tools) | |
257 | runtime_tools.add_project(babeltrace) | |
258 | ||
259 | runtime_app.add_project(ust) | |
260 | runtime_app.lttng_home = runtime_tools.lttng_home | |
261 | ||
262 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
263 | ||
264 | # Make application using the ust runtime | |
265 | shutil.copytree(Settings.apps_gen_events_folder, app_path) | |
266 | runtime_app.run("make V=1", cwd=app_path) | |
267 | ||
268 | # Start lttng-sessiond | |
269 | sessiond = utils.sessiond_spawn(runtime_tools) | |
270 | ||
271 | # Create session using mi to get path and session name | |
272 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
273 | ||
274 | # If unsupported by tools simply finish early | |
275 | if scenario == "Unsupported by tools": | |
276 | with pytest.raises(subprocess.CalledProcessError): | |
277 | runtime_tools.run('lttng enable-event -u "tp:*te*"') | |
278 | ||
279 | # TODO move this to internal runtime... | |
280 | cp = runtime_tools.subprocess_terminate(sessiond) | |
281 | if cp.returncode != 0: | |
282 | pytest.fail("Sessiond return code") | |
283 | return | |
284 | else: | |
285 | runtime_tools.run('lttng enable-event -u "tp:*te*"') | |
286 | ||
287 | runtime_tools.run('lttng start') | |
288 | ||
289 | # Run application | |
290 | cmd = './app {}'.format(nb_events) | |
291 | runtime_app.run(cmd, cwd=app_path) | |
292 | ||
293 | # Stop tracing | |
87e6d73a | 294 | runtime_tools.run('lttng stop') |
bde0c540 JR |
295 | runtime_tools.run('lttng destroy -a') |
296 | cp = runtime_tools.subprocess_terminate(sessiond) | |
297 | if cp.returncode != 0: | |
298 | pytest.fail("Sessiond return code") | |
299 | ||
300 | # Read trace with babeltrace and check for event count via number of line | |
301 | cmd = 'babeltrace {}'.format(trace_path) | |
302 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
303 | assert(utils.line_count(cp_out) == expected_events) |