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 | ||
74eb7096 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 Java 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 (1.0) | FC | TU | TU | TU | | |
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 | Third tuple member: app version to use | |
57 | Fourth tuple member: expected scenario | |
58 | """ | |
59 | ||
60 | version_to_app = {1: Settings.apps_jul_1, | |
61 | 2: Settings.apps_jul_2} | |
62 | ||
63 | test_matrix_tracing_available = [ | |
64 | ("lttng-ust-2.7", "lttng-tools-2.7", 1, True), | |
65 | ("lttng-ust-2.7", "lttng-tools-2.8", 1, False), | |
66 | ("lttng-ust-2.7", "lttng-tools-2.9", 1, False), | |
67 | ("lttng-ust-2.7", "lttng-tools-2.10", 1, False), | |
68 | ("lttng-ust-2.8", "lttng-tools-2.7", 2, False), | |
69 | ("lttng-ust-2.8", "lttng-tools-2.8", 2, True), | |
70 | ("lttng-ust-2.8", "lttng-tools-2.9", 2, False), | |
71 | ("lttng-ust-2.8", "lttng-tools-2.10", 2, False), | |
72 | ("lttng-ust-2.9", "lttng-tools-2.7", 2, False), | |
73 | ("lttng-ust-2.9", "lttng-tools-2.8", 2, False), | |
74 | ("lttng-ust-2.9", "lttng-tools-2.9", 2, True), | |
75 | ("lttng-ust-2.9", "lttng-tools-2.10", 2, True), | |
76 | ("lttng-ust-2.10", "lttng-tools-2.7", 2, False), | |
77 | ("lttng-ust-2.10", "lttng-tools-2.8", 2, False), | |
78 | ("lttng-ust-2.10", "lttng-tools-2.9", 2, True), | |
79 | ("lttng-ust-2.10", "lttng-tools-2.10", 2, True), | |
80 | ] | |
81 | ||
82 | test_matrix_agent_interface = [ | |
83 | ("lttng-ust-2.7", "lttng-tools-2.7", 1, "Success"), | |
84 | ("lttng-ust-2.7", "lttng-tools-2.8", 1, "Unsupported protocol"), | |
85 | ("lttng-ust-2.7", "lttng-tools-2.9", 1, "Unsupported protocol"), | |
86 | ("lttng-ust-2.7", "lttng-tools-2.10", 1, "Unsupported protocol"), | |
87 | ("lttng-ust-2.8", "lttng-tools-2.7", 2, "Unsupported protocol"), | |
88 | ("lttng-ust-2.8", "lttng-tools-2.8", 2, "Success"), | |
89 | ("lttng-ust-2.8", "lttng-tools-2.9", 2, "Success"), | |
90 | ("lttng-ust-2.8", "lttng-tools-2.10", 2, "Success"), | |
91 | ("lttng-ust-2.9", "lttng-tools-2.7", 2, "Unsupported protocol"), | |
92 | ("lttng-ust-2.9", "lttng-tools-2.8", 2, "Success"), | |
93 | ("lttng-ust-2.9", "lttng-tools-2.9", 2, "Success"), | |
94 | ("lttng-ust-2.9", "lttng-tools-2.10", 2, "Success"), | |
95 | ("lttng-ust-2.10", "lttng-tools-2.7", 2, "Unsupported protocol"), | |
96 | ("lttng-ust-2.10", "lttng-tools-2.8", 2, "Success"), | |
97 | ("lttng-ust-2.10", "lttng-tools-2.9", 2, "Success"), | |
98 | ("lttng-ust-2.10", "lttng-tools-2.10", 2, "Success"), | |
99 | ] | |
100 | ||
101 | runtime_matrix_tracing_available = [] | |
102 | runtime_matrix_agent_interface = [] | |
103 | ||
104 | if not Settings.test_only: | |
105 | runtime_matrix_tracing_available = test_matrix_tracing_available | |
106 | runtime_matrix_agent_interface = test_matrix_agent_interface | |
107 | else: | |
108 | for tup in test_matrix_tracing_available: | |
109 | if (tup[0] in Settings.test_only or tup[1] in | |
110 | Settings.test_only): | |
111 | runtime_matrix_tracing_available.append(tup) | |
112 | for tup in test_matrix_agent_interface: | |
113 | if (tup[0] in Settings.test_only or tup[1] in | |
114 | Settings.test_only): | |
115 | runtime_matrix_agent_interface.append(tup) | |
116 | ||
117 | ||
118 | @pytest.mark.parametrize("ust_label,tools_label,app_version,should_trace", runtime_matrix_tracing_available) | |
119 | def test_ust_java_agent_tracing_available(tmpdir, ust_label, tools_label, app_version, should_trace): | |
120 | ||
121 | nb_iter = 100 | |
122 | nb_events = 3 * nb_iter | |
123 | ||
124 | # Prepare environment | |
125 | ust = ProjectFactory.get_precook(ust_label) | |
126 | tools = ProjectFactory.get_precook(tools_label) | |
127 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
128 | ||
129 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
130 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
131 | app_path = os.path.join(str(tmpdir), "app") | |
132 | ||
133 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
134 | runtime_tools.add_project(tools) | |
135 | runtime_tools.add_project(babeltrace) | |
136 | ||
137 | runtime_app.add_project(ust) | |
138 | runtime_app.lttng_home = runtime_tools.lttng_home | |
139 | ||
140 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
141 | ||
142 | # Make application using the ust runtime | |
143 | shutil.copytree(version_to_app[app_version], app_path) | |
144 | runtime_app.run("javac App.java", cwd=app_path) | |
145 | ||
146 | # Start lttng-sessiond | |
147 | sessiond = utils.sessiond_spawn(runtime_tools) | |
148 | ||
149 | # Create session using mi to get path and session name | |
150 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
151 | ||
152 | runtime_tools.run('lttng enable-event -j jello') | |
153 | runtime_tools.run('lttng start') | |
154 | ||
155 | # Run application | |
156 | cmd = 'java App {}'.format(nb_iter) | |
157 | runtime_app.run(cmd, cwd=app_path) | |
158 | ||
159 | # Stop tracing | |
87e6d73a | 160 | runtime_tools.run('lttng stop') |
74eb7096 JR |
161 | runtime_tools.run('lttng destroy -a') |
162 | cp = runtime_tools.subprocess_terminate(sessiond) | |
163 | if cp.returncode != 0: | |
164 | pytest.fail("Sessiond return code") | |
165 | ||
166 | # Read trace with babeltrace and check for event count via number of line | |
167 | cmd = 'babeltrace {}'.format(trace_path) | |
168 | if should_trace: | |
169 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
170 | assert(utils.line_count(cp_out) == nb_events) | |
171 | else: | |
172 | with pytest.raises(subprocess.CalledProcessError): | |
173 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
174 | ||
175 | @pytest.mark.parametrize("ust_label,tools_label,app_version,outcome", runtime_matrix_agent_interface) | |
176 | def test_ust_java_agent_interface(tmpdir, ust_label, tools_label, app_version, outcome): | |
177 | """ | |
178 | Use the agent coming from ust_label, but run app under tools_version runtime using ust agent. | |
179 | """ | |
180 | ||
181 | nb_iter = 100 | |
182 | nb_events = 3 * nb_iter | |
183 | ||
184 | # Prepare environment | |
185 | ust = ProjectFactory.get_precook(ust_label) | |
186 | tools = ProjectFactory.get_precook(tools_label) | |
187 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
188 | ||
189 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
190 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
191 | app_path = os.path.join(str(tmpdir), "app") | |
192 | ||
193 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
194 | runtime_tools.add_project(tools) | |
195 | runtime_tools.add_project(babeltrace) | |
196 | ||
197 | runtime_app.add_project(ust) | |
198 | runtime_app.lttng_home = runtime_tools.lttng_home | |
199 | ||
200 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
201 | ||
202 | # Make application using the ust runtime | |
203 | shutil.copytree(version_to_app[app_version], app_path) | |
204 | runtime_app.run("javac App.java", cwd=app_path) | |
205 | ||
206 | # Start lttng-sessiond | |
207 | sessiond = utils.sessiond_spawn(runtime_tools) | |
208 | ||
209 | # Create session using mi to get path and session name | |
210 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
211 | ||
212 | runtime_tools.run('lttng enable-event -j jello') | |
213 | runtime_tools.run('lttng start') | |
214 | ||
215 | # Steal the classpath from ust project | |
216 | ust_classpath = ust.special_env_variables['CLASSPATH'] | |
217 | ||
218 | # Run application with tools runtime | |
219 | cmd = 'java App {}'.format(nb_iter) | |
220 | runtime_tools.run(cmd, cwd=app_path, classpath=ust_classpath) | |
221 | ||
222 | # Stop tracing | |
87e6d73a | 223 | runtime_tools.run('lttng stop') |
74eb7096 JR |
224 | runtime_tools.run('lttng destroy -a') |
225 | cp = runtime_tools.subprocess_terminate(sessiond) | |
226 | if cp.returncode != 0: | |
227 | pytest.fail("Sessiond return code") | |
228 | ||
229 | # Read trace with babeltrace and check for event count via number of line | |
230 | cmd = 'babeltrace {}'.format(trace_path) | |
231 | if outcome == "Success": | |
232 | assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])) | |
233 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
234 | assert(utils.line_count(cp_out) == nb_events) | |
235 | else: | |
236 | if outcome == "Unsupported protocol": | |
237 | assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))) | |
238 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
239 | assert(utils.line_count(cp_out) == 0) |