1 # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
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:
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
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
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
35 BC: Feature of the smallest version number will works.
36 TU: Tracing unavailable
38 Note: actual testing is limited by lttng-ust and lttng-tools abi/api.
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 +--------------------------+------------+------------+------------+----------------+
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
60 version_to_app
= {1: Settings
.apps_jul_1
,
61 2: Settings
.apps_jul_2
}
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),
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"),
101 runtime_matrix_tracing_available
= []
102 runtime_matrix_agent_interface
= []
104 if not Settings
.test_only
:
105 runtime_matrix_tracing_available
= test_matrix_tracing_available
106 runtime_matrix_agent_interface
= test_matrix_agent_interface
108 for tup
in test_matrix_tracing_available
:
109 if (tup
[0] in Settings
.test_only
or tup
[1] in
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
115 runtime_matrix_agent_interface
.append(tup
)
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
):
122 nb_events
= 3 * nb_iter
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
)
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")
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
)
137 runtime_app
.add_project(ust
)
138 runtime_app
.lttng_home
= runtime_tools
.lttng_home
140 trace_path
= os
.path
.join(runtime_tools
.lttng_home
, 'trace')
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
)
146 # Start lttng-sessiond
147 sessiond
= utils
.sessiond_spawn(runtime_tools
)
149 # Create session using mi to get path and session name
150 runtime_tools
.run('lttng create trace --output={}'.format(trace_path
))
152 runtime_tools
.run('lttng enable-event -j jello')
153 runtime_tools
.run('lttng start')
156 cmd
= 'java App {}'.format(nb_iter
)
157 runtime_app
.run(cmd
, cwd
=app_path
)
160 runtime_tools
.run('lttng stop')
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")
166 # Read trace with babeltrace and check for event count via number of line
167 cmd
= 'babeltrace {}'.format(trace_path
)
169 cp_process
, cp_out
, cp_err
= runtime_tools
.run(cmd
)
170 assert(utils
.line_count(cp_out
) == nb_events
)
172 with pytest
.raises(subprocess
.CalledProcessError
):
173 cp_process
, cp_out
, cp_err
= runtime_tools
.run(cmd
)
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
):
178 Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
182 nb_events
= 3 * nb_iter
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
)
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")
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
)
197 runtime_app
.add_project(ust
)
198 runtime_app
.lttng_home
= runtime_tools
.lttng_home
200 trace_path
= os
.path
.join(runtime_tools
.lttng_home
, 'trace')
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
)
206 # Start lttng-sessiond
207 sessiond
= utils
.sessiond_spawn(runtime_tools
)
209 # Create session using mi to get path and session name
210 runtime_tools
.run('lttng create trace --output={}'.format(trace_path
))
212 runtime_tools
.run('lttng enable-event -j jello')
213 runtime_tools
.run('lttng start')
215 # Steal the classpath from ust project
216 ust_classpath
= ust
.special_env_variables
['CLASSPATH']
218 # Run application with tools runtime
219 cmd
= 'java App {}'.format(nb_iter
)
220 runtime_tools
.run(cmd
, cwd
=app_path
, classpath
=ust_classpath
)
223 runtime_tools
.run('lttng stop')
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")
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
)
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)