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 | ||
2094d672 JR |
21 | import pytest |
22 | import os | |
23 | import shutil | |
24 | import signal | |
25 | import subprocess | |
26 | ||
27 | import lttng_ivc.utils.ProjectFactory as ProjectFactory | |
28 | import lttng_ivc.utils.utils as utils | |
29 | import lttng_ivc.utils.runtime as Run | |
30 | import lttng_ivc.settings as Settings | |
31 | ||
32 | """ | |
33 | ||
34 | FC: Fully Compatible | |
35 | BC: Feature of the smallest version number will works. | |
36 | TU: Tracing unavailable | |
37 | ||
38 | Note: actual testing is limited by lttng-ust and lttng-tools abi/api. | |
39 | ||
40 | +----------------------------------------------------------------------------------+ | |
41 | | LTTng UST Python agent protocol vs LTTng session daemon | | |
42 | +--------------------------+------------+------------+------------+----------------+ | |
43 | | LTTng UST Java/ LTTng Tools | 2.7 (1.0) | 2.8 (2.0) | 2.9 (2.0) | 2.10 (2.0) | | |
44 | +--------------------------+------------+------------+------------+----------------+ | |
45 | | 2.7 | NA | NA | NA | NA | | |
46 | | 2.8 (2.0) | TU | FC | BC | BC | | |
47 | | 2.9 (2.0) | TU | BC | FC | BC | | |
48 | | 2.10 (2.0) | TU | BC | BC | FC | | |
49 | +--------------------------+------------+------------+------------+----------------+ | |
50 | ||
51 | """ | |
52 | ||
53 | """ | |
54 | First tuple member: lttng-ust label | |
55 | Second tuple member: lttng-tool label | |
56 | Thirdd tuple member: expected scenario | |
57 | """ | |
58 | ||
59 | test_matrix_tracing_available = [ | |
60 | ("lttng-ust-2.7", "lttng-tools-2.7", True), | |
61 | ("lttng-ust-2.7", "lttng-tools-2.8", False), | |
62 | ("lttng-ust-2.7", "lttng-tools-2.9", False), | |
63 | ("lttng-ust-2.7", "lttng-tools-2.10", False), | |
64 | ("lttng-ust-2.8", "lttng-tools-2.7", False), | |
65 | ("lttng-ust-2.8", "lttng-tools-2.8", True), | |
66 | ("lttng-ust-2.8", "lttng-tools-2.9", False), | |
67 | ("lttng-ust-2.8", "lttng-tools-2.10", False), | |
68 | ("lttng-ust-2.9", "lttng-tools-2.7", False), | |
69 | ("lttng-ust-2.9", "lttng-tools-2.8", False), | |
70 | ("lttng-ust-2.9", "lttng-tools-2.9", True), | |
71 | ("lttng-ust-2.9", "lttng-tools-2.10", True), | |
72 | ("lttng-ust-2.10", "lttng-tools-2.7", False), | |
73 | ("lttng-ust-2.10", "lttng-tools-2.8", False), | |
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_agent_interface = [ | |
79 | ("lttng-ust-2.7", "lttng-tools-2.7", "Success"), | |
80 | ("lttng-ust-2.7", "lttng-tools-2.8", "Unsupported protocol"), | |
81 | ("lttng-ust-2.7", "lttng-tools-2.9", "Unsupported protocol"), | |
82 | ("lttng-ust-2.7", "lttng-tools-2.10", "Unsupported protocol"), | |
83 | ("lttng-ust-2.8", "lttng-tools-2.7", "Unsupported protocol"), | |
84 | ("lttng-ust-2.8", "lttng-tools-2.8", "Success"), | |
85 | ("lttng-ust-2.8", "lttng-tools-2.9", "Success"), | |
86 | ("lttng-ust-2.8", "lttng-tools-2.10", "Success"), | |
87 | ("lttng-ust-2.9", "lttng-tools-2.7", "Unsupported protocol"), | |
88 | ("lttng-ust-2.9", "lttng-tools-2.8", "Success"), | |
89 | ("lttng-ust-2.9", "lttng-tools-2.9", "Success"), | |
90 | ("lttng-ust-2.9", "lttng-tools-2.10", "Success"), | |
91 | ("lttng-ust-2.10", "lttng-tools-2.7", "Unsupported protocol"), | |
92 | ("lttng-ust-2.10", "lttng-tools-2.8", "Success"), | |
93 | ("lttng-ust-2.10", "lttng-tools-2.9", "Success"), | |
94 | ("lttng-ust-2.10", "lttng-tools-2.10", "Success"), | |
95 | ] | |
96 | ||
97 | runtime_matrix_tracing_available = [] | |
98 | runtime_matrix_agent_interface = [] | |
99 | ||
100 | if not Settings.test_only: | |
101 | runtime_matrix_tracing_available = test_matrix_tracing_available | |
102 | runtime_matrix_agent_interface = test_matrix_agent_interface | |
103 | else: | |
104 | for tup in test_matrix_tracing_available: | |
105 | if (tup[0] in Settings.test_only or tup[1] in | |
106 | Settings.test_only): | |
107 | runtime_matrix_tracing_available.append(tup) | |
108 | for tup in test_matrix_agent_interface: | |
109 | if (tup[0] in Settings.test_only or tup[1] in | |
110 | Settings.test_only): | |
111 | runtime_matrix_agent_interface.append(tup) | |
112 | ||
113 | ||
114 | @pytest.mark.parametrize("ust_label,tools_label,should_trace", runtime_matrix_tracing_available) | |
115 | def test_ust_python_agent_tracing_available(tmpdir, ust_label, tools_label, should_trace): | |
116 | ||
117 | nb_iter = 100 | |
118 | nb_events = 5 * nb_iter | |
119 | ||
120 | # Prepare environment | |
121 | ust = ProjectFactory.get_precook(ust_label) | |
122 | tools = ProjectFactory.get_precook(tools_label) | |
123 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
124 | ||
125 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
126 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
127 | app_path = os.path.join(str(tmpdir), "app") | |
128 | ||
129 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
130 | runtime_tools.add_project(tools) | |
131 | runtime_tools.add_project(babeltrace) | |
132 | ||
133 | runtime_app.add_project(ust) | |
134 | runtime_app.lttng_home = runtime_tools.lttng_home | |
135 | ||
136 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
137 | ||
138 | # Copy the python app | |
139 | shutil.copytree(Settings.apps_python, app_path) | |
140 | ||
141 | # Start lttng-sessiond | |
142 | sessiond = utils.sessiond_spawn(runtime_tools) | |
143 | ||
144 | # Create session using mi to get path and session name | |
145 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
146 | ||
147 | runtime_tools.run('lttng enable-event -p pello') | |
148 | runtime_tools.run('lttng start') | |
149 | ||
150 | # Run application | |
151 | cmd = 'python app.py -i {}'.format(nb_iter) | |
152 | runtime_app.run(cmd, cwd=app_path) | |
153 | ||
154 | # Stop tracing | |
87e6d73a | 155 | runtime_tools.run('lttng stop') |
2094d672 JR |
156 | runtime_tools.run('lttng destroy -a') |
157 | cp = runtime_tools.subprocess_terminate(sessiond) | |
158 | if cp.returncode != 0: | |
159 | pytest.fail("Sessiond return code") | |
160 | ||
161 | # Read trace with babeltrace and check for event count via number of line | |
162 | cmd = 'babeltrace {}'.format(trace_path) | |
163 | if should_trace: | |
164 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
165 | assert(utils.line_count(cp_out) == nb_events) | |
166 | else: | |
167 | with pytest.raises(subprocess.CalledProcessError): | |
168 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
169 | ||
170 | @pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_agent_interface) | |
171 | def test_ust_python_agent_interface(tmpdir, ust_label, tools_label, outcome): | |
172 | """ | |
173 | Use the agent coming from ust_label, but run app under tools_version runtime using ust agent. | |
174 | """ | |
175 | ||
176 | nb_iter = 100 | |
177 | nb_events = 5 * nb_iter | |
178 | ||
179 | # Prepare environment | |
180 | ust = ProjectFactory.get_precook(ust_label) | |
181 | tools = ProjectFactory.get_precook(tools_label) | |
182 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
183 | ||
184 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
185 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
186 | app_path = os.path.join(str(tmpdir), "app") | |
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_python, app_path) | |
199 | ||
200 | # Start lttng-sessiond | |
201 | sessiond = utils.sessiond_spawn(runtime_tools) | |
202 | ||
203 | # Create session using mi to get path and session name | |
204 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
205 | ||
206 | runtime_tools.run('lttng enable-event -p pello') | |
207 | runtime_tools.run('lttng start') | |
208 | ||
209 | # Steal the PYTHONPATH from ust project and force it on the tools | |
210 | # project | |
211 | python_path = ust.special_env_variables['PYTHONPATH'] | |
212 | tools.special_env_variables['PYTHONPATH'] = python_path | |
213 | ||
214 | # Run application with tools runtime | |
215 | cmd = 'python app.py -i {}'.format(nb_iter) | |
216 | runtime_tools.run(cmd, cwd=app_path) | |
217 | ||
218 | # Stop tracing | |
87e6d73a | 219 | runtime_tools.run('lttng stop') |
2094d672 JR |
220 | runtime_tools.run('lttng destroy -a') |
221 | cp = runtime_tools.subprocess_terminate(sessiond) | |
222 | if cp.returncode != 0: | |
223 | pytest.fail("Sessiond return code") | |
224 | ||
225 | # Read trace with babeltrace and check for event count via number of line | |
226 | cmd = 'babeltrace {}'.format(trace_path) | |
227 | if outcome == "Success": | |
228 | assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])) | |
229 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
230 | assert(utils.line_count(cp_out) == nb_events) | |
231 | else: | |
232 | if outcome == "Unsupported protocol": | |
233 | assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))) | |
234 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
235 | assert(utils.line_count(cp_out) == 0) |